akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
using namespace std;
int main(){
  int n,d[1000];
  cin>>n;
  for(int i=0;i<n;i++)cin>>d[i];
  int cnt[10000]={};
  for(int i=n-1;i>=0;i--){
    int sum=0;
    for(int j=0;j<4;j++){
      if(i-j<0)break;
      sum+=d[i-j]*pow(10,j);
      cnt[sum]++;
    }
  }
  int i=0;
  while(cnt[i])i++;
  cout<<i<<endl;
  return 0;
}



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }

  sort(h.begin(), h.end());
  int ans = 1000000000;
  for (int i = 0; i < n - k + 1; i++) {
    int tmp = h.at(i + k - 1) - h.at(i);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

 
int main() {

  double l;
  cin >> l;

  double ans=(double)l*l*l/27.0;

  printf("%.10f",ans);

 return 0;
}

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

string S;
int N;

void input() {
  cin >> N;
  cin >> S;
}

void solve() {
  input();
  string tmp = "No";
  int K = N / 2;
  if (N % 2 == 0 && S.substr(0, K) == S.substr(K, K)) tmp = "Yes";
  cout << tmp << endl;
  return;
}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    
    if ("Sunny".equals(s)) System.out.println("Cloudy");
    if ("Cloudy".equals(s)) System.out.println("Rainy");
    if ("Rainy".equals(s)) System.out.println("Sunny");
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,K;
    cin >> N >> K;
    if(N%K==0) cout << 0 << endl;
    else cout << 1 << endl;



}


Measured memory_bytes: 256
package main

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

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	a := make([]uint64, N)
	for i, _ := range a {
		t, _ := strconv.Atoi(read())
		a[i] = uint64(t)
	}

	var t uint64
	for i := 0; i < N; i++ {
		t = t ^ a[i]
	}
	if t == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []struct {
	b, c int
}

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].c > a[j].c }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 2432
h, w = [int(i) for i in input().split()]
s = []
for i in range(h):
    s.append(list(input()))

dh = (-1, 0, 0, 1)
dw = (0, -1, 1, 0)
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            for y, x in zip(dh, dw):
                if 0 <= i+y < h and 0 <= j+x < w:
                    if s[i+y][j+x] == '#':
                        break
            else:
                break
    else:
        continue
    print('No')
    break
