akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int dp[100010];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> H(N);
    for (int & h : H) cin >> h;
    dp[1] = abs(H[0]-H[1]);
    for (int i = 2; i < N; ++i) {
        dp[i] = min(dp[i-2]+abs(H[i-2]-H[i]), dp[i-1]+abs(H[i-1]-H[i]));
    }
    printf("%d\n", dp[N-1]);
    return 0;
}


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

int main()
{
  string S;
  cin >> S;
  long long int ans = 0;
  int N = S.size() + 1;
  vector<bool> a(N);
  set<int> st;
  if (S[0] == '<')
    st.insert(0);
  if (S[N - 2] == '>')
    st.insert(N - 1);
  for (int i = 1; i < N - 1; i++)
  {
    if (S[i] == '<' && S[i - 1] == '>')
    {
      st.insert(i);
    }
  }
  for (auto itr = st.begin(); itr != st.end(); itr++)
  {
    a[*itr] = 1;
  }
  long long int cnt1 = 0;
  long long int cnt2 = 0;
  for (int i = 0; i < N; i++)
  {
    if (a[i] == 1)
    {
      if (i != 0 && S[i - 1] == '<')
        cnt1++;
      else if (i != 0 && S[i - 1] == '>')
        cnt2++;
      if (cnt1 >= 1 && cnt2 == 1)
      {
        while (cnt1 > 0)
        {
          ans += cnt1;
          cnt1--;
        }
      }
      else if (cnt1 == 1 && cnt2 > 1)
      {
        while (cnt2 > 0)
        {
          ans += cnt2;
          cnt2--;
        }
      }
      else
      {
        if (cnt1 >= cnt2)
        {
          cnt2--;
          while (cnt1 > 0)
          {
            ans += cnt1;
            cnt1--;
          }
          while (cnt2 > 0)
          {
            ans += cnt2;
            cnt2--;
          }
        }
        else
        {
          cnt1--;
          while (cnt1 > 0)
          {
            ans += cnt1;
            cnt1--;
          }
          while (cnt2 > 0)
          {
            ans += cnt2;
            cnt2--;
          }
        }
      }
      cnt1 = 0;
      cnt2 = 0;
    }
    else
    {
      if (i != 0 && S[i - 1] == '<')
        cnt1++;
      else if (i != 0 && S[i - 1] == '>')
        cnt2++;
    }
  }
  while (cnt1 > 0)
  {
    ans += cnt1;
    cnt1--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6660
# include <bits/stdc++.h>
using namespace std;
 
const int maxn = 1e5+3;
int row, col, n, que[maxn<<1];
pair<int, int> arr[maxn<<1];
 
bool check(int a, int b)
{
    if(a==0 || a==row || b==0 || b==col) return true;
    return false;
}
 
int cal(int a, int b)
{
    if(a==0) return b;
    else if(b==col) return col + a;
    else if(a==row) return col + row + col - b;
    else return col + col + row + row - a;
}
 
int main()
{
    int a, b, c, d, cnt = 0, icount = 0;
    scanf("%d%d%d",&row,&col,&n);
    {
        while(n--)
        {
            scanf("%d%d%d%d",&a,&b,&c,&d);
            if(check(a, b) && check(c, d))
            {
                arr[cnt++] = make_pair(cal(a, b), icount);
                arr[cnt++] = make_pair(cal(c, d), icount++);
            }
        }
        sort(arr, arr+cnt);
        int r=0;
        for(int i=0; i<cnt; ++i)
        {
            if(!r)
                que[++r] = arr[i].second;
            else if(arr[i].second == que[r])
                --r;
            else
            que[++r] = arr[i].second;
        }
        if(!r) puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        int m = 0;
        char[] c = n.toCharArray();
        for(int i = 0; i < 3; i++){
            if(c[i] == '1'){
                m++;
            }
        }
        System.out.println(m);
    }
}

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

int main() {
	std::string S;
	std::cin >> S;

	std::string op[8] = {
		"+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"
	};

	for(int i = 0; i < 8; ++i) {
		int sum = (int) (S[0] - '0');
		for(int j = 0; j < 3; ++j) {
			if (op[i][j] == '+') {
				sum += (int) (S[j + 1] - '0');
			} else {
				sum -= (int) (S[j + 1] - '0');
			}
		}

		if(sum == 7) {
			for(int j = 0; j < 3; ++j) {
				std::cout << S[j] << op[i][j];
			} std::cout << S[3] << "=7" << std::endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 標準入力を取得
S = input()

# 求解処理
ans = "AC"
if S[0] != "A":
    ans = "WA"

if S[2:-1].count("C") != 1:
    ans = "WA"
else:
    index = 2 + S[2:-1].index("C")
    if not (S[1:index] + S[index + 1:]).islower():
        ans = "WA"

# 結果出力
print(ans)


Measured memory_bytes: 8888
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=0;
	cin>>n;
	for(ll i=1;(i*(i+1))<=(n-i);i++){
		if((n-i)%i==0)ans+=(n-i)/i;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 2e5+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

    
int main()
{
    
     
        int n;
        scf(n);
        
        
        vector<int>a(n);
        
        int ctr=0;
        
        rep(i,0,n)
        {
            scf(a[i]);
        }
        
        ll ans=0;
        
        sort(all(a),greater<int>());
        
       if(n<=3)
       {
           if(n==3)
           ans=a[0]+a[1];
           
           else
           ans=a[0];
          
          lprin(ans); 
          
       }
        
        
        else
        {
        
        ans=a[0];
          
          
          int x=0;
        
        int j=1;
        
        for(int i=1;i<n-1;i+=2)
        {
            ans+=2*a[j];
            x=a[j];
            j++;
        }
        
        if(n&1)
        ans-=x;
        
        // if(ctr==n)
        // ans=1LL*(n-1)*a[0];
            
        lprin(ans);
    }
        
    
        
}

Measured memory_bytes: 4076
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
int main(){
	int n,q,key,t,x;
	cin>>n>>q;
	queue<int> Q[1001];
	for(int i=0;i<q;i++){
		cin>>key>>t;
		if(key==0){
			cin>>x;
			Q[t].push(x);
		}else if(key==1){
			if(Q[t].empty()==0)cout<<Q[t].front()<<endl;
		}else{
			if(Q[t].empty()==0)Q[t].pop();
		}
	}
	return 0;
}


Measured memory_bytes: 4480
import math
import sys
import itertools
import queue
from fractions import gcd

sys.setrecursionlimit(10000)

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

from math import factorial
import collections

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    sl = []
    for _ in range(N):
        tmp = sorted(sys.stdin.readline().rstrip())
        sl.append(''.join(tmp))
    c = collections.Counter(sl)
    ans = 0
    for n in c.values():
        r = 2
        if n > 1:
            ans += factorial(n) // (factorial(n - r) * factorial(r))

    print(int(ans))


Measured memory_bytes: 21480
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	unsigned int n;
	scanf("%d",&n);
	if(n<15)
	printf("%d",n*800);
	else if(n>=15 && n<=100)
	printf("%d",n*800-(200*(n/15)));
	return 0;
	
}

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

int main(){
	int a, b;
	char op;
	int ans;
	while (1){
		cin >> a >> op >> b;
		if (op == '?') break;
		switch (op){
		case '+':
			ans = a + b;
			break;
		case '-':
			ans = a - b;
			break;
		case '*':
			ans = a * b;
			break;
		case '/':
			ans = a / b;
			break;
		default:
			break;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
/*
・座標の出力
n==0のとき、再起毎に両端（p1,p2）を出力すると、両端以外の点は二回出力されてしまう。
よって、ｐ１を再起前に出力して、再起内では右端（ｐ２）のみ出力にする。


*/

#include <iostream>
#include <cmath>
#include <cstdio>

const static double PI = 4*atan(1.0);

using namespace std;


int count=0;


 
void Koch_curve(int n, double p1x, double p1y, double p2x, double p2y){
    double sx, sy, tx, ty, ux, uy;
    
	if(n == 0){
		//cout << p2x << ' ' << p2y << endl;
		printf("%.4lf %.4lf\n", p2x, p2y);
		count++;
	}
	else{
		n--;
		sx = p1x + (p2x-p1x)*(1.0/3.0);
		sy = p1y + (p2y-p1y)*(1.0/3.0);
		tx = p1x + (p2x-p1x)*(2.0/3.0);
		ty = p1y + (p2y-p1y)*(2.0/3.0);

		//求め方は http://www.infra.kochi-tech.ac.jp/takagi/Survey2/3PolarRect.pdf　
		// 極座標の回転　（二次元回転行列）
		ux= sx + (tx-sx)*cos(PI/3.0) - (ty-sy)*sin(PI/3.0);
		uy= sy + (tx-sx)*sin(PI/3.0) + (ty-sy)*cos(PI/3.0);

		Koch_curve(n, p1x, p1y, sx, sy);
		Koch_curve(n, sx, sy, ux, uy);
		Koch_curve(n, ux, uy,tx, ty);
		Koch_curve(n, tx, ty, p2x, p2y);
	}
    
}
 
int main() {
    int n;
    
    cin >> n;
	//cout.setf(ios::fixed, ios::floatfield); //固定小数表記 
	//cout << 0.0 << ' ' << 0.0 << endl;
	printf("%.4lf %.4lf\n", 0.0, 0.0);
    Koch_curve(n, 0.0, 0.0, 100.0, 0.0);
        
        return 0;
}

Measured memory_bytes: 1196
from collections import deque

N, K = map(int, input().split(' '))
S = input()
arr = []
idx = 0

while idx < N:
    start = idx
    while idx + 1 < N and S[idx] == S[idx + 1]:
        idx += 1
    if S[start] == '0':
        arr.append(-(idx - start + 1))
    else:
        arr.append(idx - start + 1)
    idx += 1

if arr[0] < 0:
    arr = [0] + arr
if arr[-1] > 0:
    arr.append(0)

l, r = 0, 0     # [l, r)
ans, tmp = max(arr), 0
while l < len(arr) and r < len(arr):
    tmp += abs(arr[r])
    r += 1

    if r - l > 2 * K + 1:
        tmp -= arr[l] - arr[l + 1]
        l += 2

    if r - l <= 2 * K + 1:
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 46704
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(){
	int a, b, c, d, acum, hori, ver;
	a = b = c = d = acum = hori = ver = 0;
	char cad[1100] = {"\0"};
	
	for(int i = 0; i < 1090; i++){
		cad[i] = '\n';
	}
	
	scanf("%s",cad);
	
	for(int i = 0; cad[i] != '\n'; i++){	
		if(cad[i] == 'N' && a == 0){
			acum++;
			ver = 1;
			a = 1;
		}else if(cad[i] == 'W' && b == 0){
			acum++;
			hori = 1;
			b = 1;
		}else if(cad[i] == 'S' && c == 0){
			acum++;
			ver = 1;
			c = 1;
		}else if(cad[i] == 'E' && d == 0){
			acum++;
			hori = 1;
			d = 1;
		}
		
		if(acum == 4){
			break;
		}
	}
	if(hori == ver && acum == 4){
		printf("Yes\n");
	}else if(hori != ver && acum == 2){
		printf("Yes\n");
	}else{
		printf("No\n");
	}	
	return 0;
}

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

using namespace std;
#define endl "\n"
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> pii;
const int N = 3e3 + 5;
int R, C, k;
ll v[N][N], f[N][N][4];

ll trau(int i, int j, int taken) {
    if (i > R || j > C) return -1e18;
    if (taken > 3) return -1e18;
    if (i == R && j == C) {
        if (taken < 3) return v[R][C];
        return 0;
    }
    if (f[i][j][taken] != -1) return f[i][j][taken];
    ll res = -1e18;
    res = max(res, trau(i, j + 1, taken + 1)) + v[i][j];
    if (taken < 3) res = max(res,  trau(i + 1, j, 0) + v[i][j]);
    else res = max(res, trau(i + 1, j, 0));
    res = max(res, trau(i, j + 1, taken));
    return f[i][j][taken] = res;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> R >> C >> k;
    for (int i = 1; i <= k; ++i) {
        int r, c, va;
        cin >> r >> c >> va;
        v[r][c] = va;
    }
    memset(f, -1, sizeof f);
    cout << trau(1, 1, 0);
    return 0;
}


Measured memory_bytes: 356656
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner in=new Scanner(System.in);
        /*Random on=new Random();*/
        long a=in.nextLong();
        long b=in.nextLong();
        long k=in.nextLong();
        long ans_a=Math.max(0,a-k);
        k=Math.max(0,k-a);
        long ans_b=Math.max(0,b-k);
        System.out.println(ans_a + " "+ ans_b);
    }
}


Measured memory_bytes: 23124
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub struct Graph {
    graph: Vec<Vec<usize>>,
    v: usize,
}

type Edge = (usize, usize);
impl Graph {
    pub fn new_directed(edges: &[Edge], v: usize) -> Self {
        let mut graph = vec![Vec::new(); v];
        for &(u, v) in edges {
            graph[u].push(v);
        }
        Graph { graph, v }
    }

    pub fn solve(&self, mut indegreev: Vec<usize>) -> isize {
        let mut dp = vec![0; self.v];
        let mut que = VecDeque::new();
        for u in 0..self.v {
            if indegreev[u] == 0 {
                que.push_back(u);
                dp[u] = 1;
            }
        }
        while let Some(u) = que.pop_front() {
            for &v in &self.graph[u] {
                indegreev[v] -= 1;
                if indegreev[v] == 0 {
                    que.push_back(v);
                    dp[v] = dp[u] + 1;
                }
            }
        }

        let is_ok = indegreev.into_iter().all(|x| x == 0);
        if is_ok {
            dp.into_iter().max().unwrap_or(0) as isize
        } else {
            -1
        }
    }
}

fn solve() {
    input! {
        n: usize,
        matchv: [[Usize1; n - 1]; n]
    };

    let vn = n * (n - 1) / 2;
    let mut indegreev = vec![0; vn];
    let mut edges = Vec::new();
    let mut id_table: HashMap<(usize, usize), usize> = HashMap::new();
    let mut cur_id = 0;
    for i in 0..n {
        let a = i;
        for mv in matchv[i].windows(2) {
            let b = mv[0];
            let key = (a.min(b), a.max(b));
            let u = match id_table.get(&key) {
                Some(id) => *id,
                None => {
                    let id = cur_id;
                    id_table.insert(key, id);
                    cur_id += 1;
                    id
                }
            };
            let c = mv[1];
            let key = (a.min(c), a.max(c));
            let v = match id_table.get(&key) {
                Some(id) => *id,
                None => {
                    let id = cur_id;
                    id_table.insert(key, id);
                    cur_id += 1;
                    id
                }
            };
            indegreev[v] += 1;
            edges.push((u, v));
        }
    }

    let graph = Graph::new_directed(&edges, vn);
    let res = graph.solve(indegreev);
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 87088
#python3
n = int(input())

def dfs(s):
    if len(s) == n:
        print(s)
        return
    else:
        kind = len(set(s))
        for i in range(kind+1):   
            t = s
            t += chr(ord('a') + i)
            dfs(t)
def main():
    dfs('a')
main()

Measured memory_bytes: 4412
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
const int maxn = 405;
const ll mod = 1000000007;
const double PI = acos(-1.0);

int n;
int val[maxn];

void solve()
{
	int res = 0;
	int i, j, k;
	for (i = 1; i <= 2 * n; i++)
	{
		sa(val[i]);
	}
	sort(val + 1, val + 2 * n + 1);
	for (i = 1; i <= 2 * n - 1; i = i + 2)
	{
		res += val[i];
	}
	printf("%d\n", res);
}
int main()
{
	while (scanf("%d", &n) != EOF)
	{
		solve();
	}
	return 0;
}

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

int main()
{
	long long int N, A, B;
	scanf("%ld %ld %ld", &N, &A, &B);
	
	if((B-A)%2 == 0) printf("%ld", (B-A)/2);
	else if( N-B >= A-1) printf("%ld", (A-1)+(B-A+1)/2);
	else printf("%ld", (N-B)+(B-A+1)/2);
	
	return 0;
}



Measured memory_bytes: 128
N,M,X = map(int,input().split())
c_list = [list(map(int,input().split())) for _ in range(N)]
cost_list = []
for i in range(2**N):
  achive = [0]*M
  achive_list = [0]*M
  cost = 0
  for j in range(N):
    if ((i>>j)&1)==1:
      cost = cost + c_list[j][0]
      for k in range(M):
        achive[k] = achive[k] + c_list[j][k+1]
        if achive[k] >= X:
          achive_list[k] = -1
  if sum(achive_list) == -1*M:
    cost_list.append(cost)
print(min(cost_list) if cost_list else -1)

Measured memory_bytes: 9240
<?php
list($s) = strs();
$n = strlen($s) - 1;
// bit全探索
$ans = 0;
for ($i = 0; $i < 2 ** $n; $i++) {
    $l = 0;
    for ($j = 0; $j < $n; $j++) {
        if (($i >> $j) & 1) {
            $ans += substr($s, $l, $j - $l + 1);
            $l = $j + 1;
        }
    }
    $ans += substr($s, $l);
}
echo $ans;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 4728
from collections import deque

n = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)
ans = 0

point = deque()
point.append(A.pop(0))
for i in A:
    ans += point.popleft()
    point.append(i)
    point.append(i)

print(ans)

Measured memory_bytes: 32424
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))


int main(){
    ll N;
    cin >> N;
    vector<ll>A(N),B(N),C(N),ruiAB(N);

    for(ll i = 0;i < N;i++)
        cin >> A.at(i);

    for(ll i = 0;i < N;i++)
        cin >> B.at(i);

    for(ll i = 0;i < N;i++)
        cin >> C.at(i);
    
    for(ll i = 0;i < N;i++)
        ruiAB.at(i) = 0;

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());

    ll res = 0,b_atai;

    for(ll i = 0;i < N;i++){
        const ll j = lower_bound(ALL(A),B.at(i)) - A.begin();
        if(i == 0)
            ruiAB.at(i) = j;
        else
            ruiAB.at(i) = j + ruiAB.at(i-1);
    }

    for(ll i = 0;i < N;i++){
        const ll j = lower_bound(ALL(B),C.at(i)) - B.begin();
        if(j == 0)
            res += 0;
        else
            res += ruiAB.at(j-1);
    }

    cout << res << endl;

}

Measured memory_bytes: 6404
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cmath>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
#define downint greater<int>()
#define downchar greater<char>()
#define downstring greater<string>()
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  cin >> s;
  rep(i,3) cout << s[i];
  cout << "\n";
  return 0;
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

string solve(int a, int b) {
    if (!a || !b) return "Zero";
    if (a <= 0 && 0 <= b) return "Zero";
    if (b < 0) return ((abs(b - a) + 1) % 2) ? "Negative" : "Positive";
    return "Positive";
}

int main(void) {
    int a, b;
    cin >> a >> b;
    cout << solve(a, b) << endl;

    return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define SZ(x) (int)(x).size()

void solve(string s) {
    int n = s.size();
    set<string> S;
    for(int len=1; len<n; len++) {
        string s1 = s.substr(0,len);
        string s2 = s.substr(len, n-len);
        string t1="", t2="";
        for(int i=SZ(s1)-1; i>=0; i--) t1+=s1[i];
        for(int i=SZ(s2)-1; i>=0; i--) t2+=s2[i];
        S.insert(s1+s2);
        S.insert(s1+t2);
        S.insert(t1+s2);
        S.insert(t1+t2);
        S.insert(s2+s1);
        S.insert(s2+t1);
        S.insert(t2+s1);
        S.insert(t2+t1);
    }
    cout << S.size() << "\n";
}

int main() {
    int m; cin>>m;
    rep(i,m) {
        string s; cin>>s;
        solve(s);
    }
    return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

// 0 以上 ab 以下で x で割りきれる数  
ll f(ll ab, ll x) {
  if (ab == -1) {
    return 0;
  }
  return ab / x + 1; // 0を含むので1つ以下
}

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

  ll res = f(b, x) - f(a - 1, x);

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, b;
	cin >> a >> b;
	int cur = 1;
	int res = 0;
	while (cur < b)
	{
		cur += a - 1;
		res++;
	}
	cout << res;

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<char> t(n);
  for(int i=0;i<n;i++){
    t.at(i) = s.at(n-1-i);
  }
  
  int ans = 0;
  for(int i=0;i<(n+1)/2;i++){
    if(t.at(i) != s.at(i)) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define MAX 1e9+7
#define MIN -1e9-7
#define int long long
#define endl "\n"
#define max(x,y) (x>y)?x:y
#define min(x,y) (x<y)?x:y
#define s(n) scanf("%d",&n)
#define mem memset(a, 0, sizeof(a))
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
typedef vector<int> vi;
typedef vector<string> vs;
/*
* * * * * * * * * * * * * * * * * * * * * *
*       ☆꧁𝓑𝓐𝓒𝓚_𝓛𝓞𝓖꧂☆              **
*                                        ***
* * * * * * * * * * * * * * * * * * * * *****
*/ 

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int r,g,b;
cin>>r>>g>>b;
int k;
cin>>k;
if(b>g and g>r)
{
	cout<<"Yes"<<endl;
}
else
{
   while(g<=r and k!=0)
   {
   	g*=2;
   	k--;
   }
   while(b<=g and k!=0)
   {
   	b*=2;
   	k--;

   }
   if(b>g and g>r)
   {
   	cout<<"Yes"<<endl;
   }
   else
   {
   	cout<<"No"<<endl;
   }


}




return 0;
}

Measured memory_bytes: 3644
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int n;
    cin >> n;
    int n_ = n;
    int sum=0;
    while(n_!=0)
    {
        sum+=n_%10;
        n_/=10;
    }
    if(n%sum==0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM

build :: BS.ByteString -> V.Vector Int
build s = V.create $ do
  let !n = BS.length s
  vec <- VM.new n
  forM_ [n-2,n-3..0] $ \i -> do
    k <- VM.read vec (i + 1)
    if s `BS.index` i == 'A' && s `BS.index` (i+1) == 'C'
    then VM.write vec i (k+1)
    else VM.write vec i k
  return vec

main = do
  -- 2 <= n <= 10^5, 1 <= q <= 10^5
  [n,q] <- map read . words <$> getLine
  s <- BS.getLine
  let !t = build s
  sequence_ $ replicate q $ do
    -- 1 <= l < r < n
    [l,r] <- map read . words <$> getLine
    print $ (t V.! (l - 1)) - (t V.! (r - 1))


Measured memory_bytes: 2556
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

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

		BigDecimal L = new BigDecimal(sc.nextLine());
		BigDecimal div = new BigDecimal(3.0);
		MathContext mc = new MathContext(10,RoundingMode.HALF_UP);
		BigDecimal cutNum = L.divide(div, mc);


		System.out.println(cutNum.multiply(cutNum).multiply(cutNum));

	}
}

Measured memory_bytes: 35912
/*
	Created by Faisal Ahmed
*/

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int x, y;
	ll ans = 0;
	
	cin >> x >> y;
	
	if(x == 1){
		ans += 300000;
	}
	else if(x == 2){
		ans += 200000;
	}
	else if(x == 3){
		ans += 100000;
	}
	
	if(y == 1){
		ans += 300000;
	}
	else if(y == 2){
		ans += 200000;
	}
	else if(y == 3){
		ans += 100000;
	}
	
	if(x == 1 && y == 1){
		ans += 400000;
	}
	
	cout << ans << endl;
	
	return 0;
} 

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
ll dp[31];
void mainmain(){
	dp[1]=1;
	dp[2]=2;
	dp[3]=4;
	reep(i,4,31){
		rep(j,3){
			dp[i]+=dp[i-j-1];
		}
	}
	// reep(i,4,7){
		// cout<<dp[i]<<endl;
	// }
	// rep(i,35){
		// cout<<i<<" "<<i*3650<<endl;
	// }
	// rep(i,31){
		// cout<<i<<" "<<dp[i]<<endl;
	// }
	int n;
	while(cin>>n,n){
		ll t=dp[n]-1;
		// cout<<t<<endl;
		t/=3650;
		cout<<t+1<<endl;
	}
	// int tt=7299;
	// tt/=3650;
	// cout<<tt+1<<endl;
}

}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1152
N = int(input())
H = tuple(map(int, input().split()))
dp = [0] * N

dp[0] = 0
dp[1] = abs(H[0] - H[1])
for i in range(2, N):

    dp[i] = min(
        dp[i-1] + abs(H[i-1] - H[i]),
        dp[i-2] + abs(H[i-2] - H[i]))
print(dp[N-1])

Measured memory_bytes: 14108
#include<bits/stdc++.h>
using namespace std;
#define md 1000000007
#define ll long long 
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fastmap mp.reserve(1024);mp.max_load_factor(0.25);
#define fastset st.reserve(1024);st.max_load_factor(0.25);
ll int mpw(ll int a,ll int b,ll int m)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%m;
		}
		a=(a*a)%m;
		b>>=1;
	}
	return ans;
}
 
