akhauriyash/Code-Regression huggingface dataset:
// Standard Stuff
#include <bits/stdc++.h>
using namespace std;

// Macros
#define F  first
#define S  second
#define PB push_back
#define MP make_pair
#define ALL(container)   container.begin(),container.end()
#define RALL(container)  container.rbegin(),container.rend()
#define MAKE_UNIQUE(vec) vec.erase(unique(ALL(vec)),vec.end())

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = std::pair <int,int>;

// Random
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/* [a,b] */ template<class T> T rnd_IntType(T a, T b){ return uniform_int_distribution<T>(a, b)(rng); }
/* [a,b) */ template<class T> T rnd_RealType(T a, T b){ return uniform_real_distribution<T>(a,b)(rng); }

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const deque<T> &v)  { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef LOCAL
	#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); d__f(_it, args); }
	void d__f(__attribute__((unused)) istream_iterator<string> it) {}
	template<typename Head, typename... Tail> void d__f(istream_iterator<string> it, Head H, Tail... T) { cerr << *it << " <=> [" << H << "]\n"; d__f(++it, T...); }
#else
	#define trace(args...)
#endif


void solve(){
	ll a; ld b;
	cin >> a >> b;

	ll ans = a * b;
	cout << ans << "\n";
}

signed main (void){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}

Measured memory_bytes: 3748
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(){
  int n,x,y,i,j;
  int min,t;
  int cnt[2008];

  scanf("%d %d %d", &n, &x, &y);

  for(i = 0;i <= 2001;i++) cnt[i] = 0;
  
  for(i = 1;i <= n - 1;i++){
     for(j = i + 1;j <= n;j++){
         min = j - i;
         t = abs(x - i) + 1 + abs(y - j);
         if(t < min) min = t;
         cnt[min]++;
     }
  }
  
  for(i = 1;i < n;i++) printf("%d\n",cnt[i]);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long read() { 
    bool flag = true; long long num = 0;char c = getchar(); 
    for(;c < '0' || c > '9';c = getchar())if(c == '-') flag = false; 
    for(;c >= '0' && c <= '9';c = getchar()) num = ( num << 3 ) + ( num << 1 ) + c - 48; 
    if(flag) return num;  else return -num; 
}
int main(){
	long long n,m;
	n=read();m=read();
	long long ans=0;
	if(n>1&&m>1) ans=(long long )(n-2)*(long long )(m-2);
	 else if(n==1&&m==1) ans=1;
	 else {
	 	if(n>m) swap(n,m);
	 	ans=m-2;
	 } 
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
//		inputStream = new FileInputStream(new File("/workspace/Atcoder/agc/agc003/C_in06.txt"));
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] a = in.nextIntArray(n);
			int[] as = a.clone();
			Arrays.sort(as);

			long ans = 0;
			for (int i = 0; i < n; i++) {
				int idx = Arrays.binarySearch(as, a[i]);
				if (abs(i - idx) % 2 == 1) ans++;
			}

			out.println(ans/2);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

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

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

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

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

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

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 35252
import java.io.*;
import java.util.*;
class Main{
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);
		int [] data= new int [10];
		for(int i = 0; i < 10; i++){
			int x = sc.nextInt();
			data[i] = x;
		}
		Arrays.sort(data);
		for(int i = 9; i > 6; i--){
			System.out.println(data[i]);
		}
	}
}

Measured memory_bytes: 17168
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 0
constexpr int kMod = 1000000007;
typedef long long LL;
using namespace std;

LL dp[1000001][2];  // keta, tight/lerger

int main() {
  string S; cin >> S;
  int N = S.length();

  dp[0][0] = 0, dp[0][1] = 1;
  for (int i = 1; i <= N; ++i) {
    int v = S[i-1] - '0';
    dp[i][0] = min(dp[i-1][0] + v, dp[i-1][1] + 10 - v);
    dp[i][1] = min(dp[i-1][0] + v + 1, dp[i-1][1] + 9 - v);
  }

#if DEBUG
  for (int i = 1; i <= N; ++i) {
    cout << dp[i][0] << " ";
  }
  cout << endl;
  for (int i = 1; i <= N; ++i) {
    cout << dp[i][1] << " ";
  }
  cout << endl;
#endif
  cout << dp[N][0] << endl;
}


Measured memory_bytes: 17028
#include <stdio.h>
  
int G[100][100],d[100],v[100];
int mst(int);
  
int main(){
  int n,i,j;
    
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
    }
  }
  printf("%d\n",mst(n));
  
  return 0;
}
  