else:
    print('Yes')


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    char a, b;
    cin >> a >> b;
    if( b == 'H' ) {
        cout << (char)a;

    } else {
        if( a == 'H' ) {
            cout << 'D';

        } else {
            cout << 'H';

        }
    }
    cout << endl;
    return 0;
}



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

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 512
int main(){
  int n, i;
  char s[101];
  scanf("%d%s", &n, s);
  char f=!(n&1);
  n/=2;
  for(i=0; i<n; i++){
    if(s[i]!=s[i+n]) f=0;
  }
  puts(f?"Yes":"No");
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

int main() {
  int width, height, x, y, r;
  std::cin >> width >> height >> x >> y >> r;

  int remaining_length = std::min(std::min(width - x, x), std::min(height - y, y));
  if (remaining_length >= r) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;

/*
kが最大でも5なので、答えになるのは長さが1~5まで
最大の長さが固定されていれば、O(n)で全探索できる
*/


void pr(set<string> k){
    int siz = k.size();
    for(int i=0; i<siz; i++){
        auto itr = k.begin();
        rep(j,i){
            itr++;
        }
        cout << *itr << " " << endl;
    }
}


void solve(){
    string s;
    int k;
    cin >> s;
    cin >> k;

    int n=s.size();
    set<string> st;
    string tmp;
    rep(i,n){
        char c = s[i];
        string t{c};
        st.insert(t);
        //cout << "tmp:" << t << endl;
    }
    /*
    if(n>=2){
    for(int i=1; i<n; i++){
        st.insert(s.substr(i,2));
        cout << "tmp:" << tmp << endl;
    }
    }
    */

    for(int m=2; m<=5; m++){
        if(n>=m){
            for(int i=m-1; i<n; i++){
                string result = s.substr(i-m+1,m);
                //cout << "result:" << result << endl;
                st.insert(result);
            //cout << "tmp:" << tmp << endl;
            }
        }
    }


    //pr(st);
    auto i = st.begin();
    rep(j,k-1){
        i++;
    }
    cout << *i << endl;
}

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



Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>

using namespace std;

int main(){
    int H,W;
    int d[10][10];
    int A[10]={};
    cin>>H>>W;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>d[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int x;
            cin>>x;
            if(x != -1){
                A[x]++;
            }
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<10;i++){
        ans += d[i][1]*A[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 1000005

int n;
ll a[maxn], sum[maxn];

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

	cin >> n;
	For(i, 1, n) cin >> a[i];
	sort(a + 1, a + n + 1);
	sum[0] = 0;
	For(i, 1, n) sum[i] = sum[i - 1] + a[i];
	Ford(i, n - 1, 1){
		if(sum[i] + sum[i] < a[i + 1]){
			cout << n - i << endl;
			return 0;
		}
	}

	cout << n << endl;

    return 0;
}


Measured memory_bytes: 5120
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans[15];
int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    ll n,m;
    int k;
    scanf("%lld%lld%d",&n,&m,&k);
    ll total = (n-2)*(m-2);
    int i,j,x,y;
    int x1,x2,y1,y2;
    set< pair<int,int> > ss;
    map< pair< pair<int,int> , pair<int,int> >,int > rect;
    for(i=0;i<k;i++)
        {
        scanf("%d%d",&x,&y);
      //  printf("%d %d is included in\n",x,y);
        ss.insert(make_pair(x,y));
        int mix = max(x-2,1);
        int miy = max(y-2,1);
        for(x1 = mix; x1 <= x; x1++)
            {
            for(y1 = miy; y1<=y; y1++)
                {
                x2 = x1 + 2;
                y2 = y1 + 2;
                if(x2<=n && y2<=m)
                    {
                  //  printf("rectangel %d %d %d %d\n",x1,y1,x2,y2);
                    rect[make_pair(make_pair(x1,y1),make_pair(x2,y2))]++;
                }
            }
        }
    }
    map< pair< pair<int,int> , pair<int,int> >,int >::iterator I;
    ans[0] = total;
    for(I = rect.begin(); I!=rect.end();I++)
        {
       // sum++;
        ans[I->second]++;
        ans[0]--;
    }
    for(i=0;i<10;i++)
        printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 61184
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main()
{
	auto NT = readln.chomp.split(' ').map!(to!long).array;
    long N = NT[0];
    long T = NT[1];
    long[] B;
    auto A = readln.chomp.split(' ').map!(to!long).array;
    long minA = A[0];
    foreach(i;1 .. N)
    {
        B ~= A[i] - minA;
        minA = min(minA,A[i]);
    }
    B.count(B.reduce!((a,b) => max(a,b))).writeln();
}

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

#define ll long long int

int main() {
    ll n, w;
    cin>>n>>w;
    vector<ll> weights(n), values(n);
    for(int i=0; i<n; i++)
        cin>>weights[i]>>values[i];
    vector<ll> dp(w + 1, 0);
    for(int i=0; i<n; i++)
        for(int j = w - weights[i]; j >= 0; j--)
            dp[j + weights[i]] = max(dp[j + weights[i]], dp[j] + values[i]);
    cout<<dp[w]<<endl;
    return 0;
}


Measured memory_bytes: 1024
S = input ()

if S == 'SUN':
    print(7)

elif S == 'MON':
    print(6)

elif S == 'TUE':
    print(5)

elif S == 'WED':
    print(4)

elif S == 'THU':
    print(3)

elif S == 'FRI':
    print(2)

elif S == 'SAT':
    print(1)


Measured memory_bytes: 8992
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int h, w; cin >> h >> w;
  vector<vector<char> > a(h, vector<char>(w)); REP(i, h) REP(j, w) cin >> a[i][j];
  vector<vector<int> > cnt(h, vector<int>(w, INF));
  queue<pair<int, int> > que;
  REP(i, h) REP(j, w) {
    if (a[i][j] == '#') {
      cnt[i][j] = 0;
      que.emplace(i, j);
    }
  }
  while (!que.empty()) {
    auto pr = que.front(); que.pop();
    REP(i, 4) {
      int y = pr.first + dy[i], x = pr.second + dx[i];
      if (0 <= y && y < h && 0 <= x && x < w && a[y][x] == '.') {
        a[y][x] = '#';
        cnt[y][x] = cnt[pr.first][pr.second] + 1;
        que.emplace(y, x);
      }
    }
  }
  int ans = 0;
  REP(i, h) REP(j, w) ans = max(ans, cnt[i][j]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 13456
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

class UnionFind {
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    //ex:Parent[0] :0の親
    vector<int> Parent;

    //作るときはParentの値を全て-1にする
    //こうすると全てバラバラになる
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }

    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        //親の繋ぎ変え。
        return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//親をとってきたい]
    }

    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }

        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらひっくり返しちゃう。
        if (size(A) < size(B)) swap(A, B);

        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;

        return true;
    }
};

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

    vector<long long> ans(M);
    //全ての橋が崩落した時の不便さ
    ans[M - 1] = (long long)N * (N - 1) / 2;

    UnionFind Uni(N);

    for (int i = M - 1; i >= 1; i--)
    {
        ans[i - 1] = ans[i];

        //繋がってなかったのが繋がった時
        if (Uni.root(A[i]) != Uni.root(B[i])) {
            //崩落したと仮定したときのダメになる経路数を求める。
            ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
            //つなげるて減少分の経路数を2度数えることがないようにする。
            Uni.connect(A[i], B[i]);
        }
    }

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



Measured memory_bytes: 3328
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

X = ri()

n = 100
i = 0
while True:
	i += 1
	n = math.floor(n * 1.01)
	if n >= X:
		break
print(i)

Measured memory_bytes: 63652
use std::io;
use std::str;

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }

    pub fn tokens<T: str::FromStr>(&mut self) -> Vec<T> {
        assert!(self.buffer.is_empty());
        let mut input = String::new();
        self.reader.read_line(&mut input).expect("Failed read");
        input
            .split_whitespace()
            .map(|x| x.parse().ok().expect("Failed parse"))
            .collect()
    }
}

