akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;

public class Main {


  private static void solve() {
    int l = ni();
    int n = 1;
    for (;(1 << (n + 1)) <= l; n ++);   

    List<int[]> edges = new ArrayList<>();
    for (int i = 0; i < n; i ++) {
      edges.add(new int[] {i + 1, i + 2, 0});
      edges.add(new int[] {i + 1, i + 2, 1 << i});
    }
    
    int now = 1 << n;
    for (int i = n; i >= 1; i --) {
      if (l - now  >= (1 << (i - 1))) {
        edges.add(new int[] {i, n + 1, now});
        now += (1 << (i - 1));
      }
    }
    
    System.out.println(n + 1 + " " + edges.size());
    for (int[] e : edges) {
      System.out.println(e[0] + " " + e[1] + " " + e[2]);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

using ll = long long;
const int MOD = 1000000007;
#ifdef LOCAL_ENV
    #define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
    #define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	int len = vv.size();
	for (int i = 0; i < len; ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


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

	int a=0;
	for(int i=1;i<=n;i+=2){
		int c=0;
		for(int j=1;j<=n;j+=2){
			if(i%j==0)c++;

		}
		if(c==8){a++;debug(i);}
	}
   
  	p(a);
  
    return 0;
}



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

int main() {
  long long int N, K;
  cin >> N >> K;
  long long int sum = 0;
  for (long long int i = K; i < N + 2; i++){
    sum += ((N - i + 1 + N)*i)/2 - ((0 + i - 1)*i)/2 + 1;
    sum %= 1000000007;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
#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++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

int main()
{
    int N;
    cin >> N;
    vint a(N);
    int cnt = 0;
    rep(i, N)
    {
        cin >> a[i];
        if (a[i] % 2 == 0)
        {
            cnt++;
        }
    }
    if (cnt  != N)
        cout << "first";
    else
        cout << "second";
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007



int dp[22][1<<21];

signed main(){

	int N;
	int a[21][21];
	cin >> N;
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			cin >> a[i][j];
		}
	}

	dp[0][0]=1;

	int ans=0;
	for(int i=0; i<N;i++){
		for(signed s=0; s<(1<<N); s++){
			if(__builtin_popcount(s)!=i) continue;
			for(int j=0; j<N; j++){
				if(a[i][j]){
					if( (s & (1<<j)) == 0)
						(dp[i+1][s|(1<<j)] += dp[i][s])%=mod;
				}
			}
		}
	}

/*
	for(int i=0; i<=N;i++){
		for(int s=0; s<(1<<N); s++){
			cerr << dp[i][s] << " ";
		}
		cerr << endl;
	}
*/
	cout << dp[N][(1<<N)-1] << endl;
	
	return 0;
}


Measured memory_bytes: 309504
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  vector<vector<int> >a(m);
  for(int i=0;i<m;i++)
  {
    int s;
    cin>>s;
    a[i].resize(s);
    for(int j=0;j<s;j++)cin>>a[i][j];
  }
  vector<int>p(m);
  vector<int>s(n);
  for(int i=0;i<m;i++)cin>>p[i];
  
  int ans=0;
  for(int i=0;i<=pow(2,n)-1;i++)
  {
    int k=0; 
    for(int j=0;j<m;j++)
    {
      int so=0;
      for(auto u:a[j])
      {
        so+=(i&(1<<(u-1)))? 1:0;
      }
      if((so%2)!=p[j])
      {
        k=1;
        break;
      }
    }
    if(!k)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, N, A, B);
	if (A <= B && (N > 1 || A == B))
		out((B - A)*(N - 2) + 1);
	else
		out(0);
	return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
al = list(map(int, input().split()))

for i, a in enumerate(al, 1):
    al[i-1] = a - i

al = sorted(al)
if len(al) % 2 != 0:
    b = al[(math.floor(len(al)/2))]
    ans = sum([abs(a-b) for a in al])
    print(ans)
else:
    b1, b2 = al[math.floor(len(al)/2)], al[math.floor(len(al)/2)-1]
    tmp1 = sum([abs(a-b1) for a in al])
    tmp2 = sum([abs(a-b2) for a in al])
    ans = min(tmp1, tmp2)
    print(ans)

Measured memory_bytes: 26608
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;

int n,cnt=0,root,now=0x3f3f3f3f,cot,son=0,head[5010],sz[5010];
ll ans=0,fac[5010],inv[5010],f[2][5010];
struct edge{
	int u,v,nxt;
}e[100010];

void add(int u,int v){
	e[++cnt]=(edge){u,v,head[u]};
	head[u]=cnt;
}

ll fpow(ll x,ll y){
	ll ret=1;
	while(y){
		if(y&1)ret=ret*x%mod;
		x=x*x%mod;y>>=1;
	}
	return ret;
}
ll C(ll x,ll y){
	return fac[x]*inv[x-y]%mod*inv[y]%mod;
}

void dfs(int u,int fa){
	sz[u]=1;int mx=0;
	for(int i=head[u];i;i=e[i].nxt)
	  if(e[i].v!=fa){
	  	dfs(e[i].v,u);
	  	sz[u]+=sz[e[i].v];
	  	mx=max(mx,sz[e[i].v]);
	  }
	mx=max(mx,n-sz[u]);
	if(now==mx)cot++;
	if(now>mx)now=mx,root=u,cot=0;
}

int main()
{
	scanf("%d",&n);
	f[0][0]=fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=n;i++)fac[i]=fac[i-1]*i%mod,inv[i]=fpow(fac[i],mod-2);
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	dfs(1,0);cot=0;dfs(root,0);
	if(cot>1)return printf("%lld",fac[n/2]*fac[n/2]%mod),0;
	int tot=0;
	for(int i=head[root];i;i=e[i].nxt){
		int v=e[i].v;son++;tot+=sz[v];
		memset(f[son&1],0,sizeof(f[son&1]));
		for(int j=tot;j>=0;j--)
		  for(int k=0;k<=min(j,sz[v]);k++)
		    f[son&1][j]=(f[son&1][j]+f[(son&1)^1][j-k]*C(sz[v],k)%mod*fac[sz[v]]%mod*inv[sz[v]-k])%mod;
	}
	for(int i=0,t=1;i<n;i++,t=-t)ans=(ans+1ll*t*f[son&1][i]*fac[n-i])%mod;
	printf("%lld",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 768
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
//void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
													 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll maxn = 2005;
const ll mm = 1e+18;
void solve()
{
    int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int t1=60*h1+m1;
	int t2=60*h2+m2;
	int dif=t2-t1;
	dif-=k;
	if(dif<0) dif=0;
	pr(dif);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3656
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        Queue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < N; i++) {
            q.add(Integer.parseInt(scanner.next()));
        }
        while (M > 0) {
            q.add(q.poll() / 2);
            M--;
        }
        System.out.println(q.stream().mapToLong(x -> x).sum());
    }
}



Measured memory_bytes: 48976
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int main() {
	int n;

	cin >> n;
	vector<double> val(n);
	REP(i, n) {
		cin >> val[i];
	}
	sort(val.begin(), val.end());
	REP(i, n - 1) {
		val[i + 1] = (val[i] + val[i + 1]) / 2;
	}

	cout << val[n-1] << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace GRL3_A
{
    class Program
    {
        const int MAX = 100000;
        static List<int>[] G = Enumerable.Range(0, MAX).Select(n => new List<int>()).ToArray();
        static int N, timer = 1;
        static int[] prenum = new int[MAX], parent = new int[MAX], lowest = Enumerable.Repeat(int.MaxValue,MAX).ToArray();
        static bool[] visited = new bool[MAX];

        static void Main(string[] args)
        {
            var t = scan;
            N = t[0];
            int m = t[1];

            for (int i = 0; i < m; i++)
            {
                t = scan;
                G[t[0]].Add(t[1]);
                G[t[1]].Add(t[0]);
            }
            art_points();
        }
        static void art_points()
        {
            dfs(0, -1);
            var ap = new HashSet<int>();
            int np = 0;
            for (int i = 1; i < N; i++)
            {
                int p = parent[i];
                if (p == 0) np++;
                else if (prenum[p] <= lowest[i]) ap.Add(p);

            }
            if (np > 1) ap.Add(0);
            var a = ap.OrderBy(s => s);
            foreach (var item in a)
            {
                Console.WriteLine(item);
            }
        }
        static void dfs(int current, int prev)
        {
            prenum[current] = timer;
            lowest[current] = timer;
            timer++;
            visited[current] = true;

            int next;

            for (int i = 0; i < G[current].Count; i++)
            {
                next = G[current][i];
                if (!visited[next])
                {
                    parent[next] = current;
                    dfs(next, current);
                    lowest[current] = Math.Min(lowest[current], lowest[next]);
                }
                else if (next != prev) lowest[current] = Math.Min(lowest[current], prenum[next]);
            }
        }
        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

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

typedef int elem_t;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vcc;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vs> vss;

#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define f(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define fe(i,L,R) for (int i = L; i <= R; i++)
#define ff(i,L,R) for (int i = L; i > R; i--)
#define ffe(i,L,R) for (int i = L; i >= R; i--)
#define get1(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign
#define get2(a,b) scanf("%d%d", &a, &b)
#define get3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define TESTS wez(testow)while(testow--) //for multilple cases problems
#define whileZ int T; getI(T); while(T--) // the same as above
#define getS(x) scanf("%s", x) //get a char* string
#define clr(a,x) memset(a,x,sizeof(a)) //set elements of array to some value
#define char2Int(c) (c-'0')
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))
#define REMAX(a,b) (a)=max((a),(b)) // set a to the maximum of a and b
#define REMIN(a,b) (a)=min((a),(b));
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure
#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define PRESENT(c,x) ((c).find(x) != (c).end())
#define CPRESENT(c,x) (find(ALL(c),x) != (c).end())
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
// for debug
inline void pisz(int n) { printf("%d\n",n); }
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)
#define MAXN 10000
//for vectors
#define pb push_back
#define srt(v) sort((v).begin(),(v).end())
#define UNIQUE(c) (c).resize(unique(ALL(c))-(c).begin())
int main()
{
    ll a,b;
    cin>>a>>b;
    if(a<=8&&b<=8)
    {
        cout<<"Yay!";
    }
    else
    {
        cout<<":(";
    }
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

ll N;
vector<ll> G[200020];
int visited[200020];
ll xcnt = 0,ycnt = 0;
void dfs(int x){
   visited[x] = 1;
   if(x %2 == 0) xcnt++;else ycnt++;
   for(int i = 0;i < G[x].size();i++){
      if(!visited[G[x][i]])dfs(G[x][i]);
   }
}
int main(void){
   cin >> N;
   rep(i,N){
      ll x,y;cin >> x >> y;
      x *= 2;
      y = 1LL + 2*y;
      G[x].pb(y);
      G[y].pb(x);
   }
   ll sum = 0;
   for(int x = 0;x < 200020;x++){
      if(!visited[x]){
         xcnt = ycnt = 0;
         dfs(x);
         if(xcnt < 2 or ycnt < 2)N -= xcnt*ycnt;
         else sum += xcnt*ycnt;
      }
   }
   cout << sum - N << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  map<int,int> D;

  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int n;
      cin >> n;
      D[n];
    }
  }

  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (!D.count(i)) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int h,w;
   cin >> h >> w;
   string board[50];

   rep(i,h) cin >> board[i];
   const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1};
   const int dy[8] = { 0, 1, 0, -1, 1,  1, -1,-1};

   for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
         if(board[i][j] == '#') continue;

         int num = 0;
         for(int d=0;d<8;d++){
            const int ni = i + dy[d];
            const int nj = j + dx[d];

            if(ni < 0 || h <= ni) continue;
            if(nj < 0 || w <= nj) continue;
            if(board[ni][nj] == '#') num++;
         }
         board[i][j] = (char)(num + '0');
      }
   }

   rep(i,h) cout << board[i] << endl;


   return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define pb(x) push_back(x);

