akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int a[] = new int[N];
            for(int i=0; i<N; i++){
                a[i] = in.nextInt();
            }
            Arrays.sort(a);

            int res = a[N-1]-a[0];
            
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}

Measured memory_bytes: 21588
def dfs(v):
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] and not visited[v2]:
            dfs(v2)


n, m = map(int, input().split())
edge = [list(map(int, input().split())) for i in range(m)]

graph = [[False for i in range(n)] for j in range(n)]

for e in edge:
    graph[e[0]-1][e[1]-1] = True
    graph[e[1]-1][e[0]-1] = True

ans = 0

for e in edge:
    graph[e[0]-1][e[1]-1] = False
    graph[e[1]-1][e[0]-1] = False

    visited = [False for j in range(n)]

    dfs(0)

    for v in visited:
        if not v:
            ans += 1
            break

    graph[e[0]-1][e[1]-1] = True
    graph[e[1]-1][e[0]-1] = True

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

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

		if (22 <= A + B + C) {
			System.out.println("bust");
		} else {
			System.out.println("win");
		}
	}
}

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

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define int long long

using namespace std;

const int inf = (int)1e9 + 7;
const int N = (int)2e6 + 7;

int n,c;
int x[N],y[N];
int d1[N],d2[N];
int mx1[N],mx2[N];
int ans;

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

      for (int i = 1; i <= n; i ++) {
            cin >> x[i] >> y[i];
      }

      for (int i = 1; i <= n; i ++) {
            d1[i] = d1[i - 1] - (x[i] - x[i - 1]) + y[i];
            mx1[i] = max(mx1[i - 1],d1[i] - x[i]);
      }
      x[n + 1] = c;
      y[n + 1] = 0;
      d2[n + 1] = 0;
      mx2[n + 1] = 0;

      for (int i = n; i >= 1; i --) {
            d2[i] = d2[i + 1] - (x[i + 1] - x[i]) + y[i];
            mx2[i] = max(mx2[i + 1],d2[i] - (c - x[i]));
      }
      for (int i = 0; i <= n; i ++) {
            ans = max(ans,d1[i] + mx2[i + 1]);
            ans = max(ans,mx1[i] + d2[i + 1]);
      }
      cout << ans << endl;
}


Measured memory_bytes: 15360
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x)
{
	int next;
	Q[head] = x;
	next = (head+1)%(LEN+1);
	if(next != tail){
		if(next == 0) next = 1;
		head = next;
	}
	return;
}

P dequeue()
{
	int next;
	next = (tail+1)%(LEN+1);
	if(next != head){
		if(next == 0) next = 1;
		tail = next;
		return(Q[tail]);
	}
}

int empty()
{
	int next;
	next = (tail+1)%(LEN+1);
	if(next == head){
		return(0);
	}
	return(1);
}


int main()
{
  int elaps = 0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  head = 1;
  tail = 0;
  for ( i = 1; i <= n; i++){
    scanf("%s", &u.name);
    scanf("%d", &u.t);
	enqueue(u);
  }
  while(empty()){
	  u = dequeue();
	  u.t -= q;
	  elaps += q;
	  if(0 < u.t){
		  enqueue(u);
	  }else{
		  elaps += u.t;
		  printf("%s %d\n", u.name, elaps);
	  }
  }
  
  return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a+b>=c)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3620
program main;
var
m, n, i, total, count : integer;
a : array[1..1000] of integer;

begin
	read(n, m);
    total := 0;
    for i := 1 to n do begin
    	read(a[i]);
        total := total + a[i];
    end;
    
    
    count := 0;
    
    for i := 1 to n do begin
        if (a[i]/total) >= (1/(4*m))
            then count := count + 1
    end;
    if count >= m 
        then writeln('Yes')
            else writeln('No');
end.

Measured memory_bytes: 1316
def main():
    n, k = map(int, input().split(" "))
    s =set()
    for i in range(k):
        _ = input()
        a = list(map(int, input().split(" ")))
        for j in range(len(a)):
            s.add(a[j])
    print(n - len(s))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9128
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Program
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		long ans = 0;

		long x = long.Parse(Console.ReadLine());
		ans += (x / 11) * 2;

		if (x % 11 != 0)
		{
			if (x % 11 <= 6) { ans++; }
			else { ans += 2; }
		}

		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 13268
n, t = STDIN.gets.split.map(&:to_i)

min = 9999

n.times do |_|
  c_tmp, t_tmp = STDIN.gets.split.map(&:to_i)
  min = c_tmp if c_tmp <= min && t_tmp <= t