// f(n) -> f(n + 1), cost: |heights[n] - heights[n + 1]|
// f(n) -> f(n + 2), cost: |heights[n] - heights[n + 2]|

const INF: i32 = 1000000000;

// fn pull_dp(n: usize, heights: &[i32]) -> i32 {
//     let mut dp = vec![INF; n];
//     dp[0] = 0;
//     dp[1] = (heights[0] - heights[1]).abs();
//     for i in 2..n {
//         dp[i] = dp[i].min(min(
//             dp[i - 1] + (heights[i] - heights[i - 1]).abs(),
//             dp[i - 2] + (heights[i] - heights[i - 2]).abs(),
//         ));
//     }
//     dp[n - 1]
// }

fn push_dp(n: usize, k: usize, heights: &[i32]) -> i32 {
    let mut dp = vec![INF; n];
    dp[0] = 0;
    for i in 0..n {
        for j in 1..=k {
            if i + j < n {
                dp[i + j] = dp[i + j].min(dp[i] + (heights[i] - heights[i + j]).abs());
            }
        }
    }
    dp[n - 1]
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let n: usize = scan.token();
    let k: usize = scan.token();
    let heights: Vec<i32> = scan.tokens();
    let ans = push_dp(n, k, &heights);
    writeln!(out, "{}", ans).ok();
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}


Measured memory_bytes: 3056
program test
implicit none
integer :: i,j,k,m,n,a1=0,a2=0,a3=0,leng
character(10) :: mozi
read(*,*) mozi
leng = len_trim(mozi)

if(mozi(1:1) .ne. 'A') then
	write(*,*) 'WA'
else
	do i=2,leng
		if(i>=3 .and. i<=leng-1 .and. mozi(i:i) .eq. 'C') then
			a1 = a1 + 1
		
		else if(mozi(i:i) >= 'A' .and. mozi(i:i) <= 'Z') then
			a2 = a2 + 1
		endif
	enddo
	
	if(a1 == 1 .and. a2 == 0) then
		write(*,*) 'AC'
	else
		write(*,*) 'WA'
	endif
endif


end program

