├── .gitattributes ├── .gitignore ├── .vscode └── c_cpp_properties.json ├── AtCoder ├── Digital Graffiti.cpp ├── Gentle Pairs.py ├── Large Digits.cpp ├── Laser Marking.cpp ├── Regular Contest 115 │ └── A.cpp ├── Remove It.cpp ├── Separated Lunch.cpp ├── Takahashi san 2.py ├── Unvarnished Report.py └── Vanishing Pitch.cpp ├── CodeChef ├── A - Books.cpp ├── A Big Sale - BIGSALE.cpp ├── Ada and crayons.py ├── Akhil And Colored Balls - ACBALL.cpp ├── Andrash and Stipendium .cpp ├── Appy and Contest - HMAPPY2.cpp ├── Attendance.cpp ├── Average Number.cpp ├── Bear and Milky Cookies.cpp ├── Bear and Segment 01.cpp ├── Black cells in a chessboard - BLACKCEL.cpp ├── Body Mass Index - BMI.cpp ├── Brackets.py ├── Breaking Bricks - BRKBKS.py ├── BuyingNewTablet.cpp ├── Bytelandian gold coins - COINS.cpp ├── COVID Pandemic and Long Queue - COVIDLQ.cpp ├── CV.py ├── Candy Love.cpp ├── Chang and Bitwise OR - CHNGOR.cpp ├── Change It.cpp ├── Chef Chick.cpp ├── Chef Judges a Competition.cpp ├── Chef On Island - CCISLAND.cpp ├── Chef Swaps Digits - SWPDGT.cpp ├── Chef and Bipartite Graphs - ICPC16F.cpp ├── Chef and Bored Games.cpp ├── Chef and Chocolate.cpp ├── Chef and Cook-Off Contents.cpp ├── Chef and Difficult Contests - CHFTIRED.cpp ├── Chef and Eid.cpp ├── Chef and Employment Test.cpp ├── Chef and Friends.py ├── Chef and Gift.py ├── Chef and Glove.py ├── Chef and Groups.cpp ├── Chef and IPC Certificates - IPCCERT.cpp ├── Chef and Interactive Contests.cpp ├── Chef and Price Control.cpp ├── Chef and Secret Ingredient - PCJ18A.cpp ├── Chef and Serves - CHSERVE.cpp ├── Chef and Steps.cpp ├── Chef and String.cpp ├── Chef and his daily routine.py ├── Chef in Fantasy League.py ├── ChefAndHisStudents.cpp ├── ChefAndTableTennis.py ├── ChefandCook-Off.cpp ├── Chess Match - BLITZ3_2.cpp ├── Chocolate Monger - CM164364.cpp ├── Coder Life Matters.cpp ├── Coldplay.cpp ├── CountSubarrays.cpp ├── CuttheBoard.cpp ├── Cyclic Quadrilateral - CYCLICQD.cpp ├── DEVARRAY.cpp ├── DIET.py ├── Days in Month - NW1.cpp ├── DevuanGrapes.py ├── Downloadfile.cpp ├── EVENTUAL.cpp ├── Easy Math.cpp ├── Encoding Message.py ├── FANCY.py ├── Find Your Gift.cpp ├── Find the Maximum Value.py ├── FlatLand.py ├── Football Match - FBMT.cpp ├── Football.cpp ├── FromHeavenToEarth.cpp ├── Good and Bad Persons.py ├── Gregorian Calendar.py ├── Hidden Numbers - UWCOI21A.py ├── Highest Divisor - HDIVISR.cpp ├── How much Scholarship.cpp ├── IPL and RCB.cpp ├── Interesting XOR!.py ├── Is it a Cakewalk Problem - ISITCAKE.cpp ├── Judging Delay.cpp ├── Lazy Chef - LAZYCHF.cpp ├── LazyJem.cpp ├── Lift Requests.py ├── Lost Weekends.cpp ├── Lucky Four - LUCKYFR.cpp ├── Marbles - MARBLES.py ├── Mathison and pangrams - MATPAN.cpp ├── Max power - MAX2.cpp ├── Maximum Weight Difference.cpp ├── Medel.cpp ├── Minimum Attendance Requirement - ATTENDU.cpp ├── Multiple Choice Examp.cpp ├── MutatedMinions.cpp ├── No Time to Wait.cpp ├── Nothing in Common.py ├── One more weird game.py ├── Ordering the Soldiers.cpp ├── Pair Me.cpp ├── Palindromicsubstrings.py ├── Passing Marks - PSGRADE.cpp ├── Play Piano.py ├── Playing with Strings.cpp ├── PlayingwithMatches.py ├── Possible Victory - T20MCH.cpp ├── ProgramYourOwnCALCULATOR.py ├── Richie Rich - CHFRICH.cpp ├── Roots of a Quadratic Equation.cpp ├── SPLITIT.cpp ├── Secret Recipe.cpp ├── Sed Sequences - SEDARR.cpp ├── Sell All the Cars - CARSELL.cpp ├── SimilarDishes-brute.cpp ├── SimilarDishes-map.cpp ├── Simple Statistics.py ├── Snake Procession.py ├── Space Arrays.cpp ├── Sticks.cpp ├── Strange operations.cpp ├── Summer Heat - COCONUT.cpp ├── Temple Land.cpp ├── Testing Robot - TSTROBOT.cpp ├── That Is My Score!.cpp ├── The Next Palindrome.cpp ├── Three Friends.cpp ├── Tickets.py ├── Train Partner.py ├── UWCOI20A.cpp ├── Uniform Strings.cpp ├── Valid Pair - SOCKS1.cpp ├── WATMELON.cpp ├── WDTBAM.py ├── Whats in the Name.py ├── Workers - CHEFWORK.cpp ├── XYSTR.cpp ├── Xenny and Alternating Tasks.cpp └── in ├── CodeForces ├── #126 (Div. 2) - B.cpp ├── #141 (Div. 2) - A.cpp ├── #238 (Div. 2) - A.cpp ├── #274 (Div. 2) - A.cpp ├── 486A.cpp ├── 61A - Ultra-Fast Mathematician.cpp ├── Add to Neighbour and Remove.cpp ├── Anton and Danik.cpp ├── Bear and Big Brother.cpp ├── Beautiful Year.cpp ├── Boy or Girl.py ├── Chat room.cpp ├── Elephant.cpp ├── Even Odds.cpp ├── Favorite Sequence.cpp ├── George and Accommodation.cpp ├── HQ9+.cpp ├── Hulk.cpp ├── In Search of an Easy Problem.cpp ├── Kefa and First Steps.cpp ├── Last Year's Substring.cpp ├── Lucky Division.cpp ├── Magnets.cpp ├── Nearly Lucky Number.cpp ├── Presents.cpp ├── Queue at the School.cpp ├── Remove Smallest.cpp ├── Replacing Elements.cpp ├── Soldier and Bananas.cpp ├── Stones on the Table.cpp ├── Taxi.cpp ├── Tram.cpp ├── Translation.cpp ├── Twins.cpp ├── Unique Number.cpp ├── Vanya and Fence.cpp ├── Wizard of Orz.cpp ├── Word Capitalization.py ├── Word.cpp ├── Wrong Subtraction.cpp ├── Yet Another String Game.cpp ├── Young Physicist.cpp └── cAPS lOCK.py ├── HackerRank ├── Data Structures │ └── Print in Reverse.java ├── Interview Preparation Kit │ ├── Arrays │ │ ├── 2DArray-DS.cpp │ │ ├── ArrayManipulation.cpp │ │ ├── ArraysLeftRotation.cpp │ │ └── MinimumSwaps2.cpp │ └── Warm-up Challenges │ │ ├── Counting Valleys.cpp │ │ ├── Jumping on the Clouds.java │ │ ├── Repeated String.py │ │ └── Sock Merchant.cpp ├── Mathematics │ ├── Handshake.py │ └── Minimum Height Triangle.py └── Python │ └── Incorrect Regex.py ├── Kickstart ├── Round A 2021 │ ├── K-Goodness String.cpp │ └── L Shaped Plots.cpp └── template.cpp ├── LeetCode ├── Explore │ └── Array │ │ ├── Check If N and Its Double Exist.cpp │ │ ├── Duplicate Zeros.cpp │ │ ├── Find Numbers with Even number of Digits.cpp │ │ ├── Max Consecutive Ones.cpp │ │ ├── Merge Sorted Array.cpp │ │ ├── Remove Duplicates from Sorted Array.cpp │ │ ├── Remove Element.cpp │ │ ├── Replace Elements with Greatest Element on Right Side.cpp │ │ ├── Squares of a Sorted Array.cpp │ │ └── Valid Mountain Array.cpp ├── LongestSubstringWithoutRepeatingCharacters.cpp └── Remove Duplicates from Sorted Array II.cpp ├── README.md ├── public ├── img │ └── algorithm.png └── script │ └── commit.sh └── template.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | *.png binary 2 | *.jpg binary 3 | *.out binary 4 | *.exe binary 5 | *.out binary 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/cython,c++,java 3 | # # Edit at https://www.toptal.com/developers/gitignore?templates=cython,c++,java 4 | in 5 | ### C ### 6 | # Prerequisites 7 | *.d 8 | 9 | # Object files 10 | *.o 11 | *.ko 12 | *.obj 13 | *.elf 14 | 15 | # Linker output 16 | *.ilk 17 | *.map 18 | *.exp 19 | 20 | # Precompiled Headers 21 | *.gch 22 | *.pch 23 | 24 | # Libraries 25 | *.lib 26 | *.a 27 | *.la 28 | *.lo 29 | 30 | # Shared objects (inc. Windows DLLs) 31 | *.dll 32 | *.so 33 | *.so.* 34 | *.dylib 35 | 36 | # Executables 37 | *.exe 38 | *.out 39 | *.app 40 | *.i*86 41 | *.x86_64 42 | *.hex 43 | 44 | # Debug files 45 | *.dSYM/ 46 | *.su 47 | *.idb 48 | *.pdb 49 | 50 | # Kernel Module Compile Results 51 | *.mod* 52 | *.cmd 53 | .tmp_versions/ 54 | modules.order 55 | Module.symvers 56 | Mkfile.old 57 | dkms.conf 58 | 59 | ### C++ ### 60 | # Prerequisites 61 | 62 | # Compiled Object files 63 | *.slo 64 | 65 | # Precompiled Headers 66 | 67 | # Linker files 68 | 69 | # Debugger Files 70 | 71 | # Compiled Dynamic libraries 72 | 73 | # Fortran module files 74 | *.mod 75 | *.smod 76 | 77 | # Compiled Static libraries 78 | *.lai 79 | 80 | # Executables 81 | 82 | ### Java ### 83 | # Compiled class file 84 | *.class 85 | 86 | # Log file 87 | *.log 88 | 89 | # BlueJ files 90 | *.ctxt 91 | 92 | # Mobile Tools for Java (J2ME) 93 | .mtj.tmp/ 94 | 95 | # Package Files # 96 | *.jar 97 | *.war 98 | *.nar 99 | *.ear 100 | *.zip 101 | *.tar.gz 102 | *.rar 103 | 104 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 105 | hs_err_pid* 106 | 107 | ### Python ### 108 | # Byte-compiled / optimized / DLL files 109 | __pycache__/ 110 | *.py[cod] 111 | *$py.class 112 | 113 | # C extensions 114 | 115 | # Distribution / packaging 116 | .Python 117 | build/ 118 | develop-eggs/ 119 | dist/ 120 | downloads/ 121 | eggs/ 122 | .eggs/ 123 | lib/ 124 | lib64/ 125 | parts/ 126 | sdist/ 127 | var/ 128 | wheels/ 129 | pip-wheel-metadata/ 130 | share/python-wheels/ 131 | *.egg-info/ 132 | .installed.cfg 133 | *.egg 134 | MANIFEST 135 | 136 | # PyInstaller 137 | # Usually these files are written by a python script from a template 138 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 139 | *.manifest 140 | *.spec 141 | 142 | # Installer logs 143 | pip-log.txt 144 | pip-delete-this-directory.txt 145 | 146 | # Unit test / coverage reports 147 | htmlcov/ 148 | .tox/ 149 | .nox/ 150 | .coverage 151 | .coverage.* 152 | .cache 153 | nosetests.xml 154 | coverage.xml 155 | *.cover 156 | *.py,cover 157 | .hypothesis/ 158 | .pytest_cache/ 159 | pytestdebug.log 160 | 161 | # Translations 162 | *.mo 163 | *.pot 164 | 165 | # Django stuff: 166 | local_settings.py 167 | db.sqlite3 168 | db.sqlite3-journal 169 | 170 | # Flask stuff: 171 | instance/ 172 | .webassets-cache 173 | 174 | # Scrapy stuff: 175 | .scrapy 176 | 177 | # Sphinx documentation 178 | docs/_build/ 179 | doc/_build/ 180 | 181 | # PyBuilder 182 | target/ 183 | 184 | # Jupyter Notebook 185 | .ipynb_checkpoints 186 | 187 | # IPython 188 | profile_default/ 189 | ipython_config.py 190 | 191 | # pyenv 192 | .python-version 193 | 194 | # pipenv 195 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 196 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 197 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 198 | # install all needed dependencies. 199 | #Pipfile.lock 200 | 201 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 202 | __pypackages__/ 203 | 204 | # Celery stuff 205 | celerybeat-schedule 206 | celerybeat.pid 207 | 208 | # SageMath parsed files 209 | *.sage.py 210 | 211 | # Environments 212 | .env 213 | .venv 214 | env/ 215 | venv/ 216 | ENV/ 217 | env.bak/ 218 | venv.bak/ 219 | pythonenv* 220 | 221 | # Spyder project settings 222 | .spyderproject 223 | .spyproject 224 | 225 | # Rope project settings 226 | .ropeproject 227 | 228 | # mkdocs documentation 229 | /site 230 | 231 | # mypy 232 | .mypy_cache/ 233 | .dmypy.json 234 | dmypy.json 235 | 236 | # Pyre type checker 237 | .pyre/ 238 | 239 | # pytype static type analyzer 240 | .pytype/ 241 | 242 | # profiling data 243 | .prof 244 | 245 | # End of https://www.toptal.com/developers/gitignore/api/cython,c++,java 246 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Mac", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [], 9 | "macFrameworkPath": [ 10 | "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" 11 | ], 12 | "compilerPath": "/usr/bin/clang", 13 | "cStandard": "c17", 14 | "cppStandard": "c++17", 15 | "intelliSenseMode": "macos-clang-arm64" 16 | } 17 | ], 18 | "version": 4 19 | } -------------------------------------------------------------------------------- /AtCoder/Digital Graffiti.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define rep(_, n) for (int _ = 0; _ < n; _++) 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int H, W, vertex = 0; 8 | 9 | cin >> H >> W; 10 | 11 | char arr[H][W]; 12 | 13 | rep(i, H) 14 | rep(j, W) 15 | cin >> arr[i][j]; 16 | 17 | rep(i, H - 1) 18 | rep(j, W - 1) { 19 | int count = 0; 20 | if (arr[i][j] == '#') count++; 21 | if (arr[i + 1][j] == '#') count++; 22 | if (arr[i][j + 1] == '#') count++; 23 | if (arr[i + 1][j + 1] == '#') count++; 24 | if (count == 1 || count == 3) 25 | vertex++; 26 | } 27 | 28 | cout << vertex << '\n'; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /AtCoder/Gentle Pairs.py: -------------------------------------------------------------------------------- 1 | N = int(input()) 2 | A = [tuple(map(int, input().split())) for i in range(N)] 3 | ans = 0 4 | 5 | for i in range(N): 6 | for j in range(i): 7 | if abs(A[i][1] - A[j][1]) <= abs(A[i][0] - A[j][0]): ans += 1 8 | print(ans) 9 | -------------------------------------------------------------------------------- /AtCoder/Large Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline int S(string n) { 6 | return (n[0] - '0') + (n[1] - '0') + (n[2] - '0'); 7 | } 8 | 9 | int main() { 10 | string A, B; 11 | cin >> A >> B; 12 | 13 | cout << max(S(A), S(B)) << '\n'; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /AtCoder/Laser Marking.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | using pi = pair; 5 | 6 | long double dist(pi l, pi r) { 7 | long long v = 0; 8 | v += (l.first - r.first) * (l.first - r.first); 9 | v += (l.second - r.second) * (l.second - r.second); 10 | return sqrtl(((long double)v)); 11 | } 12 | 13 | int main() { 14 | int n, s, t; 15 | cin >> n >> s >> t; 16 | vector x(n), y(n); 17 | for (int i = 0; i < n; i++) 18 | { 19 | cin >> x[i].first >> x[i].second >> y[i].first >> y[i].second; 20 | } 21 | 22 | long double res = 8e18; 23 | vector p; 24 | for (int i = 0; i < n; i++) 25 | { 26 | p.push_back(i); 27 | } 28 | 29 | do 30 | { 31 | for (int i = 0; i < (1 << n); i++) 32 | { 33 | long double cres = 0.0; 34 | pi cur = make_pair(0, 0); 35 | for (int j = 0; j < n; j++) 36 | { 37 | int el = p[j]; 38 | if (i & (1 << j)) 39 | { 40 | cres += (dist(cur, x[el]) / ((long double)s)); 41 | cres += (dist(x[el], y[el]) / ((long double)t)); 42 | cur = y[el]; 43 | } 44 | else 45 | { 46 | cres += (dist(cur, y[el]) / ((long double)s)); 47 | cres += (dist(y[el], x[el]) / ((long double)t)); 48 | cur = x[el]; 49 | } 50 | } 51 | res = min(res, cres); 52 | } 53 | } while (next_permutation(p.begin(), p.end())); 54 | 55 | cout << fixed << setprecision(12) << res << "\n"; 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /AtCoder/Regular Contest 115/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | inline void solve() { 7 | 8 | } 9 | 10 | int main() { 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int T, i = 1; 15 | cin >> T; 16 | 17 | while (T--) { 18 | solve(); 19 | } 20 | } -------------------------------------------------------------------------------- /AtCoder/Remove It.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, x; 7 | cin >> n >> x; 8 | for (int _ = 0, a; _ < n; _++) { 9 | cin >> a; 10 | if (a != x) 11 | cout << a << " "; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /AtCoder/Separated Lunch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define N 20 6 | #define INF (int)2e+9 7 | 8 | int main() { 9 | int n, k, s, ss = 0, ans = INF; 10 | int a[N]; 11 | 12 | cin >> n; 13 | 14 | for (int i = 0; i < n; i++) { 15 | cin >> a[i]; 16 | ss += a[i]; 17 | } 18 | for (int i = 0; i < (1 << n); i++) { 19 | k = i, s = 0; 20 | for (int j = 0; j < n; j++) { 21 | if (k & (1 << j)) s += a[j]; 22 | } 23 | ans = min(ans, max(s, ss - s)); 24 | } 25 | cout << ans << '\n'; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /AtCoder/Takahashi san 2.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | if s[::-1][:3][::-1] == 'san': 3 | print('Yes') 4 | else: 5 | print('No') 6 | -------------------------------------------------------------------------------- /AtCoder/Unvarnished Report.py: -------------------------------------------------------------------------------- 1 | a = list(input()) 2 | b = list(input()) 3 | 4 | 5 | imin = min(len(a), len(b)) 6 | 7 | if a == b: 8 | print(0) 9 | exit() 10 | 11 | for _ in range(0, imin): 12 | if a[_] != b[_]: 13 | print(_+1) 14 | exit() 15 | 16 | print(imin+1) 17 | 18 | -------------------------------------------------------------------------------- /AtCoder/Vanishing Pitch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int v, t, s, d; 7 | cin >> v >> t >> s >> d; 8 | 9 | if (v * t > d || v * s < d) 10 | cout << "Yes" << '\n'; 11 | else 12 | cout << "No" << '\n'; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /CodeChef/A - Books.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n; 7 | cin >> n; 8 | vector a(n); 9 | for (int i = 0; i < n; i++) { 10 | cin >> a[i]; 11 | } 12 | reverse(a.begin(), a.end()); 13 | vector ans(n); 14 | ans[0] = 0; 15 | for (int i = 1; i < n; i++) { 16 | if (a[i] == a[i - 1]) { 17 | ans[i] = ans[i - 1]; 18 | } else { 19 | ans[i] = i; 20 | } 21 | } 22 | for (int i = n - 1; i >= 0; i--) 23 | cout << ans[i] << " "; 24 | cout << '\n'; 25 | return; 26 | } 27 | int main() { 28 | int t; 29 | cin >> t; 30 | while (t--) 31 | solve(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /CodeChef/A Big Sale - BIGSALE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int n; 11 | cin >> n; 12 | 13 | double sum = 0; 14 | while (n--) { 15 | double pi, qi, di; 16 | cin >> pi >> qi >> di; 17 | double in_am = pi + (pi * (di / 100)); 18 | double af_dis = in_am * (di / 100); 19 | double loss = (pi - (in_am - af_dis)) * qi; 20 | sum += loss; 21 | } 22 | printf("%.9lf\n", sum); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /CodeChef/Ada and crayons.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | 3 | for _ in range(int(input())): 4 | s = input() 5 | l = [i for i, j in groupby(s)] 6 | 7 | print(min(l.count('U'), l.count('D'))) -------------------------------------------------------------------------------- /CodeChef/Akhil And Colored Balls - ACBALL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | string x, y; 11 | cin >> x >> y; 12 | 13 | for (int _ = 0; _ < x.length(); _++) { 14 | if (x[_] == y[_] && x[_] == 'B') 15 | cout << "W"; 16 | else if (x[_] == y[_] && x[_] == 'W') 17 | cout << "B"; 18 | else if (x[_] != y[_]) 19 | cout << "B"; 20 | } 21 | cout << '\n'; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /CodeChef/Andrash and Stipendium .cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, a = 0, f = 0; 7 | float sum = 0.0; 8 | cin >> n; 9 | for (int _ = 0, tmp; _ < n; _++) { 10 | cin >> tmp; 11 | sum += tmp; 12 | a += (tmp == 5); 13 | f += (tmp <= 2); 14 | } 15 | if (f == 0 && a > 0 && sum / n >= 4.0) 16 | cout << "Yes" << '\n'; 17 | else 18 | cout << "No" << '\n'; 19 | return; 20 | } 21 | 22 | int main() { 23 | ios_base::sync_with_stdio(false); 24 | cin.tie(0); 25 | cout.tie(0); 26 | 27 | int t; 28 | cin >> t; 29 | while (t--) 30 | solve(); 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /CodeChef/Appy and Contest - HMAPPY2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll unsigned long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int T; 8 | cin >> T; 9 | while (T--) { 10 | ll n, a, b, k, ans; 11 | ll x, y, tmp; 12 | cin >> n >> a >> b >> k; 13 | x = a; 14 | y = b; 15 | 16 | while (y) { 17 | tmp = y; 18 | y = x % y; 19 | x = tmp; 20 | } 21 | ans = n / a + n / b - 2 * (n / ((a * b) / x)); 22 | if (ans < k) 23 | cout << "Lose"; 24 | else 25 | cout << "Win"; 26 | cout << '\n'; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /CodeChef/Attendance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n; 7 | cin >> n; 8 | string arr[n][2]; 9 | for (int _ = 0; _ < n; _++) 10 | cin >> arr[_][0] >> arr[_][1]; 11 | for (int i = 0; i < n; i++) { 12 | bool flag = true; 13 | for (int j = 0; j < n; j++) { 14 | if (i == j) 15 | continue; 16 | if (arr[i][0] == arr[j][0]) { 17 | cout << arr[i][0] << " " << arr[i][1] << '\n'; 18 | flag = false; 19 | break; 20 | } 21 | } 22 | if (flag) 23 | cout << arr[i][0] << '\n'; 24 | } 25 | } 26 | int main() { 27 | ios::sync_with_stdio(false); 28 | cin.tie(0); 29 | 30 | int t; 31 | cin >> t; 32 | while (t--) 33 | solve(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /CodeChef/Average Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | 9 | while (t--) { 10 | int n, k, v, sum = 0; 11 | cin >> n >> k >> v; 12 | int arr[n]; 13 | for (int i = 0; i < n; i++) { 14 | cin >> arr[i]; 15 | sum += arr[i]; 16 | } 17 | int total = n + k; 18 | total *= v; 19 | total -= sum; 20 | if (total > 0 && total % k == 0) 21 | cout << total / k << '\n'; 22 | else 23 | cout << "-1" << '\n'; 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /CodeChef/Bear and Milky Cookies.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | inline void solve() { 7 | int n; 8 | cin >> n; 9 | string s[n]; 10 | for (int i = 0; i < n; i++) 11 | cin >> s[i]; 12 | if (s[n - 1] == "cookie") { 13 | cout << "NO" << '\n'; 14 | return; 15 | } 16 | for (int i = 0; i < n - 1; i++) if (s[i] == "cookie" && s[i + 1] == "cookie") { 17 | cout << "NO" << '\n'; 18 | return; 19 | } 20 | cout << "YES" << '\n'; 21 | return; 22 | } 23 | int main() { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); 26 | cout.tie(0); 27 | 28 | int t; 29 | cin >> t; 30 | 31 | while (t--) 32 | solve(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /CodeChef/Bear and Segment 01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int i = 0; 7 | string s; 8 | bool can = false; 9 | cin >> s; 10 | while (i < s.length()) { 11 | if (s[i] == '1' && can == false) { 12 | can = true; 13 | while (i < s.length() && s[i] == '1') 14 | i++; 15 | } 16 | else if (s[i] == '1' && can == true) { 17 | can = false; 18 | break; 19 | } 20 | else 21 | i++; 22 | } 23 | if (can) 24 | cout << "YES" << '\n'; 25 | else 26 | cout << "NO" << '\n'; 27 | } 28 | 29 | int main() { 30 | int t; 31 | cin >> t; 32 | 33 | while (t--) 34 | solve(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /CodeChef/Black cells in a chessboard - BLACKCEL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | cout << n * n / 2 << '\n'; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /CodeChef/Body Mass Index - BMI.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int m, h; 11 | cin >> m >> h; 12 | int res = m / (h * h); 13 | if (res <= 18) 14 | cout << "1"; 15 | else if (res >= 19 && res <= 24) 16 | cout << "2"; 17 | else if (res >= 25 && res <= 29) 18 | cout << "3"; 19 | else if (res >= 30) 20 | cout << "4"; 21 | cout << '\n'; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /CodeChef/Brackets.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s = input() 3 | balance, max_balance = 0, 0 4 | for i in range(0, len(s)): 5 | if s[i] == '(': balance += 1 6 | if s[i] == ')': balance -= 1 7 | max_balance = max(max_balance, balance) 8 | print('(' * max_balance + ')' * max_balance) 9 | -------------------------------------------------------------------------------- /CodeChef/Breaking Bricks - BRKBKS.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s, w1, w2, w3 = map(int, input().split()) 3 | x = w1 + w2 + w3 4 | c = 0 5 | if s >= x: print(1) 6 | elif s >= x - w1 or s >= x - w3: print(2) 7 | else: print(3) 8 | -------------------------------------------------------------------------------- /CodeChef/BuyingNewTablet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, d, imax = -1; 7 | cin >> n >> d; 8 | while (n--) { 9 | int a, b, c; 10 | cin >> a >> b >> c; 11 | if (c <= d) 12 | imax = (a * b > imax ? a * b : imax); 13 | } 14 | if (imax == -1) 15 | cout << "no tablet" << '\n'; 16 | else 17 | cout << imax << '\n'; 18 | } 19 | int main() { 20 | int t; 21 | cin >> t; 22 | while (t--) solve(); 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/Bytelandian gold coins - COINS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | map dp; 7 | 8 | inline ll solve(ll n) { 9 | if (n <= 2) { 10 | dp[n] = n; 11 | return dp[n]; 12 | } 13 | if (dp.count(n)) 14 | return dp[n]; 15 | dp[n] = max(n, solve(n / 2) + solve(n / 3) + solve(n / 4)); 16 | return dp[n]; 17 | } 18 | 19 | int main() { 20 | ll n; 21 | while (cin >> n) 22 | cout << solve(n) << '\n'; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /CodeChef/COVID Pandemic and Long Queue - COVIDLQ.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int n; 11 | cin >> n; 12 | int a[n + 5]; 13 | for (int i = 0; i < n + 5; i++) 14 | a[i] = 0; 15 | for (int i = 0; i < n; i++) 16 | cin >> a[i]; 17 | int p = 0; 18 | for (int i = 0; i < n; i++) { 19 | if (a[i] == 1) { 20 | if (a[i + 1] == 0 && a[i + 2] == 0 && a[i + 3] == 0 && a[i + 4] == 0 && a[i + 5] == 0) 21 | continue; 22 | else { 23 | p = 1; 24 | break; 25 | } 26 | } 27 | } 28 | if (p == 1) 29 | cout << "NO" << '\n'; 30 | else 31 | cout << "YES" << '\n'; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /CodeChef/CV.py: -------------------------------------------------------------------------------- 1 | vowels = ['a', 'e', 'i', 'o', 'u'] 2 | 3 | for _ in range(int(input())): 4 | n, ans = input(), 0 5 | s = input() 6 | for i in range(1, len(s)): 7 | if s[i] in vowels and s[i - 1] not in vowels: ans += 1 8 | print(ans) 9 | -------------------------------------------------------------------------------- /CodeChef/Candy Love.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, s = 0; 7 | cin >> n; 8 | while (n--) { 9 | int tmp; 10 | cin >> tmp; 11 | s += tmp; 12 | } 13 | if (s % 2) 14 | cout << "YES" << '\n'; 15 | else 16 | cout << "NO" << '\n'; 17 | } 18 | int main() { 19 | ios_base::sync_with_stdio(false); 20 | cin.tie(0); 21 | cout.tie(0); 22 | 23 | int t; 24 | 25 | cin >> t; 26 | while (t--) 27 | solve(); 28 | } -------------------------------------------------------------------------------- /CodeChef/Chang and Bitwise OR - CHNGOR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int n, ans = 0; 11 | cin >> n; 12 | 13 | while (n--) { 14 | int tmp; 15 | cin >> tmp; 16 | ans |= tmp; 17 | } 18 | 19 | cout << ans << '\n'; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/Change It.cpp: -------------------------------------------------------------------------------- 1 | #include "bits/stdc++.h" 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, x; 7 | cin >> n; 8 | vector vi(101, 0); 9 | for (int i = 0; i < n; i++) { 10 | cin >> x; 11 | vi[x]++; 12 | } 13 | int imax = 0, ind = 0; 14 | for (int i = 1; i <= 100; i++) 15 | if (vi[i] > imax) { 16 | imax = vi[i]; 17 | ind = i; 18 | } 19 | cout << n - imax << '\n'; 20 | } 21 | int main() { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); 24 | cout.tie(0); 25 | 26 | int t; 27 | cin >> t; 28 | while (t--) 29 | solve(); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /CodeChef/Chef Chick.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n; 7 | cin >> n; 8 | vector vi(n); 9 | for (int _ = 0; _ < n; ++_) 10 | cin >> vi[_]; 11 | sort(vi.begin(), vi.end()); 12 | cout << vi[0] << '\n'; 13 | } 14 | 15 | int main() { 16 | int T; 17 | cin >> T; 18 | 19 | while (T--) 20 | solve(); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /CodeChef/Chef Judges a Competition.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n; 7 | cin >> n; 8 | int arr[2][n], ans[2]; 9 | 10 | for (int i = 0; i < 2; i++) { 11 | int imax = -1, total = 0; 12 | for (int j = 0; j < n; j++) { 13 | cin >> arr[i][j]; 14 | total += arr[i][j]; 15 | imax = (arr[i][j] > imax ? arr[i][j] : imax); 16 | } 17 | ans[i] = total - imax; 18 | } 19 | if (ans[0] > ans[1]) 20 | cout << "Bob\n"; 21 | else if (ans[0] < ans[1]) 22 | cout << "Alice\n"; 23 | else 24 | cout << "Draw\n"; 25 | 26 | } 27 | int main() { 28 | int t; 29 | cin >> t; 30 | while (t--) 31 | solve(); 32 | } 33 | -------------------------------------------------------------------------------- /CodeChef/Chef On Island - CCISLAND.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | while (T--) { 9 | double x, y, xr, yr, D; 10 | cin >> x >> y >> xr >> yr >> D; 11 | 12 | if (min(x / xr, y / yr) >= D) 13 | cout << "YES" << '\n'; 14 | else 15 | cout << "NO" << '\n'; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /CodeChef/Chef Swaps Digits - SWPDGT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | while (t--) { 9 | int a, b; 10 | cin >> a >> b; 11 | int m = a + b; 12 | int a1 = a / 10, a2 = a % 10, b1 = b / 10, b2 = b % 10; 13 | if (a1) 14 | m = max(m, b1 * 10 + b2 * 10 + a1 + a2); 15 | if (b1) 16 | m = max(m, a1 * 10 + a2 * 10 + b1 + b2); 17 | cout << m << '\n'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CodeChef/Chef and Bipartite Graphs - ICPC16F.cpp: -------------------------------------------------------------------------------- 1 | #include "bits/stdc++.h" 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | const ll mod = 1000000007; 6 | const char nl = '\n'; 7 | 8 | void solve() 9 | { 10 | ll i, j, k, l, n, r, m, u, v, x, y, d, D; 11 | 12 | cin >> n >> m >> d >> D; 13 | vector> ans; 14 | if (n * d > m || m > n * D) 15 | { 16 | cout << -1 << nl; 17 | return; 18 | } 19 | vector cnt(n); 20 | 21 | for (i = 0; i < n; i++) 22 | { 23 | for (j = 0; j < n; j++) 24 | { 25 | ans.push_back({j, (j + i) % n}); 26 | m--; 27 | cnt[j]++; 28 | if (m == 0) 29 | break; 30 | } 31 | if (m == 0) 32 | break; 33 | } 34 | 35 | for (i = 0; i < n; i++) 36 | { 37 | if (cnt[i] < d or cnt[i] > D) 38 | { 39 | cout << -1 << nl; 40 | return; 41 | } 42 | } 43 | 44 | for (auto z : ans) 45 | cout << z.first + 1 << " " << z.second + 1 << nl; 46 | } 47 | 48 | int main() 49 | { 50 | ios_base::sync_with_stdio(false); 51 | cin.tie(NULL); 52 | int t = 1, i = 1; 53 | cin >> t; 54 | while (t--) 55 | { 56 | solve(); 57 | } 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /CodeChef/Chef and Bored Games.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, ans = 0; 7 | cin >> n; 8 | for (int _ = 0; _ < n; _ += 2) 9 | ans += (n - _) * (n - _); 10 | cout << ans << '\n'; 11 | } 12 | int main() { 13 | int t; 14 | cin >> t; 15 | while (t--) 16 | solve(); 17 | } 18 | -------------------------------------------------------------------------------- /CodeChef/Chef and Chocolate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int a, b; 7 | cin >> a >> b; 8 | if (a * b % 2 == 0) 9 | cout << "Yes\n"; 10 | else 11 | cout << "No\n"; 12 | } 13 | int main() { 14 | ios::sync_with_stdio(0); 15 | cin.tie(0); 16 | 17 | int t; 18 | cin >> t; 19 | while (t--) 20 | solve(); 21 | } 22 | -------------------------------------------------------------------------------- /CodeChef/Chef and Cook-Off Contents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, ans[5] = {0}; 7 | string s; 8 | cin >> n; 9 | for (int _ = 0; _ < n; _++) { 10 | cin >> s; 11 | ans[s == "cakewalk" ? 0: s == "simple" ? 1: s == "easy" ? 2: s == "easy-medium" || s == "medium" ? 3 : 4] = 1; 12 | } 13 | cout << (ans[0] + ans[1] + ans[2] + ans[3] + ans[4] == 5 ? "Yes" : "No") << '\n'; 14 | } 15 | int main() { 16 | int T; 17 | cin >> T; 18 | while (T--) 19 | solve(); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CodeChef/Chef and Difficult Contests - CHFTIRED.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | 10 | while (t--) 11 | { 12 | int a, b; 13 | cin >> a >> b; 14 | cout << "YES\n"; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /CodeChef/Chef and Eid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | while (t--) { 9 | long long int n, d; 10 | cin >> n; 11 | long long int a[n]; 12 | for (int i = 0; i < n; i++) 13 | cin >> a[i]; 14 | sort(a, a + n); 15 | d = a[1] - a[0]; 16 | for (int i = 1; i < n; i++) { 17 | if (a[i] - a[i - 1] < d) { 18 | d = a[i] - a[i - 1]; 19 | } 20 | } 21 | cout << d << '\n'; 22 | } 23 | } -------------------------------------------------------------------------------- /CodeChef/Chef and Employment Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, k; 7 | cin >> n >> k; 8 | int arr[n]; 9 | for (auto &i: arr) 10 | cin >> i; 11 | sort(arr, arr + n); 12 | cout << arr[(n + k) / 2] << '\n'; 13 | } 14 | int main() { 15 | ios::sync_with_stdio(false); 16 | cin.tie(0); 17 | 18 | int t; 19 | cin >> t; 20 | while (t--) 21 | solve(); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/Chef and Friends.py: -------------------------------------------------------------------------------- 1 | ans = 0 2 | for _ in range(int(input())): 3 | s = input() 4 | if 'chef' in s or 'che' in s or 'hef' in s or 'ch' in s or 'he' in s or 'ef' in s: ans += 1 5 | 6 | print(ans) 7 | -------------------------------------------------------------------------------- /CodeChef/Chef and Gift.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n, k = list(map(int, input().split())) 3 | l = list(map(int, input().split())) 4 | c = 0 5 | for i in range(len(l)): 6 | if l[i]%2 == 0: 7 | c += 1 8 | if c == n and k == 0: 9 | print('NO') 10 | elif c >= k: 11 | print('YES') 12 | else: 13 | print('NO') 14 | -------------------------------------------------------------------------------- /CodeChef/Chef and Glove.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n = int(input()) 3 | l = list(map(int, input().split())) 4 | g = list(map(int, input().split())) 5 | gr = list(map(int, reversed(g))) 6 | r = [1, 1] 7 | for i in range(n): 8 | if g[i] < l[i]: 9 | r[0] = 0 10 | break 11 | for j in range(n): 12 | if gr[j] < l[j]: 13 | r[1] = 0 14 | break 15 | if r.count(1) == 2: 16 | print('both') 17 | elif r[0] == 1: print('front') 18 | elif r[1] == 1: print('back') 19 | else: print('none') 20 | -------------------------------------------------------------------------------- /CodeChef/Chef and Groups.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | inline void solve() { 5 | string s; 6 | int ans = 0; 7 | cin >> s; 8 | for (int i = 0; i < s.length(); i++) { 9 | while (s[i] == s[i + 1]) 10 | i++; 11 | ans += s[i] == '1'; 12 | } 13 | cout << ans << '\n'; 14 | } 15 | int main() { 16 | int T; 17 | cin >> T; 18 | while (T--) 19 | solve(); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CodeChef/Chef and IPC Certificates - IPCCERT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, m, k; 7 | cin >> n >> m >> k; 8 | int cnt = 0; 9 | for (int i = 0; i < n; i++) { 10 | int sum = 0, t = 0, kval = 0; 11 | for (int j = 0; j < k; j++) { 12 | cin >> t; 13 | sum += t; 14 | } 15 | cin >> kval; 16 | if (sum >= m && kval <= 10) 17 | cnt++; 18 | } 19 | cout << cnt << '\n'; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CodeChef/Chef and Interactive Contests.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, r; 7 | cin >> n >> r; 8 | while (n--) { 9 | int a; 10 | cin >> a; 11 | if (a >= r) 12 | cout << "Good boi\n"; 13 | else 14 | cout << "Bad boi\n"; 15 | } 16 | } 17 | int main() { 18 | solve(); 19 | } 20 | -------------------------------------------------------------------------------- /CodeChef/Chef and Price Control.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, p, tot = 0, ans = 0; 7 | cin >> n >> p; 8 | for (int _ = 0, tmp; _ < n; _++) { 9 | cin >> tmp; 10 | if (tmp > p) ans += p; 11 | else ans += tmp; 12 | tot += tmp; 13 | } 14 | cout << tot - ans << '\n'; 15 | } 16 | 17 | int main() { 18 | int T; 19 | cin >> T; 20 | while (T--) 21 | solve(); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /CodeChef/Chef and Secret Ingredient - PCJ18A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ll t; 9 | cin >> t; 10 | while (t--) 11 | { 12 | ll n, x, found = 0; 13 | cin >> n >> x; 14 | ll a[n]; 15 | for (int i = 0; i < n; i++) 16 | { 17 | cin >> a[i]; 18 | if (a[i] >= x) 19 | found = 1; 20 | } 21 | if (found) 22 | cout << "YES\n"; 23 | else 24 | cout << "NO\n"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CodeChef/Chef and Serves - CHSERVE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | 8 | cin >> T; 9 | 10 | while (T--) { 11 | long long int p1, p2, k; 12 | cin >> p1 >> p2 >> k; 13 | 14 | int rem = (p1 + p2) / k; 15 | if (rem % 2 == 0) 16 | cout << "CHEF"; 17 | else 18 | cout << "COOK"; 19 | cout << '\n'; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /CodeChef/Chef and Steps.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, k, tmp; 7 | cin >> n >> k; 8 | string res = ""; 9 | while (n--) { 10 | cin >> tmp; 11 | if (tmp % k == 0) { 12 | res += "1"; 13 | } else { 14 | res += "0"; 15 | } 16 | } 17 | cout << res << '\n'; 18 | } 19 | int main() { 20 | int t; 21 | cin >> t; 22 | while (t--) 23 | solve(); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /CodeChef/Chef and String.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(0); 7 | cin.tie(0); 8 | 9 | string s; 10 | int arr[4] = {0, 0, 0, 0}; 11 | cin >> s; 12 | for (int _ = 0; _ < s.length(); _++) { 13 | if (s[_] == 'C') 14 | arr[0]++; 15 | else if (s[_] == 'H' && arr[1] < arr[0]) 16 | arr[1]++; 17 | else if (s[_] == 'E' && arr[2] < arr[1]) 18 | arr[2]++; 19 | else if (s[_] == 'F' && arr[3] < arr[2]) 20 | arr[3]++; 21 | } 22 | cout << arr[3] << '\n'; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/Chef and his daily routine.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a = input() 3 | if 'EC' in a or 'SE' in a or 'SC' in a: 4 | print('no') 5 | else: 6 | print('yes') -------------------------------------------------------------------------------- /CodeChef/Chef in Fantasy League.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | (n, s) = map(int, input().split()) 3 | p = list(map(int, input().split())) 4 | o = list(map(int, input().split())) 5 | zero, one = [], [] 6 | money = 100 - s 7 | i = 0 8 | while i < n: 9 | if o[i] == 0: 10 | zero.append(p[i]) 11 | else: 12 | one.append(p[i]) 13 | i += 1 14 | if len(zero) > 0 and len(one) > 0 and min(zero) + min(one) <= money: 15 | print('yes') 16 | else: 17 | print('no') 18 | 19 | -------------------------------------------------------------------------------- /CodeChef/ChefAndHisStudents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | string s; 7 | cin >> s; 8 | for (int i = 0; i < s.length(); i++) { 9 | if (s[i] == '>') 10 | s[i] = '<'; 11 | else if (s[i] == '<') 12 | s[i] = '>'; 13 | } 14 | int ans = 0; 15 | for (int i = 0; i < s.length() - 1; i++) { 16 | if (s[i] == '>' && s[i + 1] == '<') 17 | ans++; 18 | } 19 | cout << ans << '\n'; 20 | } 21 | int main() { 22 | int t; 23 | cin >> t; 24 | while (t--) 25 | solve(); 26 | } 27 | -------------------------------------------------------------------------------- /CodeChef/ChefAndTableTennis.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s = input() 3 | a, b = s.count('1'), s.count('0') 4 | print('WIN') if (a > b or a == b) else print('LOSE') 5 | -------------------------------------------------------------------------------- /CodeChef/ChefandCook-Off.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n; 7 | cin >> n; 8 | for (int i = 0; i < n; i++) { 9 | int ans = 0; 10 | for (int j = 0; j < 5; j++) { 11 | int tmp; cin >> tmp; 12 | if (tmp == 1) ans++; 13 | } 14 | if ( ans == 0) 15 | cout << "Beginner"<<"\n"; 16 | else if ( ans == 1) 17 | cout << "Junior Developer"<<"\n"; 18 | else if ( ans == 2) 19 | cout << "Middle Developer"<<"\n"; 20 | else if ( ans == 3) 21 | cout << "Senior Developer"<<"\n"; 22 | else if ( ans == 4) 23 | cout << "Hacker"<<"\n"; 24 | else if ( ans == 5) 25 | cout << "Jeff Dean"<<"\n"; 26 | } 27 | } 28 | int main() { 29 | solve(); 30 | } 31 | -------------------------------------------------------------------------------- /CodeChef/Chess Match - BLITZ3_2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int a, b, c; 11 | cin >> a >> b >> c; 12 | 13 | cout << (2 * (180 + a)) - (b + c) << '\n'; 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /CodeChef/Chocolate Monger - CM164364.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int T; 8 | cin >> T; 9 | while (T--) 10 | { 11 | int n, x, s = 0; 12 | cin >> n >> x; 13 | int a[n], b[n]; 14 | 15 | for (int i = 0; i < n; i++) 16 | cin >> a[i]; 17 | 18 | sort(a, a + n); 19 | 20 | for (int i = 0; i < n - 1; i++) 21 | { 22 | if (a[i] != a[i + 1]) 23 | { 24 | b[s++] = a[i]; 25 | } 26 | } 27 | b[s++] = a[n - 1]; 28 | 29 | int eat = n - x; 30 | 31 | if (s == eat) 32 | cout << s << endl; 33 | else if (s > eat) 34 | cout << eat << endl; 35 | else if (eat > s) 36 | cout << s << endl; 37 | } 38 | } -------------------------------------------------------------------------------- /CodeChef/Coder Life Matters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | 7 | bool in[30],ans = 1; 8 | for (int i = 0;i < 30; i++) 9 | cin >> in[i]; 10 | for (int i = 0; i < 25; i++) 11 | if (in[i] & in[i + 1] & in[i + 2] & in[i + 3] & in[i + 4] & in[i + 5]) 12 | ans = 0; 13 | if (!ans) 14 | cout << "#coderlifematters" << '\n'; 15 | else 16 | cout << "#allcodersarefun" << '\n'; 17 | 18 | return; 19 | } 20 | int main() { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | 25 | int t; 26 | cin >> t; 27 | 28 | while (t--) 29 | solve(); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /CodeChef/Coldplay.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | while (t--) { 9 | int a, b; 10 | cin >> a >> b; 11 | int ans = a / b; 12 | cout << ans << '\n'; 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /CodeChef/CountSubarrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | inline void solve() { 7 | int n; 8 | cin >> n; 9 | int arr[n]; 10 | for (int _ = 0; _ < n; _++) 11 | cin >> arr[_]; 12 | int j = 0, _; 13 | ll ans = 0; 14 | for (_ = 1; _ < n; _++) { 15 | if (arr[_] >= arr[_ - 1]) 16 | continue; 17 | else { 18 | ll r = (_ - j); 19 | r = (r * (r + 1)) / 2; 20 | ans += r; 21 | j = _; 22 | } 23 | } 24 | _ -= j; 25 | ans += ((_ * (_ + 1)) / 2); 26 | cout << ans << '\n'; 27 | } 28 | int main() { 29 | int t; 30 | cin >> t; 31 | while (t--) { 32 | solve(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CodeChef/CuttheBoard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, m; 7 | cin >> n >> m; 8 | cout << (n - 1) * (m - 1) << '\n'; 9 | } 10 | int main() { 11 | int t; 12 | cin >> t; 13 | while (t--) { 14 | solve(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CodeChef/Cyclic Quadrilateral - CYCLICQD.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | while (T--) { 9 | int a, b, c, d; 10 | cin >> a >> b >> c >> d; 11 | if (a + c == b + d) 12 | cout << "YES\n"; 13 | else 14 | cout << "NO\n"; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /CodeChef/DEVARRAY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, q; 7 | cin >> n >> q; 8 | long long int a[n], t; 9 | for (int i = 0; i < n; i++) 10 | cin >> a[i]; 11 | sort(a, a + n); 12 | while (q--) { 13 | cin >> t; 14 | if (a[0] <= t && a[n - 1] >= t) 15 | cout << "Yes" << '\n'; 16 | else 17 | cout << "No" << '\n'; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /CodeChef/DIET.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a, b = map(int, input().split()) 3 | arr = list(map(int, input().split())) 4 | i = 1 5 | p = 0 6 | for num in arr: 7 | p += num 8 | p -= b 9 | if p < 0: 10 | print('NO', end=' ') 11 | print(i) 12 | break 13 | i += 1 14 | else: 15 | print('YES') 16 | -------------------------------------------------------------------------------- /CodeChef/Days in Month - NW1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int freq[7] = {0, 0, 0, 0, 0, 0, 0}, n, i, j, k; 11 | string week_day,week[7] = {"mon", "tues", "wed", "thurs", "fri", "sat", "sun"}; 12 | cin >> n >> week_day; 13 | for (i = 0; i < 7; i++) { 14 | if (week_day == week[i]) { 15 | k = i; 16 | for (j = 0; j < n; j++) { 17 | freq[k] = freq[k] + 1; 18 | k++; 19 | if(k == 7) 20 | k = 0; 21 | } 22 | } 23 | } 24 | for (i = 0; i < 7; i++) 25 | cout << freq[i] << ' '; 26 | cout << '\n'; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /CodeChef/DevuanGrapes.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n, k = (map(int, input().split())) 3 | m = input().split() 4 | for i in range(len(m)): 5 | m[i] = int(m[i]) 6 | count = 0 7 | for i in range(n): 8 | x = m[i] % k 9 | if m[i] >= k: 10 | count += min(x, k - x) 11 | else: 12 | count += k - x 13 | print(count) 14 | -------------------------------------------------------------------------------- /CodeChef/Downloadfile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, k, ans = 0; 7 | cin >> n >> k; 8 | int arr[n][2]; 9 | for (int _ = 0; _ < n; _++) { 10 | for (int i = 0; i < 2; i++) { 11 | cin >> arr[_][i]; 12 | } 13 | if (k != 0) { 14 | if (k > arr[_][0]) { 15 | k -= arr[_][0]; 16 | arr[_][0] = 0; 17 | } else { 18 | arr[_][0] -= k; 19 | k = 0; 20 | } 21 | } 22 | } 23 | for (int _ = 0; _ < n; _++) { 24 | if (arr[_][0] != 0) { 25 | ans += arr[_][0] * arr[_][1]; 26 | } 27 | } 28 | cout << ans << '\n'; 29 | } 30 | int main() { 31 | int t; 32 | cin >> t; 33 | while (t--) { 34 | solve(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CodeChef/EVENTUAL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int T; 8 | cin >> T; 9 | while (T--) 10 | { 11 | int n; 12 | string s; 13 | cin >> n >> s; 14 | map m; 15 | for (int i = 0; i < s.size(); i++) 16 | m[s[i]]++; 17 | int f = 0; 18 | map::iterator t = m.begin(); 19 | { 20 | while (t != m.end()) 21 | { 22 | if ((t->second) % 2 != 0) 23 | { 24 | f = 1; 25 | break; 26 | } 27 | t++; 28 | } 29 | } 30 | if (f == 0) 31 | cout << "YES" << '\n'; 32 | else 33 | cout << "NO" << '\n'; 34 | } 35 | } -------------------------------------------------------------------------------- /CodeChef/Easy Math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline int findSumDigits(int s) { 6 | int res = 0; 7 | while (s > 0) { 8 | res += s % 10; 9 | s /= 10; 10 | } 11 | return res; 12 | } 13 | inline void solve() { 14 | int n, imax = -1; 15 | cin >> n; 16 | int arr[n]; 17 | for (int _ = 0; _ < n; _++) 18 | cin >> arr[_]; 19 | for (int i = 0; i < n; i++) 20 | for (int j = i + 1; j < n; j++) 21 | imax = max(findSumDigits(arr[i] * arr[j]), imax); 22 | cout << imax << '\n'; 23 | return; 24 | } 25 | int main() { 26 | int t; 27 | cin >> t; 28 | while (t--) 29 | solve(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /CodeChef/Encoding Message.py: -------------------------------------------------------------------------------- 1 | res = [chr(i) for i in range(97, 123)] 2 | for _ in range(int(input())): 3 | n = int(input()) 4 | s = list(input()) 5 | 6 | for i in range(0, n // 2 * 2 - 1, 2): 7 | s[i], s[i + 1] = s[i + 1], s[i] 8 | for i in range(n): 9 | s[i] = res[-1 * (res.index(s[i]) + 1)] 10 | print(''.join(s)) -------------------------------------------------------------------------------- /CodeChef/FANCY.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s = input().split() 3 | if 'not' in s: print('Real Fancy') 4 | else: print('regularly fancy') 5 | -------------------------------------------------------------------------------- /CodeChef/Find Your Gift.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, x = 0, y = 0; 7 | cin >> n; 8 | string s; 9 | cin >> s; 10 | int a = 0, b = 0; 11 | for (int i = 0; i < s.length(); i++) { 12 | if (s[i] == 'L' && s[i - 1] != 'L' && s[i - 1] != 'R') 13 | x--; 14 | else if (s[i] == 'R' && s[i - 1] != 'L' && s[i - 1] != 'R') 15 | x++; 16 | else if (s[i] == 'U' && s[i - 1] != 'U' && s[i - 1] != 'D') 17 | y++; 18 | else if (s[i] == 'D' && s[i - 1] != 'U' && s[i - 1] != 'D') 19 | y--; 20 | } 21 | cout << x << ' ' << y << '\n'; 22 | return; 23 | } 24 | int main() { 25 | ios::sync_with_stdio(false); 26 | cin.tie(0); 27 | 28 | int t; 29 | cin >> t; 30 | while (t--) 31 | solve(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /CodeChef/Find the Maximum Value.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | arr = list(map(int, input().split())) 3 | n = len(arr) - 1 4 | arr.remove(n) 5 | print(max(arr)) 6 | -------------------------------------------------------------------------------- /CodeChef/FlatLand.py: -------------------------------------------------------------------------------- 1 | from math import sqrt 2 | 3 | for _ in range(int(input())): 4 | n, ret = int(input()), 0 5 | while n: 6 | ret += 1 7 | s = int(sqrt(n)) 8 | n = n - s ** 2 9 | print(ret) 10 | -------------------------------------------------------------------------------- /CodeChef/Football Match - FBMT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while (t--) 9 | { 10 | int n; 11 | cin >> n; 12 | if (n == 0) 13 | cout << "Draw" << endl; 14 | else 15 | { 16 | string str, str1, str2; 17 | cin >> str; 18 | int count = 1, count1 = 0; 19 | for (int i = 1; i < n; i++) 20 | { 21 | cin >> str1; 22 | if (str == str1) 23 | { 24 | count++; 25 | } 26 | else 27 | { 28 | str2 = str1; 29 | count1++; 30 | } 31 | } 32 | if (count == count1) 33 | cout << "Draw" << endl; 34 | else if (count > count1) 35 | cout << str << endl; 36 | else 37 | cout << str2 << endl; 38 | } 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /CodeChef/Football.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, imax = -1; 7 | cin >> n; 8 | int arr[n], arr_[n]; 9 | for (int _ = 0; _ < n; _++) 10 | cin >> arr[_]; 11 | for (int _ = 0; _ < n; _++) 12 | cin >> arr_[_]; 13 | 14 | for (int _ = 0; _ < n; _++) { 15 | int total = max(arr[_] * 20 - arr_[_] * 10, 0); 16 | imax = max(imax, total); 17 | } 18 | cout << imax << '\n'; 19 | return; 20 | } 21 | int main() { 22 | ios::sync_with_stdio(false); 23 | cin.tie(0); 24 | cout.tie(0); 25 | 26 | int t; 27 | cin >> t; 28 | while (t--) 29 | solve(); 30 | } -------------------------------------------------------------------------------- /CodeChef/FromHeavenToEarth.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | double n, v1, v2, a, b, c; 7 | cin >> n >> v1 >> v2; 8 | a = (n * 2) / v2; 9 | c = sqrt(2); 10 | b = (c * n) / v1; 11 | if (a > b) 12 | cout << "Stairs\n"; 13 | else 14 | cout << "Elevator\n"; 15 | } 16 | int main() { 17 | int t; 18 | cin >> t; 19 | while (t--) 20 | solve(); 21 | } 22 | -------------------------------------------------------------------------------- /CodeChef/Good and Bad Persons.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n, k = map(int, input().split()) 3 | s = input() 4 | c = m = 0 5 | for i in range(len(s)): 6 | if s[i].isupper(): c += 1 7 | else: m += 1 8 | if c <= k and m <= k: print('both') 9 | elif c <= k and m > k: print('chef') 10 | elif m > k and c > k: print('none') 11 | else: print('brother') 12 | -------------------------------------------------------------------------------- /CodeChef/Gregorian Calendar.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | l = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday'] 4 | for _ in range(int(input())): 5 | print(l[date(int(input()) ,1, 1).weekday()]) -------------------------------------------------------------------------------- /CodeChef/Hidden Numbers - UWCOI21A.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | print(1, int(input())) 3 | -------------------------------------------------------------------------------- /CodeChef/Highest Divisor - HDIVISR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | for (int i = 9; i >= 1; i--) 10 | { 11 | if (n % i == 0) 12 | { 13 | cout << i << '\n'; 14 | return 0; 15 | } 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /CodeChef/How much Scholarship.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | 9 | int n, ans = 0; 10 | cin >> n; 11 | 12 | if (n < 51) 13 | ans = 100; 14 | else if (n < 101) 15 | ans = 50; 16 | cout << ans << '\n'; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /CodeChef/IPL and RCB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int x, y; 7 | cin >> x >> y; 8 | if (x <= y) cout << "0" << '\n'; 9 | else cout << x - y << '\n'; 10 | } 11 | int main() { 12 | int t; 13 | cin >> t; 14 | while (t--) 15 | solve(); 16 | } 17 | -------------------------------------------------------------------------------- /CodeChef/Interesting XOR!.py: -------------------------------------------------------------------------------- 1 | from math import log 2 | 3 | for _ in range(int(input())): 4 | n = int(input()) 5 | b = 2 ** int(log(n, 2)) - 1 6 | a = n ^ b 7 | print(a * b) 8 | -------------------------------------------------------------------------------- /CodeChef/Is it a Cakewalk Problem - ISITCAKE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int times[10][10]; 11 | for (int i = 0; i < 10; i++) { 12 | for (int j = 0; j < 10; j++) { 13 | cin >> times[i][j]; 14 | } 15 | } 16 | int ans = 0; 17 | for (int i = 0; i < 10; i++) { 18 | for (int j = 0; j < 10; j++) { 19 | if (times[i][j] <= 30) 20 | ans++; 21 | } 22 | } 23 | if (ans >= 60) 24 | cout << "yes" << '\n'; 25 | else 26 | cout << "no" << '\n'; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /CodeChef/Judging Delay.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, ans = 0; 7 | cin >> n; 8 | while (n--) { 9 | int a, b; 10 | cin >> a >> b; 11 | if (b - a > 5) ans++; 12 | } 13 | cout << ans << '\n'; 14 | return; 15 | } 16 | int main() { 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int t; 21 | cin >> t; 22 | while (t--) 23 | solve(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /CodeChef/Lazy Chef - LAZYCHF.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int a, b, c; 11 | cin >> a >> b >> c; 12 | cout << min(a * b, a + c) << '\n'; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /CodeChef/LazyJem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long int lli; 4 | 5 | using namespace std; 6 | 7 | inline void solve() { 8 | lli a, b, c, ans = 0; 9 | cin >> a >> b >> c; 10 | while (a > 0) { 11 | lli solved; 12 | if (a % 2 == 0) solved = a / 2; 13 | else solved = (a + 1) / 2; 14 | ans += solved * c; 15 | a -= solved; 16 | if (a > 0) 17 | ans += b; 18 | c *= 2; 19 | } 20 | cout << ans << '\n'; 21 | } 22 | int main() { 23 | int t; 24 | cin >> t; 25 | while (t--) 26 | solve(); 27 | } 28 | -------------------------------------------------------------------------------- /CodeChef/Lift Requests.py: -------------------------------------------------------------------------------- 1 | for _ in range(0, int(input())): 2 | n, q = map(int, input().split()) 3 | initial, floors = 0, 0 4 | for j in range(0, q): 5 | f, d = map(int, input().split()) 6 | floors += (abs(initial - f) + abs(f - d)) 7 | initial = d 8 | print(floors) 9 | -------------------------------------------------------------------------------- /CodeChef/Lost Weekends.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int p, sum = 0; 7 | 8 | for (int i = 0, tmp; i < 5; i++) { 9 | cin >> tmp; 10 | sum += tmp; 11 | } 12 | cin >> p; 13 | int ans = (sum * p) - (24 * 5); 14 | if (ans > 0) 15 | cout << "Yes\n"; 16 | else 17 | cout << "No\n"; 18 | } 19 | int main() { 20 | int T; 21 | cin >> T; 22 | while (T--) 23 | solve(); 24 | } 25 | -------------------------------------------------------------------------------- /CodeChef/Lucky Four - LUCKYFR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | while (T--) { 9 | string s; 10 | int ans = 0; 11 | cin >> s; 12 | for (int i = 0; i < s.length(); i++) { 13 | if (s[i] == '4') 14 | ans++; 15 | } 16 | cout << ans << '\n'; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /CodeChef/Marbles - MARBLES.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n, k = map(int, input().split()) 3 | a = 1 4 | for i in range(1, k): 5 | a = a * (n - k + i) 6 | a = a // i 7 | print(int(a)) 8 | -------------------------------------------------------------------------------- /CodeChef/Mathison and pangrams - MATPAN.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | while (T--) { 9 | long int a[26], i, ans = 0; 10 | for (i = 0; i < 26; i++) 11 | cin >> a[i]; 12 | string s; 13 | cin >> s; 14 | int n = s.length(); 15 | int c[26] = {0}; 16 | for (i = 0; i < n; i++) 17 | c[s[i] - 'a']++; 18 | for (i = 0; i < 26; i++) 19 | if (c[i] == 0) 20 | ans += a[i]; 21 | cout << ans << endl; 22 | } 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /CodeChef/Max power - MAX2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T, ans = 0; 7 | cin >> T; 8 | string s; 9 | 10 | cin >> s; 11 | for (int _ = s.length() - 1; _ >= 0; _--) { 12 | if (s[_] == '1') 13 | break; 14 | else 15 | ans++; 16 | } 17 | cout << ans << '\n'; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /CodeChef/Maximum Weight Difference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define rep(i, n) for(int i = 0; i < (n); ++i) 3 | #define all(x) (x).begin(),(x).end() 4 | #define pb push_back 5 | #define mp make_pair 6 | #define ff first 7 | #define ss second 8 | 9 | using namespace std; 10 | 11 | vector vi; 12 | 13 | int main() { 14 | ios::sync_with_stdio(false); 15 | cin.tie(0); 16 | 17 | int t; 18 | cin >> t; 19 | while (t--) { 20 | int n, k; 21 | cin >> n >> k; 22 | for (int i = 0; i < n; i++) { 23 | int tmp; 24 | cin >> tmp; 25 | vi.pb(tmp); 26 | } 27 | sort(all(vi)); 28 | int a = 0, b = 0, c = 0, d = 0; 29 | for (int i = 0; i < k; i++) a += vi[i]; 30 | for (int i = k; i < n; i++) b += vi[i]; 31 | for (int i = 0; i < n - k; i++) c += vi[i]; 32 | for (int i = n - k; i < n; i++) d += vi[i]; 33 | cout << max(abs(a - b), abs(c - d)) << '\n'; 34 | vi.clear(); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /CodeChef/Medel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | inline void solve() { 5 | int n, imin = 110, imax = 0, mini = 0, maxi = 0; 6 | cin >> n; 7 | for (int _ = 0, tmp; _ < n; _++) { 8 | cin >> tmp; 9 | if (tmp < imin) { 10 | imin = tmp; 11 | mini = _; 12 | } 13 | if (tmp > imax) { 14 | imax = tmp; 15 | maxi = _; 16 | } 17 | } 18 | if (mini < maxi) 19 | cout << imin << " " << imax << '\n'; 20 | else 21 | cout << imax << " " << imin << '\n'; 22 | } 23 | int main() { 24 | int T; 25 | cin >> T; 26 | while (T--) 27 | solve(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /CodeChef/Minimum Attendance Requirement - ATTENDU.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | double n, cnt = 0; 11 | string s; 12 | cin >> n >> s; 13 | for (int _ = 0; _ < s.length(); _++) 14 | if (s[_] == '1') 15 | cnt++; 16 | if (((120 - n) + cnt) / 120 * 100 >= 75) 17 | cout << "YES"; 18 | else 19 | cout << "NO"; 20 | cout << '\n'; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/Multiple Choice Examp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, ans = 0; 7 | cin >> n; 8 | string in, out; 9 | cin >> in >> out; 10 | for (int i = 0; i < n; i++) { 11 | if (out[i] == 'N') 12 | continue; 13 | if (in[i] == out[i]) 14 | ans++; 15 | else 16 | i++; 17 | } 18 | cout << ans << '\n'; 19 | } 20 | int main() { 21 | int T; 22 | cin >> T; 23 | while (T--) 24 | solve(); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /CodeChef/MutatedMinions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, k, ans = 0; 7 | cin >> n >> k; 8 | for (int _ = 0; _ < n; _++) { 9 | int tmp; 10 | cin >> tmp; 11 | if ((tmp + k) % 7 == 0) 12 | ans++; 13 | } 14 | cout << ans << '\n'; 15 | } 16 | int main() { 17 | int t; 18 | cin >> t; 19 | while (t--) { 20 | solve(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /CodeChef/No Time to Wait.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int N, H, x, can = 0; 7 | cin >> N >> H >> x; 8 | for (int i = 0, tmp; i < N; i++) { 9 | cin >> tmp; 10 | if (tmp + x >= H) 11 | can = 1; 12 | } 13 | if (can) 14 | cout << "YES" << '\n'; 15 | else 16 | cout << "NO" << '\n'; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /CodeChef/Nothing in Common.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n = input() 3 | n = set(input().split()) 4 | m = set(input().split()) 5 | 6 | print(len(n.intersection(m))) -------------------------------------------------------------------------------- /CodeChef/One more weird game.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n, m = map(int, input().split()) 3 | a = m + n - 2 4 | b = (m * n) - a - 1 5 | ans = (b * 2) + a 6 | print(ans) 7 | -------------------------------------------------------------------------------- /CodeChef/Ordering the Soldiers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define rep(i, n) for(int i = 0; i < (n); ++i) 3 | #define all(x) (x).begin(),(x).end() 4 | #define pb push_back 5 | #define mp make_pair 6 | #define ff first 7 | #define ss second 8 | 9 | using namespace std; 10 | using ull = unsigned long long; 11 | using ll = long long; 12 | 13 | const ll INF = ll(1e18) + 1; 14 | 15 | inline void solve() { 16 | ll n; 17 | cin >> n; 18 | ll a[n], b[n]; 19 | for (ll _ = 0; _ < n; _++) { 20 | cin >> a[_]; 21 | b[_] = _ + 1; 22 | } 23 | for (ll i = n - 1; i >= 0; i--) { 24 | int shift = a[i]; 25 | int tmp = b[i - shift]; 26 | for (int j = i - shift; j < i; j++) 27 | b[j] = b[j + 1]; 28 | b[i] = tmp; 29 | } 30 | for (ll _ = 0; _ < n; _++) 31 | cout << b[_] << " "; 32 | cout << '\n'; 33 | } 34 | int main() { 35 | ios::sync_with_stdio(false); 36 | cin.tie(0); 37 | 38 | int t; 39 | cin >> t; 40 | while (t--) 41 | solve(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /CodeChef/Pair Me.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | while (t--) { 9 | int a, b, c; 10 | cin >> a >> b >> c; 11 | if (a == b + c || b == c + a || c == a + b) { 12 | cout << "YES" << '\n'; 13 | } 14 | else 15 | cout << "NO" << '\n'; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /CodeChef/Palindromicsubstrings.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a, b = input(), input() 3 | ans = 0 4 | for i in a: 5 | if i in b: 6 | ans = 1 7 | break 8 | print('No') if ans == 0 else print('Yes') 9 | -------------------------------------------------------------------------------- /CodeChef/Passing Marks - PSGRADE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | while (T--) { 9 | int arr[7]; 10 | for (int i = 0; i < 7; i++) { 11 | cin >> arr[i]; 12 | } 13 | if ((arr[0] > arr[4] || arr[1] > arr[5] || arr[2] > arr[6]) || (arr[4] + arr[5] + arr[6] < arr[3])) { 14 | cout << "NO" << '\n'; 15 | } else { 16 | cout << "YES" << '\n'; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CodeChef/Play Piano.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s, can = input(), True 3 | for i in range(0, len(s), 2): 4 | if s[i:i+2].count('A') != 1: 5 | can = False 6 | break 7 | print('yes') if can else print('no') 8 | 9 | -------------------------------------------------------------------------------- /CodeChef/Playing with Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, a = 0, b = 0; 7 | cin >> n; 8 | string s; 9 | cin >> s; 10 | for (int _ = 0; _ < s.length(); _++) 11 | if (s[_] == '1') 12 | a++; 13 | cin >> s; 14 | for (int _ = 0; _ < s.length(); _++) 15 | if (s[_] == '1') 16 | b++; 17 | if (a == b) 18 | cout << "YES" << '\n'; 19 | else 20 | cout << "NO" << '\n'; 21 | return; 22 | } 23 | int main() { 24 | ios::sync_with_stdio(false); 25 | cin.tie(0); 26 | 27 | int t; 28 | cin >> t; 29 | while (t--) 30 | solve(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /CodeChef/PlayingwithMatches.py: -------------------------------------------------------------------------------- 1 | t= int(input()) 2 | for _ in range(t): 3 | a, b = map(int, input().split()) 4 | s = a + b 5 | S = str(s) 6 | c = 0 7 | matches = {'0':6,'1':2,'2':5,'3':5,'4':4,'5':5,'6':6,'7':3,'8':7,'9':6} 8 | for d in S: 9 | if d in matches.keys(): 10 | c += matches[d] 11 | print(c) 12 | -------------------------------------------------------------------------------- /CodeChef/Possible Victory - T20MCH.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int R, O, C; 7 | cin >> R >> O >> C; 8 | if ((20 - O) * 6 * 6 + C > R) 9 | cout << "YES" << '\n'; 10 | else 11 | cout << "NO" << '\n'; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /CodeChef/ProgramYourOwnCALCULATOR.py: -------------------------------------------------------------------------------- 1 | a, b, c = int(input()), int(input()), input() 2 | if c == '+': print(a + b) 3 | elif c == '-': print(a - b) 4 | elif c == '*': print(a * b) 5 | elif c == '/': print(a / b) 6 | -------------------------------------------------------------------------------- /CodeChef/Richie Rich - CHFRICH.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | 9 | while (t--) { 10 | int a, b, c; 11 | cin >> a >> b >> c; 12 | cout << (b - a) / c << '\n'; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /CodeChef/Roots of a Quadratic Equation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int a, b, c; 7 | cin >> a >> b >> c; 8 | 9 | double x1 = double(-b + (double)sqrt((b * b) - 4 * a * c)) / (2 * a); 10 | double x2 = double(-b - (double)sqrt((b * b) - 4 * a * c)) / (2 * a); 11 | 12 | cout << fixed << setprecision(6) << x1 << '\n'; 13 | cout << fixed << setprecision(6) << x2 << '\n'; 14 | 15 | return; 16 | } 17 | int main() { 18 | ios::sync_with_stdio(false); 19 | cin.tie(0); 20 | 21 | solve(); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/SPLITIT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int T; 8 | cin >> T; 9 | while (T--) 10 | { 11 | int n; 12 | cin >> n; 13 | string s; 14 | cin >> s; 15 | char c = s[n - 1]; 16 | bool flag = false; 17 | for (int i = 0; i < n - 1; i++) 18 | { 19 | if (s[i] == c) 20 | { 21 | flag = true; 22 | break; 23 | } 24 | } 25 | if (flag) 26 | cout << "YES" << '\n'; 27 | else 28 | cout << "NO" << '\n'; 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /CodeChef/Secret Recipe.cpp: -------------------------------------------------------------------------------- 1 | #include "bits/stdc++.h" 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int x1, x2, x3, v1, v2; 7 | 8 | cin >> x1 >> x2 >> x3 >> v1 >> v2; 9 | 10 | long double s1 = abs(1.0 * (x3 - x1) / v1); 11 | long double s2 = abs(1.0 * (x3 - x2) / v2); 12 | 13 | if (s1 < s2) cout << "Chef\n"; 14 | else if (s1 > s2) cout << "Kefa\n"; 15 | else cout << "Draw\n"; 16 | } 17 | int main() { 18 | ios_base::sync_with_stdio(false); 19 | cin.tie(0); 20 | cout.tie(0); 21 | 22 | int t; 23 | cin >> t; 24 | while (t--) 25 | solve(); 26 | } -------------------------------------------------------------------------------- /CodeChef/Sed Sequences - SEDARR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | 9 | while (t--) { 10 | int n, k, s = 0, tmp; 11 | cin >> n >> k; 12 | 13 | while (n--) { 14 | cin >> tmp; 15 | s += tmp; 16 | } 17 | if (s % k == 0) 18 | cout << "0\n"; 19 | else 20 | cout << "1\n"; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/Sell All the Cars - CARSELL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | 9 | while (T--) { 10 | int n; 11 | cin >> n; 12 | vector vi; 13 | while (n--) { 14 | int k; 15 | cin >> k; 16 | vi.push_back(k); 17 | } 18 | sort(vi.begin(), vi.end(), greater()); 19 | long long c = 0, res = 0; 20 | for (auto x: vi) 21 | if (x != 0 && x - c > 0) { 22 | res += x - c; 23 | c++; 24 | } 25 | cout << res % 1000000007 << '\n'; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /CodeChef/SimilarDishes-brute.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, ans = 0, _, __; 7 | cin >> n; 8 | vector < vector > vs(n * 2); 9 | for (_ = 0; _ < n * 2; _++) { 10 | for (__ = 0; __ < 4; __++) { 11 | string tmp; 12 | cin >> tmp; 13 | vs[_].push_back(tmp); 14 | } 15 | } 16 | for (_ = 0; _ < n * 2; _ += 2) { 17 | int cnt = 0; 18 | for (__ = 0; __ < 4; __++) { 19 | for (int i = 0; i < 4; i++) { 20 | if (vs[_][__] == vs[_ + 1][i]) { 21 | cnt += 1; 22 | } 23 | } 24 | } 25 | if (cnt >= 2) 26 | cout << "similar\n"; 27 | else 28 | cout << "dissimilar\n"; 29 | } 30 | } 31 | int main() { 32 | int t = 1; 33 | while (t--) { 34 | solve(); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /CodeChef/SimilarDishes-map.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | map mp; 7 | for (int _ = 0; _ < 8; _++) { 8 | string tmp; 9 | cin >> tmp; 10 | mp[tmp]++; 11 | } 12 | int cnt = 0; 13 | map ::iterator it = mp.begin(); 14 | for (it = mp.begin(); it != mp.end(); it++) if (it->second == 2) 15 | cnt++; 16 | if (cnt >= 2) 17 | cout << "similar" << '\n'; 18 | else 19 | cout << "dissimilar" << '\n'; 20 | } 21 | int main() { 22 | int t; 23 | cin >> t; 24 | while (t--) { 25 | solve(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CodeChef/Simple Statistics.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n, k = map(int, input().split()) 3 | e = n - 2 * k 4 | a = sorted(list(map(int, input().split()))) 5 | ans = 0 6 | for s in range(k): 7 | del a[0] 8 | del a[-1] 9 | for c in a: 10 | ans += int(c) 11 | ans = ans / e 12 | print(format(ans, '.6f')) 13 | -------------------------------------------------------------------------------- /CodeChef/Snake Procession.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n = input() 3 | s = input().replace('.', '') 4 | f = 0 5 | if len(s) % 2: f = 1 6 | else: 7 | for i in range(0, len(s) - 1, 2): 8 | if s[i] == 'H' and s[i + 1] == 'T': 9 | continue 10 | else: 11 | f = 1 12 | break 13 | if f == 0: print('Valid') 14 | else: print('Invalid') 15 | -------------------------------------------------------------------------------- /CodeChef/Space Arrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, isum = 0; 7 | cin >> n; 8 | vector vi(n); 9 | for (int _ = 0, i; _ < n; _++) { 10 | cin >> i; 11 | vi[i - 1] += 1; 12 | } 13 | for (int _ = 0; _ < n; _++) 14 | vi[_] += vi[_ - 1]; 15 | for (int _ = 0; _ < n; _++) { 16 | if (vi[_] < _ + 1) { 17 | cout << "Second\n"; 18 | return; 19 | } 20 | isum += vi[_]; 21 | } 22 | cout << ((isum - (long long) n * (n + 1) / 2) % 2 == 0 ? "Second\n" : "First\n"); 23 | } 24 | 25 | int main() { 26 | int T; 27 | cin >> T; 28 | while (T--) 29 | solve(); 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /CodeChef/Sticks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long int lli; 4 | 5 | using namespace std; 6 | 7 | inline void solve() { 8 | int n; 9 | cin >> n; 10 | lli a[n]; 11 | int mx1 = INT_MIN, mx2 = INT_MIN; 12 | unordered_map mp; 13 | for (int i = 0; i < n; i++) { 14 | cin >> a[i]; 15 | if (mp.find(a[i]) != mp.end()) 16 | mp[a[i]]++; 17 | else 18 | mp[a[i]] = 1; 19 | if (mp[a[i]] == 2) { 20 | if (a[i] > mx1) { 21 | mx2 = mx1; 22 | mx1 = a[i]; 23 | } 24 | else if (a[i] > mx2) 25 | mx2 = a[i]; 26 | mp[a[i]] = 0; 27 | } 28 | } 29 | if (mx1 == INT_MIN || mx2 == INT_MIN) 30 | cout << -1 << '\n'; 31 | else 32 | cout << mx1 * mx2 << '\n'; 33 | } 34 | int main() { 35 | int t; 36 | cin >> t; 37 | while (t--) 38 | solve(); 39 | } 40 | -------------------------------------------------------------------------------- /CodeChef/Strange operations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, k, sum = 0, tmp; 7 | cin >> n >> k; 8 | for (int _ = 0; _ < n; _++) { 9 | cin >> tmp; 10 | sum += tmp; 11 | } 12 | int sum1 = sum + 1; 13 | for (int _ = 1; _ < k; _++) { 14 | sum1 += sum + 1; 15 | sum += (sum1 - sum - 1); 16 | } 17 | if (sum1 % 2) 18 | cout << "odd" << '\n'; 19 | else 20 | cout << "even" << '\n'; 21 | return; 22 | } 23 | int main() { 24 | ios::sync_with_stdio(false); 25 | cin.tie(0); 26 | 27 | int t; 28 | cin >> t; 29 | while (t--) 30 | solve(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /CodeChef/Summer Heat - COCONUT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | 8 | cin >> T; 9 | 10 | while (T--) { 11 | int a, b, c, d; 12 | cin >> a >> b >> c >> d; 13 | cout << (c / a) + (d / b) << '\n'; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /CodeChef/Temple Land.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n; 7 | cin >> n; 8 | int arr[n]; 9 | for (int _ = 0; _ < n; _++) cin >> arr[_]; 10 | if (n % 2 == 0) { 11 | cout << "no\n"; 12 | return; 13 | } 14 | int max = 1, flag = 1; 15 | for (int _ = 0; _ < n; _++) { 16 | if (arr[_] != max) 17 | flag = 0; 18 | if (_ < n / 2) 19 | max++; 20 | else 21 | max--; 22 | } 23 | if (flag == 1) 24 | cout << "yes\n"; 25 | else 26 | cout << "no\n"; 27 | } 28 | int main() { 29 | ios::sync_with_stdio(false); 30 | cin.tie(0); 31 | 32 | int t; 33 | cin >> t; 34 | while (t--) 35 | solve(); 36 | } 37 | -------------------------------------------------------------------------------- /CodeChef/Testing Robot - TSTROBOT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int T; 8 | cin >> T; 9 | 10 | while (T--) { 11 | ll n, x; 12 | cin >> n >> x; 13 | set visited; 14 | 15 | visited.insert(x); 16 | char directions[n]; 17 | for (int _ = 0; _ < n; _++) 18 | cin >> directions[_]; 19 | for (int _ = 0; _ < n; _++) { 20 | if (directions[_] == 'L') 21 | x--; 22 | else 23 | x++; 24 | visited.insert(x); 25 | } 26 | cout << visited.size() << '\n'; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /CodeChef/That Is My Score!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, ans = 0; 7 | cin >> n; 8 | int arr[12] = {0}; 9 | while (n--) { 10 | int x, y; 11 | cin >> x >> y; 12 | arr[x] = max(arr[x], y); 13 | } 14 | for (int _ = 1; _ <= 8; _++) 15 | ans += arr[_]; 16 | cout << ans << '\n'; 17 | 18 | return; 19 | } 20 | int main() { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | 25 | int t; 26 | cin >> t; 27 | while (t--) 28 | solve(); 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /CodeChef/The Next Palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | string s; 6 | 7 | inline void inc (int pos) { 8 | s[pos]++; 9 | if (s[pos] == ':') { 10 | s[pos] = '0'; 11 | if (pos > 0) 12 | inc(pos - 1); 13 | else 14 | s.insert(s.begin(), '1'); 15 | } 16 | } 17 | inline void solve () { 18 | cin >> s; 19 | int n = s.length(); 20 | inc(n - 1); 21 | n = s.length(); 22 | for (int i = 0; i < n / 2; i++) { 23 | int left = i, right = n - 1 - i; 24 | while (s[left] != s[right]) 25 | inc(right); 26 | } 27 | cout << s << '\n'; 28 | } 29 | int main() { 30 | ios_base::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | cout.tie(NULL); 33 | 34 | int t; 35 | cin >> t; 36 | 37 | while (t--) 38 | solve(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /CodeChef/Three Friends.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int a, b, c; 7 | cin >> a >> b >> c; 8 | int imax = max(max(a, b), c); 9 | 10 | if (a + b + c == 2 * imax) 11 | cout << "yes" << '\n'; 12 | else 13 | cout << "no" << '\n'; 14 | return; 15 | } 16 | int main() { 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | int t; 20 | cin >> t; 21 | while (t--) 22 | solve(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /CodeChef/Tickets.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): print("YES") if len(set(input())) == 2 else print('NO') 2 | -------------------------------------------------------------------------------- /CodeChef/Train Partner.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n = int(input()) 3 | a = n % 8 4 | if 1 <= a <= 6: 5 | if a == 1: s = str(n + 3) + 'LB' 6 | elif a == 4: s = str(n - 3) + 'LB' 7 | elif a == 2: s = str(n + 3) + 'MB' 8 | elif a == 5: s = str(n - 3) + 'MB' 9 | elif a == 3: s = str(n + 3) + 'UB' 10 | else: s = str(n - 3) + 'UB' 11 | else: 12 | if a == 7: s = str(n + 1) + 'SU' 13 | else: s = str(n - 1) + 'SL' 14 | print(s) 15 | -------------------------------------------------------------------------------- /CodeChef/UWCOI20A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | while (t--) { 9 | int n; 10 | cin >> n; 11 | int a[n]; 12 | for (int i = 0; i < n; i++) 13 | cin >> a[i]; 14 | sort(a, a + n); 15 | cout << a[n - 1] << '\n'; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /CodeChef/Uniform Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | string s; 7 | cin >> s; 8 | int k = 0; 9 | s[8] = s[0]; 10 | for (int _ = 0; _ < 8; _++) { 11 | if (s[_] != s[_ + 1]) 12 | k++; 13 | } 14 | if (k < 3) 15 | cout << "uniform" << '\n'; 16 | else 17 | cout << "non-uniform" << '\n'; 18 | 19 | return; 20 | } 21 | int main() { 22 | ios::sync_with_stdio(false); 23 | cin.tie(0); 24 | 25 | int t; 26 | cin >> t; 27 | while (t--) 28 | solve(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /CodeChef/Valid Pair - SOCKS1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b, c; 7 | cin >> a >> b >> c; 8 | if (a == b || a == c || b == c) 9 | cout << "YES" << '\n'; 10 | else 11 | cout << "NO" << '\n'; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /CodeChef/WATMELON.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int T; 8 | cin >> T; 9 | while (T--) 10 | { 11 | int n, isum = 0; 12 | cin >> n; 13 | while (n--) 14 | { 15 | int a; 16 | cin >> a; 17 | isum += a; 18 | } 19 | if (isum >= 0) 20 | cout << "YES" << '\n'; 21 | else 22 | cout << "NO" << '\n'; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /CodeChef/WDTBAM.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n = int(input()) 3 | c = input() 4 | chef = input() 5 | s = list(map(int, input().split())) 6 | cnt = 0 7 | for i in range(n): 8 | if c[i] == chef[i]: 9 | cnt += 1 10 | if cnt == n: 11 | print(s[n]) 12 | else: 13 | print(max(s[:cnt + 1])) 14 | -------------------------------------------------------------------------------- /CodeChef/Whats in the Name.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s = input().split() 3 | if len(s) == 1: 4 | print(s[0].capitalize()) 5 | else: 6 | for i in range(len(s)): 7 | if i == len(s) - 1: 8 | print(s[i].capitalize()) 9 | else: 10 | print(f'{s[i][0].upper()}. ', end='') 11 | -------------------------------------------------------------------------------- /CodeChef/Workers - CHEFWORK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | int c[n], t[n]; 9 | 10 | for (int i = 0; i < n; i++) 11 | cin >> c[i]; 12 | int imin[3] = {100000,100000,100000}; 13 | for (int i = 0; i < n; i++) { 14 | cin >> t[i]; 15 | if (c[i] < imin[t[i] - 1]) 16 | imin[t[i] - 1] = c[i]; 17 | } 18 | cout << min(imin[0] + imin[1], imin[2]); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /CodeChef/XYSTR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void sol() { 6 | string s; 7 | cin >> s; 8 | int a = 0; 9 | for (int i = 0; i < s.length() - 1; i++) { 10 | if (s[i] == 'x' && s[i + 1] != 'x' || (s[i] == 'y' && s[i + 1] != 'y')) { 11 | a++; 12 | i++; 13 | } 14 | } 15 | cout << a << '\n'; 16 | } 17 | int main() { 18 | int t; 19 | cin >> t; 20 | while (t--) 21 | sol(); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /CodeChef/Xenny and Alternating Tasks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n, a = 0, b = 0; 7 | cin >> n; 8 | for (int i = 0, _; i < n; i++) { 9 | cin >> _; 10 | if (i % 2 == 0) 11 | a += _; 12 | else b += _; 13 | } 14 | for (int i = 0, _; i < n; i++) { 15 | cin >> _; 16 | if (i % 2 == 0) 17 | b += _; 18 | else a += _; 19 | } 20 | cout << min(a, b) << '\n'; 21 | } 22 | 23 | int main() { 24 | int T; 25 | cin >> T; 26 | while (T--) 27 | solve(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /CodeChef/in: -------------------------------------------------------------------------------- 1 | 2 2 | 5 2 3 | 8 4 5 2 10 4 | 8 3 5 | 1 1 1 1 1 1 1 1 6 | -------------------------------------------------------------------------------- /CodeForces/#126 (Div. 2) - B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | double s = 0; 9 | for (int i = 0; i < n; i++) { 10 | double _; 11 | cin >> _; 12 | s += _; 13 | } 14 | printf("%.12f", s / n); 15 | } 16 | -------------------------------------------------------------------------------- /CodeForces/#141 (Div. 2) - A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int arr[5], ans = 3; 7 | for (int _ = 0; _ < 4; _++) 8 | cin >> arr[_]; 9 | sort(arr, arr + 4); 10 | for (int _ = 0; _ < 3; _++) 11 | if (arr[_] != arr[_ + 1]) 12 | ans--; 13 | 14 | cout << ans << '\n'; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /CodeForces/#238 (Div. 2) - A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | while (T--) { 9 | int n, l, r, k, ans = 0; 10 | cin >> n >> l >> r >> k; 11 | int arr[n]; 12 | for (int _ = 0; _ < n; _++) 13 | cin >> arr[_]; 14 | sort(arr, arr + n); 15 | 16 | for (int _ = 0; _ < n; _++) { 17 | if (k < arr[_]) 18 | break; 19 | if (arr[_] > l && arr[_] < r) { 20 | ans++; 21 | k -= arr[_]; 22 | } 23 | } 24 | cout << ans << '\n'; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /CodeForces/#274 (Div. 2) - A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b, c; 7 | cin >> a >> b >> c; 8 | 9 | int ans = a + b + c; 10 | ans = max(ans, (a + b) * c); 11 | ans = max(ans, a * (b + c)); 12 | ans = max(ans, a * b * c); 13 | 14 | cout << ans << '\n'; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /CodeForces/486A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | long long n; 7 | cin >> n; 8 | if (n % 2 == 0) { 9 | cout << n / 2 << '\n'; 10 | } else { 11 | cout << -(n + 1) / 2 << '\n'; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /CodeForces/61A - Ultra-Fast Mathematician.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string s1, s2; 7 | cin >> s1 >> s2; 8 | for (int _ = 0; _ < s1.length(); _++) { 9 | if (s1[_] == s2[_]) 10 | s1[_] = '0'; 11 | else 12 | s1[_] = '1'; 13 | } 14 | cout << s1 << '\n'; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /CodeForces/Add to Neighbour and Remove.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define all(x) (x).begin(),(x).end() 3 | #define pb push_back 4 | #define mp make_pair 5 | #define ff first 6 | #define ss second 7 | 8 | using namespace std; 9 | using ull = unsigned long long; 10 | using ll = long long; 11 | 12 | inline void solve() { 13 | int n; 14 | cin >> n; 15 | vector a(n); 16 | ll sum = 0; 17 | for (ll &x: a) { 18 | cin >> x; 19 | sum += x; 20 | } 21 | for (int i = n; i >= 1; i--) { 22 | if (sum % i == 0) { 23 | ll aSum = sum / i; 24 | ll bSum = 0; 25 | bool ok = true; 26 | for (int j = 0; j < n; j++) { 27 | bSum += a[j]; 28 | if (bSum > aSum) { 29 | ok = false; 30 | break; 31 | } else if (bSum == aSum) { 32 | bSum = 0; 33 | } 34 | } 35 | if (ok) { 36 | cout << n - i << '\n'; 37 | return; 38 | } 39 | } 40 | } 41 | } 42 | 43 | int main() { 44 | int t; 45 | cin >> t; 46 | while (t--) 47 | solve(); 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /CodeForces/Anton and Danik.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | int a = 0, b = 0; 11 | string s; 12 | 13 | cin >> s >> s; 14 | for (int i = 0; i < s.length(); i++) { 15 | a += (s[i] == 'D'); 16 | b += (s[i] == 'A'); 17 | } 18 | if (a == b) 19 | cout << "Friendship" << '\n'; 20 | else if (a > b) 21 | cout << "Danik" << '\n'; 22 | else 23 | cout << "Anton" << '\n'; 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /CodeForces/Bear and Big Brother.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | int a, b, ans = 0; 11 | cin >> a >> b; 12 | while (a <= b) { 13 | a *= 3; 14 | b *= 2; 15 | ans++; 16 | } 17 | cout << ans << '\n'; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /CodeForces/Beautiful Year.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline bool isDistinct(int var1) { 6 | int arr[10] = {0}; 7 | while (var1 > 0) { 8 | arr[var1 % 10] += 1; 9 | if (arr[var1 % 10] > 1) { 10 | return false; 11 | } 12 | var1 /= 10; 13 | } 14 | return true; 15 | } 16 | 17 | int main() { 18 | ios_base::sync_with_stdio(false); 19 | cin.tie(0); 20 | cout.tie(0); 21 | 22 | int n; 23 | cin >> n; 24 | for (int _ = n + 1; ; _++) { 25 | if (isDistinct(_)) { 26 | cout << _ << '\n'; 27 | return 0; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /CodeForces/Boy or Girl.py: -------------------------------------------------------------------------------- 1 | print('CHAT WITH HER!') if len(set(input())) % 2 == 0 else print('IGNORE HIM!') 2 | -------------------------------------------------------------------------------- /CodeForces/Chat room.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | string valid = "hello", s; 11 | 12 | cin >> s; 13 | int j = 0; 14 | for (int i = 0; i < s.length(); i++) { 15 | if (s[i] == valid[j]) 16 | j++; 17 | if (j == 5) { 18 | cout << "YES" << '\n'; 19 | return 0; 20 | } 21 | } 22 | cout << "NO" << '\n'; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /CodeForces/Elephant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0); 8 | 9 | int n; 10 | cin >> n; 11 | 12 | cout << (n + 4) / 5 << '\n'; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /CodeForces/Even Odds.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | long long n, k; 7 | cin >> n >> k; 8 | if (k <= (n + 1) / 2) 9 | cout << k * 2 - 1 << '\n'; 10 | else 11 | cout << (k - (n + 1) / 2) * 2 << '\n'; 12 | return 0; 13 | } -------------------------------------------------------------------------------- /CodeForces/Favorite Sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define pb push_back 3 | #define ll long long 4 | 5 | using namespace std; 6 | 7 | inline void solve() { 8 | ll n; 9 | cin >> n; 10 | deque d; 11 | for (int i = 1, b; i <= n; i++) { 12 | cin >> b; 13 | d.pb(b); 14 | } 15 | for (int j = 1; j <= n; j++) { 16 | if (j % 2) 17 | cout << d.front() << " ", d.pop_front(); 18 | else 19 | cout << d.back() << " ", d.pop_back(); 20 | } 21 | cout << '\n'; 22 | } 23 | int main() { 24 | int t; 25 | cin >> t; 26 | 27 | while (t--) 28 | solve(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /CodeForces/George and Accommodation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | int a, b, ans = 0; 10 | while (n--) { 11 | cin >> a >> b; 12 | 13 | if (b - a >= 2) { 14 | ans++; 15 | } 16 | } 17 | cout << ans << '\n'; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /CodeForces/HQ9+.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | string s; 11 | cin >> s; 12 | 13 | for (int i = 0; i < s.length(); i++) if (s[i] == 'H' || s[i] == 'Q' || s[i] == '9') { 14 | cout << "YES" << '\n'; 15 | return 0; 16 | } 17 | cout << "NO" << '\n'; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /CodeForces/Hulk.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | for (int _ = 0; _ < n; _++) { 10 | if (_ % 2 == 0) 11 | cout << "I hate "; 12 | else 13 | cout << "I love "; 14 | if (_ != n - 1) 15 | cout << "that "; 16 | else 17 | cout << "it "; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CodeForces/In Search of an Easy Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, tot = 0; 7 | cin >> n; 8 | 9 | while (n--) { 10 | int a; 11 | cin >> a; 12 | tot += a; 13 | } 14 | if (tot) 15 | cout << "HARD" << '\n'; 16 | else 17 | cout << "EASY" << '\n'; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /CodeForces/Kefa and First Steps.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, ans = 1, count = 1; 7 | cin >> n; 8 | int arr[n]; 9 | for (int i = 0; i < n; i++) 10 | cin >> arr[i]; 11 | for (int i = 1; i < n; i++) { 12 | if (arr[i] >= arr[i - 1]) 13 | count++; 14 | else { 15 | ans = max(ans, count); 16 | count = 1; 17 | } 18 | } 19 | ans = max(ans, count); 20 | cout << ans << '\n'; 21 | } -------------------------------------------------------------------------------- /CodeForces/Last Year's Substring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define pb push_back 3 | #define mp make_pair 4 | #define ll long long 5 | 6 | using namespace std; 7 | 8 | inline void solve() { 9 | ll n; 10 | string a; 11 | cin >> n >> a; 12 | ll L = 0, R = 0; 13 | string x, y, p = "2020"; 14 | for (int i = 0; i < 4; i++) { 15 | x += a[i]; 16 | if (x == p.substr(0, i + 1)) 17 | L = i + 1; 18 | } 19 | for (int i = n - 1; i >= n - 4; i--) { 20 | y = a[i] + y; 21 | if (y == p.substr(4 - (n - i), (n - i))) 22 | R = n - i; 23 | } 24 | if (L + R >= 4) 25 | cout << "YES\n"; 26 | else 27 | cout << "NO\n"; 28 | } 29 | int main() { 30 | int t; 31 | cin >> t; 32 | while (t--) 33 | solve(); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /CodeForces/Lucky Division.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | int n; 11 | int arr[] = {4, 7, 44, 47, 77, 444, 447, 474, 477, 774, 747, 777}; 12 | cin >> n; 13 | 14 | for (int i = 0; i < 12; i++) { 15 | if (n % arr[i] == 0) { 16 | cout << "YES" << '\n'; 17 | return 0; 18 | } 19 | } 20 | while (n > 0) { 21 | if (n % 10 != 4 && n % 10 != 7) { 22 | cout << "NO" << '\n'; 23 | return 0; 24 | } 25 | n /= 10; 26 | } 27 | cout << "YES" << '\n'; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /CodeForces/Magnets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, ans = 0; 7 | cin >> n; 8 | int a[n]; 9 | for (int _ = 0; _ < n; _++) { 10 | cin >> a[_]; 11 | } 12 | for (int _ = 0; _ < n; _++) { 13 | if (a[_] != a[_ + 1]) 14 | ans++; 15 | } 16 | cout << ans << '\n'; 17 | return 0; 18 | } -------------------------------------------------------------------------------- /CodeForces/Nearly Lucky Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | long long int n; 11 | int ans = 0; 12 | 13 | cin >> n; 14 | 15 | while (n) { 16 | ans += (n % 10 == 7 || n % 10 == 4); 17 | n /= 10; 18 | } 19 | if (ans == 7 || ans == 4) 20 | cout << "YES" << '\n'; 21 | else 22 | cout << "NO" << '\n'; 23 | 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /CodeForces/Presents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, arr[101], tmp; 7 | cin >> n; 8 | for (int _ = 1; _ <= n; _++) { 9 | cin >> tmp; 10 | arr[tmp] = _; 11 | } 12 | for (int _ = 1; _ <= n; _++) 13 | cout << arr[_] << " "; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /CodeForces/Queue at the School.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | int t; 11 | string s; 12 | cin >> t >> t >> s; 13 | 14 | while (t--) 15 | for (int i = 0; i < s.length() - 1; i++) if (s[i] == 'B' && s[i + 1] == 'G') { 16 | swap(s[i], s[i + 1]); 17 | i++; 18 | } 19 | cout << s; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CodeForces/Remove Smallest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | vector vi; 6 | inline void solve() { 7 | int n; 8 | cin >> n; 9 | while (n--) { 10 | int tmp; 11 | cin >> tmp; 12 | vi.push_back(tmp); 13 | } 14 | sort(vi.begin(), vi.end()); 15 | for (int _ = 0; _ < vi.size() - 1; _++) { 16 | if (vi[_ + 1] - vi[_] > 1) { 17 | cout << "NO" << '\n'; 18 | vi.clear(); 19 | return; 20 | } 21 | } 22 | vi.clear(); 23 | cout << "YES" << '\n'; 24 | return; 25 | } 26 | int main() { 27 | ios::sync_with_stdio(false); 28 | cin.tie(0); 29 | 30 | int t; 31 | cin >> t; 32 | while (t--) 33 | solve(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /CodeForces/Replacing Elements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | cin >> T; 8 | while (T--) { 9 | int n, d; 10 | cin >> n >> d; 11 | vector a(n); 12 | for (int i = 0, tmp; i < n; i++) { 13 | cin >> tmp; 14 | a[i] = tmp; 15 | } 16 | sort(a.begin(), a.end()); 17 | cout << (a.back() <= d || a[0] + a[1] <= d ? "YES" : "NO") << '\n'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CodeForces/Soldier and Bananas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0); 8 | 9 | int k, n, w, total = 0; 10 | cin >> k >> n >> w; 11 | for (int i = 1; i <= w; i++) 12 | total += k * i; 13 | if (n >= total) 14 | cout << "0" << '\n'; 15 | else 16 | cout << abs(total - n) << '\n'; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /CodeForces/Stones on the Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0); 8 | 9 | int n, ans = 0; 10 | cin >> n; 11 | string s; 12 | cin >> s; 13 | for (int _ = 0; _ < s.length() - 1; _++) { 14 | if (s[_] == s[_ + 1]) 15 | ans++; 16 | } 17 | cout << ans << '\n'; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /CodeForces/Taxi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, s, count[5] = {0}; 7 | cin >> n; 8 | while (n--) { 9 | cin >> s; 10 | count[s]++; 11 | } 12 | int total = count[4] + count[3] + count[2] / 2; 13 | count[1] -= count[3]; 14 | if (count[2] % 2 == 1) { 15 | total += 1; 16 | count[1] -= 2; 17 | } 18 | if (count[1] > 0) 19 | total += (count[1] + 3) / 4; 20 | cout << total << '\n'; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /CodeForces/Tram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | int n, imax = -1, tot = 0; 11 | cin >> n; 12 | 13 | while (n--) { 14 | int a, b; 15 | cin >> a >> b; 16 | tot = tot - a + b; 17 | imax = max(imax, tot); 18 | } 19 | 20 | cout << imax << '\n'; 21 | } -------------------------------------------------------------------------------- /CodeForces/Translation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | string a, b; 11 | cin >> a >> b; 12 | for (int i = 0; i < a.length(); i++) if (a[i] != b[b.length() - i - 1]) { 13 | cout << "NO" << '\n'; 14 | return 0; 15 | } 16 | 17 | cout << "YES" << '\n'; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /CodeForces/Twins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0); 8 | 9 | int n, s = 0, a = 0, ans = 0; 10 | cin >> n; 11 | 12 | vector vi(n); 13 | for (int i = 0; i < n; i++) { 14 | cin >> vi[i]; 15 | s += vi[i]; 16 | } 17 | s /= 2; 18 | sort(vi.begin(), vi.end()); 19 | while (a <= s) { 20 | ++ans; 21 | a += vi[n - ans]; 22 | } 23 | cout << ans << '\n'; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /CodeForces/Unique Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define all(x) (x).begin(),(x).end() 3 | #define ll long long 4 | #define pb push_back 5 | #define mp make_pair 6 | #define ff first 7 | #define ss second 8 | 9 | using namespace std; 10 | 11 | inline void solve() { 12 | int x; 13 | cin >> x; 14 | vector ans; 15 | int sum = 0, last = 9; 16 | while (sum < x && last > 0) { 17 | ans.pb(min(x - sum, last)); 18 | sum += last; 19 | last--; 20 | } 21 | if (sum < x) { 22 | cout << -1 << "\n"; 23 | } else { 24 | reverse(all(ans)); 25 | for (int i : ans) 26 | cout << i; 27 | cout << '\n'; 28 | } 29 | } 30 | 31 | int main() { 32 | int t; 33 | cin >> t; 34 | while (t--) 35 | solve(); 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /CodeForces/Vanya and Fence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, h, ans = 0, tmp; 7 | cin >> n >> h; 8 | while (n--) { 9 | cin >> tmp; 10 | if (tmp > h) 11 | ans += 2; 12 | else 13 | ans++; 14 | } 15 | cout << ans << '\n'; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /CodeForces/Wizard of Orz.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | int n; 7 | cin >> n; 8 | string s = "989"; 9 | if (n <= 3) { 10 | cout << s.substr(0, n) << '\n'; 11 | return; 12 | } 13 | cout << s; 14 | for (int i = 3; i < n; i++) 15 | cout << (i - 3) % 10; 16 | cout << '\n'; 17 | } 18 | int main() { 19 | int T; 20 | cin >> T; 21 | 22 | while (T--) { 23 | solve(); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /CodeForces/Word Capitalization.py: -------------------------------------------------------------------------------- 1 | a = list(input()) 2 | print(a[0].upper()+''.join(a[1:])) 3 | -------------------------------------------------------------------------------- /CodeForces/Word.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(0); 7 | cin.tie(0); 8 | cout.tie(0); 9 | 10 | int low = 0, up = 0; 11 | string n, a, b; 12 | cin >> n; 13 | 14 | for (int i = 0; i < n.length(); i++) { 15 | char th = n[i]; 16 | if (th >= 'a' && th <= 'z') 17 | low++, a += th, b += (th - 32); 18 | else if (th >= 'A' && th <= 'Z') 19 | up++, b += th, a += (th + 32); 20 | } 21 | if (up <= low) 22 | cout << a << '\n'; 23 | else 24 | cout << b << '\n'; 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /CodeForces/Wrong Subtraction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0); 8 | 9 | int n, k; 10 | cin >> n >> k; 11 | while (k--) { 12 | if (n % 10 == 0) 13 | n /= 10; 14 | else 15 | n -= 1; 16 | } 17 | cout << n << '\n'; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /CodeForces/Yet Another String Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | inline void solve() { 6 | string s; 7 | cin >> s; 8 | 9 | for (int _ = 0; _ < s.length(); _++) { 10 | if (_ & 1) { 11 | if (s[_] == 'z') 12 | s[_] = 'y'; 13 | else 14 | s[_] = 'z'; 15 | } else { 16 | if (s[_] = 'a') 17 | s[_] = 'b'; 18 | else 19 | s[_] = 'a'; 20 | } 21 | } 22 | cout << s << '\n'; 23 | } 24 | 25 | int main() { 26 | int T; 27 | cin >> T; 28 | 29 | while (T--) 30 | solve(); 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /CodeForces/Young Physicist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0); 8 | 9 | int n, a = 0, b = 0, c = 0; 10 | cin >> n; 11 | while (n--) { 12 | int aa, bb, cc; 13 | cin >> aa >> bb >> cc; 14 | a += aa; b += bb; c += cc; 15 | } 16 | if (a == 0 && b == 0 && c == 0) 17 | cout << "YES" << '\n'; 18 | else 19 | cout << "NO" << '\n'; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CodeForces/cAPS lOCK.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | if len(s) > 1: 3 | if s.isupper(): print(s.lower()) 4 | elif s[1:].isupper(): print(s[0].upper() + s[1:].lower()) 5 | else: print(s) 6 | else: 7 | print(s.swapcase()) 8 | -------------------------------------------------------------------------------- /HackerRank/Data Structures/Print in Reverse.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution { 10 | 11 | static class SinglyLinkedListNode { 12 | public int data; 13 | public SinglyLinkedListNode next; 14 | 15 | public SinglyLinkedListNode(int nodeData) { 16 | this.data = nodeData; 17 | this.next = null; 18 | } 19 | } 20 | 21 | static class SinglyLinkedList { 22 | public SinglyLinkedListNode head; 23 | public SinglyLinkedListNode tail; 24 | 25 | public SinglyLinkedList() { 26 | this.head = null; 27 | this.tail = null; 28 | } 29 | 30 | public void insertNode(int nodeData) { 31 | SinglyLinkedListNode node = new SinglyLinkedListNode(nodeData); 32 | 33 | if (this.head == null) { 34 | this.head = node; 35 | } else { 36 | this.tail.next = node; 37 | } 38 | 39 | this.tail = node; 40 | } 41 | } 42 | 43 | public static void printSinglyLinkedList(SinglyLinkedListNode node, String sep) { 44 | while (node != null) { 45 | System.out.print(node.data); 46 | 47 | node = node.next; 48 | 49 | if (node != null) { 50 | System.out.print(sep); 51 | } 52 | } 53 | } 54 | 55 | static void reversePrint(SinglyLinkedListNode head) { 56 | if (head != null) { 57 | reversePrint(head.next); 58 | System.out.println(head.data); 59 | } 60 | 61 | } 62 | 63 | private static final Scanner scanner = new Scanner(System.in); 64 | 65 | public static void main(String[] args) { 66 | int tests = scanner.nextInt(); 67 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 68 | 69 | for (int testsItr = 0; testsItr < tests; testsItr++) { 70 | SinglyLinkedList llist = new SinglyLinkedList(); 71 | 72 | int llistCount = scanner.nextInt(); 73 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 74 | 75 | for (int i = 0; i < llistCount; i++) { 76 | int llistItem = scanner.nextInt(); 77 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 78 | 79 | llist.insertNode(llistItem); 80 | } 81 | 82 | reversePrint(llist.head); 83 | } 84 | 85 | scanner.close(); 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /HackerRank/Interview Preparation Kit/Arrays/2DArray-DS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define fori(x) for(int i = 0; i < (int) x; i++) 3 | #define forj(x) for(int j = 0; j < (int) x; j++) 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | short int n = 6, m = 6, mas[n][m]; 9 | fori (6) forj(6) cin >> mas[i][j]; 10 | short int imax = mas[0][0] + mas[0][1] + mas[0][2] + mas[1][1] + mas[2][0] + mas[2][1] + mas[2][2]; 11 | fori (n - 2) 12 | forj (m - 2) { 13 | short int all = mas[i][j] + mas[i][j+1] + mas[i][j+2] + mas[i+1][j+1] + mas[i+2][j] + mas[i+2][j+1] + mas[i+2][j+2]; 14 | imax = (all > imax ? all : imax); 15 | } 16 | cout << imax << '\n'; 17 | } 18 | -------------------------------------------------------------------------------- /HackerRank/Interview Preparation Kit/Arrays/ArrayManipulation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | long int N, K, p, q, sum, i, max = 0, x = 0; 7 | cin >> N >> K; 8 | long int *a = new long int[N + 1](); 9 | 10 | for (i = 0; i < K; i++) { 11 | cin >> p >> q >> sum; 12 | a[p] += sum; 13 | if (q + 1 <= N) 14 | a[q + 1] -= sum; 15 | } 16 | for (i = 1; i <= N; i++) { 17 | x += a[i]; 18 | if (max < x) 19 | max = x; 20 | } 21 | cout << max << '\n'; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /HackerRank/Interview Preparation Kit/Arrays/ArraysLeftRotation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long int lli; 6 | 7 | vector v; 8 | lli n, d, a, shift; 9 | 10 | int main(){ 11 | cin >> n >> d; 12 | a = n; 13 | while (a--) { 14 | lli number; 15 | cin >> number; 16 | v.push_back(number); 17 | } 18 | if (n == d) 19 | for (lli i = 0; i < v.size(); i++) 20 | cout << v[i] << " "; 21 | else if(n % d == 0){ 22 | shift = n - d; 23 | for (lli i = shift; i < v.size(); i++) 24 | cout << v[i] << " "; 25 | for (lli i = 0; i < shift; i++) 26 | cout << v[i] << " "; 27 | } 28 | else if (n > d) { 29 | shift = d; 30 | for (lli i = shift; i < v.size(); i++) 31 | cout << v[i] << " "; 32 | for (lli i = 0; i < shift; i++) 33 | cout << v[i] << " "; 34 | } 35 | else if (n < d) { 36 | shift = d % n; 37 | for (lli i = shift; i < v.size(); i++) 38 | cout << v[i] << " "; 39 | for(lli i = 0; i < shift; i++) 40 | cout << v[i] << " "; 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /HackerRank/Interview Preparation Kit/Arrays/MinimumSwaps2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int a[100005]; 6 | bool visited[100005]; 7 | 8 | int solve (int n) { 9 | pair p[n]; 10 | for (int i = 0; i < n; i++) { 11 | p[i].first = a[i]; 12 | p[i].second = i; 13 | } 14 | sort(p, p+n); 15 | int ans = 0; 16 | for (int i = 0; i < n; i++) { 17 | if (visited[i] || p[i].second == i) 18 | continue; 19 | int cycle_size = 0; 20 | int j = i; 21 | while (!visited[j]) { 22 | visited[j] = 1; 23 | j = p[j].second; 24 | cycle_size++; 25 | } 26 | ans += (cycle_size - 1); 27 | } 28 | return ans; 29 | } 30 | 31 | int main() { 32 | int n; 33 | scanf("%d", &n); 34 | for (int i = 0; i < n; i++) 35 | scanf("%d", &a[i]); 36 | int ans = solve(n); 37 | printf("%d\n", ans); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /HackerRank/Interview Preparation Kit/Warm-up Challenges/Counting Valleys.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, i, s = 0, k = 0; 7 | char c; 8 | cin >> n; 9 | for (i = 0; i < n; i++) { 10 | cin >> c; 11 | if (c == 'U') 12 | k++; 13 | else 14 | k--; 15 | if (k == 0 && c == 'U') 16 | s++; 17 | } 18 | cout << s << '\n'; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /HackerRank/Interview Preparation Kit/Warm-up Challenges/Jumping on the Clouds.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | class Solution { 10 | private static final Scanner in = new Scanner(System.in); 11 | public static void main (String[] args) { 12 | int n = in.nextInt(); 13 | int c[] = new int[n]; 14 | for (int i = 0; i < n; i++) 15 | c[i] = in.nextInt(); 16 | int count = 0; 17 | int i = 0; 18 | while (i < n - 1) { 19 | if (i < n - 2 && c[i + 2] == 0) 20 | i++; 21 | count++; 22 | i++; 23 | } 24 | System.out.println(count); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /HackerRank/Interview Preparation Kit/Warm-up Challenges/Repeated String.py: -------------------------------------------------------------------------------- 1 | s, n = input().strip(), int(input().strip()) 2 | a_count = s.count('a') 3 | total = n % len(s) 4 | l = n // len(s) 5 | if n is 0: 6 | print(a_count * l) 7 | else: 8 | b = 0 9 | for i in range(0, total): 10 | if s[i] is 'a': 11 | b = b + 1 12 | print(int(a_count * l + b)) 13 | 14 | -------------------------------------------------------------------------------- /HackerRank/Interview Preparation Kit/Warm-up Challenges/Sock Merchant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | vector myInt; 8 | cin >> n; 9 | while (n--) { 10 | int a; 11 | cin >> a; 12 | myInt.push_back(a); 13 | } 14 | int counter = 0; 15 | for (int i = 0 ; i < myInt.size(); i++) 16 | for (int j = i + 1 ; j < myInt.size(); j++) 17 | if (myInt[i] == myInt[j]) { 18 | counter++; 19 | myInt.erase(myInt.begin() + j); 20 | break; 21 | } 22 | cout << counter << '\n'; 23 | } 24 | -------------------------------------------------------------------------------- /HackerRank/Mathematics/Handshake.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | import sys 5 | 6 | # 7 | # Complete the handshake function below. 8 | # 9 | def handshake(n): 10 | return ((n - 1) * n) // 2 11 | 12 | if __name__ == '__main__': 13 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 14 | 15 | t = int(input()) 16 | 17 | for t_itr in range(t): 18 | n = int(input()) 19 | 20 | result = handshake(n) 21 | 22 | fptr.write(str(result) + '\n') 23 | 24 | fptr.close() 25 | -------------------------------------------------------------------------------- /HackerRank/Mathematics/Minimum Height Triangle.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | 5 | def lowestTriangle(base, area): 6 | # Complete this function 7 | return 2 * area // base + bool((2 * area) % base) 8 | 9 | base, area = input().strip().split(' ') 10 | base, area = [int(base), int(area)] 11 | height = lowestTriangle(base, area) 12 | print(height) -------------------------------------------------------------------------------- /HackerRank/Python/Incorrect Regex.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | for _ in range(int(input())): 4 | try: 5 | re.compile(input()) 6 | print('True') 7 | except: 8 | print('False') 9 | -------------------------------------------------------------------------------- /Kickstart/Round A 2021/K-Goodness String.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | inline int solve() { 7 | int n, k, score = 0; 8 | string s; 9 | 10 | cin >> n >> k >> s; 11 | 12 | for (int i = 0; i < n / 2; ++i) { 13 | if (s[i] != s[n - 1 - i]) { 14 | score++; 15 | } 16 | } 17 | return abs(score - k); 18 | } 19 | 20 | int main() { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | 24 | int T, i = 1; 25 | cin >> T; 26 | 27 | while (T--) { 28 | cout << "Case #" << i++ << ": " << solve() << '\n'; 29 | } 30 | } -------------------------------------------------------------------------------- /Kickstart/Round A 2021/L Shaped Plots.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | const int MAXN = 1100; 6 | 7 | int R, C; 8 | int v[MAXN][MAXN]; 9 | int ps[MAXN][MAXN][4]; 10 | 11 | int xc[4] = {-1, 1, 0, 0}; 12 | int yc[4] = {0, 0, -1, 1}; 13 | 14 | inline void solve() { 15 | cin >> R >> C; 16 | for (int i = 1; i <= R; i++) 17 | for (int j = 1; j <= C; j++) 18 | cin >> v[i][j]; 19 | 20 | for (int i = 0; i < MAXN; i++) 21 | for (int j = 0; j < MAXN; j++) 22 | for (int k = 0; k < 4; k++) 23 | ps[i][j][k] = 0; 24 | 25 | for (int i = 1; i <= R; i++) 26 | for (int j = 1; j <= C; j++) { 27 | if (v[i][j]) { 28 | ps[i][j][0] = 1 + ps[i-1][j][0]; 29 | ps[i][j][2] = 1 + ps[i][j-1][2]; 30 | } 31 | } 32 | 33 | for (int i = R; i >= 1; i--) 34 | for (int j = C; j >= 1; j--) { 35 | if (v[i][j]) { 36 | ps[i][j][1] = 1 + ps[i+1][j][1]; 37 | ps[i][j][3] = 1 + ps[i][j+1][3]; 38 | } 39 | } 40 | 41 | int ans = 0; 42 | for (int i = 1; i <= R; i++) 43 | for (int j = 1; j <= C; j++) { 44 | for (int k = 0; k < 2; k++) 45 | for (int l = 2; l < 4; l++) { 46 | int x = ps[i][j][k]; 47 | int y = ps[i][j][l]; 48 | 49 | ans += max (0, (min (x, y / 2) - 1)); 50 | ans += max (0, (min (y, x / 2) - 1)); 51 | } 52 | } 53 | cout << ans << "\n"; 54 | } 55 | 56 | int main() { 57 | ios_base::sync_with_stdio(0); 58 | 59 | int T; 60 | cin >> T; 61 | for (int i = 0; i < T; i++) { 62 | cout << "Case #" << i + 1 << ": "; 63 | solve(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Kickstart/template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | inline void solve() { 7 | 8 | } 9 | 10 | int main() { 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int T, i = 1; 15 | cin >> T; 16 | 17 | while (T--) { 18 | cout << "Case #" << i++ << ": " << solve() << '\n'; 19 | } 20 | } -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Check If N and Its Double Exist.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkIfExist(vector& arr) { 4 | for (int i = 0; i < arr.size(); i++) { 5 | for (int j = 0; j < arr.size(); j++) { 6 | if (i == j) { 7 | continue; 8 | } 9 | if (arr[i] * 2 == arr[j]) { 10 | return true; 11 | } 12 | } 13 | } 14 | return false; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Duplicate Zeros.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void duplicateZeros(vector& arr) { 4 | int possibleDups = 0; 5 | int length_ = arr.size() - 1; 6 | for (int left = 0; left <= length_ - possibleDups; left++) { 7 | if (arr[left] == 0) { 8 | if (left == length_ - possibleDups) { 9 | arr[length_] = 0; 10 | length_ -= 1; 11 | break; 12 | } 13 | possibleDups++; 14 | } 15 | } 16 | int last = length_ - possibleDups; 17 | for (int i = last; i >= 0; i--) { 18 | if (arr[i] == 0) { 19 | arr[i + possibleDups] = 0; 20 | possibleDups--; 21 | arr[i + possibleDups] = 0; 22 | } else { 23 | arr[i + possibleDups] = arr[i]; 24 | } 25 | } 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Find Numbers with Even number of Digits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findNumbers(vector &nums) { 4 | int ans = 0; 5 | for (int _ = 0; _ < nums.size(); _++) { 6 | int digits = 0; 7 | while (nums[_] > 0) { 8 | digits++; 9 | nums[_] /= 10; 10 | } 11 | ans += (digits % 2 == 0); 12 | } 13 | return ans; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Max Consecutive Ones.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findMaxConsecutiveOnes(vector& nums) { 4 | int imax = 0, current = 0; 5 | for (int _ = 0; nums.size(); _++) { 6 | if (nums[_] == 1) current++; 7 | else { 8 | imax = max(imax, current); 9 | current = 0; 10 | } 11 | return max(imax, current); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Merge Sorted Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void merge(vector& nums1, int m, vector& nums2, int n) { 4 | int last = m + n - 1; 5 | int i = m-1; 6 | int j = n-1; 7 | while(i >= 0 && j >= 0) 8 | nums1[last--] = nums1[i] > nums2[j] ? nums1[i--] : nums2[j--]; 9 | while(i >= 0) 10 | nums1[last--] = nums1[i--]; 11 | while(j >= 0) 12 | nums1[last--] = nums2[j--]; 13 | } 14 | }; -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Remove Duplicates from Sorted Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | if (nums.size() == 0) return 0; 5 | int i = 0; 6 | for (int j = 1; j < nums.size(); j++) { 7 | if (nums[j] != nums[i]) { 8 | i++; 9 | nums[i] = nums[j]; 10 | } 11 | } 12 | return i + 1; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Remove Element.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeElement(vector& nums, int val) { 4 | int _ = 0, n = nums.size(); 5 | while (_ < n) { 6 | if (nums[_] == val) { 7 | nums[_] = nums[n- 1]; 8 | n--; 9 | } else _++; 10 | } 11 | return n; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Replace Elements with Greatest Element on Right Side.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector replaceElements(vector& arr) { 4 | for (int i = 0; i < arr.size() - 1; i++) { 5 | int imax = arr[i + 1]; 6 | for (int j = i + 1; j < arr.size(); j++) { 7 | imax = max(imax, arr[j]); 8 | } 9 | arr[i] = imax; 10 | } 11 | arr[arr.size() - 1] = -1; 12 | return arr; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Squares of a Sorted Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sortedSquares(vector& nums) { 4 | for (int _ = 0; _ < nums.size(); _++) nums[_] = pow(nums[_], 2); 5 | sort(nums.begin(), nums.end()); 6 | return nums; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /LeetCode/Explore/Array/Valid Mountain Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool validMountainArray(vector& arr) { 4 | int n = arr.size(), i = 0, j = n - 1; 5 | while (i + 1 < n && arr[i] < arr[i + 1]) i++; 6 | while (j > 0 && arr[j - 1] > arr[j]) j--; 7 | return i > 0 && i == j && j < n - 1; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /LeetCode/LongestSubstringWithoutRepeatingCharacters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int lengthOfLongestSubstring(string s) { 8 | int l = 0, len = 0; 9 | map dict; 10 | for (int r = 0; r < s.size(); r++) { 11 | if (dict.find(s[r]) != dict.end()) { 12 | l = max(l, dict[s[r]] + 1); 13 | } 14 | dict[s[r]] = r; 15 | len = max(len, r - l + 1); 16 | } 17 | return len; 18 | } 19 | }; 20 | int main() { 21 | Solution sol; 22 | cout << sol.lengthOfLongestSubstring("abcabcbb") << '\n'; 23 | cout << sol.lengthOfLongestSubstring("bbbbb") << '\n'; 24 | cout << sol.lengthOfLongestSubstring("pwwkew") << '\n'; 25 | } 26 | -------------------------------------------------------------------------------- /LeetCode/Remove Duplicates from Sorted Array II.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ByamB4/Algorithm-Programming-Solutions/dce2c73e28e5f1c8a178fcfd4afc37c154a1b0e5/LeetCode/Remove Duplicates from Sorted Array II.cpp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Logo 4 | 5 | 6 |