end

puts (min != 9999 ? min : 'TLE')

Measured memory_bytes: 1788
#include <cstdio>
#include <algorithm>

using namespace std;

pair<int, int> seg[1 << 21];

void add(int k, int x)
{
	k += (1 << 20) - 1;
	seg[k].first = k - (1 << 20) + 1;
	seg[k].second += x;
	
	while (k){
		k = (k - 1) / 2;
		if (seg[k * 2 + 2].second > seg[k * 2 + 1].second){
			seg[k] = seg[k * 2 + 2];
		}
		else {
			seg[k] = seg[k * 2 + 1];
		}
	}
	return;
}

pair<int, int> getMax(int a, int b, int k = 0, int l = 0, int r = 1 << 20)
{
	if (b <= l || r <= a) return (make_pair(-999999999, -999999999));
	
	if (a <= l && r <= b) return (seg[k]);
	
	pair<int, int> lch = getMax(a, b, k * 2 + 1, l, (l + r) / 2),
					rch = getMax(a, b, k * 2 + 2, (l + r) / 2, r);
	
	if (rch.second > lch.second) return (rch);
	return (lch);
}

int main()
{
	int n, q;
	
	scanf("%d %d", &n, &q);
	for (int i = 0; i < n; i++) add(i, 0);
	
	for (int i = 0; i < q; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		add(a - 1, b);
		
		pair<int, int> x = getMax(0, n);
		printf("%d %d\n", x.first + 1, x.second);
	}
	
	return (0);
}

Measured memory_bytes: 17412
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int selection_sort(vector<int> &vec, int size);

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

    vector<int> vec(n);
    for (int i = 0; i < n; ++i)
        cin >> vec[i];

    int swap_count = selection_sort(vec, n);
    cout << vec[0];
    for (int i = 1; i < n; ++i)
        cout << ' ' << vec[i];
    cout << '\n' << swap_count << '\n';
}

int selection_sort(vector<int> &vec, int size)
{
    int swap_count = 0;

    for (int i = 0; i < size; ++i) {
        int min_index = i;
        for (int j = i + 1; j < size; ++j) {
            if (vec[j] < vec[min_index])
                min_index = j;
        }

        if (i != min_index) {
            swap(vec[i], vec[min_index]);
            ++swap_count;
        }
    }

    return swap_count;
}



Measured memory_bytes: 3088
N, M, V, P = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse = True)

l = P-1
r = N

while r-l > 1:
    m = (r + l) // 2
    last = M + A[m]
    s = 0
    for i in range(P-1, N):
        if i == m:
            continue
        s += min(max(last - A[i],0), M)
    if s >= M * (V - P) and last >= A[P-1]:
        l = m
    else:
        r = m
        
print(l+1)