ll int pw(ll int a,ll int b)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans*=a;
		}
		a*=a;
		b>>=1;
	}
	return ans;
}
 
ll int mn(ll int a,ll int b)
{
	if(a<=b)
	{
		return a;
	}
	return b;
}
 
ll int mx(ll int a,ll int b)
{
	if(a>=b)
	{
		return a;
	}
	return b;
}
 
int main()
{
	fio
	int n;
	cin>>n;
	vector<ll int>nm(n);
	for(int i=0;i<n;++i)
	{
		cin>>nm[i];
	}
	vector<vector<pair<ll int,ll int>>>D(n,vector<pair<ll int,ll int>>(n,{0,0}));
	for(int i=0;i<n;++i)
	{
		for(int j=i;j>=0;--j)
		{	
			if(i==j)
			{
				D[j][i]={nm[i],0};
			}
			else{
				if(nm[j]+D[j+1][i].second>=nm[i]+D[j][i-1].second)
				{
					D[j][i]={nm[j]+D[j+1][i].second,D[j+1][i].first};
				}
				else{
					D[j][i]={nm[i]+D[j][i-1].second,D[j][i-1].first};
				}
			}
		}
	}
	cout<<D[0][n-1].first-D[0][n-1].second<<"\n";
	return 0;
}