using namespace std;

int main(){
	int n;
	cin >> n;
	int cnt = n / 500;
	n -= cnt * 500;
	cnt*= 1000;
	cnt+= (n/5) * 5;
	cout << cnt;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const X = parseInt(arg[0].split(" ")[0]);
    const A = parseInt(arg[0].split(" ")[1]);
    console.log(X < A ? 0 : 10);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <iostream>
#include <vector>
#include <math.h>
#include <queue>
#include <map>

int main(){

  char S[100005];
  int ans[100005] = {0};
  scanf("%s",S);
  //printf("%c\n",S[0]);
  int size = strlen(S);
  //printf("%d\n",size);
  int counter_L = 0;
  int counter_R = 0;
  int initial_R_index = 0;

  for (int i=size-1; i>=0; i--){
    //printf("i=%d\n",i);

    if (i==0 || (S[i]=='L' && counter_R>0)){ // Rが終わってLになった時or最後
      //答えの計算
      if(i==0){ //i=0は必ずRなのでRのカウンターを追加しておく
        counter_R++;
        if (S[1]=='L'){ // 1番目がLのときは、0でRにswitchした判定を入れておく
          initial_R_index = 0;
        }
      }
      //printf("calc answer\n");
      //printf("counter_L=%d\n",counter_L);
      //printf("counter_R=%d\n",counter_R);
      if ((counter_R+counter_L)%2==0){
        ans[initial_R_index]+=(counter_R+counter_L)/2;
        ans[initial_R_index+1]+=(counter_R+counter_L)/2;
        //printf("ans[%d]+=%d\n",initial_R_index,(counter_R+counter_L)/2);
        //printf("ans[%d]+=%d\n",initial_R_index+1,(counter_R+counter_L)/2);
      } else {
        if (counter_L%2==0){
          ans[initial_R_index]+=(counter_R+counter_L+1)/2;
          ans[initial_R_index+1]+=(counter_R+counter_L-1)/2;
          //printf("ans[%d]+=%d\n",initial_R_index,(counter_R+counter_L+1)/2);
          //printf("ans[%d]+=%d\n",initial_R_index+1,(counter_R+counter_L-1)/2);
        } else {
          ans[initial_R_index]+=(counter_R+counter_L-1)/2;
          ans[initial_R_index+1]+=(counter_R+counter_L+1)/2;
          //printf("ans[%d]+=%d\n",initial_R_index,(counter_R+counter_L-1)/2);
          //printf("ans[%d]+=%d\n",initial_R_index+1,(counter_R+counter_L+1)/2);       
        }
      }
      counter_L=1;//計算のあとLを1こカウントする
      counter_R=0;
    } else if (S[i]=='L'){ //Rがまだ出ずにLが続いている時
      //printf("continue L\n");
      counter_L++;
    } else if (S[i]=='R' && S[i+1]=='L'){ //最初にRに切り替わったタイミング
      //printf("sqitch to R\n");
      counter_R++;
      initial_R_index = i;
    } else { //Rが続いている時
      //printf("continue R\n");
      counter_R++;
    }
  }

  // print answer
  for (int i=0; i<size; i++){
    printf("%d ",ans[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 896
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

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

        // 入力
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        //String s = sc.next();

        // 処理
        int out = 0;
        if(a >= k){
            out = k;
        } else {
            out = a;
            k -= a;
            if(b >= k){
                out = a;
            } else {
                out = a;
                k -= b;
                out -= k;
            }
        }

        // 出力
        System.out.println(out);
    }
}


Measured memory_bytes: 35748
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,a[1001],p;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>a[i];
    }
    long long int m=a[0];
    for(int i=1;i<t;i++)
    {
        p=__gcd(m,a[i]);
        m=(m/p)*a[i];
    }
    cout<<m<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w;cin>>h>>w;
  vector<vector<ll>>a(h,vector<ll>(w));
  auto b=a;
  rep(i,h)rep(j,w)cin>>a[i][j];
  rep(i,h)rep(j,w)cin>>b[i][j];
  const ll geta=80*160,sz=geta*2+7;
  vector<vector<bitset<sz>>>dp(h,vector<bitset<sz>>(w));
  auto isin=[&](ll y,ll x){
    if(y>=0&&y<h&&x>=0&&x<w)return 1;
    return 0;
  };
  ll d=a[0][0]-b[0][0];
  dp[0][0][geta-d]=1;
  dp[0][0][geta+d]=1;
  rep(i,h)rep(j,w){
    //if(i==0&&j==0)continue;
    d=abs(a[i][j]-b[i][j]);
    if(isin(i-1,j)){
      dp[i][j]|=dp[i-1][j]<<d;
      dp[i][j]|=dp[i-1][j]>>d;
    }
    if(isin(i,j-1)){
      dp[i][j]|=dp[i][j-1]<<d;
      dp[i][j]|=dp[i][j-1]>>d;
    }

  }
  ll res=1e9;
  rep(i,sz){
    if(dp[h-1][w-1][i])chmin(res,abs(i-geta));
  }
  cout<<res<<endl;


  return 0;

}


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

int main() {
  string n;
  cin >> n;
  int cnt = 0;
  for (auto c : n) (cnt += (c - '0')) %= 9;
  if (cnt == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3684
import java.util.*;

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

        String S = sc.next();

        if(S.charAt(0)==S.charAt(1) && S.charAt(1)==S.charAt(2)){
            System.out.println("No");
        }
        else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

int powM(int b, int p, int m = mod)
{
    int ans = 1;
    while(p)
    {
        if(p%2LL) ans = (ans*b)%m;
        b = (b*b)%m;
        p /= 2LL;
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    int ans = powM(10, n);
    ans -= 2ll*powM(9, n) - powM(8, n);
    ans = (ans + 100ll*mod)%mod;
    cout<<ans<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
use std::convert::From;
use std::ops;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

const MODP: u64 = 1_000_000_007;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct ModU64(u64);

impl ModU64 {
    fn new(x: u64) -> Self {
        ModU64(x % MODP)
    }

    fn pow(self, mut x: u64) -> Self {
        let mut b = self;
        let mut a: ModU64 = 1.into();
        while x > 1 {
            if x & 1 == 1 {
                a = a * b;
            }
            x = x / 2;
            b = b * b;
        }
        if x == 1 {
            a = a * b;
        }
        a
    }
}

impl From<u64> for ModU64 {
    fn from(x: u64) -> Self {
        ModU64::new(x)
    }
}

impl ops::Add<ModU64> for ModU64 {
    type Output = ModU64;

    fn add(self, rhs: ModU64) -> Self::Output {
        ModU64::new(self.0 + rhs.0)
    }
}

impl ops::Mul<ModU64> for ModU64 {
    type Output = ModU64;

    fn mul(self, rhs: ModU64) -> Self::Output {
        ModU64::new(self.0 * rhs.0)
    }
}

impl ops::Div<ModU64> for ModU64 {
    type Output = ModU64;

    fn div(self, rhs: ModU64) -> Self::Output {
        self * rhs.pow(MODP - 2)
    }
}

fn main() {
    use std::cmp::max;
    use std::collections::HashMap;

    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut av = vec![0u64; n];
    for i in 0..n - 1 {
        av[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    av[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut sieve: Vec<u64> = (0..1_000_000 + 1).map(|i| i as u64).collect();
    for ri in 2..sieve.len() {
        let i = sieve.len() - ri + 1;
        // for j in ((i + 1)..sieve.len()).step_by(i) { ... }
        let mut j = i + i;
        while j < sieve.len() {
            sieve[j] = i as u64;
            j += i;
        }
    }

    assert_eq!(sieve[0..10], [0, 1, 2, 3, 2, 5, 2, 7, 2, 3]);

    let mut apv: Vec<HashMap<u64, u64>> = vec![HashMap::new(); n];
    for i in 0..av.len() {
        let mut j = av[i];
        while j != 1 {
            let p = sieve[j as usize];
            *apv[i].entry(p).or_insert(0) += 1;
            j /= p;
        }
    }

    let mut l: HashMap<u64, u64> = HashMap::new();
    for a in apv.iter() {
        for (k, v) in a.iter() {
            if let Some(lv) = l.get_mut(k) {
                *lv = max(*lv, *v);
                continue;
            }
            l.insert(*k, *v);
        }
    }

    let mut lcm: ModU64 = 1.into();
    for (&k, &v) in l.iter() {
        for _ in 0..v {
            lcm = lcm * (k as u64).into();
        }
    }

    let mut ans: ModU64 = 0.into();
    for &a in av.iter() {
        let b = lcm / a.into();
        ans = ans + b;
    }
    println!("{}", ans.0);
}


Measured memory_bytes: 20732
#include <cstdio>
#include <algorithm>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main(){
char S[200010]={};
int a=0,z=200000;
scanf("%s",S);
for(int i=0;S[i]!='A';i++){a++;}
for(int i=200000;S[i]!='Z';i--){z--;}
printf("%d",z-a+1);
return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

int S[20000];
int n;

void push(int i) {
  S[n++] = i;
}

int pop() {
  if (n > 0) {
    return S[--n];
  }

  return -1;
}

bool empty() {
  return n == 0;
}

int main() {
  string input;
  cin >> input;
  int start[10000];
  int L[10000];
  int k = 0;

  int A = 0;

  for (int i = 0; i < (int)input.size(); i++) {
    char c = input[i];

    if (c == '\\'){
      push(i);
    } else if (c == '/') {
      if(!empty()) {
        int j = pop();
        int l = i - j;
        A += l;

        while(k > 0 && j < start[k-1]) {
          k--;
          l += L[k];
        } 
        start[k] = j;
        L[k] = l;

        k++;
      }
    } else if (c == '_') {
    }
  }

  cout << A << endl;
  cout << k;
  for (int i = 0; i < k; i++) {
    cout << " " << L[i];
  }
  cout << endl;
}



Measured memory_bytes: 3284
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        String bStr = scan.next();
        int b = Integer.parseInt(bStr);
        int digits = bStr.length();
        a *= Math.pow(10, digits);
        a += b;
        for (int i = 0; i <= Math.sqrt(a); i++) {
            if (i * i == a ) {
                System.out.println("Yes"); return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21844
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

#define bitcount(n) __builtin_popcount(n)

#define debug(n) cout << n << endl;

#define PREC(n) setprecision(n)
#define DOTPREC(n) fixed << setprecision(n)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false); cin.tie(0)

template<typename T> bool chmax(T&a,T b) { if(a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T&a,T b) { if(a > b) {a = b; return true;} return false;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

const ll MOD = 1000000007;

string S;
int main(void)
{
    cin >> S;

    int l = 0, r = S.size() - 1;
    int ans = 0;
    while (l < r) {
        char color = S[l];
        int f = 0;
        int i = l + 1;
        for (; i <= r; i++) {
            if (S[i] != color) break;
            f++;
        }
        if (i > r) break; // OK

        color = S[r];
        int b = 0;
        for (int i = r - 1; i >= l; i--) {
            if (S[i] != color) break;
            b++;
        }


        if (f >= b) {
            l += f + 1;
        }
        else {
            r -= b + 1;
        }
        ans++;
    }

    debug(ans);
    return 0;
}


Measured memory_bytes: 1144
S = input()

num_flip = 0 # タイルの反転回数

if len(S) == 1:
    print(num_flip)

# 前のタイルとだけ比較する
else:
    for i in range(1, len(S)):
        if S[i-1] == S[i] :
            num_flip += 1
            
            # つぎかえ
            if S[i] == "0":
                S = S[:i] + "1" + S[i+1:]
            else:
                S = S[:i] + "0" + S[i+1:]

    print(num_flip)

Measured memory_bytes: 3432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	ll a[n+5];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll min=a[0],max=a[1];
	for(ll i=0;i<n;i++)
	{
		if(a[i]<min)	min=a[i];
	}
	for(ll i=0;i<n;i++)
	{
		if(a[i]>max)	max=a[i];
	}
	cout<<max-min;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int h[301];
	int w[301];
	int i;
	int t;
	int u;
	int v;
	int x;
	int y;
	for (i = 1; i <= 300; i++) {

		scanf("%d %d", &h[i], &w[i]);
		if ((h[i] == 0) && (w[i] == 0))break;
	}
	for (t = 1; t <= 300; t++) {
		if (i == t)break;
		for (v = 1; v <= h[t]; v++) {
			y = v % 2;
			
				for (u = 1; u <= w[t]; u++) {
					x = u % 2;
					if (y == 0) {
						x--;
					}
					if (x == 0) {
						printf(".");
					}
					else {
						printf("#");
					}
				}
			
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 576
//
// author  : Abhishek
//
#include <bits/stdc++.h>

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;

const ll mod = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    }
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    cin >> n >> k;
    vector<ll> arr;
    arr = read(n);

    vector<ll> dp(n, 0);


    Fo(i, 1, k) {
        if(i>=n){
            break;
        }
        ll mn = dp[i - 1] + abs(arr[i] - arr[i - 1]);
        for (j = i - 1; j >= 0; j--) {
            if (j < 0) {
                break;
            }
            mn = min(dp[j] + abs(arr[i] - arr[j]), mn);
        }
        dp[i] = mn;
    }

    Fo(i, k, n) {
        if(i>=n){
            break;
        }
        ll mn = dp[i - 1] + abs(arr[i] - arr[i - 1]);
        for (j = i - 1; j >= i - k; j--) {
            if (j < 0) {
                break;
            }
            mn = min(dp[j] + abs(arr[i] - arr[j]), mn);
        }
        dp[i] = mn;
    }

    cout << dp[n - 1];

    return 0;
}




Measured memory_bytes: 4764
#include "bits/stdc++.h"
using namespace std;

int W, H;
int SX, SY, GX, GY;
vector<vector<int> > A;

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

void DFS(int X, int Y, int K) {
	if (K > 10) return;
	for (int i = 0; i < 4; i++) {
		int NX = X + dx[i], NY = Y + dy[i];
		if (NX < 0 || H <= NX || NY < 0 || W <= NY) continue;
		if (A[NX][NY] == 1) continue;
		for (; ;) {
			if (NX == GX && NY == GY) {
				ANS = min(ANS, K);
				break;
			}
			NX += dx[i], NY += dy[i];
			if (NX < 0 || H <= NX || NY < 0 || W <= NY) break;
			if (A[NX][NY] == 1) {
				A[NX][NY] = 0;
				DFS(NX - dx[i], NY - dy[i], K + 1);
				A[NX][NY] = 1;
				break;
			}
		}
	}
}

int main() {
	while (cin >> W >> H) {
		if (W == 0 && H == 0) return 0;
		A.resize(H);
		for (int i = 0; i < H; i++) {
			A[i].resize(W);
			for (int j = 0; j < W; j++) {
				cin >> A[i][j];
				if (A[i][j] == 2) SX = i, SY = j, A[i][j] = 0;
				if (A[i][j] == 3) GX = i, GY = j, A[i][j] = 0;
			}
		}
		ANS = 10000;
		DFS(SX, SY, 1);
		cout << (ANS <= 10 ? ANS : -1) << endl;
	}
}


Measured memory_bytes: 3088
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int n;
ll ans = INF;
bool joc[10];
bool soc[100][10];
int bene[100][11];

void cal(int t = 0) {
	if (t == 10) {

		bool o = false;
		rep(i, 10) {
			if (joc[i])o = true;
		}
		if (!o)return;

		int sod[100] = { 0 };
		ll sum = 0;
		rep(i, n) {
			rep(j, 10) {
				if (joc[j]&&soc[i][j])sod[i]++;
			}
		}

		rep(i, n) {
			sum += bene[i][sod[i]];
		}

		if (ans == INF)ans = sum;
		else ans = max(ans, sum);
	}
	else {
		joc[t] = 0;
		cal(t + 1);
		joc[t] = 1;
		cal(t + 1);
	}

	return;
}

int main() {
	
	cin >> n;

	rep(i, n) {
		rep(j, 10) {
			cin >> soc[i][j];
		}
	}

	rep(i, n) {
		rep(j, 11) {
			cin >> bene[i][j];
		}
	}

	cal();

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1_3_C {
    class Program {
        static void Main(string[] args) {
            int i = 0;
            while(true) {
                i++;
                string[] s = Console.ReadLine().Split(' ');
                int x = int.Parse(s[0]);
                int y = int.Parse(s[1]);
                if(s[0] == "0" && s[1] == "0")
                    break;
                if(x <= y) {
                    Console.WriteLine("{0} {1}", x, y);
                } else if(x > y) {
                    Console.WriteLine("{0} {1}", y, x);
                }
            }
        }
    }
}

Measured memory_bytes: 9344
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}
    
void run(){
    int n,k;
    cin>>n>>k;
    cout<<min(n%k,k-(n%k))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
const int maxn = 100005;
ll dp[400][400];
vector<ll>p;
vector<ll>v;
ll solve(int l, int r) {
	if (~dp[l][r]) {
		return dp[l][r];
	}
	if (l == r) {
		return dp[l][r] = v[l];
	}
	ll mi = 1e18;
	for (int i = l ; i < r; i++) {
		mi = min(mi, solve(l, i) + solve(i + 1, r) + p[r + 1] - p[l]);
	}
	return dp[l][r] = mi;
}
void go() {
	int n;
	cin >> n;
	p.pb(0);
	f(n) {
		int x;
		cin >> x;
		v.pb(x);
		p.pb(p.back() + v.back());
	}
	memset(dp, -1, sizeof(dp));
	cout << solve(0, n - 1) - p[n] << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}

Measured memory_bytes: 4920
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N; cin >> N; // 配列サイズ
  vector<int> a(N,0);
  int Q; cin >> Q;
  string S; cin >> S;
  for (int i = 0; i < N-1; ++i){
    if(S[i+1]=='C' && S[i]=='A') a[i+1]=1; // a の入力
  }
  // 累積和
  vector<int> s(N+1, 0); // s[0] = 0 になる
  for (int i = 0; i < N; ++i){
    s[i+1] = s[i] + a[i];
    //cout << s[i+1] << endl;
  }
  //という感じで簡単に実装できます。各クエリに対しては

  // 区間 [left, right) の総和を求める
  rep(i,Q){
    int left, right;
    cin >> left >> right;
    cout << s[right] - s[left] << endl;
  }
  return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, L;
    cin >> N >> L;

    vector<string> S(N);

    REP(i, N){
        cin >> S[i];
    }

    sort(S.begin(), S.end());

    REP(i, N){
        cout << S[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3608