Measured memory_bytes: 14964
#include<iostream>
using namespace std;
int a[100005];
int b[100005];
int main(){
	int n;
	int i,j,k;
	int s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	k=1-a[0];
	for(i=0,j=0;i<n;i++){
		if(k==a[i]){
			j++;
		}else{
			k=a[i];
		}
		b[j]++;
	}
	for(i=0;i<=j;i++){
		k=b[i]+b[i+1]+b[i+2];
		if(s<k)s=k;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3572
#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 ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=200005;
int nxt[N][26];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  string s,t;
  cin>>s>>t;
  string s2=s;
  s2+=s2;
  rep(j,0,26)
    nxt[sz(s2)][j]=-1;
  repv(i,0,sz(s2))
    {
      int curr=s2[i]-'a';
      rep(j,0,26)
	{
	  if(curr==j)
	    nxt[i][j]=i;
	  else
	    nxt[i][j]=nxt[i+1][j];
	}
    }
  repv(i,0,sz(s))
    rep(j,0,26)
    {
      if(nxt[i][j]!=-1)
	nxt[i][j]%=sz(s);
    }
  ll ans=0;
  int curr=0;
  rep(i,0,sz(t))
    {
      int id=t[i]-'a';
      int p=nxt[curr][id];
      if(p==-1)
	{
	  cout<<-1<<endl;
	  exit(0);
	}
      if(p<curr)
	ans+=sz(s)-curr+p+1;
      else
	ans+=p-curr+1;
      curr=p+1;
      curr%=sz(s);
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 21072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int min=INF,ans;
    int l=a[n-1]/2;
    int r=(a[n-1]+1)/2;
    for(int i=0;i<n-1;i++){
        if(min>abs(l-a[i])){
            min=abs(l-a[i]);
            ans=a[i];
        }
        if(min>abs(r-a[i])){
            min=abs(r-a[i]);
            ans=a[i];
        }
    }
    cout<<a[n-1]<<" "<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <tuple>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < n; i++)

int main()
{
    int n;
    cin >> n;
    int p[n];
    REP(i, n)
    {
        cin >> p[i];
    }
    auto ans = 0;
    REP(i,n-2)
    {
        if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i] > p[i + 1] && p[i + 1] > p[i + 2]))
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {
  val nums = readLine.split(" ").map(_.toLong)
  val N = nums(0)
  val A = nums(1)
  val B = nums(2)

  val numChunks = N / (A + B)
  val remaining = N % (A + B)

  println(numChunks * A + (if (remaining > A) A else remaining))
}


Measured memory_bytes: 27208
N = int(input())
l = [int(x) for x in input().split()]
l_dict = {k: v for v, k in enumerate(l)}
l.sort()

for i, x in enumerate(l):
    if i == 0:
        print(l_dict[x] + 1, end="")
    else:
        print(" {}".format(str(l_dict[x] + 1)), end="")


Measured memory_bytes: 19744
import math
def rot60(s, t):
    v = t - s
    a = 1/2 + complex(0,(math.sqrt(3)/2))
    return v * a + s

def pr(p):
    x = p.real
    y = p.imag
    print('%.10f %.10f'%(x, y))

def dfs(p1, p2, n):
    if n == 0:
        return
    

    s = (p2 - p1) * (1/3) + p1
    t = (p2 - p1) * (2/3) + p1
    u = rot60(s, t)
    dfs(p1, s, n - 1)
    pr(s)
    dfs(s, u, n - 1)
    pr(u)
    dfs(u, t, n - 1)
    pr(t)
    dfs(t, p2, n -1)
    
n = int(input())
s = (0 + 0j)
t = (100 + 0j)
pr(s)
dfs(s, t, n) 
pr(t)


Measured memory_bytes: 5720
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <utility>
#include <random>
#include <chrono>

using namespace std;

#define ll long long

bool cmp(char* a, char* b)
{
    return strcmp(a, b) < 0;
}

int main()
{
    int n;
    vector<char *> strs;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        char* s = new char[15];
        scanf("%s", s);
        strs.push_back(s);
    }
    if (n == 1) {
        printf("1"); return 0;
    }
    sort(strs.begin(), strs.end(), cmp);
    int cnt = 1;
    for (int i = 0; i + 1 < strs.size(); i++) {
        if (strcmp(strs[i], strs[i+1]) != 0) {
            cnt++;
        }
    }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 11084
#include <iostream>
#include <math.h>

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

    std::string s;
    s = std::to_string(N);

    int out = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == '1')
        {
            out += 9 * pow(10, 2 - i);
        }
        else if (s[i] == '9')
        {
            out += 1 * pow(10, 2 - i);
        }
    }

    std::cout << out << std::endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
XYH=[list(map(int,input().split())) for _ in range(n)]

A=[]
cnt,add=0,[0,0]
for i in range(101):
    for j in range(101):
        for x,y,h in XYH:
            H=h+abs(x-i)+abs(y-j)
            A.append([H,i,j])

for H,cx,cy in A:
    flag=1
    for x,y,h in XYH:
        if max(H-abs(x-cx)-abs(y-cy),0)!=h:flag=0
        if not flag:break
    if flag:print(cx,cy,H);exit()

Measured memory_bytes: 157200
#include<iostream>
using namespace std;

