akhauriyash/Code-Regression huggingface dataset:
// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=210,mod=1e9+7;
const ll inf=1e18;

vector<int> v[maxn];
int h[maxn];

int bfs(int u){
    queue<int> q;
    memset(h,-1,sizeof h);
    q.push(u);
    int ans=0;
    h[u]=0;
    
    while(sz(q)){
	int u=q.front();
	q.pop();
	for(int y:v[u]){
	    if(h[y]==-1) h[y]= h[u]+1, ans=max(ans, h[y]), q.push(y);
	    else if(h[y]==h[u]) return -2;
	}
    }
    return ans;
}

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

    int n; cin>>n;
    for(int i=0;i<n;i++){
	string s; cin>>s;
	for(int j=0;j<n;j++){
	    if(s[j]=='1') v[i].PB(j);
	}
    }
    int ans=-2;
    for(int i=0;i<n;i++){
	ans=max(ans, bfs(i));
    }
    return cout<<ans+1<<endl,0;
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>

using namespace std;
vector<int> v[200009];

int main(){
  int n, m, check[200009];
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a, b;
    cin >> a >> b;
    a--;b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  bool ans=false;
  queue<int> q;
  for(int i=0;i<v[0].size();i++){
    if(v[0][i]==n-1)ans=true;
    q.push(v[0][i]);
  }
  while(!q.empty()){
    int fr=q.front();q.pop();
    for(int j=0;j<v[fr].size();j++){
      if(v[fr][j]==n-1)ans=true;
    }
  }
  cout << (ans?"POSSIBLE": "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 12400
s = input()
k = int(input())

a = [1]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        a[-1]+=1
    else:
        a.append(1)

ans = 0
if len(a)==1:
    ans = len(s)*k//2
elif s[0]!=s[-1]:
    for i in range(len(a)):
        ans+=(a[i]//2)*k
else:
    for i in range(1,len(a)-1):
        ans+=(a[i]//2)*k
    ans+=a[0]//2
    ans+=a[-1]//2
    ans+=((a[0]+a[-1])//2)*(k-1)
print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

//求最小次数,可以不用标记每个点走没走过 
int nextt[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int maze[25][25];
int minstep;
int n, m;
int startx, starty;

void dfs(int i, int j, int step){
	if (step>=10 || step>=minstep)	//step是已经走得步数，所以要包含10 
		return;

	for (int k=0; k<4; k++){
		int ti=i+nextt[k][0];
		int tj=j+nextt[k][1];
		if (maze[ti][tj]==1)	//不可以朝贴着墙的方向走 
			continue;
		while (maze[ti][tj]!=1 && maze[ti][tj]!=3 && ti>=1 && ti<=m && tj>=1 && tj<=n){
			ti=ti+nextt[k][0];
			tj=tj+nextt[k][1];
		} 
		if (maze[ti][tj] == 3){
			minstep = min(minstep, step+1);	//到这一点的时候step是+1的 
			return;
		}
		if (ti<1 || ti>m || tj<1 || tj>n)
			continue;	
		maze[ti][tj]=0;
		dfs(ti-nextt[k][0], tj-nextt[k][1], step+1);	//这里注意回去一个 
		maze[ti][tj]=1;
	}
}
int main(){
	while (scanf("%d%d", &n, &m)!=EOF){
		if (n==0 && m==0)
			break;
		memset(maze, 0, sizeof(maze));
		minstep = 15;
		for (int i=1; i<=m; i++){
			for (int j=1; j<=n; j++){
				scanf("%d", &maze[i][j]);
				if (maze[i][j]==2){
					startx = i;
					starty = j;
				}
			}
		}
		dfs(startx, starty, 0);	//当前这个点没动，步数为0 
		
		if (minstep==15)
			printf("-1\n");
		else
			printf("%d\n", minstep);	
	}
	return 0;
}


Measured memory_bytes: 3200
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    int n,w;
    cin>>n>>w;
    vector<vector<ll>> dp(n+1,vector<ll> (w+1));
    vector<int> weight(n);
    vector<int> val(n);
    for(int i=0;i<n;i++){
        cin>>weight[i]>>val[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(j<weight[i-1]){
                dp[i][j]=dp[i-1][j];
            }
            else{
                dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-weight[i-1]]);
            }
        }
    }
    //debug(dp);
    cout<<dp[n][w]<<"\n";
    return 0;
}

Measured memory_bytes: 83100
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const X = arg[0];
    
    if(X < 100) {
        console.log(0);
        return;
    }
    
    // 10の位をまず割り切る
    // そしたらあとは100で割れる
    // 10の位を割り切ってる間に100以下になると不可能になる？
    let digit10 = parseInt(X.split("").slice(-2).join(""));
    let temp = digit10;
    let cnt = 0;
    
    if(digit10 === 0) {
        console.log(1);
        return;
    }
    
    if(digit10 === 1) {
        cnt = digit10;
    }

    while(digit10 !== 0) {
        if(digit10 >= 5) {
            digit10 = digit10 - 5;
        } else if(digit10 >= 4) {
            digit10 = digit10 - 4;
        } else if(digit10 >= 3) {
            digit10 = digit10 - 3;
        } else if(digit10 >= 2){
            digit10 = digit10 - 2;
        } else if(digit10 >= 1) {
            digit10 = digit10 - 1;
        }
        cnt++;
    }
    
    // console.log(cnt)
    // console.log((100 * cnt) + temp);
    
    if((100 * cnt) + temp <= X) {
        console.log(1)
    } else {
        console.log(0)
    }

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

Measured memory_bytes: 11468
import math
[N,K] = list(map(int, input().split()))
#S = str(input())        
#S = "1700"
ans = 0
#[N,K] = [100000, 5]
for i in range(1,N+1):
    if i >= K:
        ans += 1/N
    else:
        max_coin = math.ceil(math.log(K/i,2))
        ans += (0.5)**max_coin/N
print(ans)

Measured memory_bytes: 3060
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    s <- getLine
    t <- getLine
    putStrLn . (\b -> if b then "Yes" else "No") $ any (\i -> let
        s' = drop i s ++ take i s
        in s' == t
        ) [0..length s]


Measured memory_bytes: 508
a0=input()
a=input().split()
b=[int(x) for x in a]

for i in range(len(b)-1):
	if b[i]<=b[i+1]:
		pass
		if b[i-1]<=(b[i]-1) and (b[i]-1)<=b[i+1]:
			b[i]-=1
	elif b[i-1]<=(b[i]-1) and (b[i]-1)<=b[i+1]:
		b[i]-=1
	else:
		print("No")
		break
else:
	print("Yes")

Measured memory_bytes: 14396
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()

for a in range(-200, 200):
	for b in range(-200, a):
		if a**5 - b**5 == X:
			print(a, b)
			exit()


Measured memory_bytes: 64996
n,k=list(map(int, input().split()))
V=list(map(int, input().split()))
ans=0
r=min(n,k)
for a in range(r+1):
    for b in range(r+1-a):
        if b==0:
            v=V[:a]
        else:
            v=V[:a]+V[-b:]
        v.sort()
        for i in range(k+1-a-b):
            if i>=len(v):
                break
            if v[i]>0:
                break
        ans=max(ans,sum(v[i:]))
print(ans)

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

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int AB = abs(a - b);
	int BC = abs(b - c);
	int CA = abs(c - a);

	if (CA<=d || (AB<=d && BC <= d))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

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

char s[55];
const char* t = "AKIHABARA";

#define NO puts("NO"), exit(0);

int main() {
	scanf("%s", s);
	const char *p = s, *q = t;
	while (*p && *q) {
		if (*p ^ *q) {
			if (*q == 'A') {
				q++;
			} else NO;
		} else {
			p++, q++;
		}
	}
	if (*p || (*q && *(q + 1)))
		NO;
	puts("YES");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
 int h1,h2,m1,m2,k;
  int s,g;
  scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
  s= (60*h1)+m1;
  g= (60*h2)+m2;
  printf("%d", g-s-k);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	long sum = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3564
#!/usr/bin/env python3
import sys

def main():
    x = int(input())
    ans = 2 * (x // 11)
    if x % 11 > 6:
        print(ans + 2)
    elif x % 11 > 0:
        print(ans + 1)
    else:
        print(ans) 

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>

int main( void )
{
	int a, b, c;
	
	scanf( "%d %d %d", &a, &b, &c );
	
	if( a < b && b < c ){
		printf( "Yes\n" );
	}else {
		printf( "No\n" );
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <numeric>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;

//template<typename Int = int>
using Int = int;
struct PrimalDual {
    struct Edge {
        int dst;
        Int cap, flow, cost;
        int rev;
        Edge(int dst, Int cap, Int flow, Int cost, int rev)
            :dst(dst), cap(cap), flow(flow), cost(cost), rev(rev) {
        }
    };

    int n;
    vector<vector<Edge>> g;
    PrimalDual(int n_) : n(n_), g(vector<vector<Edge>>(n_)) {}
    void addEdge(int src, int dst, Int cap, Int cost) {
        g[src].emplace_back(dst, cap, 0, cost, g[dst].size());
        g[dst].emplace_back(src, cap, cap, -cost, g[src].size() - 1);
    }

    vector<Int> h, dist;
    vector<int> prevv, preve;
    Int solve(int s, int t, Int f) {
        Int res = 0;
        h.assign(n, 0); dist.assign(n, 0);
        prevv.assign(n, 0); preve.assign(n, 0);
        while (f > 0) {
            if (!dijkstra(s, t)) return -1;
            Int flow, cost;
            tie(flow, cost) = push(s, t, f);
            f -= flow; res += cost;
        }
        return res;
    }

    bool dijkstra(int s, int t) {
        constexpr Int INF = numeric_limits<Int>::max();
        fill(dist.begin(), dist.end(), INF);
        dist[s] = 0;
        priority_queue<pair<Int, int>> q;
        q.emplace(0, s);
        while (q.size()) {
            int d, v;
            tie(d, v) = q.top(); q.pop();
            d = -d;
            if (dist[v] < d) continue;
            for (int i = 0; i < (int)g[v].size(); ++i) {
                Edge &e = g[v][i];
                if (residue(e) > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
                    dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
                    prevv[e.dst] = v;
                    preve[e.dst] = i;
                    q.emplace(-dist[e.dst], e.dst);
                }
            }
        }
        return dist[t] != INF;
    }

    pair<Int,Int> push(int s, int t, Int lim) {
        for (int i = 0; i < n; ++i) h[i] += dist[i];
        Int flow = lim;
        for (int v = t; v != s; v = prevv[v]) {
            Edge &e = g[prevv[v]][preve[v]];
            flow = min(flow, residue(e));
        }
        Int cost = flow * h[t];
        for (int v = t; v != s; v = prevv[v]) {
            Edge &e = g[prevv[v]][preve[v]];
            e.flow += flow;
            g[v][e.rev].flow -= flow;
        }
        return make_pair(flow, cost);
    }

    Int residue(const Edge& e) { return e.cap - e.flow; }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, f;
    cin >> n >> m >> f;
    PrimalDual pd(n);
    for (int i = 0; i < m; i++) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        pd.addEdge(u, v, c, d);
    }
    cout << pd.solve(0, n - 1, f) << endl;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main(void){int n,m=1e9+7,i;long long ans=1;cin>>n;vector<int> a(n),c(n+1,0);for(i=0;i<n;i++)cin>>a[i],++a[i];c[0]=3;for(int x:a)(ans*=c[x-1]-c[x])%=m,++c[x];cout<<ans<<endl;return 0;}


Measured memory_bytes: 4040
import sys

sys.setrecursionlimit(100000)

N = int(raw_input())
H = map(int, raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  if i == 0:
    soc=0
  elif i == 1:
    soc= sumOfCost(0)+abs(H[i]-H[0])
  else:
    c1 = sumOfCost(i-1)+abs(H[i]-H[i-1])
    c2 = sumOfCost(i-2)+abs(H[i]-H[i-2])
    soc=min(c1,c2)
  cost[i] = soc
  return soc

print sumOfCost(N-1)




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

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2")

using namespace std;

//#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;

int p[maxn][2];

int get_sum(int i, int l) {
    if (i < 0) return 0;
    return p[i][l];
}

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

    int n, k;
    cin >> n >> k;
    int l = 0, r = 1;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i == 0) {
            for (int j = 0; j <= k; j++) {
                p[j][r] = get_sum(j - 1, r) + (j <= x);
            }
            swap(l, r);
            continue;
        }
        for (int j = 0; j <= k; j++) {
            p[j][r] = get_sum(j - 1, r)  + (get_sum(j, l) - get_sum(j - x - 1, l) + mod) % mod;
            p[j][r] %= mod;
        }
        swap(l, r);
    }
    cout << (get_sum(k, l) - get_sum(k - 1, l) + mod) % mod << "\n";



    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<" "<<endl;
int main(){
  ll N,A,B;cin>>N>>A>>B;
  cout<<(N/(A+B))*A+min(N%(A+B),A)<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

char  O[60], E[60];

int main(void)
{
    int i;
    scanf("%s\n%s", O, E);
    for(i = 0; E[i]!='\0'; i++) {
        printf("%c%c",O[i], E[i]);
    }
    printf("%s\n", O+i);
    return 0;
}


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

string name[1000];
int era[1000];
int west[1000];
int main(){
	int n,q;
	while(cin>>n>>q,n|q){
		for(int i=0;i<n;i++)
			cin>>name[i]>>era[i]>>west[i];
		for(int i=0;i<q;i++){
			int a;
			cin>>a;
			bool f=false;
			for(int j=0;j<n;j++){
				if(west[j]-era[j]+1<=a&&a<=west[j]){
					cout<<name[j]<<' '<<a-(west[j]-era[j])<<endl;
					f=true;
					break;
				}
			}
			if(!f)cout<<"Unknown"<<endl;
		}
	}
	return 0;
}

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

int main(){
  int N; cin>>N;
  int V[N],C[N];
  REP(i,N){
    cin>>V[i];
  }
  REP(i,N){
    cin>>C[i];
  }
  int ans=0;
  REP(i,N){
    if(V[i]-C[i]>0) ans+=V[i]-C[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
    int N[10];
    N[0] = 0;
    N[1] = 1;
    N[2] = 2;
    
    scanf("%d %d %d",&N[0],&N[1],&N[2]);
    sort(N, N+3);
    printf("%d %d %d\n",N[0], N[1], N[2]);
   // printf("\n");


    return 0;
}

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

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define endl "\n"
#define all(V) V.begin( ), V.end( )
#define Unique(V) sort( all( V ) ), V.erase( unique( all( V ) ), V.end() )
#define Check( N , p ) ( !( ( N & ( 1LL << p ) ) == 0 ) )
#define ON( N , p ) ( N = N | ( 1LL << p ) )
#define OFF( N , p ) ( N = N & ~( 1LL << p ) )
std::mt19937 rng( chrono::steady_clock::now().time_since_epoch().count() );
#define rnd(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
#define ran(a, b) rng() % ( (b) - (a) + 1 ) + (a)
#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template < typename Arg1 >
void __f( const char* name , Arg1&& arg1 ) { cerr << name << " : " << arg1 << "\n"; }
template < typename Arg1 , typename... Args >
void __f( const char* names , Arg1&& arg1 , Args&&... args ) {
const char* comma = strchr( names + 1 , ',' );
cerr.write( names , comma - names ) << " : " << arg1 << " , " ; __f( comma + 1 , args... ); }
typedef long long int LL;
typedef pair <int,int> pii;
typedef pair <long long,long long> pll;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;

int n;
int a[ N ];
int dp[ N ];

int main( int argc , char const *argv[] ) {
        ios_base::sync_with_stdio( false ); cin.tie( nullptr );
        cin >> n;
        for( int i = 1; i <= n; i++ ) cin >> a[i];
        for( int i = 1; i <= n; i++ ) dp[i] = inf;
        dp[1] = 0;
        ///dp[i] = min total cost to reach to i'th stone from 1st stone.
        for( int i = 1; i <= n; i++ ) {
                if( i - 1 >= 1 ) dp[i] = min( dp[i] , dp[i-1] + abs( a[i] - a[i-1] ) );
                if( i - 2 >= 1 ) dp[i] = min( dp[i] , dp[i-2] + abs( a[i] - a[i-2] ) );
        }
        cout << dp[n] << endl;
        return 0;
}














Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define  nax 109
#define naxW 100009
typedef long long lld;

lld solve(lld dp[nax][naxW],lld w[nax],lld v[nax],lld W,lld N,lld peso,lld pos){
		if (dp[pos][peso]!= -1){
			return dp[pos][peso];
		}
		if(pos ==N){
			return 0;
		}
		lld siSacas = 0;
		if(peso>=w[pos]){
			siSacas=solve(dp,w,v,W,N,peso-w[pos],pos+1)+v[pos];
		}
		lld NoSacas = 0;
			NoSacas = solve(dp,w,v,W,N,peso,pos+1);
//		Max(dp - peso (pos) + valor , dp(pos))
		return dp[pos][peso] = siSacas > NoSacas ? siSacas:NoSacas;
}

int main(){
	lld N;
	lld W;
	lld w[nax];
	lld v[nax];
	lld dp[nax][naxW];
	scanf("%lld",&N);
	scanf("%lld",&W);
	for(int i=0;i<N;i++){
		scanf("%lld",&w[i]);
		scanf("%lld",&v[i]);
	}
	for(int i=0;i<nax;i++){
		for(int j=0;j<naxW;j++){
			dp[i][j] = -1;
		}
	}
	lld maxsum = solve(dp,w,v,W,N,W,0);
	printf("%lld",maxsum);
}

Measured memory_bytes: 85376
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

	int n;
	while(cin >> n){
		if(n == 3){
			cout << "2 5 63\n";
			continue;
		}else if(n == 4){
			cout << "2 5 20 63\n";
			continue;
		}

		vector<int> ans;
		int sum = 0;
		int now = 1;
		while((int)ans.size() < n){
			if(now % 2 == 0 || now % 3 == 0){
				ans.emplace_back(now);
				sum += now;
			}
			++now;
		}

		if(sum % 6 == 1){
			rrep(i, ans.size()){
				if(ans[i] % 6 == 4){
					ans.erase(ans.begin() + i);
					while(now % 6 != 3){
						++now;
					}
					ans.emplace_back(now);
					break;
				}
			}
		}else if(sum % 6 == 2){
			rrep(i, ans.size()){
				if(ans[i] % 6 == 2){
					ans.erase(ans.begin() + i);
					while(now % 6 != 0){
						++now;
					}
					ans.emplace_back(now);
					break;
				}
			}
		}else if(sum % 6 == 3){
			rrep(i, ans.size()){
				if(ans[i] % 6 == 3){
					ans.erase(ans.begin() + i);
					while(now % 6 != 0){
						++now;
					}
					ans.emplace_back(now);
					break;
				}
			}
		}else if(sum % 6 == 4){
			rrep(i, ans.size()){
				if(ans[i] % 6 == 4){
					ans.erase(ans.begin() + i);
					while(now % 6 != 0){
						++now;
					}
					ans.emplace_back(now);
					break;
				}
			}
		}else if(sum % 6 == 5){
			rrep(i, ans.size()){
				if(ans[i] % 6 == 2){
					ans.erase(ans.begin() + i);
					while(now % 6 != 3){
						++now;
					}
					ans.emplace_back(now);
					break;
				}
			}
		}

		rep(i, ans.size()){
			if(i) cout << ' ';
			cout << ans[i];
		}
		cout << endl;
	}

	cout << flush;

	return 0;
}

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

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] str = br.readLine().split("");
    for (int i = str.length-1; i >=0; i--) {
      System.out.print(str[i]);
    }
    System.out.println();
  }
}

Measured memory_bytes: 24240
n, m = map(int, input().split())
x = [int(m) for m in input().split()]
y = [int(m) for m in input().split()]
mod = 10 ** 9 + 7
bx = []
for i in range(1, n):
    bx.append(abs(x[i] - x[i - 1]))

mulx = []
for i in range(1, n):
    mulx.append(i * (n - i))

ansx = 0
for i in range(n - 1):
    ansx += bx[i] * mulx[i]
    #ansx = ansx % mod
ansx = ansx * (m - 1)
#ansx = ansx % mod


by = []
for i in range(1, m):
    by.append(abs(y[i] - y[i - 1]))

muly = []
for i in range(1, m):
    muly.append(i * (m - i))


ans = 0
for i in range(m - 1):
    ans += by[i] * ansx * muly[i] // muly[0]
    ans = ans % mod

ans = ans % mod
print(ans)

Measured memory_bytes: 27508
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long array[];
		array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = Long.parseLong(sc.next());
		}

		long sum = 0;

		for (int i = 1; i < n; i++) {
			if (array[i - 1] > array[i]) {
				sum += array[i - 1] - array[i];
				array[i] = array[i - 1];
			}
		}

		System.out.println(sum);

	}
}

Measured memory_bytes: 61380
import java.util.Scanner
import scala.io.StdIn

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]) = {
//    val sc = new Scanner(System.in)
//    val N = sc.nextInt()
//    val As = List.fill(N)(sc.nextInt())
    val N  = StdIn.readLine().toInt
    val As  = StdIn.readLine().split(" ").map(_.toInt)

    val left = As.scanLeft(0) {(pre, x) => gcd(pre, x)}
    val right = As.scanRight(0) {(pre, x) => gcd(pre, x)}

    val ret = As.indices.map {i =>
      gcd(left(i), right(i + 1))
    }.max
    println(s"$ret")
  }

  @tailrec
  def gcd(x: Int, y: Int): Int = {
    if(y == 0) x
    else gcd(y, (x % y))
  }
}

