akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<vector<ll>> dp(n+1,vector<ll>(n+1));
    rep(i,n+1) dp[i][i]=0;
    for(ll w=1;w<=n;w++){
        for(ll l=0;l+w<=n;l++){
            ll r=l+w;
            if(w%2==n%2){
                dp[l][r]=max(dp[l+1][r]+a[l],dp[l][r-1]+a[r-1]);
            }
            else{
                dp[l][r]=min(dp[l+1][r]-a[l],dp[l][r-1]-a[r-1]);
            }
        }
    }
    cout << dp[0][n] << endl;
    return 0;
} 

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)

using namespace std;

int main()
{
	int n, k; cin >> n >> k;
	string s; cin >> s;

	vector<int> starts(n + 2);
	starts[0] = 0;
	int s_count = 1;

	bool is_prev_0 = false;
	FOR_LT(i, 0, n) {
		bool is_zero = (s[i] == '0');
		if (is_prev_0 != is_zero) {
			starts[s_count] = i;
			s_count++;
		}
		is_prev_0 = is_zero;
	}
	starts[s_count] = n;
	s_count++;

	int segment_num = (s_count + 1) / 2 - k;
	if (segment_num <= 0) {
		cout << n << endl;
		return 0;
	}

	int ans = 0;
	FOR_LT(i, 0, segment_num) {
		int s_p = starts[i * 2];

		int e_i = min(s_count - 1, i * 2 + k * 2 + 1);
		int e_p = starts[e_i];

		ans = max(ans, e_p - s_p);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
   string s;
   cin>>s;
   int count=0;
   for (int i = 0; i < s.size()/2; i++)
   {
       /* code */
     
           /* code */
           if (s[i]!=s[s.size()-1-i])
           {
               /* code */
               count++;
               
           }
           
       
       
   }
   cout<<count<<endl;
   
   
   }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n;
  cin >> n;
  vi v(n);
  vi c(n);
  int ans =0;
  int d;
  rep(i,n){
    cin >> v[i];
  }
  rep(i,n){
    cin >> c[i];
  }
  rep(i,n){
    d=v[i]-c[i];
    if(d > 0){
      ans += d;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#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(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
string s;

ll calc(ll num) {
	ll res = 0;
	while (num) {
		res += num % 10;
		num /= 10;
	}
	return res;
}

int main() {
	cin >> n;
	ll ans = INF;
	FOR(i, 1, n) {
		ans = min(ans, calc(i) + calc(n - i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for (ll i = 0; i < h; i++)
    {
        cin >> grid[i];
    }
    int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};
    for (ll i = 0; i < h; i++)
    {
        for (ll j = 0; j < w; j++)
        {
            int white = 0;
            int stop = 0;
            if(grid[i][j] == '#'){
            for (ll k = 0; k < 4; k++)
            {
                ll nx = j + dx[k], ny = i + dy[k];
                if (0 > nx || 0 > ny || h <= ny || w <= nx){
                    stop++;
                    continue;
                }
                if (grid[ny][nx] == '.')
                    white++;
            }
            if (4 - white == stop)
            {
                cout << "No" << endl;
                return 0;
            }
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var L = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(L.OrderByDescending(i => i).Where((x, y) => y < nk[1]).ToArray().Sum());
    }
}

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

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define pb push_back
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double E=2.718281828459045;
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int MOD=1e3;
const int N=1e2+5;
const ll maxn=2e5+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};

int n,m;
int a[N],b[N],c[N],d[N];
int ans,match[N];
bool vis[N];
vector<int> vec[N];
bool dfs(int u)
{
	if(vis[u]) return false;
	vis[u]=1;
	for(auto v:vec[u])
	{
		if (!match[v]||dfs(match[v]))
		{
			match[v]=u;
			return true;
		}
	}
	return false;
}
int main()
{
    IO;
	cin>>n;
	rep(i,1,n+1) cin>>a[i]>>b[i];
	rep(i,1,n+1) cin>>c[i]>>d[i];
	rep(i,1,n+1)
	{
		rep(j,1,n+1)
		{
			if(a[i]<=c[j]&&b[i]<=d[j]) vec[i].pb(j);
		}
	}
	rep(i,1,n+1)
	{
		mem(vis,0);
		if(dfs(i)) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (){
    int h,w;
    cin >> h >> w;
    int state[h][w];
    char tmp;
    for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
        cin >> tmp;
        if(tmp == '#') state[i][j] = 1;
        else state[i][j] = 0 ;
    }
    }
    int row[h]={};
    int col[w]={};
    cout<<"\n";
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            row[i]+=state[i][j];
            col[j]+=state[i][j];
//            cout << state[i][j];
        }
//    cout << "\n";
    }

    for (int i = 0; i < h; i++){
        if(row[i]){
            for (int j = 0; j < w; j++){
            if(col[j]){
                if(state[i][j]) cout << "#";
                else cout << ".";
            }
        }
        cout << "\n";
        }
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func asub(x, y int) int {
	if x > y {
		return x - y
	}
	return y - x
}

func solve(a []int, start, N int) int {
	l := list.New()
	if start == 0 {
		l.PushBack(a[0])
		a = a[1:]
	} else {
		l.PushBack(a[N-1])
		a = a[:N-1]
	}
	ans := 0
	fpos := 0
	bpos := len(a) - 1
	for i := 0; i < len(a); i++ {
		f := l.Front().Value.(int)
		b := l.Back().Value.(int)
		diff := [4]int{
			asub(f, a[fpos]),
			asub(f, a[bpos]),
			asub(b, a[fpos]),
			asub(b, a[bpos]),
		}
		//out(f, b, a[fpos], a[bpos], diff)
		sel := 0
		for j := 0; j < 4; j++ {
			if diff[sel] < diff[j] {
				sel = j
			}
		}
		switch sel {
		case 0:
			l.PushFront(a[fpos])
			fpos++
		case 1:
			l.PushFront(a[bpos])
			bpos--
		case 2:
			l.PushBack(a[fpos])
			fpos++
		case 3:
			l.PushBack(a[bpos])
			bpos--
		}
		ans += diff[sel]
	}

	return (ans)
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	sort.Ints(a)

	r0 := solve(a, 0, N)
	r1 := solve(a, 1, N)
	ans := r0
	if r0 < r1 {
		ans = r1
	}
	out(ans)
}


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

namespace B159
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var N = S.Length;
            
            if (S.Substring(0, (N - 1) / 2) == S.Substring((N + 2) / 2))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    rrep(i, n - 1, 1) {
        if (i % 2)
            continue;
        bool flag = true;
        rep(j, 0, i / 2) {
            if (s[j] != s[j + i / 2])
                flag = false;
        }
        if (flag) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e9;
typedef pair<int, int> pi;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector<int>a, b;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'W')a.push_back(i);
        else b.push_back(i);
    }
    reverse(b.begin(), b.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i > ((int)a.size() - 1) || i > ((int)b.size()) - 1) {
            break;
        }
        if (a[i] > b[i])break;;
        ans++;
    }
    cout << ans;
}

Measured memory_bytes: 4692
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
// combination c(max);
// mint c(n, k)


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, k;
    cin >> n >> m >> k;
    combination c(n);
    mint ans = 0;
    for (int i = 0; i <= k; ++i) {
        mint now = c(n-1, i) * m * mint(m-1).pow(n-1-i);
        ans += now;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6296
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>


using namespace std;

int main(int argc, char *argv[])
{
	int n, i;
	cin >> n;
    vector<string> gacha(n);
	string target;
	int count = 0;

	for (i = 0; i < n; i++)
		cin >> gacha[i];

    sort(gacha.begin(), gacha.end());
	gacha.erase(unique(gacha.begin(), gacha.end()), gacha.end());

	cout << gacha.size() << endl;

	return 0;
}

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

ll gcd(ll a, ll b){
    ll tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

    ll r = a%b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

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

    ll wa = 0;

    REP(i, n) {
        cin >> a[i];
        wa += a[i];
    }

    ll snuke = 0;
    ll ans = INF_LL;

    REP(i, n) {
        snuke += a[i];
        if(i+1 < n) ans = min(ans, abs(wa - 2*snuke));
    }

    cout << ans << endl;

}
 

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

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

  if(x<a) cout<<0<<endl;
  else cout<<10<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+7,p=1e9+7;
int n,k,dp[N][N]; long long fac[N*N],ifac[N*N];
inline int pows(long long u,int v){
	long long ans=1; while(v>0) {if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;} return ans;
}
inline long long getans(int a,int b){
	return fac[a]*ifac[b]%p*ifac[a-b]%p;
}
int main(){
	cin>>n>>k,fac[0]=ifac[0]=1;
	for(int i=1;i<=n*k;i++) fac[i]=fac[i-1]*i%p,ifac[i]=pows(fac[i],p-2); dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++){
			if(j>0) dp[i][j]=(dp[i][j-1]*getans(n*k-(k-1)*(j-1)-i-1,k-2)+dp[i-1][j])%p;
			else dp[i][j]=dp[i-1][j];
		}
	if(k==1) cout<<1<<endl; else cout<<dp[n][n]*fac[n]%p<<endl;
    return 0;
} 

Measured memory_bytes: 78848
#include <stdio.h>
 int main(void){
    int n, k,d,a;
   scanf("%d %d", &n, &k);
   int data[n];
   for (int i = 0; i < n; i++){
      data[i] = 0;
   }
   for (int i = 0; i < k; i++){
      scanf("%d", &d);
      for (int j = 0; j < d; j++){
         scanf("%d", &a);
         data[a - 1]++;
      }
   }
   int count = 0;
   for (int i = 0; i < n; i++){
      if (data[i] == 0){
         count++;
      }
   }
   printf("%d", count);
}


Measured memory_bytes: 1708
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = (int)1e9 + 7;
int n, k;
 
int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n>>k;
	if(n==1){
		if(k==0) return cout<<"0 0 1 1", 0;
		else return cout<<-1, 0;
	}
	if(k>=(1<<n)) return cout<<-1, 0; 
	for(int i=0; i<(1<<n); i++){
		if(i!=k) cout<<i<<" ";
	}
	cout<<k<<" ";
	for(int i=0; i<(1<<n); i++){
		if((1<<n)-1-i!=k) cout<<(1<<n)-1-i<<" ";
	}
	cout<<k;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<assert.h>

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
	int n, x, d = 0;
	size_t i;
	scanf("%d%d", &n, &x);
	for (i = 0; i < n; i++)
	{
		int l;
		scanf("%d", &l);
		d += l;
		if (d > x)
		{
			break;
		}
	}
	printf("%d", i + 1);
}

Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define dl 998244853
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> a(n,0);
    for(int i=0;i<n;i++)cin>>a[i];
    k=min(k,n);
    vector<int> ans(k,0);
    ans[0]=0;
    for(int i=1;i<k;i++){
        int mini=INT_MAX;
        for(int j=0;j<i;j++){
            mini=min(mini,ans[j]+abs(a[i]-a[j]));
        }
        ans[i]=mini;
    }
    //cout<<ans[0]<<" "<<ans[4]<<endl;
    if(k==n){
        cout<<ans[k-1]<<endl;
        return 0;
    }
    
    for(int i=k;i<n;i++){
       int mini=INT_MAX;
        for(int j=0;j<k;j++){
            mini=min(mini,ans[j]+abs(a[i]-a[i-k+j]));
        }
        for(int j=0;j<k-1;j++){
            ans[j]=ans[j+1];
        }
        ans[k-1]=mini;
    }
    cout<<ans[k-1]<<endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class Main {

	static BufferedReader br;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));

		String s = readString();
		char[] ch = s.toCharArray();
		br.close();

		LinkedList<Character> ll = new LinkedList<Character>();
		int n = ch.length;
		ll.add(ch[0]);
		for (int i = 1; i < n; i++) {
			if (ch[i] == 'T') {
				if (ll.size() > 0) {
					char cp = ll.peekLast();
					if(cp=='S')ll.removeLast();
					else ll.add('T');
				

				}else ll.add('T');
			}else ll.add('S');
		}
		
		System.out.println(ll.size());

	}

	static public String readString() throws IOException {
		return br.readLine();

	}

	static public long readLong() throws IOException {
		return Long.parseLong(br.readLine());
	}

	static public int readInt() throws IOException {
		return Integer.parseInt(br.readLine());
	}

	static public int[] readIntArr() throws IOException {
		String[] str = br.readLine().split(" ");
		int arr[] = new int[str.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Integer.parseInt(str[i]);
		return arr;
	}

	static public Integer[] readOIntArr() throws IOException {
		String[] str = br.readLine().split(" ");
		Integer arr[] = new Integer[str.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = new Integer(str[i]);
		return arr;
	}

	static public double[] readDoubleArr() throws IOException {
		String[] str = br.readLine().split(" ");
		double arr[] = new double[str.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Double.parseDouble(str[i]);
		return arr;
	}

	static public Double[] readODoubleArr() throws IOException {
		String[] str = br.readLine().split(" ");
		Double arr[] = new Double[str.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = new Double(str[i]);
		return arr;
	}

	static public long[] readLongArr() throws IOException {
		String[] str = br.readLine().split(" ");
		long arr[] = new long[str.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Long.parseLong(str[i]);
		return arr;
	}

	static public Long[] readOLongArr() throws IOException {
		String[] str = br.readLine().split(" ");
		Long arr[] = new Long[str.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = new Long(str[i]);
		return arr;
	}

	static public double readDouble() throws IOException {
		return Double.parseDouble(br.readLine());
	}
}


Measured memory_bytes: 17060
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	REP(i,0,n) cin>>arr[i];
	sort(arr,arr+n);
	ll sum = 0;
	REP(i,0,k) sum += arr[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(){
  int a = 0, b = 0;
  scanf("%d %d", &a, &b);
  if (a < b) {
    printf("a < b\n");
  } else if (a > b) {
    printf("a > b\n");
  } else {
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a,b,c;
  cin>>a>>b>>c;
  
  if(a+b>=c) puts("Yes");
  else puts("No");
  return 0;
}

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

int main(void) {
	int ans = 0;
	char n = { '0' };
	while (n != '\n') {
		scanf("%c", &n);
		if (n >= '0' && n <= '9') {
			ans += (int)n - '0';
		}
	}
	if (ans % 9 == 0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
}

Measured memory_bytes: 1672
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

l = Counter()
r = Counter()

for i, a in enumerate(A):
    i += 1
    l[i+a] += 1
    r[i-a] += 1

res = 0
for k, v in l.items():
    res += v*r[k]

print(res)

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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using namespace std;

/* function */
//  - none - 


/* code */
int main (void) 
{

  /* Variable_Proclamation */
  int A, B, C;    // input
  int ans;        // output

  int i, j, k;    // subscript
  int count;
  int comp; // comparison

  int min_data, center_data, max_data;


  /* Input, Array_Proclamation */
  cin >> A >> B >> C;

  vector<int> data(3);
  data.at(0) = A;
  data.at(1) = B;
  data.at(2) = C;

  sort( all(data) );
  min_data    = data.at(0);
  center_data = data.at(1);
  max_data    = data.at(2);

  /* Initialize */
  ans = 0;
  count = 0;



  /* Calculation */
  while(min_data < max_data -1)
  {
    min_data += 2;
    count++;
  }
  while(center_data < max_data -1)
  {
    center_data += 2;
    count++;
  }

  if( min_data == center_data && max_data == min_data +1 )
  {
    min_data    += 1;
    center_data += 1;
    count++;
  }
  else if( min_data != center_data && max_data == min_data +1 )
  {

    min_data    += 2;
    count++;

    center_data += 1;
    max_data    += 1;
    count++;

  }
  else if( min_data != center_data && max_data == center_data +1)
  {
    
    center_data += 2;
    count++;

    min_data    += 1;
    max_data    += 1;
    count++;

  }

  /* Output */
  cout << count << endl;


  return 0;

}


/* entity */
//  - none -




Measured memory_bytes: 256
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int a[123456];
int main(){
    std::ios::sync_with_stdio(false); cin.tie(NULL);
  	int n;
  	cin>>n;
  	int i;
  	int sumi=0;
  	rep(i,n){
  		cin>>a[i];
  		sumi+=a[i];
  	}
  	int mini=inf,ind;
  	rep(i,n){
  		if(abs(sumi-n*a[i])<mini){
  			mini=abs(sumi-n*a[i]);
  			ind=i;
  		}
  	}
  	cout<<ind<<endl;
    return 0;   
}


Measured memory_bytes: 256
package main

import "fmt"

func abs(num int) int {
	if num >= 0 {
		return num
	} else {
		return -num
	}
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	var ans1, ans2 int
	ans1 = N - K*(N/K)
	ans2 = abs(N - K*((N/K)+1))
	if ans1 < ans2 {
		fmt.Println(ans1)
	} else {
		fmt.Println(ans2)
	}
}

Measured memory_bytes: 512
package main

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

func main() {
	N := ReadInt()
	A := ReadInts(N)
	ans := make([]int, N)
	for i := 0; i < N; i++ {
		ans[A[i]-1] = i + 1
	}
	for _, v := range ans {
		fmt.Printf("%d ", v)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 4932
#include<iostream>
#include<string>
using namespace std;
int main() {
	string t[1000], h[1000];
	int tp=0, hp=0, n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> h[i];
		if (t[i] > h[i]) {
			tp = tp + 3;
		}
		if (t[i] < h[i]) {
			hp = hp + 3;
		}
		if (t[i] == h[i]) {
			tp++; hp++;
		}
	}
	cout << tp << " " << hp << endl;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<ll,ll>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
int n;
cin>>n;
vector<int> a(n);
vector<int> cnt(1000006,0);
rep(i,n)cin>>a[i];
  for(auto x:a){
    if(cnt[x]!=0){
      cnt[x]=2;//それ以上の数の倍数は全て調べているので計算量を減らせる
      continue;
    }
    for(int j=x;j<1000006;j+=x){
      cnt[j]++;
    }
  }
int ans=0;
for(auto p:a){
  if(cnt[p]==1)ans++;
}
cout<<ans<<endl;
}


Measured memory_bytes: 7876
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    map<ll, ll> m;
    REP(n, N) {
        ll a, b;
        cin >> a >> b;
        m[a] += b;
    }
    ll cnt = 0;
    for(auto p: m) {
        auto a = p.first;
        auto b = p.second;
        cnt += b;
        if (cnt >= K) {
            cout << a << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N =1e5+100;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int Max =0,sum =0,x[5] ={0};
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&x[i%2]);
            if(x[i%2]<=x[(i+1)%2])
                sum++;
            else
                sum =0;
            Max =max(sum,Max);
        }
        printf("%d\n",Max);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int n,m;
vector<int> edges[200005];
bool visited[200005];
int res,ans=-1;
void dfs(int x){
	res++;
	visited[x]=1;
	for(int i=0;i<sz(edges[x]);i++){
		int fr=edges[x][i];
		if(!visited[fr]) dfs(fr);
	}
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	while(m--){
		int a,b;
		cin>>a>>b;
		edges[a].pb(b);
		edges[b].pb(a);
	}
	for(int i=1;i<=n;i++){
		res=0;
		dfs(i);
		ans=max(res,ans);
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 20956
#include <iostream>
#include <utility>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;

#define fi first
#define se second

const double EPS = 1e-9;

typedef pair<double,double> pdd;

struct circle {
	double x, y;
	double r, c;
	circle(double x_, double y_, double r_, double c_) {
		x = x_; y = y_; r = r_; c = c_;
	}
};

vector<vector<int> > edge;

template<typename T>
T sqr(T a) { return a * a; }

bool on(circle c1, circle c2) {
	double d = sqrt(sqr(c1.x - c2.x) + sqr(c1.y - c2.y));

	if(d + EPS > c1.r + c2.r) {
		return false;
	}
	return true;
}

bool used[1 << 24];

int main() {
	int n;
	while(cin >> n, n) {
		vector<circle> v;
		edge.clear();
		edge.resize(n);
		for(int i = 0; i < n; i++) {
			double x, y;
			double r, c;
			cin >> x >> y >> r >> c;
			circle in(x,y,r,c);
			for(int j = 0; j < v.size(); j++) {
				if(on(in, v[j])) {
					edge[i].push_back(j);
				}
			}
			v.push_back(in);
		}

		queue<int> q;
		q.push((1 << n) - 1);
		int res = 0;
		for(int i = 0; i < (1 << 24); i++)
			used[i] = false;
		while(!q.empty()) {
			int a = q.front();
			int flg = (1 << n) - 1;
			q.pop();

			int tmp = 0;
			for(int i = 0; i < n; i++) {
				if(a & (1 << i)) continue;
				tmp++;
			}
			res = max(res, tmp);
			for(int i = 0; i < n; i++) {
				if(a & (1 << i)) {
					for(int j = 0; j < edge[i].size(); j++) {
						if(a & (1 << edge[i][j]))
							flg &= ~(1 << i);
					}
				} else {
					flg &= ~(1 << i);
				}
			}

			for(int i = 0; i < n; i++) {
				if(flg & (1 << i)) {
					for(int j = i+1; j < n; j++) {
						if(flg & (1 << j)) {
							if(v[i].c == v[j].c) {
								int pb = a;
								pb &= ~(1 << i);
								pb &= ~(1 << j);
								if(!used[pb]) {
									q.push(pb);
									used[pb] = true;
								}
							}
						}
					}
				}
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 19008
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int n,t,x;
    scanf("%d %d %d",&n,&x,&t);
    if(n%x==0)
    {
        printf("%d",(n/x)*t);
    }
    else{
        printf("%d",(n/x+1)*t);
    }
    return 0;
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<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 ll INF = 1e18;

map<ll, ll> prime;

void prime_factorize(ll N) {
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        prime[a]+=ex;
    }

    // 最後に残った数について
    if (N != 1) prime[N]++;
    return;
}

int main(){
    ll n;
    cin >> n;
    for(int i=1;i<=n;i++){
        prime_factorize(i);
    }
    ll ans = 0;

    ll c74=0;
    ll c2=0;
    ll c24=0;
    ll c4=0;
    ll c14=0;

    
    for(auto it=prime.begin();it!=prime.end();it++){
        if(it->second>1)c2++;
        if(it->second>3)c4++;
        if(it->second>13)c14++;
        if(it->second>23)c24++;       
        if(it->second>73)c74++;
    }
    ans += c74;
    ans += c24*(c2-1);
    ans += c14*(c4-1);
    ans += (c2-2)*(c4)*(c4-1)/2;
    cout<<ans<<endl;

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x>=400&&x<600)
         cout<<8<<endl;
    else if(x>=600&&x<800)
         cout<<7<<endl;
     else if(x>=800&&x<1000)
         cout<<6<<endl;
          else if(x>=1000&&x<1200)
         cout<<5<<endl;
          else if(x>=1200&&x<1400)
         cout<<4<<endl;
          else if(x>=1400&&x<1600)
         cout<<3<<endl;
          else if(x>=1600&&x<1800)
         cout<<2<<endl;
          else if(x>=1800&&x<2000)
         cout<<1<<endl;

}


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

#define rep(i,p) for(int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

 ll int N;
 string S,T;
 cin >> N >> S >> T;

 for(int i=0;i<N;i++){
	 cout << S[i] <<T[i];
 }










	return 0;

}



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

string solve(vector<int>& moves,int k,int n){
    
    bool dp[k+1];
    
    memset(dp,0,sizeof(dp));
    
    for(int i=1;i<=k;i++){
        
        for(int j=1;j<=n;j++){
            if(moves[j]<=i && dp[i-moves[j]]==0){
                dp[i]=1;
            }
        }
        
    }
    
    return dp[k]==1 ? "First" : "Second";
}

int main() {
	// your code goes here
	
	int n ,k;
	cin>>n>>k;
	vector<int> moves(n+1);
	for(int i=1;i<=n;i++){
	    cin>>moves[i];
	}
	
	cout<<solve(moves,k,n);
	return 0;
}


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

int main(){
  int h,w,k;
  int count_bk=0,ans=0;
  cin >> h >> w >> k;
  vector<vector<char>>c(h+1,vector<char>(w+1));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c.at(i).at(j);
      if(c.at(i).at(j) == '#'){
        count_bk++;
      }
    }
  }
  for(int i=0;i<(1<<h);i++){
    for(int j=0;j<(1<<w);j++){
      int temp=count_bk;
      for(int x=0;x<h;x++){
        for(int y=0;y<w;y++){
          if(i&(1<<x) || j&(1<<y)){
            if(c.at(x).at(y)=='#'){
              temp--;
            }//if
          }//if
        }//for y
      }//for x
      if(temp == k){
        ans++;
      }
    }//for j
  }//for i
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(void){
    int a,b,c=0,f,g,h[1000]={0};
    cin>>a>>b;
    for(int i=1;i<=999;i++){
        c+=i;
        h[i-1]+=c;
    }
    for(int i=1;i<999;i++){
        f=h[i-1];
        g=h[i];
        for(int j=1;f>=a;j++){
            f--;
            g--;
            if(f==a && g==b){
                cout<<j<<endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int s,w;
	cin >> s>>w;
   string ans;
  if(s<=w)ans="unsafe";
    else ans="safe";

    cout << ans << endl;
}

Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int A, B, T;
	std::cin >> A >> B >> T;
	std::cout << T / A * B << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int cnt[100001];
int main()
{
     long long res = 0;
      int n , k;
      cin >> n >> k;
      for(int i = 1 ; i <= n ; ++i)
          cnt[i % k]++;
       for(int i = 1 ; i <= n ; ++i)
        {
               int  d = i % k;
                if(d * 2 % k == 0)res +=1ll * cnt[d] * cnt[d];
         }
      cout << res;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"

#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define inp(x) (cin>>x,x)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//	T res = v->back();
//	v->pop_back();
//	return res;
//}
//char vpop(string *v) {
//	char res = v->back();
//	v->pop_back();
//	return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

//#define lint long long
typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

const int
dx8[8] ={ 0,1,1,1,0,-1,-1,-1 },
dy8[8] ={ 1,1,0,-1,-1,-1,0,1 },
dx9[9] ={ 0,1,1,1,0,0,-1,-1,-1 },
dy9[9] ={ 1,1,0,-1,0,-1,-1,0,1 },
dx4[4] ={ 0,1,0,-1 },
dy4[4] ={ 1,0,-1,0 };

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

int main(){
	setc;
	
	lint a,b,c,x,ans=0;cin>>a>>b>>c>>x;
	rep_(i, a)rep_(j, b)rep_(k, c){
		if(500*i+100*j+50*k==x)++ans;
	}co(ans);
	gc();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define maxn 100000+5
#define P 1000000007
#define pi  3.1415926535
#define eps 0.00000001
#define pb  push_back
#define mkp make_pair
#define fi first
#define se second
#define pii  pair<int,int>
#define mii  map<int,int>
#define vi  vector<int>
#define dbg(i)  cout<<i<<endl;
#define Max(a,b) (((a)>(b))?(a):(b))
#define Min(a,b) (((a)<(b))?(a):(b))
#define me(a,b) memset(a,b,sizeof(a))
using ll=long long;
using ull=unsigned long long;
using namespace std;
inline void up(int&x,int y){x=x+y<P?x+y:x+y-P;}
inline char emm(int q,int w){return q==w?'\n':' ';}
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int ans=9999999,n;
int add(int a)
{
    int p=0;
    while (a)
    {
        p+=a%10;
        a/=10;
    }
    return p;
}
int main()
{
    //freopen("stdin.txt","r",stdin);
    //freopen("1.txt","w",stdout);
    //clock_t time=clock();
    //srand(time(0));
    cin>>n;
    for (int i=1;i<n;i++)
        ans=min(ans,add(i)+add(n-i));
    cout<<ans;
    //printf("程序运行的时间为%f\n",(double)(clock()-time)/CLOCKS_PER_SEC);
    //fclose(stdin);fclose(stdout);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b, c; cin >> a >> b >> c;
    int tmp = (c + 0.5) / a; 
    int ans = tmp * b;
    cout << ans << endl;
}

Measured memory_bytes: 256
n, y = gets.split.map(&:to_i)

(0..n).each do |a|
  (0..(n-a)).each do |b|
    if y == 10000 * a + 5000 * b + 1000 * (n - a - b)
      puts "#{a} #{b} #{n - a - b}"
      exit
    end
  end
end

puts "-1 -1 -1"

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,Y;
    cin >>N>>Y;
    
    rep(i,N+1){
        rep(j,N-i+1){
            ll m= i*10000+j*5000+(N-i-j)*1000;
            if(m==Y){
                cout<<i<<" "<<j<<" "<<(N-i-j)<<endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;


    return 0;
    

}

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

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    
   int w, h, n;
   cin >> w >> h >> n;
   vector<int> x(n), y(n), a(n);
   vector<vector<char>> board(w, vector<char>(h));
   int xmin = 0, xmax = w, ymin = 0, ymax = h;
   rep(i, n){
      cin >> x[i] >> y[i] >> a[i];
      if(a[i] == 1){
         if(xmin < x[i]){
            xmin = x[i];
         }
      }else if(a[i] == 2){
         if(xmax > x[i]){
            xmax = x[i];
         }
      }else if(a[i] == 3){
         if(ymin < y[i]){
            ymin = y[i];
         }
      }else{
         if(ymax > y[i]){
            ymax = y[i];
         }
      }
   }
   if(xmin >= xmax || ymin >= ymax){
      cout << 0 << endl;
   }else{
      cout << (xmax - xmin) * (ymax - ymin);
   }
   
return 0;}

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

int main() {
	std::string num;
	std::string::iterator ptr;
	std::cin >> num;
	int all = 0;
	int tmp;

	for (ptr = num.begin(); ptr != num.end(); ptr++) {
		char& c = *ptr;
		tmp = (int)(c - '0');
		all += tmp;
	}

	if (all % 9 == 0) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;

}

Measured memory_bytes: 3704