akhauriyash/Code-Regression huggingface dataset:
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

const int MAXN = 1e5+5;

int N, a[MAXN], cnt[MAXN];


int main(){
	scan(N);
	FOR(i,0,N) scan(a[i]);
	FOR(i,0,N){
		FOR(x,-1,2) if(a[i]+x >= 0) cnt[a[i]+x]++;
	}
	int ans = 0;
	FOR(i,0,MAXN) mxze(ans, cnt[i]);
	printf("%d\n", ans);
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,x,ans=0;  //解答数カウント
    
    while (1) {
        cin >>  n >> x;
        if (n==0 && x==0) {
            break;
        }
        for (int i=1; i<n+1; i++) {
            for (int j=i+1; j<n+1; j++) { //iの値より大きい値からループ
                for (int k=j+1; k<n+1; k++) { //jの値より大きい値からループ
                    if (i+j+k == x) { //合計値がxになった時カウント
                        ans++;
                    }
                }
            }
        }
        cout << ans <<endl;
        ans = 0;
    }
    return 0;
}


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

using namespace std;

long get_h(long cx, long cy, long x, long y, long c){
    return c + abs(x - cx) + abs(y - cy);
}

int main(){
    int N;
    cin >> N;
    long x[N], y[N], c[N];
    long CX, CY, H;
    for(int i=0; i<N; i++) cin >> x[i] >> y[i] >> c[i];

    for(int cx=0; cx <= 100; cx++){
        for(int cy = 0; cy <= 100; cy ++){
            long h;
            bool ok = true;
            bool flag = false;

            for(int i=0; i<N; i++){
                if(c[i] != 0){
                    if(!flag) {
                        flag = true;
                        h = get_h(cx, cy, x[i], y[i], c[i]);
                    }
                    else{
                        if(h != get_h(cx, cy, x[i], y[i], c[i])){
                            ok = false;
                            break;
                        }
                    }
                }
            }
            for(int i=0; i<N; i++){
                if(c[i] == 0 && c[i] + max(0l, h - abs(cx - x[i]) - abs(cy - y[i])) != 0){
                    ok = false;
                    break;
                }
            }
            if(ok) {
                CX = cx;
                CY = cy;
                H = h;
                break;
            }
        }
    }
    cout << CX << " " << CY << " " << H << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    ll a,b;
    cin >> a >> b;
    if(abs(a-b)<=1){
        cout << "Brown" << endl;
    }else{
        cout << "Alice" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1

    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret

    return ret

print(dfs(0, 'TTT'))

Measured memory_bytes: 3872
n = int(input())

if n%2==1:
    print(0)
else:
    # 2の倍数には不足しないので、5の倍数を数える
    i=1
    cnt=0
    while n//(5**i*2) > 0:
        cnt += n//((5**i)*2)
        i += 1
    print(cnt)

Measured memory_bytes: 9172
import bisect
def resolve():
    N,M,K = map(int,input().split())
    A = [0]+list(map(int,input().split()))
    B = [0]+list(map(int,input().split()))

    for i in range(1,N+1):
        A[i]+= A[i-1]
    for i in range(1,M+1):
        B[i]+= B[i-1]

    mx = 0
    for co,v in enumerate(A):
        if v > K:
            break
        cb = bisect.bisect_right(B,K-v)
        
        mx = max(mx, cb+co-1)
    print(mx)
resolve()

Measured memory_bytes: 114000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int N ,ans;
    string S;
    cin >> N >> S;

    char curc;
    curc = '1';
    ans = 0;
    for(char c: S){
        if(c != curc){
            ans++;
            curc = c;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    int n, u, k, node;
    int adjMat[101][101] = {};
    cin >> n;
    for(int i=0;i<n;++i)
    {
        cin >> u >> k;
        --u;
        for(int j=0;j<k;++j)
        {
            cin >> node;
            adjMat[u][--node] = 1;
        }
    }
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<n;++j)
        {
            if(j) cout << " ";
            cout << adjMat[i][j];
        }
        cout << endl;
    }
}



Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct subject{
	int math;
	int info;
	int science;
	int eng;
};

int main(){
	
	subject A,B;
	cin >> A.info >> A.math >> A.science >> A.eng;
	cin >> B.info >> B.math >> B.science >> B.eng;
	cout << max(A.info+A.math+A.science+A.eng,B.info+B.math+B.science+B.eng) << endl;

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
bool a[100];
vector<int> b[100];
int memo[100000];
int n,m;
void dfs(int num,int dig){
    if(num >= n)return;
    for(int i = 2;i <= 7;i++){
        if(b[i].size() == 0)continue;
        if(memo[num + i] < dig + 1){
            memo[num + i] = dig + 1;
            dfs(num + i, dig + 1);
        }
    }
}
int main(){
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        int x;
        cin >> x;
        a[x] = true;
    }
    int w[] = {0,2,5,5,4,5,6,3,7,6};
    for(int i = 9;i >= 1;i--)if(a[i])b[w[i]].push_back(i);
    dfs(0,0);
    int dig = memo[n];
    for(int i = 0;i < dig;i++){
        int d = 0;
        for(int j = 9;j >= 1;j--){
            if(a[j] && memo[n-w[j]] == memo[n] - 1){
                if(i == dig-1 && n != w[j])continue;
                cout << j;
                n -= w[j];
                break;
            }
        }
    }
    cout << endl;

}

Measured memory_bytes: 512
S = input()

def judge_1(s):
    #print(s)
    for i in range(len(s)):
        if(s[i] != s[len(s)-i-1]):
            return False
    return True

def judge_2(s):
    n = len(s)
    sub = s[0:int((n-1)/2)]
    return judge_1(sub)

def judge_3(s):
    n = len(s)
    sub = s[int((n+3)/2)-1:n]
    return judge_1(sub)

def judge(s):
    return judge_1(s) and judge_2(s) and judge_3(s)

if(judge(S)):
    print("Yes")
else:
    print("No")

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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  string s;
  cin>>n>>s;

  if(n%2!=0){
    cout<<"No"<<"\n";
  }
  else{
    if(s.substr(0, n/2)==s.substr(n/2, string::npos))
      cout<<"Yes\n";
    else
      cout<<"No\n";
  }

  return 0;
}


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;



