akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N;
    cin >> N;

    vector<int> h, a;
    inputVector(h, N);
    inputVector(a, N);

    set<pair<int, int>> prs;    // height, sum of beauty
    prs.insert(mp(0, 0));

    int ret = 0;
    rep(i, N) {
        //cerr << "i:" << i << endl;
        auto it = prs.lower_bound(mp(h[i], -1));
        it--;
        int val = it->second + a[i];
        //cerr << " found:(" << it->first << ", " << it->second << ")" << endl;
        //cerr << " val:" << val << endl;
        ret = max(ret, val);

        vector<pair<int, int>> er;
        it++;
        while (it != prs.end() && it->second <= val) {
            er.push_back(*it);
            it++;
        }

        for (auto pr : er) {
            prs.erase(pr);
        }

        prs.insert(mp(h[i], val));

        //cerr << " ";
        //for (auto pr : prs) cerr << "(" << pr.first << ", " << pr.second << "),";
        //cerr << endl;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

template<int MOD>
struct ModInt {
   using Mint = ModInt;
   int val;
   ModInt(ll __val = 0) { fix(__val % MOD + MOD); }
   Mint& fix(int __val) { val = __val; if (val >= MOD) val -= MOD; return *this; }
   explicit operator int() { return val; }
   Mint operator + (const Mint &mt) const { return Mint().fix(val + mt.val); }
   Mint operator - (const Mint &mt) const { return Mint().fix(val - mt.val + MOD); }
   Mint operator * (const Mint &mt) const { return Mint().fix(ll(val) * mt.val % MOD + MOD); }
   Mint& operator += (const Mint &mt) { return *this = *this + mt; }
   Mint& operator -= (const Mint &mt) { return *this = *this - mt; }
   Mint& operator *= (const Mint &mt) { return *this = *this * mt; }
   Mint pow(int y) const {
      Mint x = *this;
      Mint ans(1);
      for (; y > 0; y >>= 1, x *= x) {
         if (y & 1) ans *= x;
      }
      return ans;
   }
   Mint operator -() const { return Mint().fix(MOD - val); }
   Mint inv() const { return pow(MOD - 2); }
   Mint operator / (const Mint &mt) const { return *this * mt.inv(); }
   Mint& operator /= (const Mint &mt) const { return *this / mt; }
   friend ostream& operator<<(ostream& os, const Mint& mt) { return os << mt.val; }
};

using Mint = ModInt<1000000007>;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N, M;
   cin >> N >> M;
   vector<Mint> dp(M + 1);
   dp[M] = 1;
   for (int b = N - 1; b >= 0; --b) {
      vector<Mint> ndp(M + 1);
      Mint tot = 0;
      for (int i = M; i >= 0; --i) {
         ndp[i] = dp[i] * (i + 1) + tot * i;
         tot = tot + tot + dp[i];
      }
      dp = move(ndp);
   }
   Mint ans = 0;
   for (auto v : dp) ans += v;
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  bool ans = false;
  rep(i, n) {
    char c;
    cin >> c;
    if(c == 'Y') ans = true;
  }
  cout << (ans ? "Four" : "Three") << endl;
}

Measured memory_bytes: 3620
n=int(input())
x=list(map(int,input().split()))
l=min(x)
r=max(x)
cost=[]
for i in range(l,r+1):
    curcost=0
    for j in range(n):
        curcost+=(x[j]-i)**2
    cost.append(curcost)
print(min(cost))

Measured memory_bytes: 9176
n = int(input())
a = list(map(int,input().split()))

a.sort()

def mod():
    for i in range(1, len(a)):
        # print("--------")
        # print(a[i])
        # print(a[i] % a[0])
        # print("--------")
        if(a[i] % a[0] != 0):
            a[i] = a[i] % a[0]
        else:
            a[i] = a[0]
        # print(a[i])
    a.sort()
    return a

# for i in range(4):
#     a = mod()
#     print(a)

while(a.count(a[0]) != len(a)):
    a = mod()
    # print(a)

print(a[0])

Measured memory_bytes: 20008
using System;
using System.Linq;
 
public class Program
{
  public static void Main()
  {
    var inputs = Console.ReadLine().Split(' ')
      							   .Select(long.Parse)
      							   .ToList();
    var n = inputs[0];
    var k = inputs[1];
    
    var remainder = Math.Abs(n) % k;
    var answer = Math.Min(remainder, Math.Abs(remainder - k));
    Console.WriteLine(answer);
  }
}

Measured memory_bytes: 28100
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

