Problem      Given four lists A, B, C, D of integer values, compute how many tuples   (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.      To make problem a bit easier, all A, B, C, D have same length of N   where \$0 \le N \le 500\$. All integers are in the range of \$-2^{28}\$ to \$2^{28} - 1\$   and the result is guaranteed to be at most \$2^{31} - 1\$.      Example:      Input:  A = [ 1, 2] B = [-2,-1] C = [-1, 2] D = [ 0, 2]       Output:  2       Explanation:      The two tuples are:         (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0   (1, 1, 0, 0) -> A[1] + B[1] + C[0] + D[0] = 2 + (-1) + (-1) + 0 = 0      I'm wondering if there are any ideas to have a solution less than \$O(n^2)\$ time complexity.  from collections import defaultdict def build_sum_map(list1, list2, sum_map):     for index_i, i in enumerate(list1):         if i &gt; 0 and list1[index_i] == list1[index_i-1]:             continue         for index_j, j in enumerate(list2):             if j &gt; 0 and list2[index_j] == list2[index_j-1]:                 continue             sum_map[i+j].append((i,j))  def combine_sum(sum_map1, sum_map2, result):     for k,v in sum_map1.items():         if -k in sum_map2:             for i in v:                 for j in sum_map2[-k]:                     result.append(i+j)  if __name__ == "__main__":     sum_map1 = defaultdict(list)     sum_map2 = defaultdict(list)     build_sum_map([1, 2], [-2,-1], sum_map1)     build_sum_map([-1, 2], [ 0, 2], sum_map2)     result = []     combine_sum(sum_map1, sum_map2, result)     print result
This is a continued discussion from () by return count only.     Problem      Given four lists A, B, C, D of integer values, compute how many tuples   (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.      To make problem a bit easier, all A, B, C, D have same length of N   where \$0 \le N \le 500\$. All integers are in the range of \$-2^{28}\$ to \$2^{28} - 1\$   and the result is guaranteed to be at most \$2^{31} - 1\$.      Example:      Input:  A = [ 1, 2] B = [-2,-1] C = [-1, 2] D = [ 0, 2]       Output:  2       Explanation:      The two tuples are:         (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0   (1, 1, 0, 0) -> A[1] + B[1] + C[0] + D[0] = 2 + (-1) + (-1) + 0 = 0      I'm wondering if there are any ideas to have a solution less than \$O(n^2)\$ time complexity.  Source code in Python 2.7,  from collections import defaultdict def four_sum(A, B, C, D):     sum_map = defaultdict(int)     result = 0     for i in A:         for j in B:             sum_map[i+j] += 1     for i in C:         for j in D:             if -(i+j) in sum_map:                 result += sum_map[-(i+j)]      return result  if __name__ == "__main__":     A = [1, 2]     B = [-2, -1]     C = [-1, 2]     D = [0, 2]     print four_sum(A,B,C,D)
I can't seem to find an answer to this simple question, which I need for some compliance documentation.    On a default install of CentOS 6.5 (OpenSSH 5.3p1-94.el6), after how long of being idle will a user's SSH session be terminated?  I believe the following can be set to increase the idle timeout, but they are commented out by default.  $ grep -i alive /etc/ssh/sshd_config #TCPKeepAlive yes #ClientAliveInterval 0 #ClientAliveCountMax 3   Also, is there a command to dump a list of the current sshd settings?  I don't see anything in man sshd. Using fflush(stdin) Don't show pending suggested edits to me after I run out of votes After upgrading to 12.04 from 10.04, can't login to PHPMYADMIN Prove that the multiplicative groups $\mathbb{R} - \{0\}$ and $\mathbb{C} - \{0\}$ are not isomorphic. Is my proof correct? I have made use of the fact isomorphism preserves order of elements, which I proved couple of exercises back. I am also interested in other ways of proving it. Is there a more explicit way or is this explicit enough?    Problem Prove that the multiplicative groups $\mathbb{R} - \{0\}$ and $\mathbb{C} - \{0\}$ are not isomorphic.  Solution Recall that isomorphism preserves order of elements and hence if there exists an isomorphism from $\phi: \mathbb{C}-\{0\} \mapsto \mathbb{R}-\{0\}$, then $x \in \mathbb{C} - \{0\}$, and $\phi(x) \in \mathbb{R} - \{0\}$, then $\vert x \vert = \vert \phi(x) \vert$. Now note that the element $i \in \mathbb{C} - \{0\}$ has order $4$. However, no element in $\mathbb{R}-\{0\}$ has order $4$. Hence, no isomorphism can exist. Hence, the multiplicative groups $\mathbb{R} - \{0\}$ and $\mathbb{C} - \{0\}$ are not isomorphic.    Thanks Changing background color to transparent in GeoServer? How to set the background color to transparent. I want use style which describe in *.sld file for all my photo with tif format. How to do that? I am nearing the end of my PhD and I would quite like to buy a "thank you" gift for my supervisor (although, she's the socially awkward type who I'm sure will be greatly embarrassed to receive one).  I'm just wondering whether a gift is the done thing? And if so, what sort of gift seems appropriate? I suppose a bottle of wine would be a safe choice? Multi-partition multi OS bootable USB I want to create a recovery flash drive. I have my 8 gb flash drive[Kingston data traveller] with me. I also have the required .iso files for a>Ubuntu 13.10 b>Boot-repair disk c>AVG Rescue CD  I Wish to create 4 partitions(3 for each bootable .iso and one for data storage. Also, I want a way in which I can select which OS to boot each time I boot from USB.   So, is there a way to install GRUB on USB as well as the three other live distros? And how to create such a setup? How was this character poisoned in Warcraft? In Warcraft, towards the end of movie we observe the Guardian Medivh changing sides and starting to emit green light instead of blue. I might have missed that part or misunderstood but how exactly did he get poisoned? Central Moments of Symmetric Distributions I am trying to show that the central moment of a symmetric distribution:     $${\bf f}_x{\bf (a+x)} = {\bf f}_x{\bf(a-x)}$$ is zero for odd numbers. So for instance the third central moment $${\bf E[(X-u)^3] = 0}.$$ I started by trying to show that $${\bf E[(X-u)^3] = E[X^3] -3uE[X^2] + 3u^2E[X] - u^3}.$$ I am not sure where to go from here, any suggestions? Is there a better way to go about proving this? Is there a reason why we gain ghost reputation on the meta of an SE website? I'm DM'ing a play-by-post campaign and I'm at a point in the adventure where the group all meets for the first time. They've all had something stolen from them at the same time and saw a creature that took something run into a nearby alley (there's three separate parties within the play group currently, as they've only just started, so there's three separate robbers running into alleys in the marketplace).  Ideally, I want the players to have their PCs all give chase so they end up in the same part of town, all looking for the same thing. However, I don't want to railroad my players into doing this. I know I'm not supposed to take away player agency or narrate their actions for them, but the only way I could think of was to tell them that they start giving chase.  So how would you deal with this situation? And more broadly, how can I stop something like this happening again?  If it matters, we're currently playing D&amp;D 5e. Word for a male that prefers female companions (no slang such as "pimp") so there are some idiosyncrasies with the method they use to invert that part of the image which I can't figure out. It could be that they just invert the luminosity but I don't know how i would do that in a dynamic way. Sharing Jupyter notebooks within a team I would like to set up a server which could support a data science team in the following way: be a central point for storing, versioning, sharing and possible also executing Jupyter notebooks.  Some desired properties:   Different users can access the server and open and execute notebooks that were stored by them or by other team members. The interesting question here is what would be the behavior if user X executes cells in a notebook authored by user Y. I guess the notebook should NOT be changed: Solution should be self-hosted. Notebooks should be stored either on the server or on Google drive or on self-hosted instance of owncloud. (Bonus) Notebooks will be under git versioning control (git may be self-hosted. Cannot be bounded to GitHub or something of that sort).   I looked into  and . With the former, I didn't understand how to allow cross users access. The latter seems to only support GitHub as the storage of the notebooks.  Do you have experience with either of the solutions? How do I recover my accidentally lost Windows partitions after installing Ubuntu? How do I make the method return type generic? Consider this example (typical in OOP books):    I have an Animal class, where each Animal can have many friends. And subclasses like Dog, Duck, Mouse etc which add specific behavior like bark(), quack() etc.  Here's the Animal class:  public class Animal {     private Map&lt;String,Animal&gt; friends = new HashMap&lt;&gt;();      public void addFriend(String name, Animal animal){         friends.put(name,animal);     }      public Animal callFriend(String name){         return friends.get(name);     } }   And here's some code snippet with lots of typecasting:  Mouse jerry = new Mouse(); jerry.addFriend("spike", new Dog()); jerry.addFriend("quacker", new Duck());  ((Dog) jerry.callFriend("spike")).bark(); ((Duck) jerry.callFriend("quacker")).quack();   Is there any way I can use generics for the return type to get rid of the typecasting, so that I can say      jerry.callFriend("spike").bark(); jerry.callFriend("quacker").quack();   Here's some initial code with return type conveyed to the method as a parameter that's never used.   public&lt;T extends Animal&gt; T callFriend(String name, T unusedTypeObj){     return (T)friends.get(name);         }   Is there a way to figure out the return type at runtime without the extra parameter using instanceof? Or at least by passing a class of the type instead of a dummy instance. I understand generics are for compile time type-checking, but is there a workaround for this? Removing files with strange names Possible Duplicate:          Somehow I ended up with a file named "-r".  How do I remove it?  rm -r doesn't work.  I tried 'rm -i `ls -a`' to step through the file names, but it didn't prompt me to delete this one.  Edit A very hacky approach was to use python's os.unlink function.  That worked, but I'm curious to hear other ways. Name for these kinds of "sayings"? Hyperref "enquotes" metadata