int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int N;
    cin >> N;
    vi s,t;
    int M = N - N%2;
    rep(i, M/2){
        int a = i+1;
        int b = M-i;
        for(int j = i+1; j <  M/2; j++){
            s.pb(a);t.pb(j+1);
            s.pb(a); t.pb(M-j);
            s.pb(b);t.pb(j+1); 
            s.pb(b); t.pb(M-j);

        }
    }
    if(N%2){
        rep(i,N-1){
            s.pb(i+1); t.pb(N);
        }
    }
    cout << s.size() << "\n"; 
    rep(i, s.size()){
        cout << s[i] << " " << t[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline

'''

'''

x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
else:
    print(5)

Measured memory_bytes: 61596
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  int n; cin >> n;
  int sum=0;
  for(int i=1; i<=n; i++){
    sum+=i;
  }
  cout << sum <<endl;
  return 0;
}



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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

bool g[10][10];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a][b] = g[b][a] = true;
  }

  vector<int> ord(n);
  rep(i,n) ord[i] = i;

  int res = 0;
  do {
    if (ord[0] != 0) break;

    bool ok = true;
    for (int i=0; i+1<n; ++i) {
      int from = ord[i];
      int to = ord[i+1];
      if (!g[from][to]) ok = false;
    }
    if (ok) ++res;
  } while (next_permutation(ord.begin(), ord.end()));

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        if (s.equals("abc")||s.equals("acb")){
            System.out.println("Yes");
        }
        else if (s.equals("bca")||s.equals("bac")){
            System.out.println("Yes");
        }
        else if (s.equals("cab")||s.equals("cba")){
            System.out.println("Yes");
        }else{
           System.out.println("No");
        }
    }
}