int main(){
  int N,D;  cin >> N >> D;
  vector<vector<int> >X(N,vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin >> X.at(i).at(j);
    }
  }
  int ans = 0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      double distance = 0;
      for(int k=0;k<D;k++){
        distance += pow(X.at(i).at(k) - X.at(j).at(k),2);
      }
      distance = sqrt(distance);
      if(distance == floor(distance)) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] t = new int[N];
        long[] x = new long[N];
        long[] y = new long[N];
        for (int i = 0; i < N; i++) {
            t[i] = sc.nextInt();
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
        }

        boolean canTravels = true;
        int startT = 0;
        long startX = 0;
        long startY = 0;
        for (int i = 0; i < N; i++) {
            if (!canTravel(startT, startX, startY, t[i], x[i], y[i])) {
                canTravels = false;
                break;
            }
            startT = t[i];
            startX = x[i];
            startY = y[i];
        }

        if (canTravels) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

    static boolean canTravel(int t, long x, long y, int t1, long x1, long y1) {
        int diffT = t1 - t;
        long diffX = Math.abs(x1 - x);
        long diffY = Math.abs(y1 - y);

        return (diffT - diffX - diffY) >= 0 && (diffT - diffX - diffY) % 2 == 0;
    }
}

Measured memory_bytes: 94548
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
#include <sstream>
#include <stack>
#include <cstdlib>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb push_back
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

vector<string> split(string &str,char delim)
{
  vector<string> res;
  size_t current = 0,found;
  while((found = str.find_first_of(delim,current)) != string::npos)
    {
      res.push_back(string(str,current,found  - current));
      current = found + 1;
    }
  res.push_back(string(str,current,str.size() - current));
  return res;
}

int main(void){
  string s;
  while(getline(cin,s)){
    double ans;
    vector<double> res;
    vector<string> ss = split(s,' ');
    rep(i,ss.size()){
      if(ss[i] == "+"){
	double a = res.back(); res.pop_back();
	double b = res.back(); res.pop_back();
	res.pb(b+a);
      }else if(ss[i] == "-"){
	double a = res.back(); res.pop_back();
	double b = res.back(); res.pop_back();
	res.pb(b-a);
      }else if(ss[i] == "*"){
	double a = res.back(); res.pop_back();
	double b = res.back(); res.pop_back();
	res.pb(b*a);
      }else if(ss[i] == "/"){
	double a = res.back(); res.pop_back();
	double b = res.back(); res.pop_back();
	res.pb(b/a);
      }else{
	res.pb(atof(ss[i].c_str()));
      }
    }    
    printf("%.9f\n",res.back());
  }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
int main()
{
  ll sum=0;
  string s;
  cin>>s;
  for(char ch: s)
   {
     sum+=ch-48;

     if(sum%9==0)
       sum==0;
   }
   
   if(sum%9==0)
    cout<<"Yes"<<endl;

  else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3720
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		int h = scanInt(), w = scanInt(), n = scanInt();
		int ys = scanInt() - 1, xs = scanInt() - 1;
		String s1 = scanString(), s2 = scanString();
		int y1 = 0, y2 = h, x1 = 0, x2 = w;
		for (int i = n - 1; i >= 0; i--) {
			switch (s2.charAt(i)) {
			case 'R':
				x1 = max(x1 - 1, 0);
				break;
			case 'L':
				x2 = min(x2 + 1, w);
				break;
			case 'D':
				y1 = max(y1 - 1, 0);
				break;
			case 'U':
				y2 = min(y2 + 1, h);
				break;
			}
			switch (s1.charAt(i)) {
			case 'R':
				--x2;
				break;
			case 'L':
				++x1;
				break;
			case 'D':
				--y2;
				break;
			case 'U':
				++y1;
				break;
			}
			if (x1 >= x2 || y1 >= y2) {
				out.print("NO");
				return;
			}
		}
		out.print(x1 <= xs && xs < x2 && y1 <= ys && ys < y2 ? "YES" : "NO");
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 28192
#include <bits/stdc++.h>
#define N 100005

using namespace std;
typedef long long ll;

template <class T> inline void read(T &x) {
	char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	if (flag) x = -x;
}

inline int input() {
	int x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

const int mod = 1e9 + 7;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; }
inline void inc(int &x, int y) { x += y; x -= x >= mod ? mod : 0; }

inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = (ll) res * x % mod;
		x = (ll) x * x % mod, y >>= 1;
	} return res;
}

template <class T> void chkmax(T &x, T y) { x = x > y ? x : y; }
template <class T> void chkmin(T &x, T y) { x = x < y ? x : y; }
template <class T> T gcd(T x, T y) { return !y ? x : gcd(x % y, y); }