Measured memory_bytes: 144152
import java.util.Scanner;

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

        int count = 0;
        int max = 0;
        for (int i = 0; i < s.length(); i++) {
            if ("ACGT".contains(s.substring(i, i + 1))) {
                count++;
            } else {
                max = Math.max(count, max);
                count = 0;
            }
        }
        max = Math.max(count, max);

        System.out.println(max);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using lint = long long;
constexpr lint mod1 = 1e9+7;

int main(){
  int n, m; scanf("%d %d", &n, &m);
  lint s;
  if(abs(n-m) > 1) s = 0;
  else{
    s = 1;
    rep(i, n){
      s *= i+1;
      s %= mod1;
    }
    rep(i, m){
      s *= i+1;
      s %= mod1;
    }
    if(n == m){
      s *= 2;
      s %= mod1;
    }
  }
  printf("%lld\n", s);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
 
    using namespace std;
    using namespace __gnu_pbds;
 
    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long 
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>
 
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)
 
    #define what(x) cerr << #x << " is " << x << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
 
    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;
 
/*.....................................................................................................................*/
 
    const ll mod=(ll)1e9+ 7;
 
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
 
    long long binpow(long long x, long long p) 
    {
        if (p == 0) {return 1;} 
    	if (p == 2 || (p & 1)) {return mult(x, binpow(x, p - 1));}
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
 
    //A.erase(unique(A.begin(),A.end()),A.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll  man  =   (int)200005   ,  inf   =   1e18;
 
 
/*......................................................................................................................*/



signed main()
{
    fast;
    int n;
    cin>>n;
    vector<int>a(n),dp(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[0]=0;
    if(n>=2)dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n-1]<<endl;
}   

Measured memory_bytes: 4756
#include<iostream>
#include<vector>
using namespace std;
 
vector<int> a;
vector<int> b;
vector<int> used;
int ans = 0;
int verp = 1;
int n;
 
void bfs(int x){
	if(verp==n){
		ans++;
		return;
	}
	for(int i = 0;i<a.size();i++){
		if(a[i]==x&&used[b[i]]==0){
			used[b[i]]=1;
			verp++;
			bfs(b[i]);
			used[b[i]]=0;
			verp--;
		}else if(b[i]==x&&used[a[i]]==0){
			used[a[i]]=1;
			verp++;
			bfs(a[i]);
			used[a[i]]=0;
			verp--;
		}
		
	}
	return;
	
}
 
 
int main(){
	int m;
	cin>>n>>m;
	
	for(int i = 0; i < m;i++){
		int tmpa,tmpb;
		cin>>tmpa>>tmpb;
		tmpa--;
		tmpb--;
		a.push_back(tmpa);
		b.push_back(tmpb);
		used.push_back(0);
	}
	
	used[0]=1;
	bfs(0);
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>
#include <set>

using namespace std;

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

  vector<bool> A = {false};
  A.reserve(N);
  for (int n=0; n<N; ++n) {
    int a;
    cin >> a;
    A.push_back(a==1);
  }

  set<unsigned> B;
  for (int n=N; n>0; --n) {
    unsigned ball_multiples = 0;
    unsigned n_multiple=2*n;
    while(n_multiple <= N) {
      ball_multiples += B.count(n_multiple);
      n_multiple += n;
    }
    if (ball_multiples%2 != A[n])
      B.insert(n);
  }

  cout << B.size() << endl;
  for (unsigned b : B)
    cout << b << ' ';
  cout << endl;

  return 0;
}


Measured memory_bytes: 7168
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var m = long.Parse(line[1]);
        Console.WriteLine(getAns(n,m));
    }
    public static long getAns (long a, long b)
    {
        if (a > b)  return   getAns(b, a);
        if (a == 1 && b == 1) return 1;
        else if (a == 1 && b != 1) return b - 2;
        else return (a - 2) * (b - 2);
    }
}

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

