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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    string S;
    cin >> S;
    ll N = S.size();

    stack<char> st;
    REP(i, N){
    	if(st.empty()){
    		st.push(S[i]);
    	}else{
    		char tmp = st.top();
    		if(tmp=='S' && S[i] == 'T'){
    			st.pop();
    		}else{
    			st.push(S[i]);
    		}
    	}
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")

using ll = long long int;

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll N;

int main() {
    cin >> N;
    ll ans = 0;
    for (ll i = 1; i <= N; i++) {
        ll Y = N / i;  //Y項存在する
        //初項X、階差Yの階差数列
        ans += Y * (i + i * Y) / 2;
    }
    cout << ans << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int K = int.Parse(s[1]);
            var foodDict = Enumerable.Range(1, K).ToArray().ToDictionary(x => x, x => 0);
            for (int i = 0; i < N; i++)
            {
                var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                for (int j = 1; j < A.Length; j++)
                {
                    foodDict[A[j]]++;
                }
            }
            Console.WriteLine(foodDict.Count(x => x.Value == N));
        }
    }
}


Measured memory_bytes: 13408
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
int n,k;
const int BT=1<<18;
const int MA=200100;
struct segtree {//BT = size,2べき
    vector<int> seg;

    void init() {
	seg.resize(BT * 2);
	rep(i, BT * 2 - 1) seg[i] = MA;
    }

    void add(int pos, int x) {//posにxを追加,0-index nodeも0-index
		pos += BT - 1;
		seg[pos] = x;

		while (pos > 0) {
			pos = (pos - 1) / 2;
			seg[pos] = min(seg[pos * 2 + 1], seg[pos * 2 + 2]);
		}
    }

    int minQ(int a, int b, int k = 0, int l = 0, int r = BT) {//[a,b)に対するクエリ
		if (b <= l || r <= a) return MA;//交差しない
		if (a <= l && r <= b) return seg[k];//被覆する
		return min(minQ(a, b, k * 2 + 1, l, (l + r) / 2), minQ(a, b, k * 2 + 2, (l + r) / 2, r));
	}

}segm; 

int main(){
	cin>>n;
	int x;
	segm.init();
	for(int i=0;i<n;i++){
		cin>>x;
		segm.add(i,x);
	}
//cout<<"A"<<endl;
	ll ans=0;
	for(int i=0;i<n;i++){
		int now=segm.minQ(i,i+1);
		int cnt=20;
		int lefl=0,lefr=i+1,rigl=i,rigr=n;
		while(cnt--){
			int medl=(lefl+lefr)/2,medr=(rigr+rigl)/2;
			if(segm.minQ(medl,i+1)<now){
				lefl=medl;
			}else{
				lefr=medl;
			}
			
			if(segm.minQ(i,medr+1)<now){
				rigr=medr;
			}else{
				rigl=medr;
			}
		}
		//cout<<lefr<<" "<<rigl<<endl;
		ans=ans+(ll)(i-lefr+1)*(ll)(rigl-i+1)*(ll)now;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2304
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k, q;
    cin >> n >> k >> q;
    int p[100100];
    memset(p, 0, n * sizeof(int));

    rep(qi, q) {
        int a;
        cin >> a;
        p[a - 1]++;
    }

    rep(pi, n) {
        if (k - q + p[pi] > 0)
            print("Yes");
        else
            print("No");
    }

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    std::string a, b;
    std::cin >> a >> b;

    bool flag = false;
    int num = std::stoi(a+b);
    for (int i = 1; i < 1000000; i++) {
        if (i*i == num) {
            flag = true;
        } else {
            ;
        }
    }

    if (flag) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No"  << std::endl;
    }
    return 0;
}

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

#define ll  long long
#define ld long double
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define nguyendz the_best
#define pii pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;

using namespace std;
const ll maxn=2e5+2;
const ll maxx=1e16;
const ll mod=1e9+7;
const ll mod1=998244353;