Measured memory_bytes: 768
var input = require('fs').readFileSync('/dev/stdin', 'utf8').split("\n");
var sp = input[1].split(" ").map(Number);
var ans = [];
for( var i = sp.length - 1; 0 <= i; i-- ) {
  ans.push( sp[i] );
}
console.log( ans.join(" ") );

Measured memory_bytes: 15372
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <iterator>
#include <math.h>
using namespace std;

int main(void){
  long N,K;
  cin >> N >> K;
  long R,S,P;
  cin >> R >> S >> P;
  string s;
  cin >> s;
  vector<long> ten;
  for(auto it = s.begin(); it != s.end(); it++){
    long tmp = 0;
    switch (*it)
    {
    case 'r':
      ten.push_back(P);
      break;
    case 's':
      ten.push_back(R);
      break;
    case 'p':
      ten.push_back(S);
      break;
    default:
      break;
    }
  }

  long tensum = accumulate(ten.begin(),ten.end(),0);
  for(long i =0; i < N - K; i++){
    if(s[i] == s[i+K]){
      tensum -= ten[i+K];
      s[i+K] = 0;
    }
  }
  cout << tensum << endl;
  return 0;
}

Measured memory_bytes: 4484
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

cvt 'I' = 1
cvt 'V' = 5
cvt 'X' = 10
cvt 'L' = 50
cvt 'C' = 100
cvt 'D' = 500
cvt 'M' = 1000

calc s = calc' 0 s
  where
    calc' r [] = r
    calc' r (a:[]) = r + a
    calc' r (a:bs@(b:cs))
      | a < b = calc' (r+b-a) cs
      | otherwise = calc' (r+a) bs

main = do
    map (calc . map cvt) . lines <$> getContents >>= mapM_ print 

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      ll n;
      cin >> n;
      ll t[n];
      rep(i,n)cin >> t[i];
      ll ans=t[0];
      rep(i,n-1){
       ans=ans*(t[i+1]/__gcd(ans,t[i+1])); 
      }
      cout << ans << endl;
      return 0;}


Measured memory_bytes: 256
n = gets.chomp.to_i
nums = gets.chomp.split.map(&:to_i)
nums.unshift nil
count = 0
if nums[1] == 1
    nums[1] = nums[2]
    nums[2] = 1
    count += 1
end
1.upto(n) do |i|
    if nums[i] == i
        nums[i] = nums[i + 1]
        nums[i + 1] = i
        count += 1
    end
end
puts count


Measured memory_bytes: 9092
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/05/20 20:45:24
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<int> A(n); for (auto& a:A) cin>>a;
  sort(A.rbegin(), A.rend());
  long long ans = 0;
  if (n > 1) {
    int f = 0;
    ans += A[f];
    for (int k = 2; k < n; k++) {
      ans += A[k/2];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3988
let a=Int(readLine()!)!
let b=Int(readLine()!)!
let c=Int(readLine()!)!
let x=Int(readLine()!)!
var r=0
for i in 0...x/500 {
	for j in 0...(x-500*i)/100 {
		let k=x-500*i-100*j
		if k%50==0&&c>=k/50&&a>=i&&b>=j {r+=1}
	}
}
print(r)

Measured memory_bytes: 3824
n=int(input())
v=[int(x) for x in input().split()]
v_e=v[::2]
v_o=v[1::2]
vote_e={}
vote_o={}
vote_e[-1]=0
vote_o[-1]=0

for i in range(n//2):
    vote_e[v_e[i]] = vote_e[v_e[i]] + 1 if v_e[i] in vote_e else 1
    vote_o[v_o[i]] = vote_o[v_o[i]] + 1 if v_o[i] in vote_o else 1

vote_e=sorted(vote_e.items(), reverse=True, key=lambda x:x[1])
vote_o=sorted(vote_o.items(), reverse=True, key=lambda x:x[1])
popular_e=vote_e[0][1]
popular_o=vote_o[0][1]
if vote_e[0][0]==vote_o[0][0]:
    if vote_e[0][1]+vote_o[1][1]>vote_o[0][1]+vote_e[1][1]:
        popular_o = vote_o[1][1]
    else:
        popular_e = vote_e[1][1]
print(n-popular_o-popular_e)

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

namespace ABC
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var h = int.Parse(Console.ReadLine());
            var w = int.Parse(Console.ReadLine());
            var n = int.Parse(Console.ReadLine());

            var l = Math.Max(h, w);
            var result = (n + l - 1) / l;

            Console.WriteLine(result);
        }
    }
}


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

