akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

int main(){
    int n;
    string s;
    cin >> n >> s;
    char c = s[0];
    int ans = 1;
    for(int i = 1; i < n; i++){
        if (c != s[i]){
            c = s[i];
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int a,b,c,y,x,kq;

void    init()
{
    freopen("c.inp","r",stdin);
    freopen("c.out","w",stdout);
}

void    nhap()
{
    scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
}

void    xuly()
{
    int kq1=a*x+b*y;
    int kq2=0;
    if (x<y)
        kq2=c*x*2+b*(y-x);
    else
        kq2=c*y*2+a*(x-y);
    int kq3=0;
    if (x<y)
        kq3=c*y*2;
    else
        kq3=c*x*2;
    kq=min(kq1,min(kq2,kq3));
}

void    xuat()
{
    printf("%d",kq);
}

int     main()
{
    //init();
    nhap();
    xuly();
    xuat();
}



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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

void solve() {
  int n;
  cin >> n;
  cout << 1110-n << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
//# define FLAG
///delet....................................
# include <iostream>
# include <cstring>
# include <cstdlib>
# include <cstdio>
# include <string>
# include <cmath>
# include <ctime>
# include <set>
# include <map>
# include <queue>
# include <stack>
# include <bitset>
# include <vector>
# include <fstream>
# include <algorithm>
using namespace std;
# define eps 1e-8
# define pb push_back
# define mp make_pair
# define pi acos(-1.0)
# define bug puts("H");
# define mem(a,b) memset(a,b,sizeof(a))
# define IOS ios::sync_with_stdio(false);
# define FO(i,n,a) for(int i=n; i>=a; --i)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define MAX 0x7fffffffffffff
# define INF 0x3f3f3f3f
# define MOD 1000000007
///          1234567890
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef unsigned long long ULL;
typedef long long LL;
inline int Scan(){
    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;
}
///coding...................................

LL a[100005];
bool cmp(LL a,LL b) {
    return a>b;
}

int main()
{
    IOS
#ifdef FLAG
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif /// FLAG
    LL n,ans1=0,ans2=0;
    cin>>n;
    FOR(i,1,n)cin>>a[i];
    sort(a+1,a+n+1,cmp);
    FOR(i,1,n-1) {
        if(ans1==0) {
            if(a[i]==a[i+1]) {
                ans1=a[i];
                ++i;
            }
        }
        else {
            if(a[i]==a[i+1]) {
                ans2=a[i];
                break;
            }
        }
    }
    LL ans=ans1*ans2;
    cout<<ans<<endl;
    return 0;
}
///delete FLAG..............................



















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

int main(){
  int L,M,N;

  while(cin >> L){
    if(L==0) break;
    int  money=0;
    bool flag = false;

    for(int i=0; i<12; i++){
      cin >> M >> N;
      money += M - N;

      if(L <= money && flag == false){
	cout << i+1 << endl;
	flag = true;
	continue;
      }
    }
    if(flag == false) cout << "NA" << endl;

  }
  return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-10;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
struct Point{double x,y;};
double dis(Point a,Point b){
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
Point tri(Point a, Point b, Point c){
  double a1,a2,b1,b2,c1,c2;
  a1=2*(b.x-a.x);
  b1=2*(b.y-a.y);
  c1=a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y;
  a2=2*(c.x-a.x);
  b2=2*(c.y-a.y);
  c2=a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y;
  Point p;
  p.x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
  p.y=(c1*a2-c2*a1)/(a1*b2-a2*b1);
  return p;
}
int main(){
  startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,k,l,N;
  cin>>N;
  double ans=inf,fir;
  vector<Point> v(N);
  Point x;
  rep(i,N)cin>>v[i].x>>v[i].y;
  sort(all(v),[](auto const& a,auto const& b){if(a.x!=b.x){return a.x<b.x;}else if(a.y!=b.y){return a.y<b.y;}else{return true;}});
  rep(i,N)For(j,i+1,N){
    double res=dis(v[i],v[j])*0.5;
    fir=res;
    x.x=(v[i].x+v[j].x)/2;
    x.y=(v[i].y+v[j].y)/2;
    rep(k,N){
      if(i==k||j==k)continue;
      if(dis(x,v[k])>fir+eps){
        res=inf;
        break;
      }
    }
    chmin(ans,res);
  }
  rep(i,N)For(j,i+1,N)For(k,j+1,N){
    if((v[i].x-v[k].x)*(v[j].y-v[k].y)!=(v[i].y-v[k].y)*(v[j].x-v[k].x)){
      x=tri(v[i],v[j],v[k]);
      fir=dis(x,v[i]);
      rep(l,N){
        if(dis(x,v[l])>fir+eps){
        fir=inf;
        break;
        }
      }
      chmin(ans,fir);
    }
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
s = int(input())

a = s
i = 1
aa=[s]
while i < 100000:
    i+=1
    if a%2 ==0:
        a = int(a / 2)
    else:
        a = int(a * 3 + 1)
    if aa.count(a)>0:
        print(i)
        break
    else:
        aa.append(a)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
    long long int N;
    cin >> N;
    if(N%2) {
        cout << 0 << endl;
    } else {
        long long int ans=0;
        long long int pow=5;
        while(pow<=N) {
            ans += (N/pow)/2;
            pow *= 5;
        }
        cout << ans << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int[] a=cin.ArrayInt(2,0);
        int A=a[0];
        int B=a[1];
        int ans=0;
        int consent=1;
        while(consent<B)
        {
            {consent--;consent+=A;ans++;}
        }
        
        
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 13140
-- modules to import --

import qualified Data.ByteString.Char8
import qualified Data.Maybe
import           Prelude

-- functions for this task --

readInteger'    = Prelude.fst . Data.Maybe.fromJust . Data.ByteString.Char8.readInteger
readListInteger = Prelude.map readInteger'          . Data.ByteString.Char8.words

getInteger     = readInteger'    <$> Data.ByteString.Char8.getLine
getListInteger = readListInteger <$> Data.ByteString.Char8.getLine

countNumOperations :: Integer -> Integer -> Integer
countNumOperations itr x
        | val_mod == (0 :: Integer) = countNumOperations (itr + (1 :: Integer)) (val_div)
        | Prelude.otherwise         = itr
        where
                (val_div, val_mod) = Prelude.divMod (x) (100 :: Integer)

calculateAnswer :: Integer -> Integer -> Integer -> Integer -> Integer
calculateAnswer data_d data_n counter val_answer
        | counter < data_n  = calculateAnswer (data_d) (data_n) (counter_updated) (val_answer_updated)
        | Prelude.otherwise = val_answer
        where
                val_answer_updated = val_answer + (1 :: Integer)
                numOperations      = countNumOperations (0 :: Integer) (val_answer_updated)
                counter_updated    = if (numOperations == data_d) then (counter + (1 :: Integer)) else counter

task_B :: Integer -> Integer -> Integer
task_B data_d data_n = calculateAnswer (data_d) (data_n) (0 :: Integer) (0 :: Integer)

-- the main process is as follows --

main :: IO ()
main = do

        -- STEP.01
        -- read out the given data
        [d, n] <- getListInteger

        -- STEP.02
        -- calculate & output the answer of this task
        Prelude.print $ task_B (d) (n)

Measured memory_bytes: 1020
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

int main()
{
	LL a, b;
	scanf("%lld %lld", &a, &b);
	LL ans = 0;
	if(a > 3 && b > 3) ans = ans + b * 2 + a * 2 - 4;
	else {
		if(a == 2 || b == 2) ans = a * b;
		else if(a == 1 && b == 1) ans = 0;
		else if(a == 1 || b == 1) ans = 2;
	}
	LL pp = a * b;
	printf("%lld\n", pp - ans);
}

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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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 (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int factorial(int n)
{
    int x;
    if (n > 0) {
        x = n * factorial(n - 1);
    } else {
        x = 1; // 0! = 1
    }
    return x;
}

int main()
{

    double n;
    cin >> n;

    double fn = (double) factorial((int) n);

    int x, y;
    vector<pii> p;
    REP(i,n) {
        cin >> x >> y;
        p.emplace_back(pii(x,y));
    }

    double ans = 0;
    const int N =n;
    vector<int> v(N);
    iota(v.begin(), v.end(), 0);       // v に 1, 2, ... N を設定
    do {
        // for(auto x : v) cout << x << " "; cout << "\n";    
        pii befor = p[v[0]];
        REP(i,n-1) {
            pii next = p[v[i+1]];
            {
                // cout << "xi = " << befor.first << " xj = " << next.first << endl;
                // cout << "yi = " << befor.second << " xj = " << next.second << endl;
            }
            double xi = befor.first;
            double xj = next.first;
            double yi = befor.second;
            double yj = next.second;
            double dis = sqrt((xi-xj)*(xi-xj) + (yi-yj)*(yi-yj));
            //cout << dis << endl;
            ans += dis/fn;

            befor = next;  
        }
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

    cout << setprecision(12) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	ans = 0
	count = input[2]
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n").map((n) => parseInt(n));
	// s = input[0].split(' ').map((n) => (parseInt(n)))
	var s = input[0] > input[1] ? input[0] : input[1]
	ans = Math.ceil((input[2] / s))




	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 21064
from bisect import bisect_left,bisect

# ===================================== 約数のリスト   
def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret

n,m=map(int,input().split())

div=enum_div(m)+[m]
div.sort(reverse=True)

rd=[0]*len(div)
for i in range(len(div)):
    rd[i]=m//div[i]

mm=bisect_left(rd,n)

print(div[mm])


Measured memory_bytes: 9468
#include <iostream>
#include <vector>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::sort;

int main() {
  vector<int> s;

  for (int i = 0; i < 3; i++) {
    int x;
    cin >> x;
    s.push_back(x);
  }
  sort(s.begin(), s.end());

  if (s[0] + s[1] == s[2]) cout << "Yes" << endl;
  else                     cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define HelloFile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define ll long long
#define F first
#define S second
#define lcm(a,b) ((a*b)/__gcd(a,b))
int d, dp[10005][2][102];
string k;
int add(int a, int b, int Mod)
{
    return (a + b) % Mod;
}
int solve(int idx, bool smaller, int sum)
{
    if(idx == k.size())
        return sum == 0;
    int &ans = dp[idx][smaller][sum];
    if(ans != -1)
        return ans;
    ans = 0;
    for(int digit = 0; digit <= 9; digit++)
    {
        if(!smaller && digit > k[idx] - '0')
            continue;
        bool newSmaller;
        if(smaller)
            newSmaller = 1;
        else
            if(digit < k[idx] - '0')
                newSmaller = 1;
            else
                newSmaller = 0;
        ans = add(ans, solve(idx + 1, newSmaller, add(sum, digit, d)), mod);
    }
    return ans;
}
int main()
{
    memset(dp, -1, sizeof dp);
    cin >> k >> d;
    cout << (solve(0, 0, 0) - 1+mod ) % mod;
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        int N = int.Parse(Console.ReadLine());
        List<int> list = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToList();
        list.Insert(0,0);//番兵
        list.Add(0);//番兵
        var sum = list.Zip(list.Skip(1), (prev, next) => Math.Abs(prev - next)).Sum();
        int dif;
        for(var i=0;i<N;i++){
            //経路i~i+2において、点iを経由する時の距離と経由しない時の距離の差を求める
            dif = Math.Abs(list[i+1] - list[i]) + Math.Abs(list[i+2] - list[i+1]) - Math.Abs(list[i+2] - list[i]);
            Console.WriteLine(sum - dif);
        }
    }
}

Measured memory_bytes: 26844
// AOJ 1093: KND Runs for Sweets
// 2017.11.16 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define KAI 35
int x[101], y[101], v[101]; int n;
int max;

double fx(double a, double b)
{
	int i;
	double d, max;
	
	max = 0;
	for (i = 0; i < n; i++) {
		d = hypot(a-x[i], b-y[i]) / v[i];
		if (d > max) max = d;
	}
	return max;
}

double srchy(double x)
{
	int i;
	double l, r, a, b;

	l = 0, r = max;
	i = KAI; while (i--) {
		a = (2*l + r) / 3;
		b = (l + 2*r) / 3;
		if (fx(x, a) < fx(x, b) ) r = b;
		else                      l = a;
	}
	return fx(x, (l+r)/2);
}

double srch3()
{
	int i;
	double l, r, a, b;
	
	l = 0, r = max;
	i = KAI; while (i--) {
		a = (2*l + r) / 3;
		b = (l + 2*r) / 3;
		if (srchy(a) < srchy(b)) r = b;
		else                     l = a;
	}
	return srchy((l+r) / 2) ;
}

int main()
{
	int i;

	while (scanf("%d", &n) && n > 0) {
		max = 0;
		for (i = 0; i < n; i++)	{
			scanf("%d%d%d", x+i, y+i, v+i);
			if (x[i] > max) max = x[i];
			if (y[i] > max) max = y[i];
		}
		printf("%.8f\n", srch3());
	}
	return 0;
}

Measured memory_bytes: 1840
iN,iM = [int(_) for _ in input().split()]
iD = iM // iN
if iM % iN == 0:
    print(iD)
elif 2*iN > iM :
    print(1)
else:
    aD = []
    for i in range(1,int(iM**0.5)+1):
        if iM % i == 0:
            if iD > i : aD.append(i)
            j = iM // i
            if iD > j :aD.append(j)
    print(max(aD))


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



string s;
int paper;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>s;
    int score = 0;
    
    for (char c: s) {
	if (c=='p') {
	    if (paper>0) {
		paper--;
	    } else {
		paper++;
		score--;
	    }
	} else if (c=='g') {
	    if (paper>0) {
		paper--;
		score++;
	    } else {
		paper++;
	    }
	}
    }
    cout<<score<<endl;  

    return 0;
}


Measured memory_bytes: 512
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N  = parseInt(arg[0].split(" ")[0]);
    const Q  = arg[0].split(" ")[1];
    const S  = arg[1];

    let dp = new Array(N).fill(0);
    let cnt = 0;
    
    for(let i in dp) {
        if(S[i] === "A" && S[parseInt(i)+1] === "C") {
            cnt++;
        }
        
        dp[parseInt(i)+1] = cnt;
    }

    for(let i=0; i<Q; i++) {
        let lr = arg[i+2].split(" ");
        let l = lr[0];
        let r = lr[1];
        
        console.log(dp[r-1]-dp[l-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 38920
//***Faithless is he that says farewell when the road darkens***

#include<bits/stdc++.h>
using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main()
{
   ll a,b;
   cin>>a>>b;
   cout<<max(max(a+b,a-b),a*b);
}

Measured memory_bytes: 256
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
/*#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <assert.h>*/

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e6 + 6;

int n;
vector < int > vec[2];

int main() {
	ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

	cin >> n;
	forn(i, 1, n) {
        int x;
        cin >> x;
        vec[i & 1].eb(x);
	}

	if (n & 1) swap(vec[0], vec[1]);
	reverse(all(vec[0]));
	for (auto it : vec[0]) cout << it << " ";
	for (auto it : vec[1]) cout << it << " ";

	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    if((b - a) % 2){
        cout << "Borys\n";
    }else{
        cout << "Alice\n";
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
//場合分け

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] In = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            long n = In[0];
            long x = In[1];
            A = new long[n];
            P = new long[n];
            A[0] = 1; P[0] = 1;
            for (int i=1; i < n; i++)
            {
                A[i] = A[i - 1] * 2 + 3;
                P[i] = P[i - 1] * 2 + 1;
            }
            Console.WriteLine(F(n, x));
        }
        static public long[] A,P;
        static long F(long n,long x)
        {
            //if (x == 1) return 0;
            if (n == 0) return x <= 0 ? 0 : 1;
            else if (x <= 1 + A[n - 1]) return F(n - 1, x - 1);
            //else if (x == 2 + A[n - 1]) return P[n - 1] + 1;
            else return P[n - 1] + 1 + F(n - 1, x - 2 - A[n - 1]);
            //else if (x <= 2 + A[n - 1] * 2) return P[n - 1] + 1 + F(n - 1, x - 2 - A[n - 1]);
            //else if (x == 3 + A[n - 1] * 2) return P[n - 1] * 2 + 1;
            //else return -1001001001;
        }

    }
}
//RE
//namespace D
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            long[] In = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
//            n = (int)In[0];
//            long x = In[1];
//            string s = F();
//            long ans = 0;
//            for(int i=0; i < x; i++)
//            {
//                if (s[i] == 'P') ans++;
//            }
//            Console.WriteLine(ans);
//        }
//        static public int n;
//        static string F(string s="P",int cnt=0)
//        {
//            if (n == cnt) return s;
//            cnt++;
//            return F("B" + s + "P" + s + "B",cnt);
//        }

//    }
//}


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

int main(){
  int N,M;
  long long int charge=0;
  cin>>N>>M;
  vector<pair<long long int,long long int>> vec(N,pair<long long int,long long int>());
  
  for(int i=0;i<N;i++)
    cin>>vec.at(i).first>>vec.at(i).second;
  
  sort(vec.begin(),vec.end());
  
  for(int i=0;i<N;i++){
    if(M<=vec.at(i).second){
      charge += M*vec.at(i).first;
      cout<<charge<<endl;
      return 0;
    }
    else{
      charge += vec.at(i).second*vec.at(i).first;
      M -= vec.at(i).second;
    }
  }
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){

	ll n, a[200000], arai=0, sunuke=0, diff=1e15;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		arai+=a[i];
	}

	for(int i=0; i<n-1; i++){
		sunuke+=a[i];
		arai-=a[i];
		diff=min(diff, abs(sunuke-arai));
	}
	cout << diff << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>

using namespace std;


int cost_for_woodgroup(vector<int> wood_group, int goal){

    int sum_group = accumulate(wood_group.begin(), wood_group.end(), 0);

    return (wood_group.size()-1) * 10 + abs(goal - sum_group);   
}

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

    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> l;

    for (int i = 0; i < N; ++i){
        int l_val;
        cin >> l_val;
        l.push_back(l_val);
    }

    int cost = 1000000;
    for(int i = 0; i < pow(4, N); ++i){
        vector<int> woodgroupA;
        vector<int> woodgroupB;
        vector<int> woodgroupC;

        for(int i_w=0; i_w < N; ++i_w){

            string w_group = bitset<16>(i).to_string().substr(14-i_w*2, 2);
            if(w_group == string("01")){
                woodgroupA.push_back(l[i_w]);
            }
            if(w_group == string("10")){
                woodgroupB.push_back(l[i_w]);
            }
            if(w_group == string("11")){
                woodgroupC.push_back(l[i_w]);
            }
        }

        if(woodgroupA.size() > 0 && woodgroupB.size() > 0 && woodgroupC.size() > 0){
            int costA, costB, costC;
            costA = cost_for_woodgroup(woodgroupA, A);
            costB = cost_for_woodgroup(woodgroupB, B);
            costC = cost_for_woodgroup(woodgroupC, C);
            
            if(costA + costB + costC < cost){
                cost = costA + costB + costC;
            }
        }
    }

    cout << int(cost) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
int a,b;
while(true){
scanf("%d %d",&a,&b);
if(a==0) break;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
printf("#");
}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 1000
#include <iostream>

#define C 300000
using namespace std;

int main() {
    int n, q;
    int c[300000], query[100000];
    bool has_c[C+1];
    cin >> n >> q;
    for (int i=0; i<n; i++) {
        cin >> c[i];
    }
    for (int i=0; i<q; i++) {
        cin >> query[i];
    }
    for (int i=0; i<=C; i++) {
        has_c[i] = false;
    }
    for (int i=0; i<n; i++) {
        has_c[c[i]] = true;
    }
    for (int i=0; i<q; i++) {
        int max_r = -1;
        for (int r=query[i]-1; r>=0; r--) {
            for (int k=0; true; k++) {
                int x = k*query[i]+r;
                if (x > C) {
                    break;
                }
                if (has_c[x]) {
                    max_r = max(r, max_r);
                    break;
                }
            }
            if (max_r >= 0) {
                break;
            }
        }
        cout << max_r << endl;
    }
    return 0;
}

Measured memory_bytes: 3016
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define drep(i, n) for (long long i = n - 1; i > 0; i--)
#define pb push_back
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    n *= a;
    if (n < b)
    {
        cout << n << endl;
        return 0;
    }
    else
    {
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    rep(i, n){
        cin >> a[i];
        a[i] -= i - 1;
    }
    sort(ALL(a));
    vector<ll> b(n - 1);

    rep(i, n - 1){
        b[i] = a[i + 1] - a[i];
    }

    ll res = INF * INF;
    rep(i, n){
        if(i == 0){
            rep(j, n){
                sum += abs(a[j] - a[i]);
            }
            res = min(res, sum);
        }
        else {
            sum += (b[i - 1] * i - b[i - 1] * (n - i));
            res = min(res, sum);
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 3328
n,m,x = map(lambda x: int(x), input().split())
a = list()
for i in range(n):
  a.append([int(_) for _ in input().split()])

moneys = []
skips = []

for i in range(1, 2**n):
  b = [int(_) for _ in list(format(i, '0{}b'.format(n)))]
  
  sums = [0]*m
  skip = [0]*m
  money = 0
  
  for j in range(n):
    if b[j] == 1:
      money += a[j][0]
      for k in range(m):
        sums[k] += a[j][k+1]
        if sums[k] >= x:
          skip[k] = 1
  if sum(skip) == m:
    moneys.append(money)
if len(moneys) > 0:
  print(min(moneys))
else:
  print(-1)

Measured memory_bytes: 69044
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"2017/12/01"# => "2018/12/01",
// r#"5"# => "43",
// r#"21"# => "27",
// r#"24"# => "No",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: String,
    }
    s.replace("2017", "2018")
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;

const int MAX_V=10;//最大頂点数
const int INF=1e9;
struct Edge{
    int to;
    int cost;
    Edge(int to,int cost):to(to),cost(cost){}
};
vector<Edge> G[MAX_V];
vector<int> d;
//戻り値がtrueなら負の閉路を含む
bool bellman_ford(int n,int s){//頂点数と開始頂点
    d=vector<int>(n,INF);
    d[s]=0;
    rep(i,n){
        rep(v,n){
            rep(k,G[v].size()){
                Edge e=G[v][k];
                if(d[v]!=INF && d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    if(i==n-1)return true;
                }
            }
        }
    }
    return false;
}

int main() {
    int H,W;
    cin>>H>>W;
    rep(i,10)rep(j,10){
        int c;
        cin>>c;
        G[j].pb(Edge(i,c));
    }
    bellman_ford(10,1);
    int ans=0;
    rep(i,H)rep(j,W){
        int a;
        cin>>a;
        if(a>=0){ans+=d[a];}
    }
/*rep(i,10){cout<<d[i]<<" ";}
cout<<endl;*/
    cout<<ans<<endl;
}

Measured memory_bytes: 256
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');
let input = '';
process.stdin.on('data', function(chunk) {input += chunk;});
process.stdin.on('end', function() {main(input.split(/\r?\n/));});

function main(inputs){
	let n = Number(inputs[0].split(' ')[0]);
	let q = Number(inputs[0].split(' ')[1]);
	let pos, pre, tmp, i;
	let top = {};

	top.name = inputs[1].split(' ')[0];
	top.val = Number(inputs[1].split(' ')[1]);
	pos = top;
	
	for (i = 1; i < n; i++) {
		tmp = {};
		tmp.name = inputs[i+1].split(' ')[0];
		tmp.val = Number(inputs[i+1].split(' ')[1]);
		pos.next = tmp;
		pos = tmp;
	}
	pos.next = top;
	pre = pos;
	pos = top;
	top = tmp = null;

	let count = 0;
	while (n > 0) {		
		pos.val -= q;
		count += q;
		if (pos.val > 0) {
			pos = pos.next;
			pre = pre.next;
		} else {
			count += pos.val;
			console.log(`${pos.name} ${count}`);
			pos = pos.next;
			pre.next = pos;
			n--;
		}
	}
	pos = pre = null;
}


Measured memory_bytes: 49092
N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0
for l in range(N+1):
    for r in range(N+1):
        if l+r > N or l+r > K: break
        arr = V[:l]
        if r: arr += V[-r:]
        arr.sort()
        rem = K - l - r
        tmp = 0
        for a in arr:
            if a < 0 and rem:
                rem -= 1
            else:
                tmp += a
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 9096
#include<iostream>
#include<fstream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <random>
#include <set>
using namespace std;
typedef long long ll;


int main(){
    ll s;
    cin >> s;
    ll x1=1e9,x2=0,y1=1,y2;
    y2 = s/x1;
    if(s%x1){
        y2++;
        x2 = x1 - s%x1;
    }
    cout << 0 << " " << 0 << " ";
    cout << x1 << " " << y1 << " ";
    cout << x2 << " " << y2 << "\n";
}


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

class E
{
	static int Read() => int.Parse(Console.ReadLine());
	static void Main()
	{
		var a = Array.ConvertAll(new int[Read()], _ => Read());

		var l = new List<int>();
		int j;
		foreach (var v in a)
			if ((j = First(0, l.Count, i => l[i] < v)) < l.Count) l[j] = v;
			else l.Add(v);
		Console.WriteLine(l.Count);
	}

	static int First(int l, int r, Func<int, bool> f)
	{
		int m;
		while (l < r) if (f(m = l + (r - l - 1) / 2)) r = m; else l = m + 1;
		return r;
	}
}


Measured memory_bytes: 18896
using System;

namespace _4_C
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] x = Console.ReadLine().Split();
                int a = Int32.Parse(x[0]);
                int b = Int32.Parse(x[2]);
                if (x[1] == "+")
                {
                    Console.WriteLine(a + b);
                }
                else if (x[1] == "-")
                {
                    Console.WriteLine(a - b);
                }
                else if (x[1] == "*")
                {
                    Console.WriteLine(a * b);
                }
                else if (x[1] == "/")
                {
                    Console.WriteLine(a / b);
                }
                else
                {
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 9172
#include <iostream>
using namespace std;
long long n, c;
pair < long long, long long > arr[(1<<20)];
long long sumP[(1<<20)], sumS[(1<<20)];
int main () {
    cin >> n >> c;
    for ( long long i = 0 ; i < n ; i ++ ) {
        cin >> arr[i].first >> arr[i].second;
    }

    sumP[0] = arr[0].second - arr[0].first;
    for ( long long i = 1 ; i < n ; i ++ ) {
        sumP[i] = sumP[i-1] + arr[i].second - ( arr[i].first - arr[i-1].first );
    }

    sumS[n-1] = arr[n-1].second - ( c - arr[n-1].first );
    for ( long long i = n-2 ; i >= 0 ; i -- ) {
        sumS[i] = sumS[i+1] + arr[i].second - ( arr[i+1].first - arr[i].first );
    }

    long long ans = max( sumS[0], sumP[n-1] );
    ans = max( ans, 0LL );

    long long maxP = 0;
    for ( long long i = 0 ; i+1 < n ; i ++ ) {
        maxP = max( maxP, sumP[i] );

        //cout << "going for " << sumS[i+1] << " then returning with -" << (c-arr[i+1].first) << " for " << maxP << "\n";
        ans = max( ans, maxP + sumS[i+1] - ( c - arr[i+1].first ) );
    }
    long long maxS = 0;
    for ( long long i = n-1 ; i > 0 ; i -- ) {
        maxS = max( maxS, sumS[i] );
        ans = max( ans, maxS + sumP[i-1] - ( arr[i-1].first ) );
    }

    for ( long long i = 0 ; i < n ; i ++ ) {
        ans = max( ans, sumP[i] );
        ans = max( ans, sumS[i] );
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include<string>
using namespace std;
int main()
{   int num=0;
    string str;
    string line;
    cin>>str;
    while(cin>>line)
    {
        if(line=="END_OF_TEXT")
            break;
        else
            for(int i=0;i<line.length();i++)
                line[i]=tolower(line[i]);
            if(line==str) num+=1;
    }
    cout<<num<<endl;
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
using namespace std;

int main() {
string S;cin >> S;
bool C = 0;
for(int i = 0; i < 3; i++){
if(S[i] == '7')C = 1;
}
if(C)cout << "Yes";
else cout << "No";
}

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

int solve(vector<int>arr,int n,int k)
{
    vector<int>dp(n+1);

    dp[1]=0;

    for(int i=2;i<=n;i++)
    {
        dp[i]=INT_MAX;

        for(int j=i-1;(j>0 && (i-j)<=k);j--)
        {
            dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
        }
    }
    return dp[n];
}
int main()
{
    int n,k;
    cin>>n>>k;
    
    vector<int>arr(n+1);

    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    cout<<solve(arr,n,k);

}

Measured memory_bytes: 1408
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var b = new Map();
  b.set(0,1);
  var ans = 0;
  var t = 0;
  for(var i = 0; i < n; i++){
    t += a[i];
    if(b.get(t))b.set(t,b.get(t)+1); else b.set(t,1);
  }
  b.forEach(i=>ans += i * (i-1) / 2);
  return ans;
}

Measured memory_bytes: 49052
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long 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;
}
int main() {
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N);
  REP(i, N) { cin >> v[i] >> w[i]; }
  vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
  dp[0][0] = 0;
  for (int i = N - 1; i >= 0; i--) {
    for (int j = 0; j <= W; j++) {
      if (j < w[i]) {
        dp[i][j] = dp[i + 1][j];
      } else {
        dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
      }
    }
  }
  cout << dp[0][W] << endl;
  ;
}


Measured memory_bytes: 6776
n = int(raw_input())
bn = bin(n)[2:]
dp = [[0]*3 for i in range(len(bn) + 1)]
mod = 10**9+7
dp[len(bn)][0] = 1
for d in range(len(bn)-1, -1, -1):
    if bn[len(bn)-1 - d] == "1":
        dp[d][0] = dp[d+1][0]
        dp[d][1] = dp[d+1][0] + dp[d+1][1]
        dp[d][2] = 2*dp[d+1][1] + 3*dp[d+1][2]
    else:
        dp[d][0] = dp[d+1][0] + dp[d+1][1]
        dp[d][1] = dp[d+1][1]
        dp[d][2] = dp[d+1][1] + 3*dp[d+1][2]
print (dp[0][0] + dp[0][1] + dp[0][2]) % mod
                

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

int main()
{
    long long n;
    int x, m;
    std::cin >> n >> x >> m;

    long long ans = 0;
    bool *flg;
    flg = new bool[m]();
    for (; n; --n)
    {
        if (flg[x])
            break;
        ans += x;
        flg[x] = true;
        x = 1ll * x * x % m;
    }
    int tmp = x, cnt = 0;
    long long sum = 0;
    n--;
    x = 1ll * x * x % m;
    for (; n; --n)
    {
        cnt++;
        sum += x;
        if (x == tmp)
            break;
        x = 1ll * x * x % m;
    }
    ans += (n / cnt + 1) * sum;
    n %= cnt;
    for (; n; --n)
    {
        ans += x;
        x = 1ll * x * x % m;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3712
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt64(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	sort.Ints(aa)
	var l, r, sum int64
	l = int64(-1e18)
	r = int64(1e18)
	for l+1 < r {
		m := (l + r) >> 1
		sum = 0
		for i := 0; i < n; i++ {
			ll := i
			rr := n
			if aa[i] < 0 {
				for ll+1 < rr {
					mm := (ll + rr) >> 1
					if int64(aa[mm])*int64(aa[i]) < m {
						rr = mm
						continue
					}
					ll = mm
				}
				sum += int64(n - rr)
				continue
			}
			for ll+1 < rr {
				mm := (ll + rr) >> 1
				if int64(aa[mm])*int64(aa[i]) < m {
					ll = mm
					continue
				}
				rr = mm
			}
			sum += int64(ll - i)
		}
		if sum < k {
			l = m
			continue
		}
		r = m
	}
	fmt.Fprintln(writer, l)
}


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

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = long.Parse(inputs[0]);
            var d = long.Parse(inputs[1]);
            var result = 0;

            for (var i = 0; i < n; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ");
                var x = long.Parse(inputs1[0]);
                var y = long.Parse(inputs1[1]);

                var dist = Math.Sqrt(x * x + y * y);
                if (dist <= d) result++;

            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 40456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
int N; cin>>N; vector<string> a(N);
int ans=1;
for(int i=0; i<N; i++){
  cin >> a[i] ;
}
sort(a.begin(), a.end());
for(int j=0;j<N-1;j++){
  if(a[j]!=a[j+1])ans++;
}
cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9600