map<ll,map<ll,ll>> mp;
ll pw1[maxn];
ll pw2[maxn];
int main()
{
    string s;
    cin>>s;
     ll n=s.length();
     s=" "+s;
     ll nw1=0;
     ll nw2=0;
     ll ans=0;
     mp[0][0]++;
     pw1[n+1]=1;
     pw2[n+1]=1;
     for (int i=n;i>=1;i--)
     {
         pw1[i]=(pw1[i+1]*10)%3;
     }
      for (int i=n;i>=1;i--)
     {
         pw2[i]=(pw2[i+1]*10)%673;
     }

     for (int i=n;i>=1;i--)
     {
         nw1=(nw1+(s[i]-'0')*pw1[i])%(ll)(3);
         nw2=(nw2+(s[i]-'0')*pw2[i])%673;
     //   cout <<nw1<<" "<<nw2<<" ";
         ans=ans+mp[nw1][nw2];
         mp[nw1][nw2] ++;
     }
     cout <<ans;
}








Measured memory_bytes: 6852
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull =  unsigned long long;

#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)

#define pii pair<int,int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<"# "<<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))
#define MX 10005

ll n,weight;
ll w[107];
ll v[107];
ll dp[107][100007];
ll solve(int i,ll val)
{
	if(val<=0)return 0;
	if(i==n)return 1e11;
	if(dp[i][val]!=-1)return dp[i][val];
	ll ret = min(solve(i+1,val),w[i]+solve(i+1,val-v[i]));
	return dp[i][val]=ret;
	
}
int main()
{
	fast_io

	mem(dp,-1);
	cin >>n>>weight;

	for(int i=0;i<n;i++){
		cin >>w[i]>>v[i];
	}
	for(ll i=100001;i>=0;i--){
		if(solve(0,i)<=weight){
			return cout <<i<<endl,0;
		}
	}
	//cout << 0<<endl;
	//cout << solve(0,0)<<endl;
	return 0;
}

Measured memory_bytes: 83840
$dp = Array.new(30) {Array.new(3)}
$dp[0] = [1,0,0]
$count = 0
def moveDp position
  until $count >= position
    $count += 1
    $dp[$count][0] = $dp[$count-1].inject(:+) 
    $dp[$count][1] = $dp[$count-1][0] 
    $dp[$count][2] = $dp[$count-1][1] 
  end
  return $dp[position].inject(:+)
end
until 0 == a = gets.to_i
  puts moveDp(a-1) / 3650 + 1
end

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

using namespace std;