int n;
int p[N];
vector<int> G[N];
int depth[N], size[N], fa[N], res, s;
int ansa[N], ansb[N], tot, Index;

inline void AddEdge(int x, int y) {
	G[x].push_back(y);
	G[y].push_back(x);
}

void dfs(int u) {
	size[u] = 1;
	depth[u] = depth[fa[u]] + 1;
	if (depth[u] > depth[res]) res = u;
	for (int v : G[u]) {
		if (v == fa[u]) continue;
		fa[v] = u, dfs(v), size[u] += size[v];
	}
}

bool check() {
	for (int i = 1; i <= n; ++i) {
		int tmp = 0;
		for (int v : G[i]) {
			if (v == fa[i]) continue;
			if (size[v] != 1) ++tmp;
		}
		if (tmp > 1) return false;
	} return true;
}

void solvea(int u) {
	int son = 0, idu = ++Index;
	sort(G[u].begin(), G[u].end());
	for (int v : G[u]) {
		if (v == fa[u]) continue;
		if (size[v] != 1) son = v;
		else ansa[++tot] = ++Index;
	}
	ansa[++tot] = idu;
	if (son) solvea(son);
	else swap(ansa[tot], ansa[tot - 1]);
}

void solveb(int u) {
	int son = 0, idu = ++Index;
	sort(G[u].begin(), G[u].end());
	for (int v : G[u]) {
		if (v == fa[u]) continue;
		if (size[v] != 1) son = v;
		else ansb[++tot] = ++Index;
	}
	ansb[++tot] = idu;
	if (son) solveb(son);
	else swap(ansb[tot], ansb[tot - 1]);
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		AddEdge(x, y);
	}

	dfs(1), s = res, fa[res] = 0, dfs(res);
	if (!check()) return puts("-1"), 0;
	solvea(s), Index = tot = 0;
	s = res, fa[res] = 0, dfs(res);
	solveb(s);
	
	int *ans = ansa;
	for (int i = 1; i <= tot; ++i) {
		if (ansa[i] < ansb[i]) {
			ans = ansa;
			break;
		} else if (ansa[i] > ansb[i]) {
			ans = ansb;
			break;
		}
	}
	for (int i = 1; i < tot; ++i) printf("%d ", ans[i]);
	printf("%d\n", ans[tot]);
	return 0;
}

Measured memory_bytes: 12928
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        String ans="";
        int k=0;
        while(n!=0){  
            if(abs(n)%2==1)
            {ans="1"+ans; n += (k%2==0)?-1:1;}
            else
            ans="0"+ans;
            k++;
            n/=2;
        }
        if(k==0)ans="0";

        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 21204
#include <stdio.h>
#include <stdlib.h>

int main() {
  char *a = malloc(sizeof(char) * 5);
  char *b = malloc(sizeof(char) * 5);
  char *c = malloc(sizeof(char) * 5);
  char *x = malloc(sizeof(char) * 7);
  int na, nb, nc, nx;
  
  fgets(a, 4, stdin);
  fgets(b, 4, stdin);
  fgets(c, 5, stdin);
  fgets(x, 6, stdin);

  na = atoi(a);
  nb = atoi(b);
  nc = atoi(c);
  nx = atoi(x);
  
  int n = 0;
  
  for(int i = 0; i <= na; i++) {
    for(int j = 0; j <= nb; j++ ) {
      for(int k = 0; k <= nc; k++) {
	if((500*i) + (100*j) + (50*k) == nx)
	  n++;
      }
    }
  }

  printf("%d\n", n);
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif




int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);

    std::array<int, 2> X, Y;
    for(int i = 0; i < 2; ++i) std::cin >> X[i];
    for(int i = 0; i < 2; ++i) std::cin >> Y[i];
    long long int res = std::numeric_limits<long long int>::min();
    for(int i = 0; i < 2; ++i){
        for(int j = 0; j < 2; ++j){
            const long long int val = static_cast<long long int>(X[i]) * Y[j];
            if(res < val) res = val;
        }
    }
    std::cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		long n = sc.nextLong();
		long ans = 0l;
		for(; n > 0; n--) {
			if(n%3 != 0 && n%5 != 0) {
				ans += n;
			}
		}
		System.out.println(ans);
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

Measured memory_bytes: 32812
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		Main main = new Main();
		main.solve(N);

	}

	public void solve(int N) {
		for (int i = -120; i <120 ; i++) {
			for (int j = -120; j < 120; j++) {
				long ans = i*i*i*i*i - j*j*j*j*j;
				if (ans == N) {
					System.out.println(i +" " + j);
					return;
				}
			}
		}
		return;
	}
}

