Skip to content

Instantly share code, notes, and snippets.

const int base = 1000000000; const int base_digits = 9;
struct bigint {
vector<int> a; int sign;
bigint() :
sign(1) {
}
bigint(long long v) {
*this = v;
#include <bits/stdc++.h>
#ifdef __mr__
#include "prettyprint.hpp"
#else
#define endl '\n'
#endif
#define len(x) (uint)(x).size()
#define int int32_t
#define uint uint32_t
#define ulong uint64_t
from sys import stdin
from heapq import heappop, heappush, heapify
from collections import defaultdict
class unionfind(object):
def __init__(self, n):
self._number_of_nodes, self._count = n, n
self.roots, self.weights = list(xrange(n)), [1]*n
def union(self, a, b):
@zsrinivas
zsrinivas / deadpool.cpp
Created February 24, 2016 08:31
deadpool
#include <bits/stdc++.h>
using namespace std;
#define DIM 1024
#define _sq(x) ((x) * (x)) // square
unsigned char RD(int i, int j) {
return (char)(_sq(cos(atan2(j-256, i-256)/2))*255);
@zsrinivas
zsrinivas / ubuntu-gnome-16.04-setup.txt
Last active March 27, 2017 13:45
todo: after installing ubuntu-gnome-16.04
## ☐ ☑ ☒
☐ enable partner repositories
☐ install y-ppa-manager
☐ % sudo add-apt-repository -y ppa:webupd8team/y-ppa-manager
☐ % sudo apt-get update
☐ % sudo apt-get install y-ppa-manager
☐ media
☐ install vlc
print '<html>hey</html>'
@zsrinivas
zsrinivas / handle_exception.py
Created February 9, 2016 08:25
rarely used python exception handling pattern.
import webbrowser
try:
1 / 0
except Exception as e:
webbrowser.open(
'http://stackoverflow.com/search?q=[python]+' + \
'+'.join(e.args + (type(e).__name__,)))
@zsrinivas
zsrinivas / hr-city.py
Created February 2, 2016 05:45
HourRank5 - HR City
n = int(raw_input())
d = map(int, raw_input().split())
dist, coun, cdis, corn = [0]*(n + 1), [1]*(n + 1), [0]*(n + 1), [0]*(n + 1)
for x in xrange(1, n + 1):
dist[x] = (4 * dist[x - 1] + coun[x - 1] * (16 * coun[x - 1] * d[x - 1] + 12 * cdis[x - 1]) + 8 * cdis[x - 1] + 12 * coun[x - 1] * d[x - 1] + d[x - 1]) % 1000000007
coun[x] = (4 * coun[x - 1] + 2) % 1000000007
cdis[x] = (4 * cdis[x - 1] + coun[x - 1] * 8 * d[x - 1] + 3 * coun[x - 1] * corn[x - 1] + 3 * d[x - 1] + 2 * corn[x - 1]) % 1000000007
corn[x] = (2 * corn[x - 1] + 3 * d[x - 1]) % 1000000007
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <sys/types.h>
@zsrinivas
zsrinivas / subst1.cc
Created January 15, 2016 17:26
spoj subst1
#include <bits/stdc++.h>
#ifdef __mr__
#include "prettyprint.hpp"
#endif
#define endl ('\n')
#define i32inf (0x7fffffff)
#define i32_inf (-0x7fffffff-1)
#define i64inf (0x7fffffffffffffff)
#define i64_inf (-0x7fffffffffffffff-1)
#define ui32inf (0xffffffffu)