#define int long long
int A[223456];

signed main(){
  string s;cin>>s;
  reverse(s.begin(),s.end());
  for(int i=0,t=1;i<s.size();i++){
    int a=s[i]-'0';
    A[i+1]=(A[i]+a*t)%2019;
    (t*=10)%=2019;
  }
  map<int,int> m;
  for(int i=0;i<=s.size();i++)m[A[i]]++;
  int ans=0;
  for(auto p:m)ans+=p.second*(p.second-1)/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 5248
/* ****_hela**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n;
		cin>>n;
		ll int sum=0;
		for(int i=1;i<=n;i++)
		{   
			
			for(int j=1;j<=n;j++)
			{
				for(int k=1;k<=n;k++)
					{
						int gc=__gcd(j,k);
						sum+=__gcd(i,gc);
					}
			}
		}		
		cout<<sum;
	}
	return 0;
}

Measured memory_bytes: 3652
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    L = [[] for _ in range(K)]
    for t in range(K):
        l, r = map(int, input().split())
        for j in range(l, r + 1):
            L[t].append(j)

    lc = [0] * K
    mod = 998244353

    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(1,N+1):

        for k in range(K):
            CL =L[k]
            if len(CL)==1:
                lc[k]=dp[i-CL[0]] %mod
            else:
                if CL[-1] > i:
                    lc[k] = lc[k] %mod +dp[i-L[k][0]] %mod
                else:
                    lc[k] =( lc[k] + dp[i - L[k][0]] - dp[i - L[k][-1]-1] )%mod
            dp[i] += lc[k]



    print(dp[N - 1]%mod)


if __name__ == "__main__":
    main()

# \n


Measured memory_bytes: 82556
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, i = 0, j = 0, count = 0, flag = 0;
    cin >> n;
    int h[n];
    for(i = 0; i < n; i++){
        cin >> h[i];
    }
    count = 1;
    for(i = 1; i < n; i++){
        flag = 0;
        for(j = 0; j < i; j++){
            
            if(h[i] >= h[j]){
                flag = 1;
            }
            else{
                flag = 0;
                break;
            }
            
        }
        if(flag == 1){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl
using namespace std;
int main()
{
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
    return 0;
}

Measured memory_bytes: 3640
'use strict'

function main(s) {

  s = s.split('\n');
  const H = Number(s[0].split(' ')[0]);
  const W = Number(s[0].split(' ')[1]);
  const table = s.slice(1, -1).map(line => line.split(''));

  for (let h = 0; h < H; h++) {
    for (let w = 0; w < W; w++) {
      if (table[h][w] === '#') continue;

      let count = 0;

      // 上の行
      if (h >= 1) {
        
        // 左上
        if (w >= 1) {
          if (table[h - 1][w - 1] === '#') count += 1;
        }

        // 真上
        if (table[h - 1][w] === '#') count += 1;

        // 右上
        if (w < W - 1) {
          if (table[h - 1][w + 1] === '#') count += 1;
        }
      }

      // 該当行
      // 左
      if (w >= 1) {
        if (table[h][w - 1] === '#') count += 1;
      }

      // 右
      if (w < W - 1) {
        if (table[h][w + 1] === '#') count += 1;
      }

      // 下の行
      if (h < H - 1) {

        // 左下
        if (w >= 1) {
          if (table[h + 1][w - 1] === '#') count += 1;
        }

        // 真下
        if (table[h + 1][w] === '#') count += 1;

        // 右下
        if (w < W - 1) {
          if (table[h + 1][w + 1] === '#') count += 1;
        }
      }

      table[h][w] = count;
    }
  }

  const ans = table.map(line => line.join('')).join('\n');
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
# -*- coding: utf-8 -*-
import sys


def main():
    N = int( sys.stdin.readline() )
    D_list = [ list(map(int, sys.stdin.readline().split())) for _ in range(N) ]


    cnt = 0

    for i in range(len(D_list)):
        if D_list[i][0] == D_list[i][1]:
            cnt += 1
        else:
            cnt = 0
        
        if cnt == 3:
            print("Yes")
            return
    

    print("No")



if __name__ == "__main__":
    main()


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

int main()
{
	string s; cin >> s;

	string ans;

	for (int i = 0; i < s.size(); i++) {

		if (i % 2 == 0) ans += s.at(i);

	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main() {
	int k;
	char str[100];
	
	scanf("%d", &k);
	scanf("%s", &str);
	
	int len = strlen(str);
	if (len <= k) {
		printf("%s", str);
	}
	else {
		for (int i = 0; i < k; i++) {
			printf("%c", str[i]);
		}
		puts("...");
	}
	
	return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
 
int main() {
  int N; cin >> N;
  ll A[N][N]; rep(i,N) rep(j,N) cin >> A[i][j];
  rep(i,N) if (A[i][i]!=0) { cout << -1 << endl; return 0; }
  rep(i,N) rep(j,N) if (A[i][j]!=A[j][i]) { cout << -1 << endl; return 0; }

  vector<vector<int>> omit;
  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      for (int k=j+1; k<N; k++) {
        ll load[3] = {A[i][j], A[j][k], A[i][k]};
        sort(load, load+3);
        if (load[0]!=0) {
          if (load[0]+load[1]<load[2]) { cout << -1 << endl; return 0; }
          if (load[0]+load[1]==load[2]) {
            if (A[i][j]>=A[j][k] && A[i][j]>=A[i][k]) omit.push_back({i,j});
            else if (A[j][k]>=A[i][j] && A[j][k]>=A[i][k]) omit.push_back({j,k});
            else omit.push_back({i,k});
          }
        }
      }
    }
  }

  ll result = 0;
  for (int i=0; i<N; i++) for (int j=i+1; j<N; j++) result += A[i][j];
  sort(omit.begin(), omit.end());
  omit.erase(unique(omit.begin(), omit.end()), omit.end());
  for (auto x: omit) result -= A[x[0]][x[1]];
  cout << result << endl;
  return 0;
}

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

using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	vector<int> pS(S.size()), pT(T.size());
	pS[0] = S[0] == 'A' ? 1 : 2;
	for (int i = 1; i < S.size(); ++i) {
		pS[i] = S[i] == 'A' ? 1 : 2;
		pS[i] += pS[i-1];
		pS[i] %= 3;
	}
	pT[0] = T[0] == 'A' ? 1 : 2;
	for (int i = 1; i < T.size(); ++i) {
		pT[i] = T[i] == 'A' ? 1 : 2;
		pT[i] += pT[i-1];
		pT[i] %= 3;
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		--a; --b; --c; --d;
		int sS = pS[b] - (a-1 >= 0 ? pS[a-1] : 0);
		sS = (sS+3)%3;
		int sT = pT[d] - (c-1 >= 0 ? pT[c-1] : 0);
		sT = (sT+3)%3;
		cout << (sS == sT ? "YES" : "NO") << "\n";
	}
}

Measured memory_bytes: 1664
import std;


const AB = 1;
const AC = 2;
const BA = 3;
const BC = 4;
const CA = 5;
const CB = 6;

void calc(int a, int b, int c, string[] ss) {

    string move(int mv) {
        switch (mv) {
            case AB:
                if (a == 0 && b == 0) return "X";
                if (a == 0) { a++; b--; return "A";}
                else { a--; b++; return "B";}
                break;

            case AC:
                if (a == 0 && c == 0) return "X";
                if (a == 0) { a++; c--; return "A";}
                else { a--; c++; return "C";}
                break;

            case BA:
                if (b == 0 && a == 0) return "X";
                if (b == 0) { b++; a--; return "B";}
                else { b--; a++; return "A";}
                break;

            case BC:
                if (b == 0 && c == 0) return "X";
                if (b == 0) { b++; c--; return "B";}
                else { b--; c++; return "C";}
                break;

            case CA:
                if (c == 0 && a == 0) return "X";
                if (c == 0) { c++; a--; return "C";}
                else { c--; a++; return "A";}
                break;

            case CB:
                if (c == 0 && b == 0) return "X";
                if (c == 0) { c++; b--; return "C";}
                else { c--; b++; return "B";}
                break;

            default: break;
        }
        return "X";
    }


    string[] ans;
    for (int i = 0; i < ss.length; i++) {
        string s = ss[i];
        if (i+1 == ss.length) {
            int mv = AB;
            if (s == "AB") mv = AB;
            if (s == "AC") mv = AC;
            if (s == "BC") mv = BC;
            // writeln(a, " ", b, " ", c, " ", " mv ", mv);
            string ch = move(mv);
            if (ch == "X") {
                writeln("No");
                return;
            }
            ans ~= ch;
        }

        else {
        string t = ss[i + 1];
        int mv = AB;
        if (s == "AB") {
            if (t == "AB") mv = AB;
            if (t == "AC") mv = BA;
            if (t == "BC") mv = AB;
        }
        else if (s == "AC") {
            if (t == "AB") mv = CA;
            if (t == "AC") mv = AC;
            if (t == "BC") mv = AC;
        }
        else if (s == "BC") {
            if (t == "AB") mv = CB;
            if (t == "AC") mv = BC;
            if (t == "BC") mv = BC;
        } else assert(false);

        string ch = move(mv);
        if (ch == "X") {
            writeln("No");
            return;
        }
        ans ~= ch;
        }
    }

    writeln("Yes");
    foreach (e; ans) writeln(e);
}

void main() {
    int n, a, b, c; scan(n, a, b, c);

    string[] ss;
    foreach (_; 0..n) ss ~= read!string;
    calc(a, b, c, ss);
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 8624
#include<stdio.h>
#include<string.h>

int main(){
    char str[1000]={},p[20]={},h[1000]={},rev;
    int q,a,b,rep;
    scanf("%s",str);
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%s",p);
        if(strcmp(p,"replace")==0){
            rep =0;
            scanf("%d %d %s",&a,&b,h);
            for(int i=a;i<=b;i++){
                str[i] = h[rep];
                rep++;
            }
        }else if(strcmp(p,"reverse") == 0){
            scanf("%d %d",&a,&b);
            for(int i=a;i<b;i++){
                rev = str[i];
                str[i] = str[b];
                str[b] = rev;
                b--;
            }
        }else if(strcmp(p,"print")==0){
            scanf("%d %d",&a,&b);
            for(int i=a;i<=b;i++){
                printf("%c",str[i]);
            }
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2112
#include<stdio.h>
#include<string.h>
char s[250];
int main ()
{

	while(scanf("%s",s)!=EOF)
	{
		int i,len,n;
		len=strlen(s);
		n=len/2-1;
		while(n)
		{
			int k=0;
			for(i=0;i<n;i++)
				if(s[i]!=s[i+n])
					k++;
			n--;
			if(k==0){
				printf("%d\n",n*2+2);	
				break;
			}		
		}
	}
} 


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
//↓✟MLE魔、TLE魔✟
#define int long long
//↑✟MLE魔、TLE魔✟
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using namespace boost::multiprecision;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
signed main(){
    char c;
    cin>>c;
    if(c=='A')cout<<'T'<<endl;
    if(c=='T')cout<<'A'<<endl;
    if(c=='G')cout<<'C'<<endl;
    if(c=='C')cout<<'G'<<endl;
}

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

int main(){
    vector<int> nums(3);
    for (int i=0; i<3; i++){
        cin >> nums.at(i);
    }
    sort(nums.begin(), nums.end());
    if (nums.at(0)+nums.at(1)==nums.at(2)) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        long a = in.nextLong(), b = in.nextLong(), n = in.nextLong();

        long x = 0;
        if (n >= b) {
            x = b - 1;
        } else {
            x = n;
        }
        System.out.println((a * x / b) - a * (x / b));
    }
}


Measured memory_bytes: 35592
import sys

n = int(sys.stdin.readline().strip())
a_ls = []
for i in range(n):
    a = int(sys.stdin.readline().strip())
    a_ls.append(a)

if a_ls[0] != 0:
    print(-1)
else:
    cur = a_ls[-1]
    res = cur
    for a in a_ls[::-1][1:]:
        cur -= 1
        if a - cur > 0:
            res += a
            cur = a
        elif a == cur:
            continue
        else:
            res = -1
            break
    print(res)

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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T> inline void scf(T &x) {
	bool f = 0;
	x = 0;
	char c = getchar();
	while(c != '-' && (c < '0' || c > '9')) c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	if(f) x = -x;
	return;
}

template <typename T1, typename T2> void scf(T1 &x, T2 &y) {
	scf(x);
	return scf(y);
}

template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z) {
	scf(x);
	scf(y);
	return scf(z);
}

template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
	scf(x);
	scf(y);
	scf(z);
	return scf(w);
}

inline char mygetchar() {
	char c = getchar();
	while(c == ' ' || c == '\n') c = getchar();
	return c;
}

template <typename T> inline bool chkmax(T &x, const T &y) {
	return y > x ? x = y, 1 : 0;
}

template <typename T> inline bool chkmin(T &x, const T &y) {
	return y < x ? x = y, 1 : 0;
}

#ifdef King_George
#define DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

//---------------------------------------------------------head----------------------------------------------------

const int maxn = 2010;

int A[maxn], n, S;
bitset<maxn * 2000> f;

int main() {
	scanf("%d", &n);
	f.set(0);
	forn(i, 1, n) {
		scf(A[i]);
		S += A[i];
		f |= (f << A[i]);
	}
	if(S & 1) {
		++S;
	}
	S >>= 1;
	while(f[S] == 0) {
		++S;
	}
	printf("%d\n", S);
	return 0;
}

Measured memory_bytes: 1664
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);

    string s;
    cin>>s;

    int len = s.length();

    int dp[len+1]; //dp[i] will store the remainder
    //if we divide the suffix started position i
    // by 2019


    memset(dp,0,sizeof dp );

    //120 = 1*100 + 2*10+ 0*1;
    int p=1;
    int cnt[2019]; //cnt[i] will be holding
    //the frequency for i occuring as remainder

    memset(cnt,0,sizeof cnt);

    ll ans = 0;
    cnt[0]=1;
    for(int i=len-1;i>=0;i--){
        dp[i]=(dp[i+1]+(s[i]-'0')*p)%2019;
        p*=10;
        p%=2019;

        int currem = dp[i];
        ans+= cnt[currem];
        cnt[currem]++;
    }
    /*for(int i=0;i<len;i++){
        cout<<s[i]<<" ";
    }
    cout<<"\n";
    for(int i=0;i<len;i++){
        cout<<dp[i]<<" ";
    }
    cout<<"\n";*/
    cout<<ans<<"\n";
}


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