Measured memory_bytes: 38828
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)

int main(){
    long long N, M, L;
    cin >> N >> M >> L;
    long long d[N][N];
    long long ans[N][N];
    long long inf = 1e15;
    rep(i, N){
        rep(j, N){
            if(i == j){
                d[i][j] = 0;
                ans[i][j] = 0;
            }
            else{
                d[i][j] = inf;
                ans[i][j] = inf;
            }
        }
    }
    long long a, b, c;
    rep(i, M){
        cin >> a >> b >> c;
        d[a-1][b-1] = c;
        d[b-1][a-1] = c;
    }
    rep(i, N){
        long long tmpd[N][N];
        rep(j, N){
            rep(k, N){
                tmpd[j][k] = min(d[j][k], d[j][i]+d[i][k]);
            }
        }
        rep(j, N){
            rep(k, N){
                d[j][k] = tmpd[j][k];
            }
        }
    }
    rep(i, N){
        rep(j, N){
            if(d[i][j] <= L && i != j) ans[i][j] = 1;
        }
    }
    rep(i, N){
        long long tmpans[N][N];
        rep(j, N){
            rep(k, N){
                tmpans[j][k] = min(ans[j][k], ans[j][i]+ans[i][k]);
            }
        }
        rep(j, N){
            rep(k, N){
                ans[j][k] = tmpans[j][k];
            }
        }
    }
    long long Q;
    cin >> Q;
    long long s[Q], t[Q];
    rep(i, Q){
        cin >> s[i] >> t[i];
    }
    rep(i, Q){
        if(ans[s[i]-1][t[i]-1] == inf) cout << -1 << endl;
        else cout << ans[s[i]-1][t[i]-1]-1 << endl;
    }
}

Measured memory_bytes: 3328
use proconio::{input, fastout , marker::*};
#[fastout]
fn main() {
  input!{
    h:usize,
    w:usize,
    s:[Chars;h]
  }
  let dx:Vec<i64> = vec![1,-1,0,0];
  let dy:Vec<i64> = vec![0,0,1,-1];
  let mut can : bool = true;
  for i in 0..h {
      for j in 0..w {
          if s[i][j] != '#' {continue;}
          let mut hoge : bool = false;
          for n in 0..4 {
              let x : i64 = j as i64 + dx[n];
              let y : i64 = i as i64 + dy[n];
              if 0 <= x && x < w as i64 && 0 <= y && y < h as i64 {
                if s[y as usize][x as usize] == '#'{
                    hoge = true;
                    break;
                }
              }
          }
          if !hoge {can = false;}
      }
  }
  println!("{}", if can {"Yes"} else {"No"});
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
	int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N, M = LI()
A = LI()
ans = int(0)

A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)

for _ in range(M):
    cur = heapq.heappop(A)