int mst(int n){
  int i,j,k=1,min,minp,sum=0;
    
  d[0]=0;
  v[0]=1;
  
  for(i=1;i<n;i++) v[i]=0;
  
  while(1){
    min = 2001;
    for(i=0;i<k;i++){
      for(j=0;j<n;j++){
    if(G[d[i]][j]<min && G[d[i]][j] != -1 && v[j] != 1){
      min = G[d[i]][j];
      minp = j;
    }
      }
    }
      
    if(k==n) break;
    d[k] = minp;
    v[minp] = 1;
    sum += min;
    k++;
  }
  
  return sum;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	while ( true )
	{
		int n, m;
		cin >> n >> m;

		if ( !( n | m ) )
		{
			break;
		}

		vector<PII> secs( n );
		FOR( s, secs )
		{
			cin >> s.snd >> s.fst;
		}
		sort( ALL( secs ), greater<PII>() );

		REP( i, 0, n )
		{
			int minus = min( secs[i].snd, m );
			secs[i].snd -= minus;
			m -= minus;
		}
		
		LL res = 0;
		REP( i, 0, n )
		{
			res += secs[i].fst * secs[i].snd;
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

bool Check(vector<int> s,int l) {
  if (s.empty()) {
    return l == 0;
  }
  int N = s.size();
  int R = 0;
  for (int i = 0; i < N; i++) {
    R += s[i];
  }
  bool DP[N+1][2*R + 1];
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= 2*R; j++) {
      DP[i][j] = false;
    }
  }
  DP[0][R] = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 2*R; j++) {
      if (DP[i][j]) {
        DP[i+1][j + s[i]] = true;
        DP[i+1][j - s[i]] = true;
      }
    }
  }
  if (abs(l) > R) {
    return false;
  } else {
    return DP[N][R+l];
  }
}

int main() {
  string S;
  cin >> S;
  int x,y;
  cin >> x >> y;
  int N = S.size();
  int xstart = 0;
  int ystart = 0;
  vector<int> xlis;
  vector<int> ylis;
  int cnt = 0;
  int streak = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'F') {
      streak++;
    } else {
      if (streak == 0) {
        streak = 0;
        cnt++;
        continue;
      }
      if (cnt == 0) {
        xstart += streak;
      } else if (cnt % 2 == 1) {
        ylis.push_back(streak);
      } else {
        xlis.push_back(streak);
      }
      streak = 0;
      cnt++;
    }
  }
  if (streak != 0) {
    if (cnt == 0) {
      xstart += streak;
    } else if (cnt % 2 == 1) {
      ylis.push_back(streak);
    } else {
      xlis.push_back(streak);
    }
  }
  if (Check(xlis , x - xstart) && Check(ylis , y - ystart)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 19256
#include<cstdio>
#include<cmath>
int ans;
double n,d,a,b;
int main() {
	scanf("%lf%lf",&n,&d);
	for (int i=1;i<=n;++i) {
		scanf("%lf%lf",&a,&b);
		double tmp=sqrt(a*a+b*b);
		if (tmp<=d) ++ans;
	}
	printf("%d\n",ans);
	
	return 0;
} 

Measured memory_bytes: 2220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//ll dp[110][11100];

int main()
{
    int h, n; cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    vector<vector<ll>> dp(n + 1, vector<ll>(h + 1, MOD));
    dp[0][0] = 0;
    rep(i, n)
    {
        rep(j, h + 1)
        {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][min(j+a[i], h)], dp[i+1][j] + b[i]);
        }
    }
    cout << dp[n][h] << endl;

    // rep(i, n + 1)
    // {
    //     COUT(i);
    //     rep(j, h + 1)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
}