Competitive Programming

7 | 8 |

9 | Mostly self learning, code snippets and archive CP contests 10 |
11 |
12 | CodeChef 13 | · 14 | LeetCode 15 | · 16 | HackerRank 17 | . 18 | CodeForces 19 |

20 |

21 | 22 | -------------------------------------------------------------------------------- /public/img/algorithm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ByamB4/Algorithm-Programming-Solutions/dce2c73e28e5f1c8a178fcfd4afc37c154a1b0e5/public/img/algorithm.png -------------------------------------------------------------------------------- /public/script/commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git add . 4 | git commit --allow-empty-message -m '' 5 | git push origin master 6 | -------------------------------------------------------------------------------- /template.cpp: -------------------------------------------------------------------------------- 1 | // Last updated: 2020-06-01 2 | #include 3 | #define rep(i, n) for(int i = 0; i < (n); ++i) 4 | #define all(x) (x).begin(),(x).end() 5 | #define pb push_back 6 | #define mp make_pair 7 | #define ff first 8 | #define ss second 9 | 10 | using namespace std; 11 | using ull = unsigned long long; 12 | using ll = long long; 13 | 14 | const ll INF = ll(1e18) + 1; 15 | 16 | int main() { 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | return 0; 21 | } 22 | --------------------------------------------------------------------------------