Measured memory_bytes: 23764
/**
*	created: 10.08.2020 17:04:33
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n,-1) {}
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x,y);
        par[x] += par[y]; par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);}
    int size(int x) {return -par[root(x)];}
};

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    reverse(all(a));
    reverse(all(b));
    UnionFind uf(n);
    int cnt = 0;
    vector<int> v;
    v.push_back(0);
    rep(i,m) {
        int x = a[i], y = b[i];
        if (uf.same(x,y)) v.push_back(cnt);
        else {
            cnt += uf.size(x) * uf.size(y);
            v.push_back(cnt);
            uf.unite(x,y);
        }
    }
    reverse(all(v));
    rep2(i,1,m+1) cout << n*(n-1)/2 - v[i] << endl;
    return 0;
}

Measured memory_bytes: 6612
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int sen[10][10000];
int w,h,ans,mai,x;
int main()
{
while(1){
	cin>>h>>w;
if(!h&&!w) return 0;
ans=0;
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>sen[i][j];
	for(int i=0; i < 1<<h ; i++){
		mai=0;
		for(int j=0;j<w;j++){
			x=0;
			for(int k=0;k<h;k++){
				if( (i>>k & 1) != (sen[k][j]) ) x++;
			}
			mai+=max(x,h-x);
		}
		ans=max(ans,mai);
	}
	cout<<ans<<endl;
}}

Measured memory_bytes: 1548
#include <stdio.h>

int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    for ( int i=0 ; i<=x ; i++) {
        if ( (2*i + 4*(x-i)) == y) {
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 1732
import java.io.*;

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

  String[] str = br.readLine().split(" ");

  int x=Integer.parseInt(str[0]);
  int y=Integer.parseInt(str[1]);

  System.out.println(x*y + " " + (2*x+2*y));
 }
}

Measured memory_bytes: 24184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=2050;
typedef bitset<2048> state;

int l[N],r[N],tot,par[N],dep[N];
int lca[N][N],goup[N][N];
int n,m,u,v;
state son[N],negs[N],g[N],gopar[N],all;
VI e[N];
int t;
PII q[N*N/2];
void dfs(int u,int f) {
	l[u]=++tot;
	par[u]=f;
	if (f!=-1)
		gopar[u]=gopar[f],
		dep[u]=dep[f];
	dep[u]++;
	gopar[u][u]=1;
	for (auto v:e[u]) {
		if (v==f) continue;
		dfs(v,u);
		son[u]|=son[v];
	}
	son[u][u]=1;
	negs[u]=all^son[u];
	r[u]=tot;
}

int findlca(int u,int v) {
	if (lca[u][v]!=-1) return lca[u][v];
	if (u==v) return lca[u][v]=lca[v][u]=u;
	else {
		if (dep[u]>dep[v]) swap(u,v);
		return lca[u][v]=lca[v][u]=findlca(u,par[v]);
	}
}
int findgoup(int u,int v) {
	if (goup[u][v]!=-1) return goup[u][v];
	if (par[v]==u) return goup[u][v]=v;
	return goup[u][v]=findgoup(u,par[v]);
}

int main() {
//	freopen("F.in","r",stdin);
	scanf("%d%d",&n,&m);
	rep(i,0,n) all[i]=1;
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		--u; --v;
		e[u].pb(v);
		e[v].pb(u);
	}
	dfs(0,-1);
	rep(i,0,n) g[i][i]=1;
	rep(i,0,m) {
		scanf("%d%d",&u,&v);
		--u; --v;
		g[u][v]=g[v][u]=1;
		q[t++]=mp(u,v);
	}
	memset(lca,-1,sizeof(lca));
	memset(goup,-1,sizeof(goup));
	rep(i,0,t) {
		int u=q[i].fi,v=q[i].se;
		if (dep[u]>dep[v]) swap(u,v);
		int w=findlca(u,v);
		state ch=gopar[u]^gopar[v];
		ch[w]=1;
		ch|=son[v];
		if (l[u]<=l[v]&&r[u]>=r[v]) {
			ch|=negs[findgoup(u,v)];
		} else ch|=son[u];
		auto add=[&](int a,int b) {
			g[a][b].flip();
			g[b][a].flip();
			q[t++]=mp(a,b);
		};
		auto finddiff=[&](const state &a,const state &b,int u) {
			state c=b&(all^a);
			auto data=(ull*)&c;
			rep(i,0,32) {
				while (data[i]) {
					int c=__builtin_ctzll(data[i]);
					add(i*64+c,u);
					data[i]^=1ull<<c;
				}
			}
		};
		finddiff(g[u],ch&g[v],u);
		finddiff(g[v],ch&g[u],v);
	}
	printf("%d\n",t);
}

Measured memory_bytes: 52352
#include <iostream>
#include <math.h>
using namespace std;

int main(){
	long n;
	cin >> n;
	long total=0;
	for(long i=1;i<=n;i++){
		if( fmod(i,3)==0 ) continue;
		if( fmod(i,5)==0 ) continue;
		total+=i;
	}
	cout << total << endl;
	return 0;
}



Measured memory_bytes: 3252
#include <boost/math/common_factor.hpp>
#include <boost/math/common_factor_rt.hpp>
#include <algorithm>
#include <iterator>
#include <iostream>
using namespace std;

void Main()
{
    int k;
    long s = 0;
    cin >> k;
    for (int a = 1; a <= k; a++)
    {
        for (int b = 1; b <= k; b++)
        {
            int ab = boost::math::gcd(a, b);
            for (int c = 1; c <= k; c++)
            {
                s += (long)boost::math::gcd(ab, c);
            }
            
        }
        
    }
    
    cout << s << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<string>
#include<bitset>
#include<queue>
#include<map>
using namespace std;



int main() {
	int X;
	cin >> X;
	if (X >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define deb(x) cout<<#x<<" "<<x<<endl;
#define ll long long int
#define ld long double
#define fo(i, n) for(ll i = 0; i<n; i++)
#define Fo(i, a, n) for(ll i = a; i<n; i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pi pair<int, int>
#define pl pair<ll, ll>
#define u_m unordered_map
#define u_s unordered_set
#define p_q priority_queue
using namespace std;
const int N = 1e5+2;
ll dp[N];
const ll MOD = 1e9+7;
void solve()
{
	int n, k;
	cin>>n>>k;
	vi h(n+1, 0);
	Fo(i,1,n+1) cin>>h[i];
	dp[1] = 0;
	dp[2] = abs(h[2]-h[1]);
	Fo(i, 3, n+1)
	{
		dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
		Fo(j, 2, k+1)
		{
			if(i-j<=0) continue;
			dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n]<<endl;
}
int main()
{
    ios::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    int t;
    //cin>>t;
    //while(t--)
		solve();	
    return 0;
}


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

using namespace std;

int main(){
        int N,sum,l,r;
        sum = 0;
        cin >> N;
        for(int i=0;i<N;i++){
        cin >> l >> r;
        sum += r-l+1;
        }
        cout << sum << endl;
        return 0;
        }

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a[4];
	int b[4];
	int i,j;
	int hit,blow;

	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF)
	{
		hit=0;blow=0;
		scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		for(i=0;i<4;i++)
		{
			for(j=0;j<4;j++)
			{
				if(a[i]==b[j])
				{
					if(i==j){hit++;}
					else{blow++;}
				}
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int long long int
#define pb push_back
#define M 1000000007
#define ff first
#define ss second
#define deb(x) cout< #x< " "< x< endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<=n;i++)
#define FORR(a,b,c) for(int a= b;a>=c;a--)
#define fa(arrr) for(auto x:arrr)
#define iPair pair<int, pair<int,int>>
#define sz size()
// #define mp make_pair
#define mxm3(a,b,c) max(a, max(b,c))
#define mi3(a,b,c) min(a, min(b,c))
#define mxn 500005
#define PII pair<int,int>
#define aint(v) v.begin(), v.end()
#define endl "\n"
// #define N 1000
#define C 4
#define nfs ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
// Ordered Set Tree
// typedef tree<PII, null_type, less<PII>,
//         rb_tree_tag,
//         tree_order_statistics_node_update>
//         oset;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

int fact[1005];

int power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = res * x % M;
		x = (x * x) % M;
		y = y / 2;
	}
	return res;
}


int modInv(int n) {
	return power(n, M - 2);
}
void facto() {
	fact[0] = 1;
	fact[1] = 1;
	for (int i = 2; i <= 1000; i++)
		fact[i] = (i * fact[i - 1]) % M;
}

int fermat(int n, int r) {
	return (fact[n] * modInv(fact[r]) % M * modInv(fact[n - r]) % M) % M;
}
int i = 1;
void solve() {
	int n;
	cin >> n;
	vector<int>arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	vector<int>dp(n);
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);
	for(int i = 2;i<n;i++){
		dp[i] = min(dp[i-2] + abs(arr[i]-arr[i-2]) , dp[i-1] + abs(arr[i]-arr[i-1]));
	}
	cout << (dp[n-1]) << endl;
}


int32_t main()
{


	nfs;
	int t;
	// facto();
	// cin >> t;
	t = 1;
	while (t--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
#define MAX 50;

int main() {
    int n; cin >> n;
    vector<int> cnt(26);
    for (int i = 0; i < 26; i++) cnt[i] = MAX;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (char j = 'a'; j <= 'z'; j++) {
            int t = 0;
            for (int k = 0; k < s.size(); k++) {
                if (s[k] == j) t++;
            }
            cnt[j - 'a'] = min(cnt[j - 'a'], t);
        }
    }
    for (char i = 'a'; i <= 'z'; i++) {
        for (int j = 0; j < cnt[i - 'a']; j++) {
            cout << i;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
ll a[200001],d[200001],tmp;
int i,j,k,n,m,b[200001],q[200001],t1,t2;
struct scmp{
	bool operator() (int x,int y){
		return a[x]>a[y]||a[x]==a[y]&&x<y;
	}
};
set<int,scmp> h;
set<int,scmp>::iterator it;
set<int> h1,h2;
set<int>::iterator p1,p2;
int main(){
	while (scanf("%d%d",&n,&m)!=EOF){
		h.clear();h1.clear();h2.clear();
		for (i=1;i<=n;i++) scanf("%d",&b[i]);
		for (i=1;i<n;i++) a[i]=b[i]+b[i+1],d[i]=b[i],h.insert(i),h1.insert(i),h2.insert(-i);
		for (i=k=1;i<n;i++){
			it=h.begin();j=*it;h.erase(j);h1.erase(j);h2.erase(-j);q[i]=j;
			p1=h1.lower_bound(j);p2=h2.lower_bound(-j);t1=-(*p2);t2=*p1;
			if (a[j]<m){
				k=0;break;
			}
			if (p1!=h1.end()){
				h.erase(t2);tmp=a[j]-d[t2];
				a[t2]+=tmp;d[t2]+=tmp;h.insert(t2);
			}
			if (p2!=h2.end()){
				h.erase(t1);
				a[t1]+=a[j]-d[j];h.insert(t1);
			}
		}
		if (!k) puts("Impossible");else{
			puts("Possible");
			for (i=n-1;i;i--) printf("%d\n",q[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 17280
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); i++)
#define rep1(i,n) for(int (i) = 1; (i) <= (int)(n); i++)
#define INF 1000000
#define MOD 998244353



int main()
{
    int N,M;
    cin >> N >> M;
    
    int sum=0,A;
    rep(i, M) {
        cin >> A;
        sum += A;
    }
    
    if (sum <= N) {
        cout << N-sum << endl;
    } else{ cout << -1 << endl;}
    
    
    
    return 0;
}




Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int length = s.length();
        
        System.out.println("" + s.charAt(0) + (length - 2) + s.charAt(length - 1)) ;
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using ull = unsigned long long;
using ul = unsigned;
using ll = long long;
#define mod 10e+7+7
#define rep(i,a,b) for (int i =a;i<b;++i)
using namespace std;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin); 
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
#endif
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();
	 cout<<"\n";
	}
	
	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;

}

std::vector<int>  g[100001];
int dp[100005];
bool visited[100005];
void visit(int v)
{
	visited[v]=true;
	dp[v]=0;
	for(int c:g[v])
	{
		if(!visited[c]){
			visit(c);
		}
		dp[v]=max(dp[v],1+dp[c]);
	}
}
void solve()
{
	int n,m;
	cin>>n>>m;
	rep(i,0,m)
	{
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
	}
	rep(i,1,n+1)
	{
		if(!visited[i]){
			visit(i);
		}
	}
	int an=0;
	for(int i=1;i<=n;i++)
	{
		an=max(an,dp[i]);
	}
	cout<<an;
}

Measured memory_bytes: 12520
#include<stdio.h>

int main(void)
{
   int a, b;
   double c;
   
   scanf("%d", &a);   scanf("%d", &b);
   
   printf("%d %d ", a/b,a%b);
	
	c = (double)a/(double)b;
   
   printf("%f\n", c);
   
   return 0;
}


Measured memory_bytes: 2092
while True:
	n, x = map(int, input().split())

	if n == 0 and x == 0:
		break
	
	ans = 0
	for i in range(1, n+1):
		for j in range(i+1, n+1):
			for k in range(j+1, n+1):
				if i + j + k == x:
					ans += 1
	print(ans)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
    SPEED;  
    string s;
    cin>>s;
    int dp[200001],i,freq[2019]={0},count=0;
    dp[0]=1;freq[0]=1;
    for(i=1;i<200001;++i)
    {
       dp[i]=(10*dp[i-1])%2019;
    }
    int k=0,rem=0,c=0;
    for(i=s.length()-1;i>=0;--i)
    {
        if((dp[k]*(s[i]-'0') +rem)% 2019==0)
        {
           c++;
           rem=0;
        }
        else
           rem=(dp[k]*(s[i]-'0')+rem)% 2019;
        freq[rem]++;
       k++;
    }
    for(i=0;i<2019;++i)
    {
        count+=(freq[i]*(freq[i]-1))/2;
    }
    cout<<count;
}

Measured memory_bytes: 5352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
#define fi first
#define sec second
#define INF 1000000000
#define DINF 1000000000.0
#define eps 1e-18
int N,M;
int A[100100],B[100100];
ll x[100100];
struct edge{
	int to;
	vector<ll> costs;
	edge(){}
	edge(int to,vector<ll> costs):to(to),costs(costs){}
};
vector<edge> g[100100];
bool used[100100];
vector<ll> pr = {1000000007ll,1000000009ll,998244353ll};
vector<ll> dp[100100];
vector<ll> add(vector<ll>& a,vector<ll>& b){
	vector<ll> res;
	for(int i=0;i<a.size();i++){
		res.pb((a[i]*b[i])%pr[i]);
	}
	return res;
}
ll mypow(ll a,ll x,ll mod){
	ll res = 1ll;
	while(x){
		if(x&1ll)res = (res*a)%mod;
		a = (a*a)%mod;
		x >>= 1;
	}
	return res;
}
int main(){
	cin >> N >> M;
	cout << fixed << setprecision(20);
	for(int i=0;i<M;i++){
		cin >> A[i] >> B[i] >> x[i];
		A[i]--;B[i]--;
		vector<ll> c,d;
		for(int j=0;j<pr.size();j++){
			c.pb(x[i]%pr[j]);
			d.pb(mypow(x[i],pr[j]-2,pr[j]));
		}
		g[A[i]].pb(edge(B[i],c));
		g[B[i]].pb(edge(A[i],d));
		// cout << log(x[i]) << endl;
	}
	// toposort();
	/*for(int i=0;i<M;i++){
		if(rev[A[i]]>rev[B[i]]){
			cout << "No" << endl;
			return 0;
		}
	}*/	
	for(int i=0;i<N;i++){	
		if(dp[i].size()>0)continue;
		for(int j=0;j<pr.size();j++)dp[i].pb(1ll);
		queue<int> q;
		q.push(i);
		while(!q.empty()){
			int a = q.front();
			q.pop();
			for(int i=0;i<g[a].size();i++){
				edge& e = g[a][i];
				vector<ll> c = add(dp[a],e.costs);
				if(dp[e.to].size()==0){
					dp[e.to] = c;
					q.push(e.to);
				}else{
					if(dp[e.to]!=c){
						cout << "No" << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 27820
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {
	int n;
	cin >> n;
	
	ll ans = 1LL;

	rep(i, n) {
		ll t;
		cin >> t;

		ans = lcm(ans, t);
	}

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int a[3050],b[3050],dp[3050][3050];
int main()
{
	int N,T,S,ans=0;
	cin >> N >> T >> S;
	for(int i=1;i<=N;i++)
	{
		cin >> a[i] >> b[i];
	}
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<=T;j++)
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			if(!(j-b[i]<S&&j>S)&&j-b[i]>=0)
			{
				dp[i][j]=max(dp[i][j],dp[i-1][j-b[i]]+a[i]);
			}
			ans=max(ans,dp[i][j]);
		}
	}
	/*for(int i=0;i<=N;i++)
	{
		for(int j=0;j<=T;j++)
		{
			cout << dp[i][j] << ' ';
		}
		cout << endl;
	}*/
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 36936
N = int(input())
A = list(map(int, input().split()))
asum=0
bsum=0
cnt=0
while True:
    asum+=max(A)
    A.remove(max(A))
    cnt+=1
    if cnt==N:
        break
    bsum+=max(A)
    A.remove(max(A))
    cnt+=1
    if cnt==N:
        break

print(asum-bsum)

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

signed main()
{
	ios::sync_with_stdio(false);
	int s;
	cin>>s;
	if(s==(int)1e18) cout<<0<<" "<<0<<" "<<0<<" "<<(int)1e9<<" "<<(int)1e9<<" "<<0<<endl;
	else cout<<0<<" "<<0<<" "<<1<<" "<<(int)1e9<<" "<<s/(int)1e9+1ll<<" "<<(int)(1e9-(int)(s%(int)1e9))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

struct UF{
    vector<ll> d;
    UF(ll size):d(size,-1){}
    void init(){
        fill(d.begin(),d.end(),-1);
    }
    bool u(ll x,ll y){
        x = r(x); y = r(y);
        if(x != y){
            if(d[y] < d[x]) swap(x,y);
            d[x] += d[y]; d[y] = x;
        }
        return x!=y;
    }
    bool f(ll x,ll y){
        return r(x) == r(y);
    }
    ll r(ll x){
        return d[x] < 0 ? x:d[x] = r(d[x]);
    }
    ll s(ll x){
        return -d[r(x)];
    }
};

ll n,m;
struct edge{
    ll u,v,cost;
    edge(){}
    edge(ll u,ll v,ll cost):u(u),v(v),cost(cost){}
    bool operator < (const edge& e) const{
        return cost < e.cost;
    }    bool operator > (const edge& e) const{
        return cost > e.cost;
    }
};
ll solve(){
    ll res = LINF;
    vector<ll> s(m),t(m),c(m);
    vector<edge> edges(m);
    for(int i = 0; i < m;i++){
        ll s,t,c; cin >> s >> t >> c; s--; t--;
        edges[i] = edge(s,t,c);
    }
    sort(edges.begin(),edges.end());
    UF uf(n);
    vector<int> f(m);
    vector<ll> C;
    for(int i = 0; i < m;i++){
        if(uf.f(edges[i].u,edges[i].v)) continue;
        f[i] = true;
        uf.u(edges[i].u,edges[i].v);
        C.push_back(edges[i].cost);
    }
    sort(C.begin(),C.end());
    res = C[(n-1)/2];
//    for(int i = 0; i < m;i++){
//        if(edges[i].cost > res) break;
//        if(f[i]) continue;
//        C.clear();
//        uf.init();
//        C.push_back(edges[i].cost);
//        uf.u(edges[i].u,edges[i].v);
//        for(int j = 0; j < m;j++){
//            if(i == j) continue;
//            if(uf.f(edges[j].u,edges[j].v)) continue;
//            uf.u(edges[j].u,edges[j].v);
//            C.push_back(edges[j].cost);
//        }
//        if(uf.s(0) != n) continue;
//        sort(C.begin(),C.end());
//        res = min(res,C[(n-1)/2]);
//    }
    return res;
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n >> m,n|m){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

int main() {
    int N, Q;  cin >> N >> Q;
    string S;  cin >> S;
    vector<int> l(Q);
    vector<int> r(Q);
    rep(i, Q) cin >> l[i] >> r[i];

    vector<int> T;
    rep(i, N) {
        if (i < N-1 && S[i] == 'A' && S[i+1] == 'C') {
            T.push_back('a');
        } else {
            T.push_back(S[i]);
        }
    }
    int cnt = 0;
    vector<int> t;
    rep(i, T.size()) {
        if (T[i] == 'a') cnt++;
        t.push_back(cnt);
    }

    rep(i, Q) {
        if (l[i] == 1)  print(t[r[i]-2]);
        else print(t[r[i]-2] - t[l[i]-2]);
    }
}

Measured memory_bytes: 2744
#include <cstdio>
#include <algorithm>
using namespace std;
const int NIL = -1;
struct node {
	int parent;
	int left;
	int right;
};

node nodes[100000];

int degree(int v) {
	int count = 0;
	if (nodes[v].left != NIL) count++;
	if (nodes[v].right != NIL) count++;
	return count;
}

int depth(int v) {
	int count = 0;
	while (nodes[v].parent != NIL) {
		v = nodes[v].parent;
		count++;
	}
	return count;
}

int height(int v) {
	if (v == NIL) return - 1;
	int h1 = height(nodes[v].left) + 1;
	int h2 = height(nodes[v].right) + 1;
	return max(h1, h2);
}

void type(int i) {
	if (nodes[i].parent == NIL) {
		printf("root");
	} else if (nodes[i].left == NIL && nodes[i].right == NIL) {
		printf("leaf");
	} else {
		printf("internal node");
	}
	printf("\n");
}

int main()
{
	int n;
	for (int i = 0; i < 100000; ++i) {
		node &p = nodes[i];
		p.parent = NIL;
		p.left = NIL;
		p.right = NIL;
	}
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int v, l, r;
		scanf("%d %d %d", &v, &l, &r);
		node &p = nodes[v];
		p.left = l;
		p.right = r;
		if (l != NIL) nodes[l].parent = v;
		if (r != NIL) nodes[r].parent = v;
	}

	for (int v = 0; v < n; ++v) {
		node &r = nodes[v];
		int s = NIL;
		if (r.parent != NIL) {
			s = nodes[r.parent].left == v ? nodes[r.parent].right : nodes[r.parent].left;
		}

		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
				v, r.parent, s, degree(v), depth(v), height(v));
		type(v);
	}

	return 0;
}

Measured memory_bytes: 2204
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

fn main () {
    let (N, W) = get!(usize, usize);
    let wvs = get!(usize, u64; N);
    let mut dp = vec![vec![0; W+1]; N+1];
    for (i, &(w, v)) in wvs.iter().enumerate() {
        for k in 0..(W+1) {
            if k >= w {
                dp[i+1][k] = std::cmp::max(dp[i][k], dp[i][k-w]+v);
            } else {
                dp[i+1][k] = dp[i][k];
            }
        }
    }
    println!("{}", dp[N].iter().max().unwrap());
}


Measured memory_bytes: 106748
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        if(a.equals("abc") || a.equals("acb")||a.equals("bac") || a.equals("bca") ||a.equals("cab") ||a.equals("cba")) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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(ll 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;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
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];
  }
};


int main(){
    int n,k;
    cin >> n >> k;
    combination c(n);
    mint ans = 0;
    k=min(n-1,k);
    for(int i=0;i<=k;i++){
        ans+=c(n,i)*c(n-1,i);
    }
    cout << ans.x << endl;
    return 0;
}

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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (long long)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005



int32_t main(){
sp;
    int a,b;
    cin>>a>>b;
    int ans=0;
    int init=1;
    while(init<b){
        --init;
        init+=a;
        ++ans;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int max_profit = numeric_limits<int>::min();
    int min_value = numeric_limits<int>::max();

    for (int x; n--;) {
        cin >> x;
        int profit = x - min_value;
        if (profit > max_profit)
            max_profit = profit;

        if (x < min_value)
            min_value = x;
    }

    cout << max_profit << endl;

    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
int per(int i,int d){
if(i%d==0)  
  return i/d; 
else    
{ 
  return i/d+1;
}
  
}

int main(){
int n,d,x;
cin>>n>>d>>x;
int a[n],count=0;
rep(i,n){
cin>>a[i];
count+=per(d,a[i]);

}

cout<<count+x<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pi = pair <int, int>;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 2e5 + 10;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    if (n % 2)
	{
		cout << 0;
		return 0;
	}
	ll ans = 0;
	for (ll i = 5; i <= n; i *= 5)
		ans += n / i / 2;
	cout << ans;
}


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

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string w;
  cin >> w;
  int n = (int) w.length();
  vector<int> a (n);
  vector<int> componente;
  for (int i = 0; i < n;) {
    int p = i, cur = 0;
    while (p < n && w[i] == w[p]) {
      p++;
      cur++;
    }
    componente.emplace_back(cur);
    i = p;
    cur = 1;
  }
  int atual = 0;
  for (int i = 0; i < n - 1; i++) {
    if (w[i] == 'R' && w[i + 1] == 'L') {
      int divisao = (componente[atual] + componente[atual + 1]) / 2;
      int resto = (componente[atual] + componente[atual + 1]) - divisao;
      if (((componente[atual] + componente[atual + 1]) - componente[atual + 1]) % 2 == 0) {
        a[i] = divisao;
        a[i + 1] = resto;
      } else {
        a[i] = resto;
        a[i + 1] = divisao;
      }
      atual += 2;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << ' ';
  }
  return 0;
}

Measured memory_bytes: 1480
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//typedef long long ll;
int min(int a,int b)
{
  if(a>=b) return b;
  else return a;
}
int main(void)
{
  int n,x,y;
  scanf("%d%d%d",&n,&x,&y);
  int a[n],z;
  z=x+(y-x)/2;
  for(int i=1;i<n;i++)  a[i]=0;
  for(int i=1;i<=n-1;i++){
    for(int j=i+1;j<=n;j++){
      if(i<x){
        if(j<=z) a[j-i]++;
        else if(j<=y) a[x-i+1+y-j]++;
        else if(j<=n) a[x-i+1+j-y]++;
      }else if(i<=y){
        if(j<=y) a[min(j-i,(y-x+1)-(j-i))]++;
        else if(j<=n) a[min(y-i,y-x+1-(y-i))+j-y]++;
      }else if(i<=n){
        a[j-i]++;
      }
    }
  }
  for(int i=1;i<n;i++)  printf("%d\n",a[i]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
//桁
int kt(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(b),d(b);
  rep(i,b)
  cin>>c[i]>>d[i];
  int e=0,f=1000000;
rep(i,b){
if(c[i]>e)
  e=c[i];
if(d[i]<f)
  f=d[i];
}
if(e>f)
cout<<0;
else
cout<<f-e+1;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
string s;
int d[100005][4];
int add(int &a,int b){
	return a = (a + b)%mod;
}
signed main(){
	cin >> s;
	d[0][0] = 1;
	for(int i = 0; i < s.size() ; i ++){
		for(int j = 0 ; j < 4 ; j ++)
			if(s[i] != '?') add(d[i + 1][j], d[i][j]);
			else add(d[i + 1][j], d[i][j] * 3);
		if(s[i] == 'A' || s[i] == '?')
			add(d[i + 1][1], d[i][0]);
		if(s[i] == 'B' || s[i] == '?')
			add(d[i + 1][2], d[i][1]);
		if(s[i] == 'C' || s[i] == '?')
			add(d[i + 1][3], d[i][2]);
	}
	
	cout << d[s.size()][3];
}


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

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for(int & x : H)
        cin >> x;
    vector<long long> dp(N, INT_MAX);
    dp[0] = 0;
    for(int i=0; i<N; i++) {
        if(i+1 < N)
            dp[i+1] = min(dp[i+1], dp[i] + abs(H[i]-H[i+1]));
        if(i+2 < N)
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i]-H[i+2]));
    }
    cout << dp[N-1] << "\n";
}

Measured memory_bytes: 1408