public static int solve(int x, int y, int time, Set<Gem> gems, int gain, int max) {
			if(time == 0) return gain;
			else {
				Set<Gem> nGems = new HashSet<Gem>();
				for(Gem m : gems) {
					if(distance(x, y, m) <= time) nGems.add(m);
				}
				gems = nGems;
				if(gems.isEmpty()) return gain;
				else {
					for(Gem m : gems) {
						Set<Gem> s = new HashSet<Gem>(gems);
						s.remove(m);
						if(max < better(m.x,m.y,s,time-distance(x,y,m))+m.value+gain) {
							max = Math.max(max, solve(m.x,m.y,time-distance(x,y,m),
									s,gain+m.value,max));
							
						}	
					}
					return max;
				}
			}
		}