int parse(string s){
	int tmp = 0;
	if(s[0] >= 'a' && s[0] <= 'f') tmp = s[0] - 'a' + 10;
	else tmp = s[0] - '0';
	if(s[1] >= 'a' && s[1] <= 'f') tmp = tmp * 16 + s[1] - 'a' + 10;
	else tmp = tmp * 16 + s[1] - '0';
	return tmp;
}

int main(){
	string s;
	string name[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	int color[3][8] = {{0,0,0,0,255,255,255,255},{0,0,255,255,0,0,255,255},{0,255,0,255,0,255,0,255}};
	while(1){
		int d[8] = {};
		cin >> s;
		if(s == "0") break;
		for(int i = 0;i < 3;i++){
			int num = parse(s.substr(i * 2 + 1,2));
			for(int j = 0;j < 8;j++){
				d[j] += (num - color[i][j]) * (num - color[i][j]);
			}
		}
		int mi = 1e+9,clr;
		for(int i = 0;i < 8;i++){
			if(mi > d[i]){
				mi = d[i];
				clr = i;
			}
		}
		cout << name[clr] << endl;
	}
	return 0;
}

Measured memory_bytes: 3032
#include <iostream>
#include <vector>
#include <queue>

#define MAX_V 100001

using namespace std;

struct edge { int to; long long cost; };
struct sets { int v, p; long long d; };
vector<edge> tree[MAX_V];
long long depth[MAX_V];

void bfs(int v, int p, long long d) {
    queue<sets> q;
    q.push(sets{v, p, d});

    while (!q.empty()) {
        sets cur = q.front(); q.pop();
        depth[cur.v] = cur.d;
        for (int i = 0; i < tree[cur.v].size(); i++) {
            edge e = tree[cur.v][i];
            if (e.to == cur.p) { continue; }
            q.push(sets{e.to, cur.v, cur.d + e.cost});
        }
    }
}

int main() {
    int N, a, b, c;
    int Q, K, x, y;

    cin >> N;

    for (int i = 0; i < N-1; i++) {
        cin >> a >> b >> c;
        a--; b--;
        tree[a].push_back(edge{b, c});
        tree[b].push_back(edge{a, c});
    }

    cin >> Q >> K; K--;
    bfs(K, -1, 0);

    for (int i = 0; i < Q; i++) {
        cin >> x >> y;
        x--; y--;
        cout << depth[x] + depth[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 11248
N, K = map(int, input().split())
if K == 0:
  print(N * N)
else:
  S = 0
  for i in range(K+1, N+1):
    m = N // i
    S += m * (i - K)
    S += max(0, N % i - K + 1)
  print(S)

Measured memory_bytes: 3060
def decode(string, num):
    a, z = ord('a'), ord('z')
    return ''.join([chr(((ord(s) - a) + num) % 26 + a) if a <= ord(s) <= z else s for s in string])


while 1:
    try:
        line = raw_input()
        for i in range(26):
            tmp = decode(line, i)
            for x in tmp.split():
                x = x.strip('.')
                if 'this' in x or 'the' in x or 'that' in x:
                    print tmp
                    break
    except:
        break

Measured memory_bytes: 4220
N, x = map(int, input().split())
a = sorted([int(i) for i in input().split()])
b = []
for i, v in enumerate(a):
    if i != N - 1:
        c = min(v, x)
    elif x > v:
        c = x
    else:
        c = min(v, x)
    b.append(c)
    x -= c
ans = 0
for i,j in zip(a,b):
    if i == j:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;


int main(){
    int n;cin>>n;
    vi a(n);
    rep(i,n){
        cin>>a.at(i);
    }
    int hu=a.at(0);
    for(int i=1;i<n;i++){
        hu^=a.at(i);
    }
    rep(i,n){
        int ans=hu^a.at(i);
        cout<<ans<<" ";
    }
    cout<<endl;


}

Measured memory_bytes: 3984
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll x, y;
    cin >> x >> y;
    if (abs(x - y) <= 1) {
        cout << "Brown" << endl;
    }
    else {
        cout << "Alice" << endl;
    }
}

Measured memory_bytes: 256
n, a, b = [int(i) for i in input().split()]
a,b=max(a,b),min(a,b)

if (a - b) % 2 == 0:
    print((a - b) // 2)
else:
    c = b + (a -1- b) // 2
    d = n - a + 1 + (n - (n - a + 1) - b) // 2
    print(min(c,d))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int MODN=1e9+7;
int quick_pow(int a,int b,int modn=MODN){
    int di=a;
    int ret=1;
    while(b){
        if(b&1)ret*=di;
        ret%=modn;
        
        di*=di;
        di%=modn;
        b>>=1;
    }
    return ret;
}
int C(int n,int r){
    int fi=1;
    for(int i=n-r+1;i<=n;i++){fi*=i;fi%=MODN;}
    int se=1;
    for(int i=1;i<=r;i++){
        se*=i;
        se%=MODN;
    }
    return fi*quick_pow(se,MODN-2)%MODN;
}
int32_t main(){
    int n,a,b;cin>>n>>a>>b;
    //cerr<<quick_pow(2,3)<<endl;
    cout<< ((quick_pow(2,n)-1-C(n,a)-C(n,b))%MODN+MODN)%MODN<<endl;
	return 0;
}

Measured memory_bytes: 256