#    print(cur)
    heapq.heappush(A, ((cur+1)//2))

#print(A)
print(-sum(A))

Measured memory_bytes: 14172
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool kaibun(string, string);

int main(void) {
	string s;
	cin >> s;
	string tmp1, tmp2;
	tmp1 = s.substr(0, s.length() / 2);
	tmp2 = s.substr(s.length() / 2 + 1);
	if (!kaibun(tmp1, tmp2)) {
		
		cout << "No";
		return 0;
	}


	if (s.substr(0, s.length() / 2).length() % 2 == 0) {
		tmp1 = s.substr(0, s.length() / 4);
		tmp2 = s.substr(s.length() / 4, s.length() / 4);
	}
	else {
		tmp1 = s.substr(0, s.length() / 4);
		tmp2 = s.substr(s.length() / 4+1, s.length() / 4);
	}
	
	//cout << tmp1 << " " << tmp2;

	if (!kaibun(tmp1, tmp2)) {\
		cout << "No";
		return 0;
	}

	cout << "Yes";
	return 0;
}

bool kaibun(string s1,string s2){
	if (s1.length() != s2.length()) {
		return false;
	}
	
	for (int i = 0; i < s1.length(); i++) {
		if (s1[i] != s2[s2.length() - i-1]) {
			return false;
		}
	}

	return true;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))


//const vector の中身を変える
struct Rolling_hash{
    static const int base1=1007,base2=2009;
    static const int mod1=1e9+7,mod2=1e9+9;
    vector<long long> hash1,hash2,pow1,pow2;
    
    Rolling_hash(const string &v){
        int n=(int)v.size();
        hash1.assign(n+1,0);
        hash2.assign(n+1,0);
        pow1.assign(n+1,1);
        pow2.assign(n+1,1);
        for(int I=0;I<n;I++){
            hash1[I+1]=(hash1[I]*base1+v[I]) % mod1;
            hash2[I+1]=(hash2[I]*base2+v[I]) % mod2;
            pow1[I+1]=(pow1[I]*base1) % mod1;
            pow2[I+1]=(pow2[I]*base2) % mod2;
        }
    }
    //hash[l:r]
    inline pair<long long,long long> getHash(int l,int r)const{
        long long res1=hash1[r]-hash1[l]*pow1[r-l] % mod1;
        if(res1<0)res1+=mod1;
        long long res2=hash2[r]-hash2[l]*pow2[r-l] % mod2;
        if(res2<0)res2+=mod2;
        return {res1,res2};
    }
    //LCP s[a],s[b]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (getHash(a, a+mid) != getHash(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
    //LCP s[a],t[b]
    inline int getLCP(const Rolling_hash &T,int a,int b)const{
        int len=min((int)hash1.size()-a,(int)hash1.size()-b);
        int low=0,high=len;
        while (high-low>1) {
            int mid=(low+high)>>1;
            if(getHash(a,a+mid)!=T.getHash(b,b+mid)) high=mid;
            else low = mid;
        }
        return low;
    }
};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    string s; cin >> s;
    string ss=s;
    Rolling_hash lol(s);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int lcp=lol.getLCP(i,j);
            chmin(lcp,j-i);
            chmax(ans,lcp);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>

using namespace std;
using Point = complex< double >;
const double EPS = 1e-10, PI = acos(-1);

bool eq(double a, double b){ return fabs(a-b) < EPS; }

istream &operator>> (istream &is, Point &p) {
  double a, b;
  is >> a >> b;
  p = Point(a, b);
  return is;
}

ostream &operator<< (ostream &os, Point &p) {
  return os << fixed << setprecision(10) << p.real() << " " << p.imag();
}

bool operator<(const Point &a, const Point &b) {
  return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
}

// rotate Φ(rad)
// x = r * cos(θ + Φ)
//   = r * cos(θ) * cos(Φ) - r * sin(θ) * sin(Φ)
//   = x * cos(Φ) - y * sin(Φ) (∵ cos(θ) = x/r, sin(θ) = y/r)  
Point rotate(double phi, const Point &p) {
  double x = p.real(), y = p.imag();
  return Point(x * cos(phi) - y * sin(phi), x * sin(phi) + y * cos(phi));
}

double radian_to_degree(double r) {
  return (r * 180.0 / PI);
}

double degree_to_radian(double d) {
  return (d * PI / 180.0);
}

struct Line{
  Point a, b;

  Line() = default;

  Line(Point a, Point b) : a(a), b(b){}

  Line(double A, double B, double C){
    //ax + by = c
    if(eq(A, 0)){
      a = Point(0, C/B), b = Point(1, C/B);
    }else if(eq(B, 0)){
      a = Point(C/A, 0), b = Point(C/A, 1);
    }else{
      a = Point(0, C/B), b = Point(C/A, 0);
    }
  }

  friend istream &operator>>(istream &is, Line &a) {
    return is >> a.a >> a.b;
  }
  friend ostream &operator<<(ostream &os, Line &a) {
    return os << a.a << " to " << a.b;
  }
};

struct Segment: Line{
  Segment() = default;

  Segment(Point a, Point b) : Line(a, b) {}
};

struct Circle {
  Point p;
  double r;

  Circle() = default;

  Circle(Point p, double r): p(p), r(r){}
};

using Points = vector<Point>;
using Polygon = vector<Point>;
using Segments = vector<Segment>;
using Lines = vector<Line>;
using Circles = vector<Circle>;

double cross(const Point &a, const Point &b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(const Point& a, const Point &b) {
  return a.real() * b.real() + a.imag() * b.imag();
}


// https://mathtrain.jp/projection
Point projection(const Line &l, const Point &p){
  double t = dot(p - l.a, l.b-l.a) / norm(l.a - l.b);
  return l.a + (l.b - l.a) * t;
}

Point projection(const Segment &l, const Point &p){
  double t = dot(p - l.a, l.b-l.a) / norm(l.a - l.b);
  return l.a + (l.b - l.a) * t;
}

int main(){
  Line l;
  cin >> l;
  int q;
  cin >> q;
  while(q--){
    Point p; cin >> p;
    Point x = projection(l, p);
    cout << x << endl;
  }
}


Measured memory_bytes: 3364
object Main{
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val arr = List.fill(26)(0).toArray
    while (sc.hasNext){
      val chars = sc.next.toLowerCase.toCharArray
      chars.withFilter(c => 'a' <= c && c <= 'z').foreach(c => arr(c - 'a') += 1)
    }
    'a' to 'z' foreach(c => println(c + " : " + arr(c - 'a')))
  }
}

Measured memory_bytes: 45640
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut ans = 0;
    for i in 0..n - 2 {
        if s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C' {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define mp make_pair
#define X first
#define Y second
#define INF 1987654321987654321
#define PI 3.14159265358979323846264
#define MOD 20091101
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef complex<double> base;
ll POW(ll a, ll b) { if (b == 0)return 1; if (b == 1)return a; if (b & 1)return (a*POW(a, b - 1)) % MOD; ll t = POW(a, b / 2); return (t*t) % MOD; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };//동북남서

Pll p[1000];
int main() {
	int n;
	scanf("%d", &n);
	fup(i, 0, n - 1, 1)
		scanf("%lld%lld", &p[i].X, &p[i].Y);
	fup(i, 1, n - 1, 1)
	{
		ll t1 = (p[i - 1].X - 1) / p[i].X + 1;
		ll t2 = (p[i - 1].Y - 1) / p[i].Y + 1;
		p[i].X *= max(t1, t2);
		p[i].Y *= max(t1, t2);
	}
	printf("%lld", p[n - 1].X + p[n - 1].Y);
}

Measured memory_bytes: 256
/*Shivam Bhalla */
  /* f2016941@pilani.bits-pilani.ac.in */



  #include <iostream>
  #include <cstdio>
  #include <cstring>
  #include <cstdlib>
  #include <cctype>
  #include <algorithm>
  #include <map>
  #include <vector>
  #include <list>
  #include <set>
  #include <queue>
  #include <deque>
  #include <stack>
  #include <iostream>
  #include <string>
  #include <cmath>
  #include <cassert>
  #include <bits/stdc++.h>
  #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
  using namespace std;
  long long maxv = 1e9;

  int main()
  {
    fast_cin();
    vector<int>arr(26);
    string str;
    cin>>str;
    for(int i=0;i<4;i++)
      arr[str[i]-'A']++;
    int total=0;
    for(int i=0;i<26;i++){
      if(arr[i]==2)
        total++;
    }
    if(total==2)
      cout<<"Yes";
    else
      cout<<"No";
    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(), (VECTOR).end()

int main(){

	ll A, B;
	cin >> A >> B;
	A *= 2;
	ll ans = min(A, B) / 2;
	B -= ans * 2;
	ans += B / 4;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

using namespace std;

vector<string> ans;
int n,m;
int main(){
	while(1){
		cin >> n;
		if(n == 0) break;
		bool map[21][21] = {false};
		for(int i = 0;i < n;i++){
			int x,y;
			cin >> x >> y;
			map[y][x] = true;
		}
		cin >> m;
		int count = 0;
		int nx = 10,ny = 10;
		for(int i = 0;i < m;i++){
			char dir;
			int dis;
			cin >> dir >> dis;
			for(int j = 0;j < dis;j++){
				if(dir == 'N'){
					ny++;
					if(map[ny][nx]){count++;map[ny][nx] = false;}
				}
				else if(dir == 'E'){
					nx++;
					if(map[ny][nx]){count++;map[ny][nx] = false;}
				}
				else if(dir == 'S'){
					ny--;
					if(map[ny][nx]){count++;map[ny][nx] = false;}
				}
				else{
					nx--;
					if(map[ny][nx]){count++;map[ny][nx] = false;}
				}
			}
		}
		if(count == n) ans.push_back("Yes");
		else ans.push_back("No");
	}
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3168
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------

    int k,s;
    cin >> k >> s ;

    int i;
    int ans =0;
    for(i=min(k,s);i>=0;i--){
        int g = s - i;
        if(g>k*2) break; 
        ans += (min(g,k)-max(g-k,0)+1);
    }
    pri(ans);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  if(a % 2 == 0 || b % 2 == 0){
  	cout << "Even" << endl;
  }
  else{
  	cout << "Odd" << endl;
  }
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int N;
	cin >> N;

	int maxValue = 0;
	vector<int> P;
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		maxValue = max(maxValue, p);
		P.push_back(p);
	}

	int total = 0;
	for (int i = 0; i < N; i++) {
		total = total + P[i];
	}

	cout << total-maxValue/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

ll gcd(ll a, ll b) { return (a == 0) ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

void solve() {
  int n, m;
  cin >> n >> m;
  vi a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i] /= 2;
  rep(j, 30) {
    int cnt = 0;
    rep(i, n) {
      if ((a[i] >> j) & 1) cnt++;
    }
    dump(j, cnt);
    if (cnt == n) break;
    if (cnt != 0) {
      cout << 0 << endl;
      return;
    }
  }
  dump(a);
  ll mn = a[0];
  for (int i = 1; i < n; i++) mn = lcm(mn, a[i]);
  dump(mn);
  if (m < mn) {
    cout << 0 << endl;
    return;
  }
  ll ans = m / mn;
  if (ans & 1)
    ans = (ans + 1) / 2;
  else
    ans /= 2;
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 


int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    LL ans = min(N * A, B);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a[200000], b[200000];
int main()
{
	int n, m, x, y, k, ans = 0;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++)
	{
		a[i] = 1;
		b[i] = 0;
		}
	b[1] = 1;
	for(int i = 0; i < m; i++)
	{
		scanf("%d %d", &x, &y);
		a[x]--;//printf("a[%d] = %d\n", x, a[x]);
		a[y]++;//printf("a[%d] = %d\n", y, a[y]);
		//printf("b[%d] = %d\n", x, b[x]);
		if(b[x] == 1)
		{
			//printf("a[%d] = %d\n", x, a[x]);
			if(a[x] == 0)
			{
				b[x] = 0;
				}
			b[y] = 1;
			}
		}
	for(int i = 1; i <= n; i++)
	{
		if(b[i] == 1)
		{
			ans++;
			}
		}
	printf("%d\n", ans);
	}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e16;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll X; cin >> N >> X;
    vector<ll> sum(N+1,0);
    for (int i=N;i>0;--i) cin >> sum[i];
    for (int i=0;i<N;++i) sum[i+1]+=sum[i];
    ll ans=INF;
    for (int i=1;i<=N;++i){
        ll cnt=(N+i)*X;
        int j=i;
        for (;j<=N;j+=i){
            cnt+=(sum[j]-sum[j-i])*max(5,2*(j/i-1)+3);
            if (ans<cnt) break;
        }
        cnt+=(sum[N]-sum[j-i])*max(5,2*(j/i-1)+3);
        ans=min(ans,cnt);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
import random

n=int(input())
l=list(map(int,input().split()))
m=[]
for i in range(1,n+1):
    t=(l[i-1],i)
    m.append(t)
m.sort()
s=""
for k in range(n):
    if k==n-1:
        s+=str(m[k][1])
    else:
        s+=str(m[k][1])+" "
print(s)
#print(m)


Measured memory_bytes: 19960
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector <ld> vld;
typedef vector <ll> vll;
typedef vector <pll> vpll;
typedef set <ld> sld;
typedef set <ll> sll;
typedef set <pll> spll;
typedef char ch;
typedef string str;
typedef tree <int,
            null_type,
            less<int>,
            rb_tree_tag,
            tree_order_statistics_node_update> super_set;
const ll DIM = 1*1e5+7;
const ll MODULO = 1e9+7;
const ld INF = 1e9;
const ld eps = 1e-9;
const ld pi = acos(-1.0);
const ld e = pow(1.0 + 1.0/INF, INF);
const ld gr = (1.0+sqrt(5.0))/2.0;
const ld alpha0 = 2*cos(pi/8)/(1+cos(pi/8));
const ld beta0 = 2*sin(pi/8)/(1+cos(pi/8));
ll n,k,a[DIM],F[DIM];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("paintbarn.in", "r", stdin);
    //freopen("paintbarn.out", "w", stdout);

    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    F[1] = 0;
    F[2] = abs(a[2]-a[1]);
    for (int i = 3; i <= n; i++) {
        F[i] = INF;
        for (int j = 1; j <= k; j++) {
            if (i-j <= 0)
                continue;
            F[i] = min(F[i], F[i-j] + abs(a[i-j]-a[i]));
        }
    }
    cout << F[n] << endl;
    return 0;
}
///if (dist[v]+dd < dist[to]) dist[to] = dist[v]+dd;


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
    int N= 0;
    cin >> N;
    double A[N];
    double sum = 0;
    for(int i = 0; i < N; ++i ){
        cin >> A[i];
        sum += 1/A[i];
    }
    cout << 1/sum<<endl;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

bool v[22][22];
int dp[22][1 << 22];
const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    
    for (int i = 0; i < n; ++i) 
        for (int j = 0; j < n; ++j) 
            cin >> v[i][j];
    
    dp[n][(1 << n) - 1] = 1;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < (1 << n) - 1; j++) {
            if(__builtin_popcount(j) != i) continue;
            for (int k = 0; k < n; ++k) {
                if(!(j & (1 << k)) and v[i][k]) {
                   dp[i][j] += dp[i + 1][j | (1 << k)]; 
                   dp[i][j] %= mod;
                }
            }
        }
    }

    cout << dp[0][0] << "\n";
            
    return 0;
}


Measured memory_bytes: 178432
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

signed main(){
    int N,M;
    cin>>N>>M;
    vin p(M);
    vector<string> S(M);

    vin flag(N,0);
    int ac=0,wa=0;
    rep(0,M){
        cin>>p.at(i)>>S.at(i);
    }
    rep(0,M){
        if(S.at(i)=="WA"){
            if(flag.at(p.at(i)-1)>=0){
                flag.at(p.at(i)-1)++;
            }
        }
        else{
            if(flag.at(p.at(i)-1)>=0){
                wa+=flag.at(p.at(i)-1);
                ac++;
                flag.at(p.at(i)-1)=-1;
            }
        }
    }
    cout<<ac<<" "<<wa<<endl;
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;

int main (){
  int n;
  cin >> n;
  vector<unsigned long long> a(n);
  unsigned long long ans = 1;
  
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    if(a.at(i)==0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i = 0; i < n; i++){
    if(a.at(i) > 1000000000000000000 / ans){
      cout << -1 << endl;
      return 0;
    }
    ans*=a.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]!=s[i+1]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 512
import java.util.BitSet;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] arg) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			BitSet[] bs = new BitSet[N];
			for (int i = 0; i < N; ++i) {
				bs[i] = new BitSet(N);
			}
			for (int i = 0; i < N; ++i) {
				int M = sc.nextInt();
				for (int j = 0; j < M; ++j) {
					int p = sc.nextInt() - 1;
					bs[i].set(p);
				}
			}
			int K = sc.nextInt();
			BitSet reveal = new BitSet(N);
			for (int i = 0; i < K; ++i) {
				int l = sc.nextInt() - 1;
				reveal.set(l);
			}
			int ans = -1;
			for (int i = 0; i < N; ++i) {
				bs[i].and(reveal);
				if (bs[i].equals(reveal)) {
					if (ans != -1) {
						ans = -1;
						break;
					} else {
						ans = i + 1;
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 68684
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[10][10];
int n;
int m;
int row[110];
int col[110];
int sz[110];
pair<int,pair<int,int> > p[110];
int v[10][10];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int dfs(int a,int s,int c,int d){
	if(a==m)return 1;
	if(s==sz[a])return dfs(a+1,0,row[a+1],col[a+1]);
	for(int i=0;i<4;i++){
		if(c+dx[i]<0||c+dx[i]>=n||d+dy[i]<0||d+dy[i]>=n||v[c+dx[i]][d+dy[i]])continue;
		if(s+b[c+dx[i]][d+dy[i]]>sz[a])continue;
		v[c+dx[i]][d+dy[i]]=1;
		if(dfs(a,s+b[c+dx[i]][d+dy[i]],c+dx[i],d+dy[i]))return 1;
		v[c+dx[i]][d+dy[i]]=0;
	}
	return 0;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)scanf("%d",&b[i][j]);
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)v[i][j]=0;
		n=a;
		m=0;
		int SUM=0;
		for(int i=0;i<a;i++)for(int j=0;j<a;j++){
			SUM+=b[i][j];
			if(b[i][j]<0){
				p[m++]=make_pair(-b[i][j],make_pair(i,j));
				v[i][j]=1;
			}
		}
		if(SUM){
			printf("NO\n");continue;
		}
		std::sort(p,p+m);
		for(int i=0;i<m;i++){
			row[i]=p[i].second.first;
			col[i]=p[i].second.second;
			sz[i]=p[i].first;
		}
		int ret=dfs(0,0,row[0],col[0]);
		if(ret)printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 1016
#include <iostream>
#include <string>
#include <vector>
#include <set>
int main()
{
    int N;
    std::cin >> N;

    std::vector<std::string> S(N);
    std::set<std::string> D;
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
        D.insert(S[i]);
    }

    if (D.size() != N) {
        std::cout << "No" << std::endl;
        return 0;
    }

    int i;
    for (i = 1; i < N; i++) {
        if (S[i-1].back() != S[i].front()) break;
    }

    if (i != N) {
        std::cout << "No" << std::endl;
    }
    else {
        std::cout << "Yes" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=1;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

int main(){
int N;
cin>>N;
string s;
cin>>s;
char before=s[0];
int ans=1;

rep(i,N){
    if(s[i]!=before){
    ans++;
    }
    before=s[i];
}
cout<<ans<<endl;
 return 0;
}
/*
10
aabbbbaaca

5

5
aaaaa

1


20
xxzaffeeeeddfkkkkllq

10
*/

Measured memory_bytes: 512