akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N=301;
typedef long long LL;
int dp[N][N],n,ok=1,dope;
LL rez;
void check(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dope=0;
            for(int k=1;k<=n;k++){
                if(dp[i][j]!=min(dp[k][j]+dp[k][i],dp[i][j])){
                    ok=0;
                    return ;
                }
                if(dp[i][j]==dp[k][i]+dp[k][j] &&(k!=i && k!=j)){            // ako se ne moze predsatviti uska
               //     printf("(%d %d)=(%d %d)+(%d %d)\n",i,j,k,i,k,j);
                    dope=1;
                }
            }
            if(!dope)
                rez+=(LL)dp[i][j];
        }
    }
    return ;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            scanf("%d",&dp[i][j]);
        }
    }
    check();
    if(!ok){
        printf("-1");
        return 0;
    }
    cout<<rez/2;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int a, b; cin >> a >> b;

  cout << (a<=b ? a : a-1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  int N;
  string S;

  cin >> N;
  cin >> S;

  vector<int> num1('z' - 'a', 0);
  vector<int> num2('z' - 'a', 0);

  rep(i, 0, N){
    num2[S[i]-'a']++;
  }

  int count=0;
  int count_max=0;
  rep(i, 0, N){
    if(num1[S[i]-'a']==0 && num2[S[i]-'a']>1){
      count++;
    }else if(num1[S[i]-'a']>0 && num2[S[i]-'a']==1){
      count--;
    }
    count_max = max(count, count_max);
    num1[S[i]-'a']++;
    num2[S[i]-'a']--;
  }

  cout << count_max << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
main()
{
    int n,i;
    scanf("%d",&n);
    for(i=sqrt(2*n)+1;i>0;i--)
    {
        //printf("%d",i);
        if((i*(i+1)/2)>=n&&(i*(i-1)/2)<n)
        {
            printf("%d",i);
            break;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int travel;
	int i;
	int get[12],use[12];
	int sa[12];
	int sum = 0;
	int count = 0;
	int flag = 0;
	while(scanf("%d",&travel)){
		if(travel == 0){
			break;
		}
		for(i = 0;i < 12;i++){
			scanf("%d %d",&get[i],&use[i]);
			sa[i] = get[i] - use[i];
		}
		for(i = 0;i < 12;i++){
			sum += sa[i];
			count++;
			if(travel <= sum){
				flag = 1;
				break;
			}
		}
		if(flag == 1){
			printf("%d\n",count);
			count = 0;
			flag = 0;
			sum = 0;
		}
		else{
			printf("NA\n");
			count = 0;
			sum = 0;
		}
	}
	return 0;
}

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

int main(){
  int K, S;
  cin >> K >> S;
  int ans=0;
  for(int x=0; x<=K; x++){
    for(int y=0; y<=K; y++){
      if(S-x-y<=K && S-x-y>=0) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int[] array = new int[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        
        
        System.out.println(array[k-1]);
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;

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;}

void END(){cout << 0 << endl; exit(0);}

const LL limit = 1000010;  // n の上限値
VLL modfac(limit);        // n! を mod で割った余り
VLL invmodfac(limit);     // フェルマーの小定理における n! の逆元

LL modpow(LL a, LL b, LL mod)
{
  // a^b を mod で割った余りを計算する。
    LL res = 1;
    while (b > 0)
    {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void setmodfactorial(LL _limit, LL mod)
{
  REP(i, _limit+1)
  {
    if (i == 0) modfac[i] = 1;
    else modfac[i] = i * modfac[i-1] % mod;
  }
}

void setinvmodfactorial(LL _limit, LL mod)
{
  invmodfac[_limit] = modpow(modfac[_limit], mod-2, mod);
  REPR(i, _limit) invmodfac[i] = invmodfac[i+1] * (i+1) % mod;
}

LL modnCk(auto n, auto k, auto mod)
{
  return modfac[n] * invmodfac[k] % mod * invmodfac[n-k] % mod;
}
int main()
{
 cin.tie(0);
 ios::sync_with_stdio(false);
 LL x, y;
 cin >> x >> y;
 if ((x+y)%3) END();
 setmodfactorial(limit, MOD);
 setinvmodfactorial(limit, MOD);
 int n, m;
 n = (2*y-x)/3; m = (2*x-y)/3;
 if (n < 0 || m < 0) END();
 cout << modnCk(n+m, n, MOD) << endl;

 return 0;
}

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

long long h;
vector<long long> v;

int main() {
  cin >> h;
  v.resize(h + 1);
  for(int i = 0; i < h; ++i) cin >> v[i + 1];
  for(int i = 0; i < h; ++i) {
    int id = i + 1;
    cout << "node " << id << ": key = " << v[id] << ", ";
    if(id > 1) cout << "parent key = " << v[id / 2] << ", ";
    if(id * 2 <= h)
      cout << "left key = " << v[id * 2] << ", ";
    if(id * 2 < h)
      cout << "right key = " << v[id * 2 + 1] << ", ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3064
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end
class Integer
  # 約数の組み合わせを列挙する
  def divisor_combinations
    (1..Math.sqrt(self).to_i).
      select { |i| self % i == 0 }.
      map { |i| [i, self / i] }
  end
end

N = gi
d_n = gli

puts d_n.combination(2).inject(0) { |sum, (x, y)| sum + (x * y) }


Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<algorithm>
const int mod=1e9+7;
int n,K,link[610];
int cnt[610][610],g[610];
int f[610][610],ans;
void input(){
	scanf("%d%d",&n,&K);n<<=1;
	for(int i=1,u,v;i<=K;++i){
		scanf("%d%d",&u,&v);
		link[u]=v;
		link[v]=u;
	}
	return;
}
void work(){
	for(int i=1;i<=n;++i)
		for(int j=i;j<=n;++j)
			cnt[i][j]=cnt[i][j-1]+(!link[j]);
	g[0]=1;
	for(int i=2;i<=n;i+=2)
		g[i]=1ll*g[i-2]*(i-1)%mod;
	
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;j+=2){
			bool getOut=0;
			for(int k=i;k<=j;++k)
				if(link[k]&&(link[k]>j||link[k]<i)){
					getOut=1;
					break;
				}
			if(getOut)continue;
			f[i][j]=g[cnt[i][j]];
			for(int k=i+1;k<=j-1;k+=2)
				f[i][j]=(f[i][j]+1ll*(mod-f[i][k])*g[cnt[k+1][j]])%mod;
			ans=(ans+1ll*f[i][j]*g[n-2*K-cnt[i][j]])%mod;
		}
	return;
}
void output(){
	printf("%d\n",ans);
	return;
}
int main(){
	input();
	work();
	output();
	return 0;
}

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

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

ll add(ll a, ll b){
    return (a+b+MOD)%MOD;
}

ll mul(ll a, ll b){
    return (1LL*a*b)%MOD;
}

pair <ll, ll> a[200005];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, k;
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> a[i].second;
        a[i].first = abs(a[i].second);
    }
    sort(a+1, a+1+n);
    reverse(a+1, a+1+n);
    int neg = 0, posp = 0, posn = 0;
    a[0].first = 1;
    for(int i=1; i<=k; i++){
        if(a[i].first == 0){
            cout << 0;
            return 0;
        }
        if(a[i].second < 0){
            neg++;
            posn = i;
        }
        else posp = i;
    }
    if(neg%2 == 0){
        ll res = 1;
        for(int i=1; i<=k; i++){
            res = mul(res, a[i].first);
        }
        cout << res << "\n";
        return 0;
    }
    int sledp = 0, sledn = 0;
    for(int i=k+1; i<=n; i++){
        if(a[i].second < 0 && !sledn) sledn = i;
        else if(a[i].second > 0 && !sledp) sledp = i;
    }
    if((sledp == 0 || posn == 0) && (sledn == 0 || posp == 0)){
        int br = 0;
        ll res = 1;
        for(int i=n; i>=1; i--){
            if(br == k) break;
            res = mul(res, a[i].first);
            br++;
        }
        cout << (MOD-res)%MOD << "\n";
        return 0;
    }
    ll res = 1;
    if(posp == 0 || sledn == 0){
        /// menjamo negativan
        for(int i=1; i<=k; i++){
            if(i == posn) continue;
            res = mul(res, a[i].first);
        }
        res = mul(res, a[sledp].first);
        cout << res;
        return 0;
    }
    if(posn == 0 || sledp == 0){
        /// menjamo pozitivan
        for(int i=1; i<=k; i++){
            if(i == posp) continue;
            res = mul(res, a[i].first);
        }
        res = mul(res, a[sledn].first);
        cout << res;
        return 0;
    }
    if(a[sledn].first*a[posn].first >= a[sledp].first*a[posp].first){
        /// menjamo pozitivan
        for(int i=1; i<=k; i++){
            if(i == posp) continue;
            res = mul(res, a[i].first);
        }
        res = mul(res, a[sledn].first);
        cout << res;
        return 0;
    }
    /// menjamo negativan
    for(int i=1; i<=k; i++){
        if(i == posn) continue;
        res = mul(res, a[i].first);
    }
    res = mul(res, a[sledp].first);
    cout << res;
    return 0;
}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
//#define int long long
#define N 200010
using namespace std;
const int INF = 1e9;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
string str;
int n;
int Bit[N];

void init(){for(int i=1;i<=n;i++) Bit[i] = Bit[i-1] ^ (1LL<<(str[i-1]-'a'));}


int solve(){
  vector<int> opt(N,INF);
  vector<int> dp(1<<26,INF);
  opt[0] = dp[0] = 0;

  for(int i=1;i<=n;i++) {
    int bit = Bit[i];
    opt[i] = dp[bit]+1;
    for(int j=0;j<26;j++) Min(opt[i],dp[bit^(1<<j)]+1);
    Min(dp[bit],opt[i]);
  }
  return opt[n];
}

signed main(){
  cin>>str;
  n = str.size();
  init();

  cout<<solve()<<endl;
  return 0;
}


Measured memory_bytes: 264324
def main():
    N = int(input())
    i = 1
    sm = 1
    while sm < N:
        i += 1 
        sm += i

    y = sm - N
    for i in range(1, i + 1):
        if i == y:
            continue
        print(i)

if __name__ == "__main__":
    main()

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

int n;
int a[210];

int main() {
  cin >> n;
  for (int i=0; i < n; ++i) {
    cin >> a[i];
  }
  int counter = 0;
  while(true) {
    bool exist_odd = false;
    for (int i=0; i < n; ++i) {
      if (a[i] % 2 != 0) exist_odd = true;
    }

    if (exist_odd) break;

    for (int i=0; i<n; i++) {
      a[i] /= 2;
    }
    ++counter;
  }
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
    print("POSSIBLE")
    exit()
if max(A) < K or N == 1:
    print("IMPOSSIBLE")
    exit()

A.sort()
for i in range(1, N):
    tmp = abs(A[i - 1] - A[i])
    if not tmp == 0 and K % tmp == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){
    
    //??\???
    string s; cin >> s;
    //cout << s << endl;
    bool flag = true;
    while(1){

        //????????????
        if(s.size() < 3){
            flag = false;
            break;
        }
        
        //???ABC"?????????????????§??????
        if(s == "ABC"){
            flag = true;
            break;
        }

        //"ABC"??????X"??????????????????
        vector<int> v;
        flag = false;
        for(int i = 0; i < s.size() - 2; i++){
            if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
                v.push_back(i);   //A??????????????????
                flag = true;
            }
        }

        if(!flag) break;
        

        for(int i = 0; i < v.size(); i++){
            s.erase(s.begin() + v[i] - 2*i, s.begin() + v[i] - 2*i + 3);
            s.insert(s.begin() + v[i] - 2*i, 'X');
        }

        bool f[3] = {0, 0, 0};
        for(int i = 0; i < s.size(); i++){
            if(s[i] == 'A') f[0] = true;
            if(s[i] == 'B') f[1] = true;
            if(s[i] == 'C') f[2] = true;
        }

        if(f[0] && f[1] && f[2]){
            flag = false;
            break;
        }

        char x;
        //????????????????±???????

        for(int i = 0; i < s.size(); i++){
            if(s[i] == 'X'){
                if(i == 0){
                    x = 'A';
                }else{
                    if(s[i - 1] == 'A'){
                        x = 'B';
                    }else if(s[i - 1] == 'B'){
                        x = 'C';
                    }else{
                        flag = false;
                    }
                }
                break;
            }
        }

        if(!flag) break;
        
        flag = false;
        for(int i = 0; i < s.size(); i++){
            if(s[i] == 'X'){
                s[i] = x;
                flag = true;
            }
        }

        if(!flag) break;
        //cout << s << endl;
        //int input; cin >> input;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        string s = Console.ReadLine();
        s = s.Replace("BC", "X");

        //逆に言えば、全部のAについて、それより右に隣接するAXが連続する部分の塊に含まれるXの数をカウント
        long ans = 0;
        long xCnt = 0;
        for(int i = s.Length - 1; i >= 0; i--)
        {
            if (s[i] == 'A')
            {
                ans += xCnt;
            }
            else if (s[i] == 'X')
            {
                xCnt += 1;
            }
            else
            {
                xCnt = 0;
            }
        }

        Console.WriteLine(ans);
    }
}

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n ;
  cin >> n ;
  vll a(n) ;
  vll b(n) ;
  vll dif(n) ;
  ll suma = 0 ;
  ll sumb = 0 ;
  ll cnts = 0 ;
  ll answ = 0 ; 
  REP(i,n){
    cin >> a[i] ;
    suma += a[i] ;
  }
  REP(i,n){
    cin >> b[i] ;
    sumb += b[i] ;
    dif[i] = a[i] -b[i] ;
  }
  
  if(suma<sumb){
    cout << -1 <<endl;
    return 0 ;
  }
  sort(ALL(dif)) ;
  reverse(ALL(dif)) ;
  
  vll ruiseki(n,0) ;
  ruiseki[0] = dif[0] ;
  if(dif[n-1]>=0){
    cout << 0 <<endl ;
    return 0 ;
  }
  REP(i,n-1){
    ruiseki[i+1] = ruiseki[i] + dif[i+1] ;
  }
  REP(i,n){
    if(a[i]<b[i]){
      cnts += b[i] - a[i] ;
      answ++ ;
    }
  }
  REP(i,n){
    if(ruiseki[i]<cnts){
      answ++ ;
    }
    else{
      break ;
    }
  }
  
  
  
  cout << answ+1 <<endl ;
      
    
  
  
  
  return 0 ;
}



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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long ans = a[n-1];
    int c = 2;
    for (int i = n-2; i >= 0; i--) {
        for (int cnt = 0; cnt < 2; cnt++) {
            if (c < n) {
                ans += a[i];
                c++;
            }
        }
    }
    cout << ans << endl;
}


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

int main(void){
	stack<int> st;
	int x;

	while(scanf("%d", &x) != EOF){
		if(x != 0){
			st.push(x);
		}else{
			printf("%d\n", st.top());
			st.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 0
# https://atcoder.jp/contests/abc154/tasks/abc154_d

N, K = map(int, input().split())
s = list(map(int, input().split()))

# 初期値として0~Kのサイコロの目を最大値として保持しておく
max = x = sum(s[:K])
for i in range(N - K):
    x += (s[K + i] - s[i])
    if max < x:
        max = x

# 期待値はサイコロの目の数の合計+1*サイコロの数/2
print((max + K) / 2)



Measured memory_bytes: 24804
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;

#define LL long long

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int INF=9999999;
const int MAXN=300010;

int N,M;
int a[MAXN+1]; 
int ans[MAXN+1],sta[MAXN+1],ge[MAXN+1];
int cnt,cnt3,cnt2;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(),M=read();
	for(int i=1;i<=M;i++) {
		a[i]=read();
		if(a[i]&1) sta[++cnt]=a[i];
		else ge[++cnt2]=a[i];
	}
	if(cnt>2) {puts("Impossible"); return 0;}
	if(cnt) ans[++cnt3]=sta[cnt--];
	for(int i=1;i<=cnt2;i++) ans[++cnt3]=ge[i];
	if(cnt) ans[++cnt3]=sta[cnt--];
	for(int i=1;i<=cnt3;i++) printf("%d ",ans[i]);
	ans[1]++; ans[cnt3]--; puts("");
	if(cnt3>1){
		if(!ans[cnt3]) --cnt3;
		printf("%d\n",cnt3);
		for(int i=1;i<=cnt3&&ans[i];i++) printf("%d ",ans[i]);
	}
	else {
		if(N&1){
			printf("%d\n",(N+1)>>1);
			for(int i=1;i<=(N>>1);i++) printf("%d ",2);
			printf("%d\n",1);
		}
		else {
			cnt3=0; int now=1;
			ans[++cnt3]=1;
			if((N>>1)&1){
				while(now<(N>>1)){
					now+=2; ans[++cnt3]=2;
				} printf("%d\n",cnt3*2);
				for(int i=1;i<=cnt3;i++){
					printf("%d ",ans[i]);
				}
				for(int i=1;i<=cnt3;i++){
					printf("%d ",ans[i]);
				}
			}
			else{
				while(now<(N>>1)-1){
					now+=2; ans[++cnt3]=2;
				} printf("%d\n",cnt3*2+1);
				for(int i=1;i<=cnt3;i++){
					printf("%d ",ans[i]);
				}
				for(int i=1;i<=cnt3;i++){
					printf("%d ",ans[i]);
				} printf("%d\n",2);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2432
package main

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

func main() {
	var n, x, sum, cnt int
	fmt.Scan(&n, &x)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	l := make([]int, n)
	for i := range l {
		sc.Scan()
		l[i], _ = strconv.Atoi(sc.Text())
	}

	cnt = 1
	for _, v := range l {
		if sum+v > x {
			fmt.Println(cnt)
			return
		}
		sum += v
		cnt++
	}
	fmt.Println(cnt)
}


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

int main() {
    string s;
    cin>>s;
    int ans=1;
    rep(i,s.size()-1) if (s[i]!=s[i+1]) ans++;
    cout<<ans-1<<endl;
}   


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=20005;
const int mod=998244353;
int n,m,jc[N],jcn[N],len=1,l,rev[N],w[N],f[N],g[N],tmp[N],ans;
void Inc(int &x,int y){
	x+=y;x>=mod?x-=mod:x;
}
int C(int x,int y){
	return 1ll*jc[x]*jcn[y]%mod*jcn[x-y]%mod;
}
int fastpow(int x,int y){
	int res=1;
	while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}
	return res;
}
void ntt(int *p,int op){
	for(int i=0;i<len;++i)if(i<rev[i])swap(p[i],p[rev[i]]);
	for(int i=1,t=1;i<len;i<<=1,++t)
		for(int j=0;j<len;j+=i<<1)
			for(int k=0;k<i;++k){
				int x=1ll*w[(len>>t)*k]*p[j+k+i]%mod;
				p[j+k+i]=p[j+k];
				Inc(p[j+k],x);Inc(p[j+k+i],mod-x);
			}
	if(op==-1){
		reverse(p+1,p+len);int inv_len=fastpow(len,mod-2);
		for(int i=0;i<len;++i)p[i]=1ll*p[i]*inv_len%mod;
	}
}
int main(){
	scanf("%d%d",&n,&m);
	jc[0]=1;
	for(int i=1;i<N;++i)jc[i]=1ll*jc[i-1]*i%mod;
	jcn[N-1]=fastpow(jc[N-1],mod-2);
	for(int i=N-1;i;--i)jcn[i-1]=1ll*jcn[i]*i%mod;
	while(len<=n+n)len<<=1,++l;
	for(int i=0;i<len;++i)rev[i]=(rev[i>>1]>>1)|((i&1)<<l-1);
	w[0]=1;w[1]=fastpow(3,mod>>l);
	for(int i=2;i<len;++i)w[i]=1ll*w[i-1]*w[1]%mod;
	for(int i=1;i<=n;++i)g[i]=jcn[i+2];
	ntt(g,1);f[0]=1;
	for(int i=1;i<=m;++i){
		for(int j=0;j<=n;++j)tmp[j]=f[j],f[j]=1ll*f[j]*jcn[j]%mod;
		ntt(f,1);
		for(int j=0;j<len;++j)f[j]=1ll*f[j]*g[j]%mod;
		ntt(f,-1);
		for(int j=0;j<=n;++j)f[j]=(1ll*f[j]*jc[j+2]+1ll*tmp[j]*(1+C(j+1,2)))%mod;
		for(int j=n+1;j<len;++j)f[j]=0;
	}
	for(int i=0;i<=n;++i)ans=(ans+1ll*f[i]*C(n,i))%mod;
	printf("%d\n",ans);return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 998244353 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  1e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x , k , Q , ans ; string s;
ll dp[101][MAX];
ll w  ;
vector < pair < ll , ll > > v;

ll solve(int i , ll cur){

    if(i == n ) return 0;

    ll & ret = dp[i][cur];

    if(~ret)
        return ret;

    ret = solve(i + 1 , cur);
    if(v[i].f + cur <= w)
        ret = max(ret,v[i].s + solve(i + 1, cur + v[i].f));

    return ret;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//   freopen("test.in","r",stdin);

    cin>>n>>w;

    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j <= w ; ++j)
            dp[i][j] = -1;

    for(int i = 0 ; i < n ; ++i)
        cin>>x>>k,v.pb({x,k});

    cout<<solve(0,0)<<'\n';

    return 0;
}


Measured memory_bytes: 78464
import sys
input = sys.stdin.readline
n = int(input())
X = [list(map(int,input().split())) for i in range(n)]
eps = 10**-8
import math
def gaisin(xa,ya,xb,yb,xc,yc):
    a=((xb-xc)**2 + (yb-yc)**2)**0.5
    b=((xa-xc)**2 + (ya-yc)**2)**0.5
    c=((xb-xa)**2 + (yb-ya)**2)**0.5
    # print("abc",a,b,c)
    ca=(b**2+c**2-a**2) / (2*b*c)
    cb=(a**2+c**2-b**2) / (a*2*c)
    cc=(a**2+b**2-c**2) / (a*b*2)
    sa2=2*ca*(max(0,1-ca**2)**0.5)
    sb2=2*cb*(max(0,1-cb**2)**0.5)
    sc2=2*cc*(max(0,1-cc**2)**0.5)
    if sa2+sb2+sc2 < eps:
        x = (max(xa,xb,xc) - min(xa,xb,xc)) / 2
        y = (max(ya,yb,yc) - min(ya,yb,yc)) / 2
    else:
        x=(sa2*xa + sb2*xb + sc2*xc) / (sa2+sb2+sc2)
        y=(sa2*ya + sb2*yb + sc2*yc) / (sa2+sb2+sc2)
    return [x,y]

def gaisin2(xa,ya,xb,yb):
    x = (xa+xb)/2
    y = (ya+yb)/2
    return [x,y]


ans = float("inf")
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            g = gaisin(X[i][0],X[i][1],X[j][0],X[j][1],X[k][0],X[k][1])
            x = g[0]
            y = g[1]
            r2 = ((x-X[i][0]) ** 2 + (y-X[i][1]) ** 2 +\
                 (x-X[j][0]) ** 2 + (y-X[j][1]) ** 2 +\
                     (x-X[k][0]) ** 2 + (y-X[k][1]) ** 2) / 3
            # print(x,y,r2)
            ok = 0
            for a in range(n):
                if (x-X[a][0]) ** 2 + (y-X[a][1]) ** 2 <= r2 + eps:
                    ok += 1
            if ok == n:
                ans = min(ans, r2)

for i in range(n):
    for j in range(i+1,n):
        g = gaisin2(X[i][0],X[i][1],X[j][0],X[j][1])
        x = g[0]
        y = g[1]
        r2 = ((x-X[i][0]) ** 2 + (y-X[i][1]) ** 2 +\
                 (x-X[j][0]) ** 2 + (y-X[j][1]) ** 2) / 2
        # print(x,y,r2)
        ok = 0
        for a in range(n):
            if (x-X[a][0]) ** 2 + (y-X[a][1]) ** 2 <= r2 + eps:
                ok += 1
        if ok == n:
            ans = min(ans, r2)

print(ans**0.5)



Measured memory_bytes: 56792
N, X, Y = map(int,input().split())

ans_list = [0]*(N-1)

for i in range(1,N+1):
    for j in range(i+1,N+1):
        ans_list[min(abs(i-j),abs(X-i)+1+abs(Y-j),abs(Y-i)+1+abs(X-j))-1] +=1

for i in ans_list:
    print(i)

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

int dp[40010][202];

int main(){
    int n;
    cin>>n;
    int t[n],v[n];
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int lmt[40010]={},crt=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<2*t[i];j++){
            lmt[++crt]=2*v[i];
        }
    }
    for(int i=0;i<40010;i++){
        for(int j=0;j<202;j++){
            dp[i][j]=-INF;
        }
    }
    dp[0][0]=0;
    for(int i=1;i<40010;i++){
        for(int j=0;j<=lmt[i];j++){
            if(j>0)dp[i][j]=max(dp[i][j],dp[i-1][j-1]+2*j+1);
            if(j<lmt[i])dp[i][j]=max(dp[i][j],dp[i-1][j+1]+2*j-1);
            dp[i][j]=max(dp[i][j],dp[i-1][j]+2*j);
        }
    }
    cout<<fixed<<setprecision(5)<<dp[40009][0]/8.0<<endl;
}


Measured memory_bytes: 32000
package main

import "fmt"

func main() {
	var n int
	var tmp int
	fmt.Scan(&n)
	m := make(map[int]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		m[tmp]++
	}
	fmt.Println(len(m))
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>
#include <complex>
#include <bitset>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

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

int main() {
    int n; cin >> n;
    map<int, int> mp;
    for (int i = 2; i <= n; i++) {
        int num = i;
        int j = 2;
        while (j * j <= num) {
            while (num % j == 0) {
                mp[j]++;
                num /= j;
            }
            j++;
        }
        if (num > 1) mp[num]++;
    }

    vector<int> box;
    for (auto m: mp) {
        box.push_back(m.second);
    }
    sort(box.begin(), box.end());

    int ans = 0;

    for (int i = 0; i < box.size(); i++) {
        if (box[i] >= 74) ans++;
        for (int j = i+1; j < box.size(); j++) {
            if (box[i] >= 2 && box[j] >= 24) ans++;
            if (box[i] >= 24 && box[j] >= 2) ans++;
            if (box[i] >= 4 && box[j] >= 14) ans++;
            if (box[i] >= 14 && box[j] >= 4) ans++;
            for (int k = j+1; k < box.size(); k++) {
                if (box[i] >= 2 && box[j] >= 4 && box[k] >= 4) ans++;
                if (box[i] >= 4 && box[j] >= 2 && box[k] >= 4) ans++;
                if (box[i] >= 4 && box[j] >= 4 && box[k] >= 2) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


    


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll K, X;
    cin >> K >> X;

    if (X <= 500*K) {
        Yes;
    } else {
        No;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	int start,end;
};

int N = 1;
Info* donut;

void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int update_left,int update_right,int new_value_start,int new_value_end,int node_id,int node_left,int node_right){
	if(update_right < node_left || update_left > node_right){
		return;
	}
	else if(update_left <= node_left && update_right >= node_right){

		if(donut[node_id].start == 0 && donut[node_id].end == 0){
			donut[node_id].start = new_value_start;
			donut[node_id].end = new_value_end;
		}else{
			if(donut[node_id].end+1 == new_value_start){
				donut[node_id].end = new_value_end;
			}else{

				donut[node_id].start = BIG_NUM;
				donut[node_id].end = BIG_NUM;
			}
		}

	}else{

		if(donut[node_id].start != 0){
			update(node_left,node_right,donut[node_id].start,donut[node_id].end,2*node_id+1,node_left,(node_left+node_right)/2);
			update(node_left,node_right,donut[node_id].start,donut[node_id].end,2*node_id+2,(node_left+node_right)/2+1,node_right);
		}

		donut[node_id].start = 0;
		donut[node_id].end = 0;

		update(update_left,update_right,new_value_start,new_value_end,2*node_id+1,node_left,(node_left+node_right)/2);
		update(update_left,update_right,new_value_start,new_value_end,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}

void merge_range(int node_id){

	int loc = node_id+N-1;
	int left = donut[loc].start,right = donut[loc].end;

	int parent_id = (loc-1)/2;

	while(true){
		if(donut[parent_id].start == 0 && donut[parent_id].end == 0){
			//Do nothing
		}else{
			if(left == 0 && right == 0){
				left = donut[parent_id].start;
				right = donut[parent_id].end;
			}else{
				if(right+1 == donut[parent_id].start){
					right = donut[parent_id].end;
				}else{
					left = BIG_NUM;
					right = BIG_NUM;
					break;
				}
			}
		}
		if(parent_id == 0)break;
		parent_id = (parent_id-1)/2;
	};

	donut[loc].start = left,donut[loc].end = right;
}

int main(){

	int first_N,K,T;
	scanf("%d %d",&first_N,&K);
	scanf("%d",&T);

	init(first_N);
	donut = new Info[2*N-1];

	for(int i = 0; i <= 2*N-2; i++){
		donut[i].start = 0;
		donut[i].end = 0;
	}

	int left,right,task_id;
	for(int loop = 0; loop < T; loop++){
		scanf("%d %d %d",&left,&right,&task_id);
		left--;
		right--;

		update(left,right,task_id,task_id,0,0,N-1);
	}

	for(int i = 0; i < first_N; i++)merge_range(i);

	int ans = 0;
	for(int i = 0; i < first_N; i++){
		if(donut[N-1+i].start == 1 && donut[N-1+i].end == K)ans++;
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
    ll N,S,K;
    // cin >> N >> S >> K;
    // vector<ll> x(N);// 
    // vector<ll> y(N);//
    // vector<pair<ll,ll>> pos(N); // position
    // vector<ll> c(N);// power

    // for (ll i = 0; i < N; i++){
    //     cin >> x[i] >> y[i] >> c[i]; 
    //     pos[i] = make_pair(x[i],y[i]);
    // }

    // vector<vector<ll>> p(S,vector<ll>(K)); // p[i] 木Ti 木T i の頂点は p[i][j] : V[i][j] Tiに対応する出力

    string s;
    cin >> s;

    map<string,ll> week;
    week.insert(std::make_pair("SUN", 7));
    week.insert(std::make_pair("MON", 6));
    week.insert(std::make_pair("TUE", 5));
    week.insert(std::make_pair("WED", 4));
    week.insert(std::make_pair("THU", 3));
    week.insert(std::make_pair("FRI", 2));
    week.insert(std::make_pair("SAT", 1));
    week["a"] = 100;
    
    cout << week[s] <<endl;


    
    
}


Measured memory_bytes: 256
n = gets.to_i

max = 0
second = 0
max_index = 0
n.times{|i|
    val = gets.to_i
    if val > max
        second = max
        max = val
        max_index = i
    elsif val > second
        second = val
    end
}

n.times{|i|
    puts i == max_index ? second : max
}

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

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

  int surplus = N % 500;
  if (surplus == 0) {
    cout << "Yes" << endl;
  } else if (surplus <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#define int long long
using namespace std;

const int INF = 1e18;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, budget, totV = 0;
    cin >> n >> budget;
    vector <pair<int, int>> items(n);
    for(auto &x : items) {
        int w, v;
        cin >> w >> v;
        totV += v;
        x = {w, v};
    }

    //????
    //non funziona lel
    
    vector <int> dp(totV + 1, INF); //dp[i] <= dp[i + 1], where i is the total value
    dp[0] = 0;
    auto prev = dp;

    for(int i = 0; i < n; i++) {
        int w = items[i].first, v = items[i].second;
        for(int j = 0; j <= totV; j++) {
            if(v <= j) {
                dp[j] = min(w + prev[j - v], prev[j]);
            }
            else {
                dp[j] = prev[j];
            }
        }

        prev = dp;
    }

    for(int i = totV; i >= 0; i--) {
        if(dp[i] <= budget) {
            cout << i << "\n";
            return 0;
        }
    }
}

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

int main() {
    int n = 0;
    scanf("%d\n", &n);
    int min_abs = 1000000001;
    long long int ans = 0;
    int count = 0;
    int buf = 0;
    for (int i=0; i<n; i++) {
        scanf("%d", &buf);
        if (buf < 0) count++;
        int ab = abs(buf);
        ans += ab;
        if (ab < min_abs) min_abs = ab;
    }
    if (count%2 == 1) ans -= 2*min_abs;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
/*
[abc101] B - Digit Sums
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int N;

bool solve() {
    int s = 0;
    for (int n = N; n > 0; n /= 10) {
        s += n % 10;
    }
    return (N % s) == 0;
}

int main() {
    cin >> N;

    cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
//
//
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define ll long long
#define ld long double
#define gap ' '
#define endl '\n'

void solve() {
	int n,k;
	cin>>n>>k;
	vector<int> h(n+1);
	for(int i=1;i<=n;i++) cin>>h[i];
	int dp[n+1];
	dp[1]=0;
	for(int i=2;i<=n;i++) {
		dp[i]=1e10;
		for(int j=1;j<=k and i-j>=1;j++) {
			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n]<<endl;
}
void solve(bool testcase) {
	int t;cin>>t;while(t--)solve();
}
int32_t main() {
	fio
	solve();
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n,m,ans=0,x;
    cin>>n>>m;
    r(i,n){
        cin>>x;
        if(x>m)ans+=x-m;
    }
    if(!ans)cout<<"kusoge"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 3088
#include<iostream>
using namespace std;
int n, i, nr, u;
int v[100005];
int main(){
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> v[i];
        if(v[i] != v[u]){
            v[++u] = v[i];
        }
    }
    n = u;
    for(i = 2; i < n; i++){
        if( (v[i - 1] < v[i] && v[i + 1] < v[i]) || (v[i - 1] > v[i] && v[i + 1] > v[i]) ){
            nr++;
            i++;
        }
    }
    cout<< nr + 1;
}


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

int par[100001];

int main() {
    ios::sync_with_stdio(false);
    int n, q, x;
    char s[2];
    par[1] = 1;
    while (scanf("%d%d", &n, &q) != EOF) {
        if (n == 0 && q == 0) break;
        for (int i = 2; i <= n; i++) scanf("%d", &par[i]);
        long long sum = 0;
        for (int i = 0; i < q; i++) {
            scanf("%s%d", s, &x);
            if (s[0] == 'Q') {
                while (x != par[x]) x = par[x];
                sum += x;
            } else {
                par[x] = x;
            }
        }
        cout << sum << "\n";
    }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  int n,m,k;
  cin>>n>>m>>k;
  for(int h=0;h<=n;h++){
    for(int v=0;v<=m;v++){
      if(h*m+v*n-2*h*v==k){
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

#define ll long long // -2^63 to +2^63-1 (upper limit ~ 9*(10^18))
bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;} 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//code
	int a[10000],i,k=2;
	a[0] = 2;
	a[1] = 3;
	for(i=5;i<=100003;i+=2)
	{
		if(isprime(i))
		{
			a[k++] = i;
		}
	}
	int x;
	cin>>x;
	for(i=0;i<k;++i)
	{
		//cout<<a[i]<<" ";
		if(x <= a[i])
		{
			break;
		}
	}
	cout<<a[i];
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
#define ll long long 
// #define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=2*1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	map<string,int> ma;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		ma[s]++;
	}
	int mx=-1;
	for(auto x:ma)
	{
		mx=max(mx,x.se);
	}
	vector<string> ans;
	for(auto x:ma)
	{
		if(x.se==mx)
		{
			ans.pb(x.fi);
		}
	}
	sort(all(ans));
	for(auto x:ans)
	{
		cout<<x<<"\n";
	}
} 
// I never lose. I either win or I learn

Measured memory_bytes: 25584
# -*- coding: utf-8 -*-
n = int(input())
s = list(input())

ans = 0
for i in range(n - 2):
    #print(s[i], s[i+1], s[i+2])
    if s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'C':
        ans += 1
print(ans)


Measured memory_bytes: 2940
using static System.Math;
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        if (s.Contains('(')) getAns1(s);
        else getAns2(s);
    }
    static void getAns2(string s)
    {
        var adec = decimal.Parse(s);
        var p = s.IndexOf('.');
        var ud = s.Length - (p + 1);
        var a1 = (int)Pow(10, ud);
        var a2 = (int)(adec * a1);
        var k = gcd(a1, a2);
        a1 /= k;
        a2 /= k;
        Console.WriteLine("{0}/{1}", a2, a1);
    }
    static void getAns1(string s)
    {
        s = s.Replace(")", "");
        string[] line = s.Split('(');
        var a = line[0];
        var b = line[1];
        var adec = decimal.Parse(a);
        var p = a.IndexOf('.');
        var ud = a.Length - (p + 1);
        var a1 = (int)Pow(10, ud);
        var a2 = adec * a1;
        var a3 = (int)Pow(10, b.Length) * a1;
        var a4 = adec * a3 + int.Parse(b);
        var a5 = (int)(a4 - a2);
        var a6 = a3 - a1;
        var k = gcd(a5, a6);
        a5 /= k;
        a6 /= k;
        Console.WriteLine("{0}/{1}", a5, a6);
    }
    public static int gcd(int a, int b)
    {
        if (a < b) return gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}



Measured memory_bytes: 18428
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
string s;
int main()
{fast
	double h,a;
	cin>>h>>a;
	printf("%d\n",(int)ceil(h/a));		
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){

  int A, B, C; cin >> A >> B >> C;
  cout << max(B + C - A, 0) << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

vector<long long int> a;
vector<long long int> b;
vector<long long int> c;
vector<long long int> d;
vector< vector< pair<int, int> > > t;
int n, q, k;
int dfs(int p, long long int cost){
  d[p] = cost;
  for(int i=0; i<t[p].size(); i++){
    if( d[ t[p][i].first ] == -1 ) dfs( t[p][i].first, cost + t[p][i].second );
  }
  return 0;
}

int main() {

  cin >> n;
  a.resize(n);
  b.resize(n);
  c.resize(n);
  d.resize(n, -1);
  t.resize(n);
  for(int i=0; i<n-1; i++){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    t[ a[i] ].push_back({b[i], c[i]});
    t[ b[i] ].push_back({a[i], c[i]});
  }
  cin >> q >> k;
  k--;
  dfs(k, 0);
  int x, y;
  for(int i=0; i<q; i++){
    cin >> x >> y;
    x--; y--;
    cout << d[x] + d[y] << endl;
  }

  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 200005;

int p[maxn], s[maxn];
set<pair<int, pair<int, int>>> edges;
int n, m;

inline int find(int a)
{
    return p[a] == a ? a : p[a] = find(p[a]);
}

inline bool unite(int a, int b)
{
    a = find(a);
    b = find(b);
    if (a == b) return false;
    if (s[a] < s[b]) swap(a, b);
    p[b] = a;
    if (s[a] == s[b]) s[a]++;
    return true;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        edges.insert({c, {a, b}});
        edges.insert({c + 1, {a + 1, b}});
    }
    for (int i = 0; i < n; i++) p[i] = i, s[i] = 0;
    ll answer = 0;
    while (!edges.empty())
    {
        int cura = edges.begin()->se.fi % n;
        int curb = edges.begin()->se.se % n;
        int curc = edges.begin()->fi;
        edges.erase(edges.begin());
        if (unite(cura, curb))
        {
            edges.insert({curc + 2, {cura + 1, curb + 1}});
            answer += curc;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 26752