Measured memory_bytes: 51188
s = input()
k = int(input())

if s[0] != "1":
    print(s[0])
    exit()
else:
    cnt = 0
    not_1 = 0
    for i in range(len(s)):
        if s[i] == "1":
            cnt += 1
        else:
            not_1 = i
            break
    if cnt >= k:
        print(1)
        exit()
    else:
        print(s[not_1])

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

using namespace std;

#define fo(i,n) for(int i=0; i<n; i++)
#define Fo(i,k,n) for(int i=k; i<n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int N,K,len;
vi a;
vector<bool> dp;

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

    cin>>N>>K;
    a.resize(N);
    Fo(i,0,N){
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    len = a.size();
    dp.resize(K+1, 0);
    Fo(i,1,K+1){
        for(auto ele:a){
            if(i-ele >= 0){
                if(dp[i-ele] == 0){
                    dp[i] = 1;
                    break;
                }
            }
        }
        // cout<<dp[i]<<endl;
    }
    cout<<(dp[K]==1 ? "First" : "Second")<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc,char** argv){
  string s,t;
  cin >> s >> t;
  vector<int> s_(s.size());
  vector<int> t_(t.size());
  s_[0] = 0;
  t_[0] = 0;
  int s_idx = 0;
  int t_idx = 0;
  for(int i = 1; i < s.size(); i++){
    bool f = true;
    int l = 0;
    for(int j = 0; j < i;j++){
      if(s[j] == s[i]){
        f = false;
        l = j;
        break;
      }
    }
    if(f){
      s_idx++;
      s_[i] = s_idx;
    }else{
      s_[i] = s_[l];
    }
  }
  for(int i = 1; i < t.size(); i++){
    bool f = true;
    int l = 0;
    for(int j = 0; j < i;j++){
      if(t[j] == t[i]){
	f = false;
	l = j;
	break;
      }
    }
    if(f){
      t_idx++;
      t_[i] = t_idx;
    }else{
      t_[i] = t_[l];
    }
  }
  
  if(equal(s_.cbegin(),s_.cend(),t_.cbegin())){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 2312
def main():
    n = int(input())
    s = input()
    ans = []
    a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    for _s in s:
        k = 0
        p = a.find(_s)
        if p + n >= 26:
            k = (p + n) % 26
        else:
            k = p + n
        ans.append(a[k])

    print("".join(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}

int main () {
  long double a,b,c;
  long double eps = 1.0E-14;

  cin >> a >> b >> c;

  if(sqrt(a) + sqrt(b) + eps < sqrt(c)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

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

  vector<ll> X(N);
  for(int i=0;i<N;i++){
	cin >> X[i];
  }

  ll ans = 0;
  for(int i=1;i<N;i++){
	if(A * (X[i] - X[i-1]) < B) ans += A * (X[i] - X[i-1]);
	else ans += B;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int c=0;
    cin>>s;
    sort(s.begin(),s.end());
    int r=s.size();
    if(s[r-1]!=s[r-2])
    {
        cout<<"No";
        return 0;
    }
    for(int i=0;i<r-1;i++)
    {

        c++;
        if(s[i]!=s[i+1])
        {
            if(c%2==1)
            {
                cout<<"No";
                return 0;
            }
            c=0;
        }

    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int b1,b2,b3;
    cin >>b1>>b2>>b3;
    if((b1==1&&b2==1)||b3==1){
        cout <<"Open"<<endl;
    }
    else{
        cout <<"Close"<<endl;
    }
}



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s, h;
    cin >> s >> h;
    int a[s.size() + 1][h.size() + 1];
    for (int i = 0; i <= s.size(); i++)
    {
        a[i][0] = 0;
    }
    for (int i = 0; i <= h.size(); i++)
    {
        a[0][i] = 0;
    }
    string ans;
    for (int i = 1; i <= s.size(); i++)
    {
        for (int j = 1; j <= h.size(); j++)
        {
            if (s[i - 1] == h[j - 1])
            {
                //ans.push_back(s[i - 1]);
                a[i][j] = a[i - 1][j - 1] + 1;
            }
            else
            {
                a[i][j] = max(a[i - 1][j], a[i][j - 1]);
            }
        }
    }
    int x = s.size(), y = h.size();
    while (x > 0 && y > 0)
    {
        if (s[x - 1] == h[y - 1])
        {
            ans.push_back(s[x - 1]);
            x--;
            y--;
        }
        else if (a[x][y - 1] > a[x - 1][y])
            y--;
        else
            x--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}


Measured memory_bytes: 35456
#include <cstdio>
#include <algorithm>

int main()
{
	int n, t; scanf("%d%d", &n, &t);
	int next = 0, last = 0;
	long long ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		int x; scanf("%d", &x);
		next < x ? ans += t : ans += x - last;
		next = x + t; last = x;
	}
	ans += t;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
from math import factorial

N, M = [int(n) for n in input().split()]
if abs(N-M) == 0:
    result = factorial(N)**2 * 2
elif abs(N-M) == 1:
    result = factorial(N) * factorial(M)
else:
    result = 0
    
print(result % (10**9 + 7))

Measured memory_bytes: 5176
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var n = int.Parse(s[0]);
            var m = int.Parse(s[1]);

            Console.WriteLine(n == m ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11092
#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>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int n,k;
    cin >> n >> k;
    int count = 0;
    rep(i,n){
        int a;
        cin >> a;
        if(a >= k) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	int a, b, c,d; cin >> a>>b>>c>>d;
	//string s,t,u; cin >> s>>t>>u;
	//vector<int> n(3);
	if (a >= b) {
		cout << b * c + (a - b) * d;
	}
	else {
		cout << a * c;
	}
	

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a,b,c,count[11] = {0};

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

    count[a] ++;
    count[b] ++;
    count[c] ++;

    if((count[5] == 2) && (count[7] == 1))
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    
    
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;

int n;
int p[30], l[30], r[30];

void dfs(int n, int depth){
  if(p[n] == -1){
    cout << "depth = " << depth << ", ";
    return ;
  }

  dfs(p[n], depth + 1);
  return ;
}

int height(int i, int h){
  int hl = 0, hr = 0;

  if(l[i] == -1 && r[i] == -1) return h;
  if(l[i] != -1) hl = height(l[i], h + 1);
  if(r[i] != -1) hr = height(r[i], h + 1);

  return max(hl, hr);
}

void searchsibling(int i){
  if(p[i] == -1) cout << "sibling = " << -1 << ", ";
  else if(l[p[i]] == i) cout << "sibling = " << r[p[i]] << ", ";
  else cout << "sibling = " << l[p[i]] << ", ";
}

void searchdegree(int i){
  if(l[i] == r[i]) cout << "degree = " << 0 << ", ";
  else if(l[i] == -1 || r[i] == -1) cout << "degree = " << 1 << ", ";
  else cout << "degree = " << 2 << ", ";
}

void searchtype(int i){
  if(p[i] == -1) cout << "root";
  else if(l[i] == -1 && r[i] == -1) cout << "leaf";
  else cout << "internal node";
}

void solve(){
  for(int i = 0;i < n;i++){
    cout << "node " << i << ": ";
    cout << "parent = " << p[i] << ", ";
    searchsibling(i);
    searchdegree(i);
    dfs(i, 0);
    cout << "height = " << height(i, 0) << ", ";
    searchtype(i);
    cout << endl;
  }
}

int main(){
  cin >> n;
  for(int i = 0;i < n;i++) p[i] = l[i] = r[i] = -1;
  for(int i = 0;i < n;i++){
    int id, left, right;

    cin >> id >> left >> right;
    l[id] = left;
    r[id] = right;
    p[left] = p[right] = id;
  }

  solve();

  return 0;
}



Measured memory_bytes: 3104
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func calc(sign, a, sum int) (int, int64) {
	nsum := sum + a
	if sign < 0 && nsum < 0 || 0 < sign && 0 < nsum {
		//println(sign, a, sum, " -> ", 0, nsum)
		return nsum, 0
	}

	if sign > 0 {
		nsum = 1
		na := nsum - sum
		//println(sign, a, sum, " -> ", na, absInt(na-a), nsum)
		return nsum, int64(absInt(na - a))
	} else {
		nsum = -1
		na := nsum - sum
		//println(sign, a, sum, " -> ", na, absInt(na-a), nsum)
		return nsum, int64(absInt(na - a))
	}
}

func main() {
	defer stdout.Flush()

	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	//println(a)
	//println()
	sum := make([]int, n)

	var sign, i int
	var min, tmp int64

	sign = 1
	i = 0
	sum[i], tmp = calc(sign, a[i], 0)
	for i = 1; i < n; i++ {
		sign *= -1
		var c int64
		sum[i], c = calc(sign, a[i], sum[i-1])
		tmp += c
	}
	//println(tmp, sum)
	//println()

	min = tmp

	sign = -1
	i = 0
	sum[i], tmp = calc(sign, a[i], 0)
	for i = 1; i < n; i++ {
		sign *= -1
		var c int64
		sum[i], c = calc(sign, a[i], sum[i-1])
		tmp += c
	}
	//println(tmp, sum)
	min = minInt64(min, tmp)

	println(min)
}


Measured memory_bytes: 3840
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}
vector<bool> primenumber(int n){
	vector<bool> a(n+1);
	rep(i,n+1){
		a[i]=1;
	}
	a[0]=0;
	a[1]=0;
	for(int i=2;i*i<=n;i++){
		if(a[i]==1){
			for(int j=i+1;j<=n;j++){
				if(j%i == 0){
					a[j]=0;
				}
			}
		}
	}
	return a;
}

int main(){
	vector<bool> a;
	vector<int> b(100001);
	a=primenumber(100000);
	b[0]=0;
	FOR(i,1,100001){
		if(a[i]==1 && a[(i+1)/2] ==1){
			b[i]=b[i-1]+1;
		}else{
			b[i]=b[i-1];
		}
	}
	int q;
	cin>>q;
	vector<int> l(q),r(q);
	rep(i,q){
		cin>>l[i]>>r[i];
	}
	rep(i,q){
		cout<<b[r[i]]-b[l[i]-1]<<endl;
	}

}

Measured memory_bytes: 1792
# include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846
 
void solve()
{
        ll n; cin >> n;
        ll cnt = 0;
        set<ll> st;
        while(true)
        {
                cnt++;
                st.insert(n);
                if(n % 2 == 0)
                {
                        n /= 2;
                }
                else 
                {
                        n = (3 * n + 1);
                }
                if(st.find(n) != st.end())
                {
                        cout << cnt + 1 << endl;
                        return;
                }
        }
}
 
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        solve();
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#pragma region Library
using namespace std;

using ll = long long int; // int_fast64_t;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
using vi = vt<int>;
using vvi = vvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;

constexpr int INF = 1 << 30;  // 1073741824 2倍すると-2147483648
constexpr ll INFL = 1l << 62; // 4611686018427387904 2倍すると-0.9*10^18
constexpr int dx4[] = {0, 1, 0, -1};
constexpr int dy4[] = {1, 0, -1, 0};
constexpr int dx8[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy8[] = {0, -1, 0, 1, -1, -1, 1, 1};
// [a, b)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); i--)
// [a, b]
#define RANGE(i, a, b) for (int i = (a); i <= (b); i++)
#define RANGER(i, a, b) for (int i = (b); i >= (a); i--)
// [0, n)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) RFOR(i, 0, (n))

#pragma endregion
// === Library ===
// Vectors: vt vvt vi vvi vl vvl
// Consts:  INF INFL dx4 dy4 dx8 dy8
// Loops:   FOR FORR RANGE RANGER REP REPR

int main() {
  int a, b, x, v, ans = 0;
  cin >> x;
  FOR(a, 1, 1000) {
    v = a;
    REP(b, 10) {
      v *= a;
      if (v > x)
        break;
      ans = max(ans, v);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int N, A;
	cin >> N;
	int total = 0;
	for (int i = 0; i < N; i++) {
		cin >> A;
		if (A % 2 == 0 && A % 3 == 0) {
			total++;
		}
		else if (A % 2 == 0 && A % 5 == 0) {
			total++;
		}
		else if (A % 2 != 0) {
			total++;
		}
		else {
			continue;
		}
	}
	if (total == N) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}
}

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

using namespace std;

//#define int long long

main()
{
    ios_base::sync_with_stdio(false);
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int an = 1e9;
    for(int i = 0; i <= x; i++){
        int cost = a * i;
        int needa = (x - i);
        cost += 2 * needa * c;
        int needb = max(0, y - needa);
        cost += needb * b;
        an = min(an, cost);
    }
    for(int i = 0; i <= y; i++){
        int cost = b * i;
        int needb = (y - i);
        cost += 2 * needb * c;
        int needa = max(0, x - needb);
        cost += needa * a;
        an = min(an, cost);
    }
    for(int i = 0; i <= max(x, y); i++){
        int cost = 2 * i * c;
        int needa = max(0, x - i);
        int needb = max(0, y - i);
        cost += needa * a;
        cost += needb * b;
        an = min(an, cost);
    }
    cout << an << endl;
}


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


#define ll long long
#define MOD 1000000007
#define PI 3.1415


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

    ll num=0;

    for(ll i=0;i<s.size();i++){
        num += s.at(i) - '0';
    }

    if(num%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}



Measured memory_bytes: 3720
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    l: i64,
    r: i64,
  }
  let m = 2019;
  let a = r / m * m;
  if l <= a {
    puts!("0\n");
    return;
  }
  let mut ans = m;
  for i in l .. r + 1 {
    for j in i + 1 .. r + 1 {
      ans = cmp::min(ans, i * j % m);
    }
  }

  puts!("{}\n", ans);
}


Measured memory_bytes: 4352