Measured memory_bytes: 78592
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 dx[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dy[9] = {1, 1, 1, 0, 0, 0, -1, -1, -1};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h, w, n;
	cin >> h >> w >> n;
	vector<int> a(n), b(n);
	set<P> s;
	rep(i,n){
		cin >> a[i] >> b[i];
		s.insert(P(a[i], b[i]));
	}
	ll sum = (h-2) * (w-2);
	map<P, int> mp;
	rep(i,n){
		rep(k,9){
			int nx = b[i] + dx[k];
			int ny = a[i] + dy[k];
			if(nx < 2 || w-1 < nx) continue;
			if(ny < 2 || h-1 < ny) continue;
			mp[P(ny, nx)]++;
		}
	}
/*
	for(int i = 1; i <= h; ++i){
		for(int j = 1; j <= w; ++j){
			cout << mp[P(i,j)] << " ";
		}
		cout << endl;
	}
*/
	cout << sum - (ll)(mp.size()) << endl;
	for(int j = 1; j <= 9; ++j){
		int ans = 0;
		for(auto p : mp){
			int y = p.first.first, x = p.first.second;
			if(x < 2 || w-1 < x) continue;
			if(y < 2 || h-1 < y) continue;
			if(p.second == j) ++ans;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 64000
import java.util.Scanner

object Main {

  def check2(num: Int, input: => Array[Array[Boolean]]): Int = {
    var ans = 0
    for (j <- 0 until input(0).length) {
      ans += {
        var N = 0
        for (i <- 0 until input.length) {
          N += (if (if ((num >> i) % 2 == 1) input(i)(j) else !(input(i)(j))) 0 else 1)
        }
        math.max(N, input.length - N)
      }
    }
    ans
  }

  def make(R: Int, C: Int, sc: => Scanner): Int = {
    val input: Array[Array[Boolean]] = Array.fill(R)(Array.fill(C)(sc.nextInt == 1))
    (0 until 1 << (R - 1)).view.foldLeft(0)((acc, i) => math.max(acc, check2(i, input)))
  }

  def solve(sc: => Scanner): Unit = {
    val R: Int = sc.nextInt
    val C: Int = sc.nextInt
    if (R != 0 && C != 0) {
      println(make(R, C, sc))
      solve(sc)
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 285508
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, M;
int l, r = INF;

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

    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        l = max(l, a);
        r = min(r, b);
    }
    int ans = 0;
    ans = max(0ll, r - l + 1ll);
    cout << ans << endl;
    

    return 0;
}
/*


*/

Measured memory_bytes: 256
from itertools import combinations as combi
N, M = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
def check(s):
  for i in range(M):
    temp = 0
    for j in range(1, S[i][0] + 1):
      if S[i][j] in s:
        temp += 1
    if temp % 2 != p[i]:
      return False
  return True
res = 0
for i in range(0, N + 1):
  for com in combi(range(1, N + 1), i):
    if check(set(com)) == True:
      res += 1
print(res)

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200010],l[200010];
int main(){
	int n,m,i,j,t;
	scanf("%d%d",&n,&m);
	n*=2;
	for(i=1;i<=n;i++)scanf("%d",a+i);
	sort(a+1,a+n+1);
	j=1;
	for(i=n;i>0;i--){
		for(;j<i&&a[j]+a[i]<m;j++);
		if(i==j)break;
		l[i]=j;
	}
	j=n;
	for(i=1;i<=n/2;i++){
		if(!l[n-i+1])break;
		j=min(j,n+i-l[n-i+1]);
		if(j<i*2)break;
	}
	j=(i-1)*2;
	t=0;
	for(i=1;i<(n-j+1-i);i++)t=max(t,a[i]+a[n-j+1-i]);
	for(i=1;i<=j/2;i++)t=max(t,a[n-j+i]+a[n-i+1]-m);
	printf("%d",t);
}

Measured memory_bytes: 1664
#\??¨?????????????´???????????????????
RL=[]
#?°´??????????????????????????¨??¢??????????´???????????????????
SL=[]

#\?????????RL????????????????????????????????????
def downer(index):
    RL.append(index)

#/?????????RL??????\????????????????????¢???????¨???????SL???????´?
def upper(index):
    if len(RL) > 0:
        p = RL.pop()
        q = index
        s = q - p
        if len(SL) > 0:
            QL = SL[::-1]
            for i in QL:
                if i[0] > p:
                    s += SL.pop()[1]
                else:
                    break
            SL.append([p, s])
        else: SL.append([p, s])
    else:return

L = input()
index = 0
for i in L:
    if i =="\\":
        downer(index)
        index += 1
    elif i =="/":
        upper(index)
        index += 1
    else:
        index += 1
AL =[]
for i in SL:
    AL.append(i[1])
print(str(sum(AL)))
if len(AL) == 0:
    print(len(AL))
else:
    print(len(AL),end=" ")
    print(" ".join(map(str,AL)))

Measured memory_bytes: 7996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define vi vector<int>
#define vl vector<long long>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define MOD 1e9+7;

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

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

const ll MAX_N = 1e5+10;
const ll MAX_M = 1e5*5+10;
struct edge{int to, cost;};
ll d[MAX_N];
vector< vector<edge> > es;

void dijkstra(int s) {
    priority_queue< P, vector<P>, greater<P> > q;
    d[s] = 0;
    q.push(P(0, s));
    while (!q.empty()) {
        P p = q.top(); q.pop();
        int u = p.second;
        if (d[u] < p.first) continue; //すでに最短経路が更新されていたらcontinue
        REP(i, (int)es[u].size()) {
            int v = es[u][i].to;
            if (d[v] > d[u]+es[u][i].cost) {
                d[v] = d[u]+es[u][i].cost;
                q.push(P(d[v], v));
            }
        }
    }
}

void solve(int r, int N) {
    dijkstra(r);
    REP(i, N) {
        if (d[i] != INF) {
            cout << d[i] << endl;
        }
        else cout << "INF" << endl;
    }
}

int main() {
    int V, E, r;
    cin >> V >> E >> r;
    es.resize(V);
    REP(i, E) {
        int s, t, d;
        cin >> s >> t >> d;
        es[s].push_back(edge{t, d});
    }
    REP(i, V) d[i] = INF;
    solve(r, V);
    return 0;
}


Measured memory_bytes: 13280
var N = 0
var A = 0

fun main(args: Array<String>) {
    readLine()?.split(" ")?.map {
        it.toInt()
    }?.let {
        N = it[0]
        A = it[1]
    }


    val x = IntArray(N + 1)
    readLine()?.split(" ")?.map {
        it.toInt()
    }?.forEachIndexed { i, n ->
        x[i + 1] = n
    }

    val dp = Array(N + 1) {
        Array(N + 1) {
            LongArray(N * A + 1)
        }
    }
    for (i in 0..N) {
        dp[i][0][0] = 1
    }

    for (i in 1..N) {
        for (j in 1..i) {
            for (k in 1..(N * A)) {
                dp[i][j][k] = if (k < x[i]) {
                    dp[i - 1][j][k]
                } else {
                    dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]]
                }
            }
        }
    }

    var ans = 0L
    for (j in 1..N) {
        ans += dp[N][j][j * A]
    }

    println(ans)
}



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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<long long> A(n);
    map<long long, long long> mp;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        mp[A[i]]++;
    }

    long long als = 0;
    for(auto x : mp){
        als += x.second * (x.second - 1) / 2;
    }

    for(int i = 0; i < n; i++){
        long long ans = als;
        ans -= (mp[A[i]] - 1);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 11136
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  string a,b;
  cin >> a >> b;
  sort(a.begin(),a.end());
  sort(b.rbegin(),b.rend());
  if(a < b)cout << "Yes" << endl;
  else cout << "No" << endl;
  cerr << a << endl;
  cerr << b << endl;
  return 0;
} 