using namespace std;

typedef long long ll;

ll N, K, L, R;
ll a[40];

decltype(auto) enumerate(int sidx, int size) {
  vector<pair<ll, ll>> ret;
  for(int i=0; i<1<<size; i++) {
    int cnt = 0; ll sum = 0;
    for(int j=0; j<size; j++)
      if(i >> j & 1) cnt++, sum += a[sidx + j];
    ret.emplace_back(cnt, sum);
  }
  return ret;
}

ll solve() {
  auto v0 = enumerate(0, N / 2);
  auto v1 = enumerate(N / 2, (N + 1) / 2);
  sort(v0.begin(), v0.end());
  ll ret = 0;
  for(int i=0; i<(int)v1.size(); i++)
    ret +=  upper_bound(v0.begin(), v0.end(), make_pair(K - v1[i].first, R - v1[i].second))
          - lower_bound(v0.begin(), v0.end(), make_pair(K - v1[i].first, L - v1[i].second));
  return ret;
}

int main() {
  cin >> N >> K >> L >> R;
  for(int i=0; i<N; i++) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 43720
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  if(N == 0 || N == 26){
     myout(input[1]);
  }else{
    var inList = myconv(input[1],6);
    var list = "abcdefghijklmnopqrstuvwxyz".toUpperCase().split("");
    var output = "";
    for(var i = 0; i < inList.length; i++){
      var tmp = inList[i];
      var no = list.indexOf(tmp);
      no += N;
      //myout("in:" + tmp + ",no:" + no);
      if(no > 25){
         no -= 26;
      }
      
      output += list[no];
      //myout("no:" + no + ",add:" + list[no]);
    }
    myout(output);
  }
}

Main(myin());


Measured memory_bytes: 21400