int main(){
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);

    int N;
    cin >> N;
    vector<int> A(N),B(N);
    for(int i=0;i<N; i++){
        cin >> A[i] >> B[i]; 
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    if( N % 2 ){
        cout<< B[N/2] - A[N/2] + 1 << endl;
    }else{
        int start = A[N/2 -1] + A[N/2];
        int end = B[N/2 -1 ] + B[N/2];
        cout << end - start + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 4752
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

check = list(map(int, readline().split()))
prize = [3 * 10 ** 5, 2 * 10 ** 5, 10 ** 5]
ans = 0
if check.count(1) == 2:
    ans = 10 ** 6
else:
    if check[0] <= 3:
        ans += prize[check[0] - 1]
    if check[1] <= 3:
        ans += prize[check[1] - 1]
print(ans)


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	while(true){
		int a, b, c;
		cin >> a >> b >> c;
		if(a+b+c==0) break;
		int res[a+b+c];
		REP(i, a+b+c) res[i] = 2;
		int n;
		cin >> n;
		int as[n], bs[n], cs[n], rs[n];
		REP(i, n) cin >> as[i] >> bs[i] >> cs[i] >> rs[i];
		REP(i, n){
			if(rs[i] == 1){
				res[as[i]-1] = 1;
				res[bs[i]-1] = 1;
				res[cs[i]-1] = 1;
			}
		}
		REP(i, n){
			if(rs[i] == 0){
				if(res[as[i]-1]==1 && res[bs[i]-1]==1) res[cs[i]-1] = 0;
				if(res[as[i]-1]==1 && res[cs[i]-1]==1) res[bs[i]-1] = 0;
				if(res[cs[i]-1]==1 && res[bs[i]-1]==1) res[as[i]-1] = 0;
			}
		}
		REP(i, a+b+c) cout << res[i] <<endl;
	}
	return 0;
} 


Measured memory_bytes: 3112
k = int(input())
a = 0
data = list(map(int, input().split()))
data = sorted(data)
#print(data)
for num in range(len(data)-1):
    a += data[num]
#print("k is", k)
#print("a is", a)
if data[-1] < a:
    print('Yes')
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> mp; 
    rep(i, h) {
        string s; cin >> s;
        mp.emplace_back(s);
    }
    rep(i, h) {
        rep(j, w) {
            if (mp[i][j] == '#') {
                if (!((i > 0  && mp[i-1][j] == '#')
                || (i < h-1 && mp[i+1][j] == '#')
                || (j > 0   && mp[i][j-1] == '#')
                || (j < w-1 && mp[i][j+1] == '#'))) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    } 
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1;
  cin >> s2;
  VI a;
  for(int i = 0; i < n;) {
    if(s1[i] == s2[i]) {
      a.push_back(1);
      i++;
    }
    else {
      a.push_back(2);
      i+=2;
    }
  }
  VL ans(a.size(), 0);
  a[0] == 1 ? ans[0] = 3 : ans[0] = 6;
  rep(i, a.size()-1) {
    if(a[i+1] == 1 && a[i] == 1) ans[i+1] = ans[i] * 2 % MOD;
    else if(a[i+1] == 1 && a[i] == 2) ans[i+1] = ans[i] % MOD;
    else if(a[i+1] == 2 && a[i] == 1) ans[i+1] = ans[i] * 2 % MOD;
    else if(a[i+1] == 2 && a[i] == 2) ans[i+1] = ans[i] * 3 % MOD;
  }
  out(ans[a.size()-1]);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 10001;

int main(){
    int N;
    int ans[MAX] = {0};

    cin >> N;

    for(int i = 1;i <= 100;i++){
        for(int j = 1;j <= 100;j++){
            for(int k = 1;k <= 100;k++){
                int x = i*i + j*j + k*k + i*j + j*k + k*i;
                if(x < MAX){
                    ans[x]++;
                }
            }
        }
    }

    for(int i = 1;i <= N;i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3108
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete


main = getInts >>= putStrLn . cond "yes" "no" . (>=3) . length . filter ((==1) . length . group) . splitRec 4 . sort



Measured memory_bytes: 3704
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "abc160_b.cpp"

int main() {
  ll x;
  cin >> x;
  cout << (x / 500) * 1000 + ((x % 500) / 5) * 5 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int fast_exp_mod_p(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (((lli)res)*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (((lli)x)*x) % p;  
    }  
    return res;  
}
void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int n;
    int M = 998244353;
    cin>>n;
    vector<int> v(100000,0);
    int temp;
    int mx = 0;
    int flag = 0;
    rep(i,0,n){
        cin>>temp;
        if(i==0 && temp!=0) flag=1;
        mx =max(mx,temp);
        v[temp]++;
    }
    if(flag || (mx==0 && n>1) || v[0]>1){
        cout<<"0"<<endl;
        return;
    }
    int ans=1;
    rep(i,0,mx){
        ans=(ans*fast_exp_mod_p(v[i],v[i+1],M))%M;

    }
    cout<<ans<<endl;

}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 1024
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

result = []
for x in range(h):
    for y in range(w):
        if a[x][y]%2==1:
            if y+1 < w:
                a[x][y+1] += 1
                result.append([x+1, y+1, x+1, y+1+1])
            elif x+1 < h:
                a[x+1][y] += 1
                result.append([x+1, y+1, x+1+1, y+1])
print(len(result))
for i in result:
    print(*i)

Measured memory_bytes: 30276
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
	int n,d;
	cin>>n>>d;
	vector<vector<double> > a(n,vector<double>(d));
	rep(i,0,n){
		rep(j,0,d){
			cin>>a[i][j];
		} 
	}
	int res=0;
	rep(i,0,n){
		rep(j,i+1,n)
		{
			double ans=0;
			rep(k,0,d){
				ans+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			int x = sqrt(ans);
			if(x*x == ans){
				res++;
			}
		}
	}
	cout<<res;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

void solve(){
	int n,ans=0;cin>>n;
	vector<int>a(n);
	vector<vector<pair<int,int> > >xy(n,vector<pair<int,int> >());
	int alp=pow(2,n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<a[i];j++){
          	int p,q;
			cin>>p>>q;
          	xy[i].push_back(make_pair(p,q));
		}
	}
	for(int i=0;i<alp;i++){
		vector<int>patern(n);
		bool is_able=true;
		int p=alp/2,q=i;
		for(int j=0;j<n;j++){
			patern[j]=(int)q/p;
			q%=p;p/=2;
		}
		for(int j=0;j<n;j++){
          if(patern[j]==1){
				for(int k=0;k<a[j];k++){
					if(xy[j][k].second!=patern[xy[j][k].first-1]){
						is_able=false;
					}
				}
          	}
		}
		if(is_able){
			int sum=0;
			for(int j=0;j<n;j++){sum+=patern[j];}
			if(ans<sum)ans=sum;
		}
	}
  cout<<ans<<endl;
}

int main(){
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	reus;
	int a,b;
	cin>>a>>b;
	if(a>=13)
	{
		cout<<b<<endl;
	}
	else if(a<=12&&a>=6)
	{
		cout<<b/2<<endl;
	}
	else if(a>=0&&a<=5)
	{
		cout<<"0"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
t1, x1, y1 = 0, 0, 0
feasible = True
for _ in range(n):
    t2, x2, y2 = map(int, input().split())
    movements = abs(x2 - x1) + abs(y2 - y1)
    if movements > (t2 - t1) or movements % 2 != (t2 - t1) % 2:
        feasible = False
    t1, x1, y1 = t2, x2, y2
print('Yes') if feasible else print('No')

Measured memory_bytes: 3064
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
void chmin(ll &a,ll b){ if(a>b) a = b ;}

const int MAX = 2000000 ;

//initのbで関数を指定する（0:sum,1:min,2:max,3:gcd）
class SGT{
public :
	int n = 1;
	ll d ;
	ll num[MAX] ;
	int fan ;

	ll f(ll a,ll b){
		if(fan==0) return a+b ;
		else if(fan==1) return min(a,b) ;
		else if(fan==2) return max(a,b) ;
		else if(fan==3) return gcd(a,b) ;
		else return d ;
	}

	void d_set(int b){
		fan = b ;
		if(fan==0) d = 0 ;
		else if(fan==1) d = INF ;
		else if(fan==2) d = -INF ;
		else if(fan==3) d = 0 ;
	}
	
//	配列を渡して初期化
	void init(vector<ll> &a,int b){
		d_set(b) ;
		while(a.size()>n) n *= 2 ;
		for(int i=0;i<n;i++){
			if(i<a.size()) num[n-1+i] = a.at(i) ;
			else num[n-1+i] = d ;
		}
		for(int i=n-2;i>=0;i--){
			num[i] = f(num[i*2+1],num[i*2+2]) ;
		}
	}
// 	サイズと初期値を渡して初期化
	void init(ll a,ll sz,int b){
		d_set(b) ;
		while(sz>n) n *= 2 ;
		for(int i=0;i<n;i++){
			if(i<sz) num[n-1+i] = a ;
			else num[n-1+i] = d ;
		}
		for(int i=n-2;i>=0;i--){
			num[i] = f(num[i*2+1],num[i*2+2]) ;
		}
	}

//	0-indexedで場所を指定、update後の値を渡す
	void update(int i,ll a){
		i += n-1 ;
		num[i] = a ;
		while(i>0){
			i = (i-1)/2 ;
			num[i] = f(num[i*2+1],num[i*2+2]) ;
		}
	}

//	最初に呼び出すときはa,bだけ指定すればOK
	ll query(int a,int b,int l=0,int r=-1,int now=0){
		if(r==-1) r = n ;
		if(r<=a||b<=l) return d ;
		if(a<=l&&r<=b) return num[now] ;
		ll r1 = query(a,b,l,(l+r)/2,now*2+1) ;
		ll r2 = query(a,b,(l+r)/2,r,now*2+2) ;
		return f(r1,r2) ;
	}
};


int main(){
	ll n,k ;
	cin >> n >> k ;
	static SGT sgt ;
	sgt.init(0,3e5,2) ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		ll sub = sgt.query(max(0ll,a-k),min(a+k,300000ll)+1) ;
		sgt.update(a,max(sgt.num[a+sgt.n-1],sub+1)) ;
	}
	ll ans = 0 ;
	for(int i=0;i<=3e5;i++) ans = max(ans,sgt.num[i+sgt.n-1]) ;
	cout << ans << endl ;
}

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

int main(){
	int n,num[10000],max;
	int hantei[10000]={0};
	int i,j,k=0;
	
	while(1){
	scanf("%d",&n);
		if(n==0)break;
		
	for(i=0;i<n;i++)scanf("%d",&num[i]);
		max=num[0];
		
	for(i=0;i<n;i++){
		hantei[0]=num[i];
		for(j=i+1,k=0;j<n;j++,k++){
			hantei[k+1]=num[j]+hantei[k];
		}
		for(j=0;j<n;j++)if(max<hantei[j])max=hantei[j];
	}
	
	printf("%d\n",max);
	}
return 0;
}

Measured memory_bytes: 1092
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using ll = long long;
using namespace std;

const long long MOD = 1000000007;
const ll LINF = 1LL << 50;


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

int main() {
  int N, W;
  cin >> N >> W;
  vector<ll> vn(100010, 0);
  vector<ll> wn(100010, 0);

  vector<vector<ll>> dp(110, vector<ll>(100100, 0));

  REP(n,N)cin >> wn.at(n) >> vn.at(n);


  for (int n = 0; n<N; n++){
    for (int w = 0; w <= W; w++){
      if( w - wn[n] >=0){
        chmax(dp[n+1][w], dp[n][w-wn[n]]+vn[n]);
      }

      chmax(dp[n+1][w], dp[n][w]);
    }
  }

  cout << dp[N][W] << endl;

}


Measured memory_bytes: 88832
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  string n;
  cin >> n;
  char x = n[0];
  bool yes = false;
  int c = 1;
  for (int i = 1; i < n.size(); i++) {
    if (x == n[i]) {
      c += 1;
      if (c >= 3)
        yes = true;
    } else {
      c = 1;
      x = n[i];
    }
  }

  if (yes) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n=int(input())
u=list(map(int,input().split()))
l=list(map(int,input().split()))
ans=[]

for v in range(n):
    s=0
    un=v
    for p in range(un+1):
        s+=u[p]
    for q in range(p,n):
        s+=l[q]
    ans.append(s)

print(max(ans))

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {
  // Target 4n
  // q: 1
  // h: 2
  // s: 4
  // d: 8
  
  private static long solve(long q, long h, long s, long d, long n) {
    long minQ = q;
    long minH = Math.min(2 * minQ, h);
    long minS = Math.min(2 * minH, s);
    long minD = Math.min(2 * minS, d);
    
    return (n / 2) * minD + (n % 2) * minS;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    long q = reader.nextLong();
    long h = reader.nextLong();
    long s = reader.nextLong();
    long d = reader.nextLong();
    long n = reader.nextLong();
    
    out.println(solve(q, h, s, d, n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int ans = 1000;
    rep(i, S.size() - 2) {
        int X = 100;
        int Y = 0;
        rep(j, 3) {
            Y += (S[i + j] - '0') * X;
            X /= 10;
        }
        ans = min(ans, abs(753 - Y));
    }
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 256
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) (a)<=(i) && (i)<(b)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;

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

  int n,k;
  cin >> n >> k;

  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  vector<int> dp(n,INF);
  dp[0] = 0;
  FOR(i,1,n){
    REP(j,k){
      if(i-j-1 < 0) break;
      dp[i] = min(dp[i-j-1]+abs(a[i-j-1]-a[i]),dp[i]);
    }
  }

  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1792
/*input
8 8 1
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define input(str) freopen(str,"r",stdin);
#define output(str) freopen(str,"w",stdout);
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF  3e16+1
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld\n",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define modd 1000000007
#define len(x) x.size()
#define all(v) (v.begin(),v.end())
#define ll int
#define pi 3.1415926535897932384626
#define ld double
#define endl '\n'
const int N =6e5+5;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
int powmod(int base,int exp,int mod)
{
	int res=1LL;
	while(exp>0)
	{
		if(exp&1LL)
			res=(res*base)%mod;
		exp/=2LL;
		base=(base*base)%mod;
	}
	return res%mod;
}
signed main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(c<=b)
	{
		cout<<(b+c)<<endl;
	}
	else
	{
		if(c>a+b+1)
		{
			cout<<a+2*b+1<<endl;
		}
		else
		{
			cout<<b+c<<endl;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
   int R[MAX], n;
   
   cin >> n;
   for (int i =0; i<n;i++) cin >> R[i];
   
   int maxv = -2000000000;
   int minv = R[0];
   
   for (int i =1 ;i <n; i++){
       maxv = max(maxv, R[i]-minv);
       minv = min(minv,R[i]);
   }
   cout << maxv << endl;
   
   
   return 0;
   
}



Measured memory_bytes: 3884
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
int maska[25];
int mod=1e9+7;
int dp[25][(1<<22)];
int main(){
	cin>>n;
	for(int i=1;n>=i;i++)
	{
		int val=1;
		for(int j=0;n>j;j++)
		{
			int a;
			cin>>a;
			if(a==1)
				maska[i]^=val;
			val*=2;
		}
	}
	dp[0][(1LL<<n)-1]=1;
	for(int i=1;n>=i;i++)
	{
		for(int mas=0;(1<<n)>mas;mas++)
		{
			if(__builtin_popcount(mas)!=n-i)
				continue;
			for(int j=0;n>j;j++)
			{
				if(((1<<j)&mas)==0 and (maska[i]&(1<<j))>0)
					dp[i][mas]=(dp[i][mas]+dp[i-1][mas^(1<<j)])%mod;
			}
		}
	}
	cout<<dp[n][0];
	return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> A(N);
  
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A.at(i)=make_pair(a,i+1);
  }
  sort(A.begin(),A.end());
  
  for(int i=0;i<N;i++){
    int a;
    tie(ignore,a)=A.at(i);
    cout<<a<<" ";
  }
   cout<<endl;
}

Measured memory_bytes: 1664
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MN 300005
using namespace std;
int x,y,a[MN];
int main(){
	scanf("%d%d",&x,&y);
	if(x%2==0){printf("%d ",x/2);for(int i=2;i<=y;i++)printf("%d ",x);}
	else {
		for(int i=1;i<=y;i++)a[i]=(x+1)/2;int j=y;
		for(int i=1;i<=y/2;i++){
			while(a[j]==0)j--;a[j]--;
			if(a[j]){for(int k=j+1;k<=y;k++)a[k]=x;j=y;}
		}
		while(a[y]==0)y--;
		for(int i=1;i<=y;i++)printf("%d ",a[i]);
	}
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL H(N);
    REP(i,N) cin >> H[i];

    int acc = 0;
    int cur = 1;
    int ans = 0;
    LL pre = H[0];
    while(cur < N){
        if(pre >= H[cur]){
            acc++;
            pre = H[cur];
            cur++;
        }
        else{
            ans = max(ans,acc);
            acc = 0;

            pre = H[cur];
            cur++;

        }
        dump(acc)
    }
    ans = max(ans,acc);
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

#define SORT(c) sort((c).bigin(), (c).end())

typedef long long ll;

int main()
{
    int a[3];
    REP(i, 3)
        cin >> a[i];
    sort(a, a + 3);
    cout << a[2] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int x,y,kx,ky;
int main () {
	cin >> x >> y;
	if (x==2){
		kx=1;
	} else if ((x==4) || (x==6) || (x==9) || (x==11)){
		kx=2;
	} else {
		kx=3;
	}
	if (y==2) {
		ky=1;
	} else if ((y==4) || (y==6) || (y==9) || (y==11)){
		ky=2;
	} else {
		ky=3;
	}
	if (kx==ky){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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

int main() {
	int n;cin>>n;
	vector< tuple<int,int,char,int64_t, string> > dd(n);
	for(int i=0;i<n;++i) {
		int u,w;
		char t;
		int64_t d;
		string s;cin>>u>>w>>t>>d>>s;
		dd[i] = make_tuple(u,w,t,d,s);
	}

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

	for(auto &&di: dd){
		cout<<get<0>(di)<<" "<<get<1>(di)<<" "<<get<2>(di)<<" "<<get<3>(di)<<" "<<get<4>(di)<<endl;
	}
	
  return 0;
}



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

const bool DEBUG = false;

int main(int argc, char const *argv[]) {
  string S, T;
  cin >> S >> T;
  int total = 0;
  for (size_t i = 0; i < 3; i++) {
    if (S[i] == T[i]) total++;
  }
  cout << total << endl;

  return 0;
}


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

#define REP(i,j) for(int i=0;i<j;i++)
#define REPR(i,j) for(int i=j;i>=0;i--)
#define FOR(i,j,k) for(int i=j;i<k;i++)

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

    int N;
    cin >> N;
    int L[2*N];
    REP(i,2*N) {cin >> L[i];}
    sort(L,L+2*N);
    int length = 0;
    REP(i,N){
        length += L[2*i];
    }
    cout << length << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 1000002
#define pie 3.14159265358979323
#define minuss 1e-6
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
    ll t;
    cin>>t;
    map<string,ll>mp;
    map<string,ll>::iterator it;
    for(int i=0;i<t;i++)
    {
        char s[100];
        cin>>s;
        mp[s]++;
    }
    ll mx=-1000;
    for(it=mp.begin();it!=mp.end();it++)
    {
        mx=max(it->second,mx);
    }
    for(it=mp.begin();it!=mp.end();it++)
    {
        if(it->second==mx)
            cout<<it->first<<endl;
    }

}


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

int main(){
	long long int n,m;
	cin >>n >>m;
	vector<long long int> a(n);
	rep(i,n)
		cin >>a[i];
	vector<pair<long long int,long long int>> p(m);
	rep(i,m){
		long long int b,c;
		cin >>b>>c;
		p[i] = make_pair(c,b);
	}
	sort(a.begin(),a.end());
	int cur=0;
	sort(p.rbegin(),p.rend());
	rep(i,n){
		if (a[cur]>p[i].first)
			break;
		a[cur++] = p[i].first;
		p[i].second--;
		if (p[i].second)
			i--;
	}
	long long int sum = 0;
	rep(i,n){
		sum +=a[i];
	}
	cout <<sum;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n,t,e;
	cin>>n>>t>>e;
	vi x(n);
	rep(i,0,n) cin>>x[i];
	int ans=-1;
	rep(i,0,n){
		for(int j=1;;j++){
			if(t-e<=j*x[i] && j*x[i]<=t+e){
				ans=i+1;
				i=n;
				break;
			}
			if(j*x[i]>t+e) break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1196
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val p = (x: Int) => math.pow(x, 2)
    val sc = new Scanner(System.in)

    var xyz = List(sc.nextInt, sc.nextInt, sc.nextInt).sorted

    while (xyz != List(0, 0, 0)) {
      val enterable = math.sqrt(p(xyz.head) + p(xyz(1))) / 2

      (0 until sc.nextInt).map(_ => if (sc.nextInt > enterable) "OK" else "NA").foreach(println)

      xyz = List(sc.nextInt, sc.nextInt, sc.nextInt).sorted
    }

    sc.close()
  }
}

Measured memory_bytes: 45024
#include <bits/stdc++.h>
using namespace std;
class fastio {
public:
    fastio() {
        ios_base::sync_with_stdio(false);
        cout.tie(nullptr);
        cin.tie(nullptr);
    }
} __fastio;
int solve() {
  int n, r; cin >> n;
  int max = -1;
  for(int i=0; i<n; i++) {
    cin >> r;
    if(r > max) max = r;
    if(r < max - 1) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
int main() {
  __fastio;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int a,b;

  scanf("%d %d",&a,&b);

  if(a == 2 || b == 2){

    if(a == 2 && b == 2) printf("Yes\n");
    else printf("No\n");

    return 0;

  }

  if(a == 4 || a == 6 || a == 9 || a == 11){

    if(b == 4 || b == 6 || b == 9|| b == 11)  printf("Yes\n");
    else printf("No\n");

    return 0;

  }

  if(b == 4 || b == 6 || b == 9|| b ==11){

    if(a == 4 || a == 6 || a == 9|| a == 11)  printf("Yes\n");
    else printf("No\n");

    return 0;

  }

  printf("Yes\n");

  return 0;

}

Measured memory_bytes: 128