Measured memory_bytes: 256
-- | Main entry point to the application.
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace
import Text.Printf
import Data.Array

isPrime n = null [i | i <- takeWhile (\x -> x * x <= n) primes, n `rem` i == 0]
primes = 2:3:[x | i <- [1..], j <- [-1,1], let x = 6*i+j, isPrime x]

-- | The main entry point.
main :: IO ()
main = do
    _ <- getLine
    ns <- concatMap (fmap (read :: String -> Int) . words) . lines <$> getContents
    putStrLn $ show $ length $ filter isPrime ns

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

double pai=3.1415926535;

int main() {
	double a,b,x;
	cin>>a>>b>>x;
	
	double ans;
	if(x>a*a*b/2){
		double res=atan(2*(a*b-x/a)/(a*a));
		ans=res*180/pai;
	}else{
		double res=atan(2*x/(a*b*b));
		ans=180*(pai/2-res)/pai;
	}
	
	cout<<fixed<<setprecision(10)<<ans<<endl;
	
	
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


int n;
char s[110];

int main()
{
	scanf("%d\n", &n);
	scanf("%s", s);
	
	int rCount = 0, bCount = 0;
	for (int i = 0 ; i < n ; i++)
		if (s[i] == 'R')
			rCount++;
		else if (s[i] == 'B')
			bCount++;
			
	if (rCount > bCount)
		printf("Yes\n");
	else
		printf("No\n");
	
	
	return 0;
}


Measured memory_bytes: 128
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll gcd(ll a,ll b){
  if(a%b == 0) return b;
  else return gcd(b,a%b);
}

int main(){
  int n;
  cin >> n;
  ll a[n],b[n];
  pair<ll,ll> ab[n];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    ab[i] = make_pair(a[i]+b[i],i);
  }
  sort(ab,ab+n);
  reverse(ab,ab+n);
  ll ans[2];
  ans[0] = 0;
  ans[1] = 0;
  for(int i=0;i<n;i++){
    if(i%2 == 0){
      ans[0] += a[ab[i].second];
    }
    else{
      ans[1] += b[ab[i].second];
    }
  }
  cout << ans[0] - ans[1] << endl;
  return 0;
}


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

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