int main(){
  int N,ans=0;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++){
    cin>>a[i];
    }
  for(int i=0;i<N;i++){
    if(a[i]==i+1){
      swap(a[i],a[i+1]);
      ans+=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

signed main(){
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	for(int i = 0; i < k; i++) ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N), dp(N, -1);
    rep(i,0,N)cin >> V[i];
    rep(i,0,N){
        auto itr = lower_bound(dp.rbegin(), dp.rend(), V[i]);
        itr--;
        //cout << distance(dp.rbegin(), itr) << endl;
        *itr = V[i];
    }
    //rep(i,0,N)cout << dp[i] << endl;
    for(int i = N-1;i >= 0;i--){
        if(dp[i] != -1){
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << N << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
using namespace std;


int main(){
    string s,t;
    cin >> s >>t;
    int ans =0;
    //cout << s[1];
    //cout << s.length()<< endl;
    
    for(int i=0;i<s.length();++i){
        if(s[i]!=t[i]){
            //cout << i << endl;
            ans += 1;
        }
    }
    cout << ans << endl;;
}



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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    lint N;
    cin >> N;
    vector<lint> A(N, 0);
    rep(i, N) cin >> A[i];

    lint ans = 0;
    lint f   = 1;
    for (int d = 0; d <= 61; d++) {
        lint cnt0 = 0, cnt1 = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] & (1ll << d))
                cnt1++;
            else
                cnt0++;
        }
        lint add = (cnt0 * cnt1) % MOD * f % MOD;
        ans      = (ans + add) % MOD;
        f        = (f * 2ll) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5588
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  long a[N];

  for(int i = 0;i < N;i++) scanf("%ld",&a[i]);

  int i = N-1;
  for(;i >= 0;i -= 2) printf("%ld ",a[i]);
  if(N%2 != 0) i += 3;
  else i++;
  for(;i < N;i += 2){
    if(i+2 >= N) printf("%ld\n",a[i]);
    else printf("%ld ",a[i]);
  }

  return 0;
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 998244353;

using namespace std;

ll add(ll x,ll y){
	return ((x%mod+y%mod)%mod+mod)%mod;
}

void solve(){
	int n;ll ans=0;
	cin>>n;
	vii vs(n);
	vi dir(n+10,0),dp(n+10,0);
	for(ii &x:vs) cin >> x.ff >> x.ss;
	sort(all(vs));
	dp[n]=1;
	for(int i=n-1;i>=0;--i){
		dir[i] = i;
		while(dir[i] < n-1 && vs[i].ff + vs[i].ss > vs[dir[i]+1].ff){
			dir[i]=dir[dir[i]+1];
		}
		dp[i] = add(dp[i+1],dp[dir[i]+1]);
	}
	cout<<dp[0]<<endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 6340
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

void check(vector<Int> V, vector<Int> A, vector<Int> B){
  Int N = V.size();

  for(Int i=0;i<N-1;i++) assert(A[i] < A[i + 1]);
  for(Int i=0;i<N-1;i++) assert(B[i] > B[i + 1]);

  Int pre = -INF;
  for(Int i=0;i<N;i++){
    Int v = V[i] - 1;
    assert(0 <= v && v < N);
    assert(1 <= A[v] && A[v] <= 1e9);
    assert(1 <= B[v] && B[v] <= 1e9);
    Int c = A[v] + B[v];
    assert(pre < c);
    pre = c;
  }
}

pair<vector<Int>, vector<Int> > solve(vector<Int> V){
  Int N = V.size();
  vector<Int> A(N);
  for(Int i=0;i<N;i++) A[i] = (i + 1) * 30000;
  auto B = A; reverse(B.begin(), B.end());

  vector<Int> C;
  for(Int i=0;i<N;i++){
    Int v = V[i] - 1;
    A[v] -= (N - i);
    B[v] -= (N - i);
    C.push_back(A[v] + B[v]);
  }
  //pr(C);
  return {A, B};
}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int> V(N);
  cin>>V;

  vector<Int> A, B;
  tie(A, B) = solve(V);
  cout<<A<<endl;
  cout<<B<<endl;
  check(V, A, B);
  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>

int main(void)
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> ds(N);
    for (auto& d : ds) {
        std::cin >> d;
    }

    std::sort(ds.begin(), ds.end());

    std::cout << ds.at(N/2) - ds.at(N/2-1) << std::endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
#define MAX(a, b, c) max(max(a, b), c)
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> s(m, 0), p(m);
  REP(i,m){
    int k;
    cin >> k;
    REP(j,k){
      int ss;
      cin >> ss;
      s[i] |= (1 << (ss-1));
    }
  }
  REP(i,m) cin >> p[i];
  int cnt = 0;
  REP(bit,(1<<n)){
    REP(i,m){
      int pat = s[i]&bit;
      if(__builtin_parity(pat) != p[i]) break;
      if(i==m-1) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    int c=0,d=0;
    for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        if(a[i] == (i+1)){
            c++;
        }
        if(a[i] != (i+1)){
            d++;
        }
    }
    if(c==n){
        printf("YES\n");
    }
    else if(d<=2){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 1636
import Data.List(intercalate)

main :: IO ()
main = interact $ unlines . map (box . strToIntList) . takeWhile (/="0 0") . lines

strToIntList :: String -> [Int]
strToIntList = map read . words

box :: [Int] -> String
box [h, w] = (intercalate "\n" . replicate h . replicate w $ '#') ++ "\n"

Measured memory_bytes: 4940
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
const int maxn=1e6+5;
int q,t,f;
char c,s[maxn];
int main(){
	int beg=300000,flg=1;
	scanf("%s",s+beg);
	int end=strlen(s+beg)+beg;
	cin>>q;
	while(q--){
		int t;
		cin>>t;
		if(t==1){
			flg=(3-flg);
		}
		else{
			cin>>f>>c;
			if(flg==1){
				if(f==1)
					s[--beg]=c;
				else
					s[end++]=c;	
			}
			else{
				if(f==2)
					s[--beg]=c;
				else
					s[end++]=c;
			}
		}
	}
	if(flg==1){
		for(int i=beg;i<end;i++)
			cout<<s[i]; 
	}
	else{
		for(int i=end-1;i>=beg;i--){
			cout<<s[i];
		}
	}
	return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int a,b;
		
		a=A/C;
		b=B/D;
		if(A%C!=0) a++;		
		if(B%D!=0) b++;
		if(a>b) System.out.println(L-a);
		else System.out.println(L-b);
	}
}

Measured memory_bytes: 17172
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var a, b int
	fmt.Fscan(read, &a, &b)

	fmt.Fprintln(write, ((b-1)+(a-1)-1)/(a-1))
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<tuple>
using namespace std;
typedef vector<int> vi;
const int INF=1e9;
typedef long long ll;
int d[35][35];
int n,m,p,a,b;
int horse[10];
double dp[1<<10][35];//残っている馬車券の情報&現在位置
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
  std::fill( (T*)array,(T*)(array+N),val );
}

int main(void)
{
  
  while(cin >> n >> m >> p >> a >> b && n)
    {
      for (int i = 0; i < 1<<n; ++i)
	{
	  fill(dp[i],dp[i]+m+1,INF);
	}
      for(int i=0;i<n;i++)
	{
	  cin >> horse[i];
	}
      for (int i = 1; i <= 30; ++i)
	{
	  for (int j = 1; j <= 30; ++j)
	    {
	      d[i][j]=-1;
	    }
	}
      for (int i = 0; i < p; ++i)
	{
	  int x,y,z;
	  cin >> x >> y >> z;
	  d[x][y]=z;
	  d[y][x]=z;
	}
      dp[(1<<n)-1][a]=0;
      double ans=INF;
      for (int S = (1<<n)-1; S >= 0; S--)
	{
	  ans=min(ans,dp[S][b]);
	  for(int v=1;v<=m;v++)
	    {
	      for(int i=0;i<n;i++)
		{
		  if((S >> i)&1)
		    {
		      //i番目の馬車券を使う
		      for(int u=1;u<=m;u++)
			{
			  if(d[v][u]>=0)
			    {
			      dp[S & ~(1<<i)][u]=min(dp[S & ~(1<<i)][u],dp[S][v]+(double)d[v][u]/horse[i]);
			    }
			}
		    }
		}
	    }
	}
      if(ans==INF)
	{
	  cout << "Impossible" << endl;
	}
      else
	{
	  cout << fixed << setprecision(9) << ans << endl;
	}
    }
  return 0;
 
}



Measured memory_bytes: 3236
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        Map<Integer, Integer> m = new HashMap<>();
        for(int i=0; i<n; i++){
            int a = scan.nextInt();
            if(m.containsKey(a)){
                m.put(a, m.get(a)+1);
            }else{
                m.put(a, 1);
            }
        }

        int cnt = 0;
        for(int key : m.keySet()){
            while(key != m.get(key) && m.get(key) != 0){
                m.put(key, m.get(key)-1);
                cnt++;
            }
        }

        System.out.println(cnt);
        scan.close();
        
    }
}

Measured memory_bytes: 66604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

constexpr int MOD = 1e9 + 7;

template<long long mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((mod + x) % mod) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint &a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint &a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint &a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint& operator/=(const mint &a) {
        long long n = mod - 2;
        mint<mod> u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

//powMod
ll powMod(ll k, ll n, ll mod) {
    ll x = 1;
    while (n > 0) {
        if (n & 1) {
            x = x * k % mod;
        }
        k = k * k % mod;
        n >>= 1;
    }
    return x;
}

// comb (一つのみ) O(r)
ll comb(ll n, ll r, ll mod) {
    ll ret = 1;
    while (true) {
        if (r == 0) break;
        ll N = n % mod;
        ll R = r % mod;
        if (N < R) return 0;
        for (int i = 0; i < R; i++)
        {
            ret = ret * (N - i) % mod;
        }
        ll imul = 1;
        for (int i = 0; i < R; i++)
        {
            imul = imul * (i + 1) % mod;
        }
        ret = ret * powMod(imul, mod - 2, mod) % mod;
        n /= mod; r /= mod;
    }
    return ret;
}

int main() {
    int n, m; cin >> n >> m;
    ll k; cin >> k;
    mint<MOD> c = comb((ll)n*m - 2, k - 2, MOD);
    mint<MOD> ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans += (mint<MOD>(n - 1 - i)*(m - 1 - j)*(n + m - i - j) / 2 + mint<MOD>(n - 1 - i)*(n - i) / 2 + mint<MOD>(m - 1 - j)*(m - j) / 2 + mint<MOD>(n - 1 - i)*j*(n - i + j + 1) / 2) * c;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int l[100000],r[100000];
int main() {
	int n,i,sum=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>l[i]>>r[i];
	}
	for(i=0;i<n;i++){
		sum+=r[i]-l[i]+1;
	}
	cout<<sum;
	return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	bool a = false, b = false, c = false, d = false;
	rep(i, 4) {
		int n;
		cin >> n;
		if (n == 1) a = true;
		if (n == 9) b = true;
		if (n == 7) c = true;
		if (n == 4) d = true;
	}
	
	if (a and b and c and d) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    int B[N]; fill(B, B + N, 0);
    int a;
    for(int i=0; i<N-1; i++){
        cin >> a;
        a--;
        B[a]++;
    }    
    for(int i=0; i<N; i++){
        cout << B[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  vector<P> v[n];
  int c[n];mem(c);
  rep(i,m) {
    int x,y,z;
    cin >> x >> y >> z;
    v[x].pb(P(y,z));
    c[y]++;
  }
  int d[n];
  memset(d,-1,sizeof(d));
  d[0]=0;
  queue<int> que;
  que.push(0);
  while(!que.empty()) {
    int x=que.front();que.pop();
    rep(i,v[x].size()) {
      P p=v[x][i];
      int y=p.F,cc=p.S;
      d[y]=max(d[y],d[x]+cc);
      c[y]--;
      if(!c[y]) que.push(y);
    }
  }
  pr(d[n-1]);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll n, t;
map<ll, ll, greater<ll>> cnt;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> t;
    vector<ll> a(n);
    for (auto& i : a) cin >> i;

    ll mn = -1;
    for (auto i : a) {
        if (mn == -1 || i < mn) {
            mn = i;
        } else {
            ++cnt[i - mn];
        }
    }

    for (auto i : cnt) {
        cout << i.second;
        break;
    }
}


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

using namespace std;

const int N = 2e5 + 2;

int n;
pair <int, int> a[N];
long long ans, mx, ind, pref[N], suff[N];

int main(){
      cin >> n;

      for(int i = 1; i <= n; i ++){
            cin >> a[i].first >> a[i].second;
      }

      sort(a + 1, a + n + 1);

      for(int i = 1; i <= n; i ++){
            pref[i] += pref[i - 1] + a[i].first;
      }

      for(int i = n; i >= 1; i --){
            suff[i] += suff[i + 1] + a[i].first;
      }

      for(int i = 1; i <= n; i ++){
            if(a[i].first > a[i].second){
                  long long res = pref[i - 1] + suff[i + 1];
                  res += a[i].first - a[i].second;
                  ans = max(ans, res);
            }
      }

      cout << ans << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  int i,j,cnt=0;
  int a,b,c;
  cin>>a>>b>>c;
  int A=a,B=b,C=c;
  while(a%2==0 && b%2==0 && c%2==0){
    int p=(b+c)/2,q=(c+a)/2,r=(a+b)/2;
    a=p;b=q;c=r;
    cnt++;
    if(A==a && B==b && C==c){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<cnt;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int x1 = scan.nextInt();
		int y1 = scan.nextInt();
		int x2 = scan.nextInt();
		int y2 = scan.nextInt();
		
		scan.close();
		
		int xDiff = x1 - x2;
		int yDiff = y1 - y2;
		
		int x3 = x2 + yDiff;
		int y3 = y2 - xDiff;
		
		int x4 = x3 + xDiff;
		int y4 = y3 + yDiff;
		
		System.out.print(x3 + " " + y3 + " " + x4 + " " + y4);
	}
}


Measured memory_bytes: 22868
import sys
import collections as c
sys.setrecursionlimit(10**6)

import sys
sys.setrecursionlimit(10**7)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N, K, L = map(int,input().split())
p = []
q = []
l = []
r = []

for _ in range(K):
	p_tmp, q_tmp = map(int ,input().split())
	p.append(p_tmp)
	q.append(q_tmp)

for _ in range(L):
	l_tmp, r_tmp = map(int, input().split())
	l.append(l_tmp)
	r.append(r_tmp)

road = UnionFind(N)
train = UnionFind(N)

for i in range(K):
	road.Unite(p[i], q[i])

for i in range(L):
	train.Unite(l[i], r[i])

ar = []

for i in range(1,N+1):
	a = road.Find_Root(i)
	b = train.Find_Root(i)
	ar.append(str([a,b]))

Car = c.Counter(ar)

for i in range(N):
	print(Car[ar[i]], end = " ")

Measured memory_bytes: 56564
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }

int main(){
    ll R; cin >> R;
    cout<<setprecision(10)<< 2.0* M_PI*R<<endl;
    return 0;
}


Measured memory_bytes: 3260
// Running Offline
// g++ tester.cpp
// ./a.out
//#include "/Users/manasgupta/Desktop/stdc++.h"

 #include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pi pair<int,int>
#define pb push_back
#define fi first
#define se second
// #define mp make_pair
#define inf 1e9
#define EPS 1e-6
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FILEIO(name1, name2) \
    freopen(name1".txt","r",stdin); \
    freopen(name2".txt","w",stdout);

const int N=300005;
const int mod = 119 << 23 | 1;

int power(int a, int b, int c)
{
	int res=1;
	while (b)
	{
		if (b&1) res=(res*a)%c;
		a=(a*a)%c;
		b=b>>1;
	}
	return res;
}

int n,k;
int a[N];
int dp[N];

signed main()
{
	IOS;
	cin>>n>>k;
	for (int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for (int i=2; i<n; i++)
	{
		int temp=1e9;
		for (int j=max(i-k, 0LL); j<i; j++)
		{
			temp=min(temp, abs(a[i]-a[j])+dp[j]);
		}
		dp[i]=temp;
	}
	cout<<dp[n-1]<<endl;
    return 0;
}





Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define int ll
#define ld double
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 2e5 + 6, MOD = 998244353;

int dp[N], t[4 * N];
pi a[N];

void change(int v, int l, int r, int pos, int val) {
    if (l == pos && r == pos) {
        t[v] = val;
        return;
    }
    int m = l + r >> 1;
    if (m >= pos)
        change(2 * v + 1, l, m, pos, val);
    else
        change(2 * v + 2, m + 1, r, pos, val);
    t[v] = max(t[2 * v + 1], t[2 * v + 2]);
}

int ask(int v, int l, int r, int L, int R) {
    if (l > R || r < L)
        return 0;
    if (l >= L && r <= R) 
        return t[v];
    int m = l + r >> 1;
    return max(ask(2 * v + 1, l, m, L, R), ask(2 * v + 2, m + 1, r, L, R));
}

void solve() {
    int n; cin >> n;
    loop(i, n)
        cin >> a[i].F >> a[i].S;
    sort(a, a + n);
    loop(i, n)
        change(0, 0, n - 1, i, i);
    dp[n] = 1;
    for (int i = n - 1; i >= 0; --i) {
        int lef = i, rig = n;
        while (rig - lef > 1) {
            int m = rig + lef >> 1;
            if (a[i].F + a[i].S > a[m].F)
                lef = m;
            else rig = m;
        }
        int x = ask(0, 0, n - 1, i, lef);
        change(0, 0, n - 1, i, x);
        dp[i] = (dp[i + 1] + dp[x + 1]) % MOD;
    }
    cout << dp[0];
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
signed main(){
	int n=read();
	int k=1;while (k<n) k<<=1;
	if (k==n){
		printf("No\n");
		return 0;
	}	
	printf("Yes\n");
	printf("%d %d\n",n+1,n+2);
	printf("%d %d\n",n+2,3);
	printf("%d %d\n",3,1);
	printf("%d %d\n",1,2);
	printf("%d %d\n",2,n+3);
	for (int j=4;j+1<=n;j+=2){
		int k=j+1;
		printf("%d %d\n",j,1);
		printf("%d %d\n",j,n+k);
		printf("%d %d\n",k,1);
		printf("%d %d\n",k,n+j);
	}	
	if (!(n&1)){
		for (int x=2;x<=n-1;++x){
			int y=n^x^1;
			if (y>=2&&y<=n-1) {
				printf("%d %d\n",n+n,x);
				printf("%d %d\n",n,y);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int D,T,S; cin >> D >> T >> S;
    if(D <= T*S){
        cout << "Yes" << enld;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
n, k = map(int, input().split())

import numpy as np
xy = np.zeros((n, 2), dtype=int)

for i in range(n):
	buf = input().split()
	xy[i][0] = int(buf[0])
	xy[i][1] = int(buf[1])

index = np.argsort(xy.T[0])
xysort = xy[index]

area = -1
for i in range(n-k+1):#nankotoruka
	num = k+i
	for j in range(n-(k+i)+1):
		y = np.sort(xysort[j: j+(k+i)].T[1])
		w = xysort[j+k+i-1][0] - xysort[j][0]
		hmin = y[k-1]-y[0]
		for p in range(i+1):
			if(y[p+k-1]-y[p] < hmin):
				hmin = y[p+k-1]-y[p]
		if(area == -1):
			area = w*hmin
		elif(w*hmin < area):
			area = w*hmin
			
print(area)
				


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

int main(){
    int N;
    cin >> N;
    string S; // Sの中に"ABC"が何個あるか
    cin >> S;
    int cnt = 0;

    for (int i = 0; i < S.size()-2; i++){
        if (S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C')
            cnt += 1;
    }
    cout << cnt << endl;
}

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

int main()
{
    // string  S, T, U;
    // int A, B;
    // cin >> S >> T;
    // cin >> A >> B;
    // cin >> U;
    
    // if(U == S){
    //     A--;
    // }else{
    //     B--;
    // }
    // cout << A << " " << B;
    string S;
    cin >> S;
    int i;
    for(i=0; i < S.length(); i++){
      cout << "x";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    ll n;
    cin >> n;
    vector<vector<ll> > a(n, vector<ll> (3));
    vector<vector<ll> > dp(n, vector<ll> (3));

    rep(i, n) cin >> a[i][0] >> a[i][1] >> a[i][2];
    rep(j, 3) {
        dp[0][j] = a[0][j];
    }
    rep2(i, 1, n) {
        rep(j, 3) {
            dp[i][j] = max(dp[i-1][(j+1)%3] + a[i][j], dp[i-1][(j+2)%3] + a[i][j]);
        }
    }
    
    ll ans = 0;
    rep(j, 3) {
        chmax(ans, dp[n-1][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 14024
#include <iostream>

using namespace std;

int const NMAX = 50;
int v[1 + NMAX];

int main()
{
  int n, ans = 0;
  cin >> n;
  for(int i =1;i <= n;i++){
    cin >> v[i];
  }
  for(int i =1;i <= n;i++){
    for(int j = i+1;j <= n;j++){
      if(i != j){
        ans += v[i] * v[j];
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Arrays;

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

    int input1 = scan.nextInt();

    int[][] map = new int[input1][input1];
    for(int[] _arr : map) Arrays.fill(_arr,-1);

    for(int i = 0; i < input1; i++) {
      int point = scan.nextInt();
      int input2 = scan.nextInt();
      for(int j = 0; j < input2; j++) {
        int aite = scan.nextInt();
        int omomi = scan.nextInt();

        map[point][aite] = omomi;
      }
    }

    boolean[] moved = new boolean[input1];
    int[] maxInterval = new int[input1];
    Arrays.fill(maxInterval,1<<30);
    maxInterval[0] = 0;
    moved[0] = true;

    check(0,moved,maxInterval,map);

    for(int i = 0; i < maxInterval.length; i++) {
      System.out.println(i+" "+maxInterval[i]);
    }
  }

  static void check(int nowPos, boolean[] moved, int[] maxInterval, int[][] map) {
    for(int i = 0; i < map[nowPos].length; i++) {
      if(map[nowPos][i] >= 0) {
        if(maxInterval[i] > maxInterval[nowPos]+map[nowPos][i]) {
          maxInterval[i] = maxInterval[nowPos]+map[nowPos][i];
        }
      }
    }
    int nextIndex = -1;
    int min = 1<<30;
    for(int i = 0; i < moved.length; i++) {
      if(!moved[i]) {
        if(maxInterval[i] <= min) {
          nextIndex = i;
          min = maxInterval[i];
        }
      }
    }
    if(nextIndex>0) {
      moved[nextIndex] = true;
      check(nextIndex,moved,maxInterval,map);
    }
  }
}

Measured memory_bytes: 40348