const long long INF = 1LL << 60;

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

    vector<long long> dp(110000);
    for(int i=0; i<110000; i++) dp[i] = INF;

    dp[0] = 0;
    for(int i=1; i<=N; i++) {
        for(int pow6=1; pow6<=i; pow6*=6) {
            chmin(dp[i], dp[i-pow6] + 1);
        }
        for(int pow9=1; pow9<=i; pow9*=9) {
            chmin(dp[i], dp[i-pow9] + 1);
        }
    }

    cout << dp[N] << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    deque<int> B;
    rep(i, N) {
        if (i % 2 == 0) {
            B.push_back(A[i]);
        } else {
            B.push_front(A[i]);
        }
    }

    if (N % 2 == 0) {
        rep(i, N) cout << B[i] << " ";
    } else {
        rep(i, N) cout << B[N - 1 - i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    ll a[n], ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += a[i] - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import heapq


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

n, m = map(int,input().split())
q = Heapq(list(map(int,input().split())),True)
for i in range(m):
    q.push(q.pop()//2)
ans = 0
for i in range(n):
    ans += q.pop()
print(ans)

Measured memory_bytes: 14380
// AtCoder Grand Contest 011
// B - Colorful Creatures

#include <cstdio>
#include <queue>
#define MAX_N 100000
using namespace std;
typedef long long int ll;
typedef pair<ll, int> PLI;


int N;
priority_queue<PLI, vector<PLI>, greater<PLI> > q;

int main() {

  ll a;
  PLI c1, c2;

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a);
    q.push(make_pair(a, 1));
  }

  for (int i = 1; i < N; i++) {
    c1 = q.top(); q.pop();
    c2 = q.top(); q.pop();
    if (c1.first * 2 >= c2.first) {
      c2.second += c1.second;
    }
    c2.first += c1.first;
    q.push(c2);
  }
  printf("%d\n", q.top().second);

  return 0;

}




Measured memory_bytes: 2420
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

A = deque(input())
B = deque(input())
C = deque(input())

def DFS(N, name):
	if N == deque([]):
		print(name)
	else:
		p = N.popleft()
		if p ==  "a":
			DFS(A, "A")
		elif p == "b":
			DFS(B, "B")
		else:
			DFS(C, "C")

DFS(A, "A")

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define FOR(v1, v2) for (v1 = 0; v1 < v2; ++v1)
#define FORE(v1, v2) for (v1 = 0; v1 <= v2; ++v1)
#define FORO(v1, v2) for (v1 = 1; v1 < v2; ++v1)
#define FOROE(v1, v2) for (v1 = 1; v1 <= v2; ++v1)
using ll = long long;
constexpr int kSMax = 1'000'000'000;

int main () {
  int n, k, s;
	cin >> n >> k >> s;
	int i;
  if (s == kSMax) {
	  FOR(i, k) {
		  cout << s << " ";
		}
	  FOR(i, n - k) {
		  cout << s-1 << " ";
		}
	} else {
	  FOR(i, k) {
		  cout << s << " ";
		}
	  FOR(i, n - k) {
		  cout << s+1 << " ";
		}
	}
	cout << endl;
  return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        System.out.println("A"+b.charAt(0)+"C");
    }
}


Measured memory_bytes: 23508
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();
        int[][] array = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        }
        int count = 0;
        double dis = 0;
        for (int i = 0; i < n-1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        }
        System.out.println(count);
    }
}



Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include<math.h>

using namespace std;



typedef long long ll;


#define rep(i,n) for(ll i = 0; i < n; i++)



int main() {
	
	vector<int>a(3);

	rep(i, 3)cin >> a[i];

	sort(a.rbegin(), a.rend());

	ll ans = 0;

	

		ans += a[0] - a[1];

		if (a[0] == a[1] && a[1] == a[2]) {
			cout << ans << endl;
			return 0;
		}

		
		else {

			a[2] = a[2] + ans;
			a[1] += ans;

		

			while (a[2]<a[1]) {
				a[2] += 2;
				ans += 1;
			}

			if (a[0] == a[1] && a[1] == a[2]) {
				cout << ans << endl;
				return 0;
			}

			else {
				cout << ans + 1 << endl;
			}


		}
	return 0;
}


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

vector<ll> a(51), p(51);

ll f(ll N, ll X) {
  if (N == 0 && X >= 1) {
    return 1;
  } else if (X <= 0) {
    return 0;
  } else if (X <= 1 + a[N - 1]) {
    return f(N - 1, X - 1);
  } else {
    return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1]);
  }
}

int main() {
  ll n, x;
  cin >> n >> x;
  a[0] = 1;
  p[0] = 1;
  for (int i = 1; i <= 50; ++i) {
    a[i] = 2 * a[i - 1] + 3;
    p[i] = 2 * p[i - 1] + 1;
  }
  cout << f(n, x) << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	sort(A);
	int ans = 0;
	int a = 0;
	for (int i = 0; i < 100000-2; i++) {
		a = upper(A, i + 2) - lower(A, i);
		ans = max(ans, a);
	}
	cout << ans << endl;
}




Measured memory_bytes: 640
D = {}
N = int(input())
for n in range(N):
    S = list(input())
    S.sort()
    T = tuple(S)
    D[T] = D.setdefault(T, 0) + 1

res = 0
for v in D.values():
    res += v * (v - 1) // 2

print(res)

Measured memory_bytes: 23652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, X;

int main(void){
    
    scanf("%d %d", &N, &X);
    int ans = 0, sum = 0, mn = INT_MAX;
    for(int i = 0; i < N; ++i){
        int m; scanf("%d", &m);
        sum += m;
        if(sum <= X) ++ans;
        mn = min(mn, m);
    }
    
    if(sum > X) printf("%d\n", ans);
    else printf("%d\n", ans + (X - sum) / mn);
    
    return 0;
}

Measured memory_bytes: 256
def resolve():
    N, X, M = map(int, input().split())
    x = X
    mod = [x]
    while x**2 % M not in mod:
        mod.append(x**2%M)
        x = x**2%M

    ans = 0
    if N <= len(mod):
        for i in range(N):
            ans += mod[i]
    else:
        if mod[-1] == 1:
            ans = sum(mod) + N-len(mod)
        elif mod[-1] == 0:
            ans = sum(mod)
        else:
            first = mod.index(mod[-1]**2%M)
            head = mod[:first]
            loop = mod[first:]

            mo = (N-first)%len(loop)
            div = (N-first)//len(loop)
            ans += sum(head)+ div*sum(loop)
            for i in range(mo):
                ans += loop[i]
    print(ans)
resolve()

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

typedef pair<int,int> P;
typedef pair<P,int> PP;

int N, K, S;
vector<PP> V;

bool check(PP a, PP b) {
    if (!(a.first.first > b.first.first + S || a.first.first + S < b.first.first)) {
        if (!(a.first.second > b.first.second + S || a.first.second + S < b.first.second)) {
            if (a.second >= b.second + S || a.second + S <= b.second) return false;
            else return true;
        }
    }

    return false;
}

int diff(int a, int b) {
    int sub_x = S - abs(V[a].first.first - V[b].first.first);
    int sub_y = S - abs(V[a].first.second - V[b].first.second);
    int sub_z = S - abs(V[a].second - V[b].second);

    return (sub_x * sub_y + sub_z * sub_y + sub_z * sub_x) * 2;
}

int dfs(vector<vector<bool>>& inter, vector<bool>& used, int now, int k, int men, int pre) {
    if (k == K- 1) {
        for (int i = 0; i < N; i++) {
            if (inter[now][i] && used[i] && pre != i) {
                return diff(i, now);
            }
        }
        return 0;
    }
    used[now] = true;

    int res = -(1<<28);
    for (int i = 0; i < N; i++) {
        if (used[i] == false && inter[now][i])
            res = max(res ,dfs(inter, used, i, k + 1, men, now) + diff(now, i));
    }
    used[now] = false;

    return res;
}

void solve() {
    V.resize(N);
    for (int i = 0; i < N; i++) cin >> V[i].first.first >> V[i].first.second >> V[i].second;
    vector<vector<bool>> inter(N, vector<bool>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            inter[i][j] = check(V[i], V[j]);
        }
    }

    int ans = 1 << 28;
    for (int i = 0; i < N; i++) {
        vector<bool> used(N);
        ans = min(ans, S * S * 6 * K - dfs(inter, used, i, 0, 0, -1));
    }

    if (ans == 1 << 28) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

int main() {
    while (cin >> N >> K >> S, N || K || S) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3272
from fractions import gcd
import bisect

N, X = map(int, input().split())
x = [int(i) for i in input().split()]
a = x[-1]
x.append(a)
x.sort()
bisect.insort_left(x, X)
ans = 0
for y, z in zip(x[:-1], x[1:]):
    ans = gcd(ans, z-y)
print(ans)

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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) //cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

ll inf = 2e18; 
ll mod = 1e9 + 7;

void resposta(vl &a, int k){
    ll ans = 1;
    int i;
    for(i=0;i<k;i++){
        ans *= a[i];
        ans %= mod;
        if(ans < 0) ans += mod;
    }
    cout << ans << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, i, j;
    cin >> n >> k;
    vl a, ap, an;
    bool hasP = false;
    for(i=0;i<n;i++){
        ll x; cin >> x;
        a.push_back(x);
        if(x > 0){
            hasP = true;
            ap.push_back(x);
        }else{
            an.push_back(x);
        }
    }
    if(k == n){
        resposta(a, k);
        return 0;
    }
    if(k%2 == 1 && (!hasP)){
        sort(all(an), greater<ll>());
        resposta(an, k);
        return 0;
    }
    if(k%2 == 0 && (!hasP)){
        sort(all(an));
        resposta(an, k);
        return 0;
    }
    sort(all(ap));
    sort(all(an), greater<ll>());
    debug(ap);
    debug(an);

    vl sol;
    while(sol.size() + ap.size() < k){
        sol.push_back(an.back());
        an.pop_back();
        sol.push_back(an.back());
        an.pop_back();
    }
    
    while(sol.size() < k){
        sol.push_back(ap.back());
        ap.pop_back();
    }
    debug(sol);
    i = sol.size()-1;
    while(true){
        if(i-1 < 0) break;
        if(sol[i] < 0 || sol[i-1] < 0) break;
        if(an.size() < 2) break;
        debug(sol);
        debug(an);
        ll op1 = sol[i]*sol[i-1];
        ll op2 = an.back() * an[an.size()-2];
        if(op1 >= op2) break;
        sol[i] = an.back();
        sol[i-1] = an[an.size()-2];
        an.pop_back();an.pop_back();
        i -= 2;
    }
    resposta(sol, k);
    return 0;
}

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

using namespace std;
using ll = long long;

#define INF (1ll << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> h(N);
    REP(i,0,N) cin >> h[i];

    vector<ll> dp(N+K, INF);

    dp[0] = 0;
    REP(i,0,N) {
        REP(j,1,K+1){
            dp[i+j] = MIN(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }

    _PR(dp[N-1]);

    return 0;
}

/*



*/

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

using namespace std;

typedef long long ll;
const ll N = 1e5;

int n;
int a[N+5];

int main()
{
    std::ios::sync_with_stdio(false);
    while ( cin >> n )
    {
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }

        sort(a, a+n);

        // +1 -2 +2 -2 +2 ......+1(odd) -1(even)
        ll ans1 = 0;
        int minus2 = (n-1)/2;
        int plus2 = (n-2)/2;
        int plus1 = n%2 ? 2 : 1;
        int minus1 = 2 - plus1;
        for (int i = 0; i < n; i++)
        {
            if (minus2)
            {
                minus2--;
                ans1 -= 2*a[i];
            }
            else if (minus1)
            {
                minus1--;
                ans1 -= a[i];
            }
            else if (plus1)
            {
                plus1--;
                ans1 += a[i];
            }
            else
            {
                ans1 += 2*a[i];
            }
        }

        // -1 +2 -2 +2 -2 ......-1(odd) +1(even)
        ll ans2 = 0;
        minus2 = (n-2)/2;
        plus2 = (n-1)/2;
        plus1 = n%2 ? 0 : 1;
        minus1 = 2 - plus1;
        for (int i = 0; i < n; i++)
        {
            if (minus2)
            {
                minus2--;
                ans2 -= 2*a[i];
            }
            else if (minus1)
            {
                minus1--;
                ans2 -= a[i];
            }
            else if (plus1)
            {
                plus1--;
                ans2 += a[i];
            }
            else
            {
                ans2 += 2*a[i];
            }
        }

        //cout << ans1 << " " << ans2 << endl;

        cout << max(ans1, ans2) << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

long long const MOD = 1000000007;
typedef vector<long long> vec;
typedef vector<vec> mat;
mat mat_plus(mat a, mat b) {
	mat c(a.size(), vec(a[0].size()));
	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < a[0].size(); j++) {
			c[i][j] = (a[i][j] + b[i][j]) % MOD;
		}
	}
	return c;
}
mat mat_mul(mat a, mat b) {
	mat ans(a.size(), vec(b[0].size()));
	for (int i = 0; i < a.size(); i++) {
		for (int k = 0; k < b[0].size(); k++) {
			ans[i][k] = 0;
		}
	}
	for (int i = 0; i < a.size(); i++) {
		for (int k = 0; k < b[0].size(); k++) {
			for (int j = 0; j < a[0].size(); j++) {
				ans[i][k] = (ans[i][k] + (a[i][j] * b[j][k]) % MOD) % MOD;
			}
		}
	}
	return ans;
}

mat mat_pow(mat a, long long n) {
	if (n == 1) {
		return a;
	}
	mat b(a.size(), vec(a[0].size()));
	b = mat_pow(a, n / 2);
	b = mat_mul(b, b);
	if (n % 2 == 1) {
		b = mat_mul(b, a);
	}
	return b;
}

long long mod_p(long long a, long long b) {
	return (a + b) % MOD;
}
long long mod_m(long long a, long long b) {
	return a * b%MOD;
}

int main() {
	long long r,h;
	cin >> r >> h;
	mat y(r, vec(r));
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < r; j++) {
			cin >> y[i][j];
		}
	}
	mat z(r, vec(r));
	z = mat_pow(y, h);
	ll ans = 0;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < r; j++) {
			ans = (ans + z[i][j]) % MOD;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2944
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
if a.all?(0)
  puts "Yes"
else
  cnt = Hash.new(0)
  a.each do |x|
    cnt[x] += 1
  end
  if cnt.length == 2 && a.length % 3 == 0
    f1 = false
    f2 = false
    cnt.each do |k,v|
      if k == 0
        f1 = true
      elsif v == 2 * a.length / 3
        f2 = true
      end
    end
    if f1 && f2
      puts "Yes"
    else
      puts "No"
    end
    exit
  elsif cnt.length == 3 && a.length % 3 == 0
    f = true
    x = 0
    cnt.each do |k,v|
      if v != a.length / 3
        f = false
      end
      x = x ^ k
    end
    if x == 0 && f
      puts "Yes"
    else
      puts "No"
    end
    exit
  end
  puts "No"
end

Measured memory_bytes: 24860
n=gets.to_i
s=[]
(0..n-1).each do |x|
    s[x]=gets.chomp.to_s
end
max=0
s2=Array.new(s.sort!)
s2.uniq!
s3=Array.new(s2.size(),0)
z=0
(0..n-1).each do |y|
    if s2[z]==s[y]&& z<s2.size()
        s3[z]+=1
    else
        z+=1
        if s2[z]==s[y] && z<s2.size()
            s3[z]+=1
        end
    end
end
max=s3.max
(0..s2.size()-1).each do |i|
    if s3[i]==max
        puts s2[i]
    end
end


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

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<int>> dp(10, vector<int>(10));
  rep(i, 10) {
    rep(j, 10) {
      cin >> dp.at(i).at(j);
    }
    dp.at(i).at(i) = 0;
  }

  rep(k, 10) {
    rep(i, 10) {
      rep(j, 10) {
        dp.at(i).at(j) = min(dp.at(i).at(j), dp.at(i).at(k) + dp.at(k).at(j));
      }
    }
  }

  int ans = 0;
  rep(i, H) {
    rep(j, W) {
      int c;
      cin >> c;

      if (c == -1) continue;
      ans += dp.at(c).at(1);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int GCD(int x,int y){
  if(y == 0) return x;
  return GCD(y,x%y);
}

int main() {
  int n,k;
  cin >> n >> k;
  vector<int>a(n);
  rep(i,0,n) cin >> a[i];
  sort(a.begin(),a.end());
  if(n == 1){
    if(k == 0 || k == a[0]) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  int gcd = GCD(a[0],a[1]);
  rep(i,1,n) gcd = GCD(gcd,a[i]);
  if(a[n-1] >= k && k%gcd == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

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

int main(){
    int n; cin>>n;
    string s; cin>>s;
    s.erase(unique(s.begin(),s.end()),s.end());
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <set>
using namespace std;

set<string> S;

int main(int argc, char** argv)
{
	int n; cin>>n;
	while(n--)
	{
		string s;
		cin>>s;
		S.insert(s);
	}
	cout<<S.size()<<endl;
	return 0;
}

Measured memory_bytes: 19076