akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int length = sc.nextInt();
			int min = 9999999, max = -9999999;
			long sum = 0;
			for(int i = 0 ; i < length ; i++) {
				int num = sc.nextInt();
				min = num<min?num:min;
				max = num>max?num:max;
				sum += num;
			}
			System.out.println(String.format("%d %d %d", min, max, sum));
		}
	}
}


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

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

int main()
{
 while(1){
	int a,b;
	cin>>a>>b;

	if(cin.eof()) break;
	if(a==0||b==0)break;
	
	int g=gcd(a,b);
	cout<<g<<' '<<a/g*b<<endl;
 }
 return 0;
}
	

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

bool is_prime(int x) {
    if (x == 1) return false;
    if (x == 2) return true;
    else {
        bool prime = true;
        int upper = pow(x, 0.5)+1;
        for (int i = 2; i <= upper; i++) {
            if (x % i == 0) prime = false;
        }
        return prime;
    }
}

//累積和
vector<ll> memo(100001, -1); //memo[x]は1~xで2017に似た数の個数
ll f(int x) {
    if (memo[x] != -1) return memo[x]; //memo済みだったらすぐ値を返す
    if (x == 0) return 0; //f(y)のyが0になったら0を返す
    //再帰
    ll res; 
    int y = x-1;
    bool alike = true; //xが2017に似ているかどうか
    if (!is_prime(x)) alike = false;
    if (x % 2 == 0) alike = false;
    if (!is_prime((x+1)/2)) alike = false; 
    if (alike) res = f(y)+1;
    else res = f(y);
    return memo[x] = res;
}

int main() {
    int Q; cin >> Q;
    vector<ll> ans;
    for (int i = 0; i < Q; i++) {
        int l, r; cin >> l >> r;
        ans.push_back(f(r)-f(l-1));
    }
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 7156
from itertools import*
from scipy.sparse.csgraph import floyd_warshall
n,m,r=map(int,input().split())
*R,=map(int,input().split())

table=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    table[a-1][b-1]=c
    table[b-1][a-1]=c
d,p=floyd_warshall(csgraph=table, directed=False, return_predecessors=True)
cost=[sum(d[i[j]-1][i[j+1]-1]for j in range(r-1))for i in permutations(R)]
print(int(min(cost)))

Measured memory_bytes: 21284
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a*b>c*d)cout<<a*b<<endl;
	else cout<<c*d<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,W;
  cin >> N >> W;

  vector<ll> vec[5]; // vec(5)はダメ
  for(int i=0;i<5;i++) vec[i].clear();

  ll w,v,w0;
  cin >> w0 >> v;
  vec[0].push_back(v);
  for(int i=1;i<N;i++){
    cin >> w >> v;
    vec[w-w0].push_back(v);
  }
  for(int i=0;i<4;i++)sort(vec[i].begin(),vec[i].end(),greater<ll>());

  ll sum[5][120];
  for(int it=0;it<4;it++){
    sum[it][0]=0;
    for(int i=0;i<110;i++){
      sum[it][i+1]=sum[it][i]+(i<vec[it].size()?vec[it][i]:0);
    }
  }

  ll ans=0;
  for(int a=0;a<=N && w0*a <=W; a++){
    for(int b=0;b+a<=N && w0*a+(w0+1)*b <=W; b++){
      for(int c=0;c+b+a<=N && w0*a+(w0+1)*b+(w0+2)*c <=W; c++){
        ll d = min(N-a-b-c, (W-w0*a-(w0+1)*b-(w0+2)*c)/(w0+3));
        if (d < 0) continue;
        //ll d=(ll)N-a-b-c;
        //if(d<0 || w0*a+(w0+1)*b+(w0+2)*c+(w0+3)*d>W)continue;
        ll cnt=sum[0][a]+sum[1][b]+sum[2][c]+sum[3][d];
        if(ans<cnt)ans=cnt;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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



Measured memory_bytes: 2080
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int k;
cin>>k;
string s;
cin>>s;
if(k>=s.length())
{
cout<<s<<endl;
}
else
{
cout<<s.substr(0,k)<<"...";
}
}

Measured memory_bytes: 3652
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	for  {
		if x < y {
			x, y = y, x
		}
		x, y = y, x%y
		if y <=0 {
			break
		}
	}
	fmt.Println(x)
}



Measured memory_bytes: 1124
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void  solve(){
  ll n,m;
  cin>>n>>m;
  ll a[n];
  rep(i,0,n) cin>>a[i];
  vector<ll> pre(n,0);
  map<ll,int> m1;
  pre[0]=a[0]%m;
  m1[pre[0]]++;
  rep(i,1,n) pre[i]=(pre[i-1]+a[i])%m,m1[pre[i]]++;
  ll ans=0;
  ll modsum=0;
  rep(i,0,n){
    if(i!=0) ans+= m1[pre[i-1]];
    else ans+=m1[0];
    m1[pre[i]]--;
  }
  cout<<ans<<endl;
}

int main(){
    optimizeIO();
    solve();
    // solve1();
}


Measured memory_bytes: 8636
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  int x,y,z;
  cin>>x>>y>>z;
 
  cout<<z<<" "<<x<<" "<<y<<endl;
  
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
B = sorted(A)
ans = []
flag = 0
for i in range(N-K+1):
  ans.append(B[i+K-1]-B[i])
  flag = 1
print(min(ans) if flag == 1 else "0")

Measured memory_bytes: 17820
s = list(input())
s = [''] + s
t = list(input())
t = [''] + t
dp = [[0] * (len(t)) for _ in range(len(s))]

# dpテーブル作成

for i in range(1, len(s)):
    for j in range(1, len(t)):

        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]) 

answer_len = dp[len(s)-1][len(t)-1]

# dpテーブル逆走
answer = [0] * answer_len
i = len(s) -1
j = len(t) -1

while True:
    if dp[i][j] - dp[i-1][j-1] == 1 and dp[i][j] - dp[i][j-1] == 1 and dp[i][j] - dp[i-1][j] == 1:
        answer[answer_len-1] = s[i]
        answer_len -= 1
        i -= 1
        j -= 1
        if answer[0] != 0:
            break
    elif dp[i][j] - dp[i][j-1] == 1 and dp[i][j] - dp[i-1][j] != 1:
        i -= 1
    elif dp[i][j] - dp[i][j-1] != 1 and dp[i][j] - dp[i-1][j] == 1:
        j -= 1
    else:
        j -= 1

    if j == 0:
        j += 1
        i -= 1
    
    if i == 0:
        break
 
print(''.join(answer))

Measured memory_bytes: 144480
#include <iostream>
#include <vector>
#include <string.h>
#include <climits>
#include <algorithm>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

int N;
int L[210];

signed main()
{
    cin >> N;
    REP(i,2*N) cin >> L[i];

    sort(L, L + (2 * N));

    int ans = 0;
    for (int i=0; i<2*N; i+=2) {
        ans += L[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
// C++ 14
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define MAX_N 101

Int N;

void input() {
  cin >> N;
}

void solve() {
  loop(a,1,10) {
    loop(b,1,10) {
      if (N == a * b) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
  return;
}

int main() {
  input();
  solve();
}

Measured memory_bytes: 256
n,m = gets.strip.split.map(&:to_i)
pref = Array.new(n){Array.new}
i = 1
while i <= m do
  p,y = gets.strip.split.map(&:to_i)
  pref[p-1] << [i,y].to_a  #[市の番号,誕生年]
  i += 1
end
#すべて入力完了
#全ての配列を年代順にソート
city = Array.new(m)
j = 0
while j < n do
  unless pref[j] == nil
    pref[j].sort! {|a, b| a[1] <=> b[1] }
    k = 0
    while k < pref[j].size do
      city[pref[j][k][0]-1] = ('%012d' % ((j+1)*(10**6)+(k+1)))
      k += 1
    end
  end
  j += 1
end
m.times do |d|
  puts city[d]
end

Measured memory_bytes: 34316
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define swap(a,b) do{ll w=a;a=b;b=w;}while(0)
#define swapd(a,b) do{double w=a;a=b;b=w}while(0)
#define in(a) scanf("%lld", &(a))
#define ind(a) scanf("%lf", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a));
//def   puts(a) printf("%s\n", a) 文字はこっち
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll p=0, idx[5]={0};
    char s[3][101];
    rep(i,3) scanf("%s", s[i]);
    while(1){
        if(s[p][idx[p]]=='\0'){
            if(p==0) puts("A");
            else if(p==1) puts("B");
            else puts("C");
            return 0;
        }
        if(s[p][idx[p]]=='a'){
            idx[p]++;
            p=0;
        }
        else if(s[p][idx[p]]=='b'){
            idx[p]++;
            p=1;
        }
        else {
            idx[p]++;
            p=2;
        }
    }
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート 1,2....9
}


Measured memory_bytes: 128
from collections import defaultdict

n = int(input())
alist = list(map(int,input().split()))
q = int(input())


dict_n = defaultdict(lambda:0)

for i in alist:
    dict_n[i] += 1

bclist = []
for i in range(q):
    b,c  = map(int,input().split())
    bclist.append([b,c])

sum = sum(alist)
for i in range(q):
    
    b = bclist[i][0]
    c = bclist[i][1]

    sum += dict_n[b]*c - dict_n[b]*b
    dict_n[c] += dict_n[b]
    del(dict_n[b])

    print(sum)

Measured memory_bytes: 36548
import Data.List

func n (x:xs)
    | n > 0 = x + func (n-1) xs
    | otherwise = 0
func n [] = 0

main :: IO ()
main = do
    [n, k] <- map read . words <$> getLine :: IO [Int]
    h <- map read . words <$> getLine :: IO [Int]
    let v = sort h;
    print $ (func (n-k) v)

Measured memory_bytes: 96636
open Batteries

let read_two () = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))

let read_three () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> (a, b, c))

let read_four () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c d -> (a, b, c, d))

let read_list () =
  read_line () |> String.split_on_char ' '
  |> List.map (fun s -> int_of_string s)

(* a**x *)
let pow a x =
  let rec aux acc = function 0 -> acc | n -> aux (acc * a) (n - 1) in
  aux 1 x

let rec pow2 n = if n mod 2 = 0 then 1 + pow2 (n / 2) else 0

let rec f a b c =
  if a mod 2 <> 0 || b mod 2 <> 0 || c mod 2 <> 0 then 0
  else if a = b && b = c then -1
  else
    let aa = a / 2 and bb = b / 2 and cc = c / 2 in
    f (bb + cc) (aa + cc) (aa + bb) + 1

let () =
  let a, b, c = read_three () in
  let ans = f a b c in
  print_int ans;
  print_newline ()


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

int main() {
  uint64_t n, m;
  std::cin >> n >> m;
  std::vector<std::set<uint64_t>> e(n);

  for (uint64_t i = 0; i < m; i++) {
    uint64_t a, b;
    std::cin >> a >> b;
    e[a - 1].insert(b - 1);
    e[b - 1].insert(a - 1);
  }

  bool flag6 = false;
  uint64_t count4 = 0;
  for (const auto &i : e) {
    if (i.size() % 2 != 0) {
      std::cout << "No" << std::endl;
      return 0;
    } else if (i.size() == 4) {
      count4++;
    } else if (6 <= i.size()) {
      flag6 = true;
    }
  }

  if (flag6) {
    std::cout << "Yes" << std::endl;
    return 0;
  }

  if (3 <= count4) {
    std::cout << "Yes" << std::endl;
    return 0;
  } else if (count4 <= 1) {
    std::cout << "No" << std::endl;
    return 0;
  }

  int count = 0;
  std::vector<uint64_t> v;
  v.reserve(n);

  for (uint64_t i = 0; i < n; i++) {
    if (e[i].size() != 4) {
      continue;
    } else {
      bool flag = false;
      for (const auto j : e[i]) {
        auto now = i;
        auto next = j;
        while (e[next].size() != 4) {
          if (*e[next].cbegin() != now) {
            now = next;
            next = *e[next].cbegin();
          } else {
            now = next;
            next = *e[next].crbegin();
          }
        }
        if (next == i) {
          flag = true;
        }
      }

      if (flag) {
        std::cout << "Yes" << std::endl;
      } else {
        std::cout << "No" << std::endl;
      }
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 14336
#include<iostream>
#include<map>
#include<queue>
#include<string>
using namespace std;
int main(){
  int h,w,n,px,py,ans;
  int field[1000][1000];
  int ch[1000][1000];
  while(cin >>h>>w>>n){
    ans = 0;
    string s;
    for(int i=0; i<h; i++){
      cin >>s;
      for(int j=0; j<w; j++){
	if(s[j] == 'S'){px = j;py = i;field[j][i] = 0;}
	else if(s[j]>='1' && s[j]<='9'){field[j][i] = s[j]-'0';}
	else if(s[j] == 'X'){field[j][i] = -1;}
	else{field[j][i] = 0;}
      }
    }
    for(int i=0; i<n; i++){
      queue<pair<int,int> > play;
      play.push(make_pair(px,py));
      for(int j=0; j<h; j++){
	for(int k=0; k<w; k++){
	  ch[k][j] = 0;
	}
      }
      ch[px][py] = 1;
      for(;;){
	int x = play.front().first;
	int y = play.front().second;
	if(field[x][y] == i+1){ans+=ch[x][y]-1; px = x; py = y;break;}
	if(x>0){if(field[x-1][y] != -1){if(ch[x-1][y] == 0){play.push(make_pair(x-1,y)); ch[x-1][y] = ch[x][y]+1;}}}
	if(y>0){if(field[x][y-1] != -1){if(ch[x][y-1] == 0){play.push(make_pair(x,y-1)); ch[x][y-1] = ch[x][y]+1;}}}
	if(x<w-1){if(field[x+1][y] != -1){if(ch[x+1][y] == 0){play.push(make_pair(x+1,y)); ch[x+1][y] = ch[x][y]+1;}}}
	if(y<h-1){if(field[x][y+1] != -1){if(ch[x][y+1] == 0){play.push(make_pair(x,y+1)); ch[x][y+1] = ch[x][y]+1;}}}
	play.pop();
      }
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 9036
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        v: [i64; n],
    }

    let mut l_sum = vec![0];
    let mut l_mns = vec![vec![]];
    for vi in v.iter().copied() {
        let last = *l_sum.last().unwrap();
        l_sum.push(last + vi);

        let mut mns = l_mns.last().unwrap().clone();
        if vi < 0 {
            mns.push(vi);
        }
        l_mns.push(mns);
    }
    let l_sum = l_sum;
    let l_mns = l_mns;
    // dbg!(&l_mns);

    let mut r_sum = vec![0];
    let mut r_mns = vec![vec![]];
    for vi in v.iter().rev().copied() {
        let last = *r_sum.last().unwrap();
        r_sum.push(last + vi);

        let mut mns = r_mns.last().unwrap().clone();
        if vi < 0 {
            mns.push(vi);
        }
        r_mns.push(mns);
    }
    let r_sum = r_sum;
    let r_mns = r_mns;
    // dbg!(&r_mns);

    let mut ans = std::i64::MIN;
    for i in 0..=n {
        for j in 0..=(n - i) {
            if k < i + j {
                break;
            }
            let s = l_sum[i] + r_sum[j];
            let mut mns = l_mns[i].clone();
            let mut tmp = r_mns[j].clone();
            mns.append(&mut tmp);
            mns.sort();
            let k0 = k - (i + j);
            let d: i64 = mns[0..std::cmp::min(k0, mns.len())].iter().sum();
            let now = s - d;
            // dbg!(i, j, s, k0, mns, d, now);

            ans = std::cmp::max(ans, now);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2280
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	LL X, Y;
	cin >> X >> Y;
	LL ans = 0;
	while (X <= Y) {
		ans++;
		X *= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int n = Math.Abs(a-b);
    Console.WriteLine(n%2==1 ? "IMPOSSIBLE" : (Math.Min(a,b)+n/2).ToString());
  }
}


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

typedef long long ll;

int choose(int n) {
    return n * (n - 1) / 2;
}

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

    int n, m;
    cin >> n >> m;

    cout << choose(n) + choose(m) << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;   //author: madmin2619/mintu_agarwal
     
#define nfs() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define pf push_front
#define forin(i, n) for(int i=0;i<n;i++)
#define tr(c, it) for(auto it=c.begin();it!=c.end();it++)
#define sz(c) c.size()
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define m_p(x, y) make_pair(x, y)
     
const int M = 1e9 + 7;
     
int32_t main(){
    nfs()
    int t, n, i, j, k;
    cin >> n;
    vector<int> h(n);
    forin(i, n)	cin >> h[i];
    vector<int> dp(n, M);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++){
    	dp[i]=min(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
    	dp[i]=min(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << "\n";
    return 0;
}

Measured memory_bytes: 1792
using System.Collections.Generic;
using System;

public class P
{
    public string parent { get; set; }
    public List<string> child { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var a = new string[m];
            var pp = new string[n];
            var ppp = 0;
            var d = new Dictionary<string, P>();
            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine();
                var sp = s.Length - s.Replace(" ", "").Length;
                ppp = sp;
                s = s.Trim();
                pp[ppp] = s;
                if (sp >= 1)
                {
                    d[pp[sp - 1]].child.Add(s);
                    d[s] = new P { parent = pp[sp - 1], child = new List<string>() };
                }
                else d[s] = new P { parent = "no", child = new List<string>() };
            }
            var t = new string[3];
            for (int i = 0; i < m; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                var a1 = line[0];
                var a2 = line[3];
                var a3 = line[5].Replace(".", "");
                Console.WriteLine(getAns(d, a1, a2, a3) ? "True" : "False");
            }
            Console.WriteLine();
        }
    }
    static bool IsAncestor(Dictionary<string, P> d, string a1, string a3)
    {
        var nt = a3;
        while (true)
        {
            var np = d[nt].parent;
            if (np == a1) return true;
            else if (np == "no") return false;
            nt = np;
        }
    }
    static bool getAns(Dictionary<string, P> d, string a1, string a2, string a3)
    {
        if (a2 == "child") return d[a3].child.Contains(a1);
        if (a2 == "parent") return d[a3].parent == a1;
        if (a2 == "sibling") return d[a1].parent == d[a3].parent;
        if (a2 == "ancestor") return IsAncestor(d, a1, a3);
        else return IsAncestor(d, a3, a1);
    }
}



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

l_march = [0] * 5
for _ in range(n):
    lin = input()
    initial = lin[0]
    if initial == 'M':
        l_march[0] += 1
    elif initial == 'A':
        l_march[1] += 1
    elif initial == 'R':
        l_march[2] += 1
    elif initial == 'C':
        l_march[3] += 1
    elif initial == 'H':
        l_march[4] += 1

l_march = (list)(filter(lambda x: x > 0, l_march))

len_l = len(l_march)
ans = 0


for i in range(len_l):
    for j in range(i+1, len_l):
        for k in range(j+1, len_l):
            ans += l_march[i] * l_march[j] * l_march[k]

print(ans)


Measured memory_bytes: 3064
import sys
import itertools
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
D = LI()

ans = 0
for v in itertools.combinations(D, 2):    
    ans += v[0]*v[1]
print(ans)


Measured memory_bytes: 38512
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();int m=sc.nextInt();
	int po[]=new int[n];
  for(int i=0;i<n;i++){
    po[i]=sc.nextInt();
    m-=po[i];
  }
  Arrays.sort(po);
  System.out.println(n+m/po[0]);
}}

Measured memory_bytes: 21844
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 1000100
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans;
}
ll inv(ll a)
{
    return power(a,MOD-2,MOD);
}
//code begins
ll b[N];
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin.sync_with_stdio(false);
    ll t;
    t=1;
//    cin>>t;
    while(t--)
    {
        ll h,c;cin>>h>>c;
        if(h==1 || c==1)
        {
            cout<<1<<endl;
            continue;
        }
        ll ans=((h/2)*(c/2))+(ceil(h*1.0/2.0)*ceil(c*1.0/2.0));
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
cnt1=0
cnt=0
for i in range(n):
    if a[i]%4==0:
        cnt+=1
    if a[i]%4!=0 and a[i]%2==0:
        cnt1+=1
if cnt+cnt1//2>=n//2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

vi dp(101010,-1);

int dfs(int pos, vvi &v){
    if(dp[pos]>0)return dp[pos];
    else if(v[pos].size()==0){
        return 0;
    } else {
        int res=0;
        for(int i=0;i<v[pos].size();i++){
            chmax(res,1+dfs(v[pos][i],v));
        }
        return dp[pos]=res;
    }
}

int main() {
    
    int n,m;
    cin>>n>>m;
    vvi v(n);
    int ans=0;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].pb(b);
    }
    rep(i,n){
        chmax(ans,dfs(i,v));
    }
    fin(ans);
}

Measured memory_bytes: 8192
#include<iostream>
using namespace std;
int main(){
    int i,j,k,H,W;
    while(1){
        cin >>H >>W;
        if(H==0 && W==0) break;
        for (i=1; i<=H; i++){
            if (i==1 ||i==H){
                for (j=1;j<=W;j++){
                    cout<<"#";
                }
            
            }
            else{
            for (k=1;k<=W;k++){
                if(k==1 || k==W)  {
                    cout<<"#";
                }
                else{
                    cout<<".";
                }
        
            }
            
            }
        
        
       
        
        cout<<endl;
       
        
    }
    
    cout<<endl;
    }

    return 0;
}



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

using namespace std;

const int MAXN = 1E5;
int a[MAXN];
long long sv[MAXN];

int main()
{
    int n, m;
    cin >> n >> m;
    int prev;
    cin >> prev;
    prev--;
    long long ans = 0;
    for (int i = 0; i < n - 1; i++)
    {
        int cur;
        cin >> cur;
        cur--;
        ans += (cur - prev + m) % m;
        if ((cur - prev + m) % m >= 2)
        {
            int s = (prev + 2) % m;
            int t = cur;
            sv[s]++;
            if (s > t)
            {
                int k = m - s;
                sv[0] += k + 1;
                sv[1] -= k;
            }
            int x = (t - s + m + 1) % m;
            if (t + 1 < m)
                sv[t + 1] -= x + 1;
            if (t + 2 < m)
                sv[t + 2] += x;
        }
        prev = cur;
    }
    for (int i = 0; i < 2; i++)
    {
        for (int j = 1; j < m; j++)
        {
            sv[j] = sv[j] + sv[j - 1];
        }
    }
    long long bigSave = 0;
    for (int i = 0; i < m; i++)
        bigSave = max(bigSave, sv[i]);
    cout << ans - bigSave << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(void)
{

	int num;
	int ave;
	
	while (cin >> num && num != 0 )
	{
		int a[num];
		int sum = 0, max = 0, min = 1000;
		for(int i = 0;i < num; i++)
		{
			cin >> a[i];
			sum += a[i];
			if(a[i] <= min)
				min = a[i];
			if(a[i] >= max)
				max = a[i];
		}
		ave = (sum - max - min) / (num - 2);
		cout << ave << endl;
	}

	return 0;
}


Measured memory_bytes: 3084
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num[] = new int[3];
		int n;
		
		n = scanner.nextInt();
		for(int i = 0; i < n; i++) {
			num[i] = scanner.nextInt();
		}
		
		int minNum;
		
		if (n == 2) {
			minNum = Math.min(num[0], num[1]);
			for(int i = 1; i <= minNum; i++) {
				if (num[0] % i == 0 && num[1] % i == 0) {
					System.out.println(i);
				}
			}
		} else {
			minNum = Math.min(Math.min(num[0], num[1]), num[2]);
			for(int i = 1; i <= minNum; i++) {
				if (num[0] % i == 0 && num[1] % i == 0 && num[2] % i == 0) {
					System.out.println(i);
				}
			}
		}
	}
}

Measured memory_bytes: 26124
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      int d = sc.nextInt();
      Boolean f = true;
      for (int ii = 0; ii < arr.length; ii++) {
        if (arr[ii] == d) {
          f = false;
          break;
        }
      }
      if (f) {
        arr[i] = d;
        cnt += 1;
      }
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 23636
#include "bits/stdc++.h"
using namespace std;
vector<int> a;
int main()
{
    int n,i,count=0;
    scanf("%d",&n);
    a.resize(n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<n-1;i++)
    {
        if(a[i]>a[i-1]&&a[i]<a[i+1])
        {
            count++;
        }
        else if(a[i]<a[i-1]&&a[i]>a[i+1])
        {
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

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

int main(){
	int n,c;
	cin>>n>>c;
	vector<valarray<int>> tm(c+1,valarray<int>(0,100001));
	rep(i,n){
		int s,t,cc; cin>>s>>t>>cc;
		tm[cc][s-1]++;  tm[cc][t]--;
	}
	for(auto&p:tm){
		partial_sum(begin(p),end(p),begin(p));
		p=p.apply([](int x){return x?1:0;});
	}
	cout<<accumulate(all(tm),tm[0]).max()<<endl;

	return 0;
}


Measured memory_bytes: 12920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
int n;
int euler(int n)
{
  int s=n;
  int m=sqrt(n);
  for(int i=2;i<=m;i++)
  {
      if(n%i==0) s=s/i*(i-1);
      while(n%i==0) n/=i;
  }
  if(n>1) s=s/n*(n-1);
  return s;

}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    printf("%d\n",euler(n));
    return 0;

}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

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

ll cal(vector<P> v){
	ll ret = 0;
	priority_queue<ll> pq;
	ll pla = 0;
	REV(i, v.size()){
		while(pla < v.size() && v[pla].FI >= i){
			pq.push(v[pla].SE);
			pla++;
		}
		if(!pq.empty()){
			ret += pq.top();
			pq.pop();
		}
	}
	return ret;
}

void solve(){
	ll n;cin >> n;
	vector<P> a;
	vector<P> b;
	ll ans = 0;

	REP(i, n){
		ll k, l, r;cin >> k >> l >> r;
		if(l < r)b.PB(MP(n - k - 1, r - l));
		else a.PB(MP(k - 1, l - r));
		ans += min(l, r);
	}

	sort(ALL(a), greater<P>());
	sort(ALL(b), greater<P>());
	ans += cal(a);
	ans += cal(b);
	cout << ans << endl;
}

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

	ll t;cin >> t;
	REP(i, t)solve();

	return 0;
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, q;
  cin >> n >> q;

  UnionFind uf(n);
  rep(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if(com == 0) uf.unite(x, y);
    else cout << uf.same(x, y) << endl;
  }

  return 0;
}

Measured memory_bytes: 3312
import java.util.*;

public class Main {

    long MOD = (long) 1e9 + 7;

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n + 1];
        int[] c0 = new int[n + 1];
        c0[0] = 1;

        HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();

        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            b[i] ^= b[i - 1] ^ a[i];
            c0[i] = c0[i - 1] + (b[i] == 0 ? 1 : 0);
            if (b[i] != 0) {
                ArrayList<Integer> l = map.getOrDefault(b[i], new ArrayList<>());
                l.add(i);
                map.put(b[i], l);
            }
        }

//        debug(a);
//        debug(b);
//        debug(c0);
//        debug(map);

        if (b[n] != 0) {
            long[] z = new long[2];
            long[] x = new long[2];

            int f = 0;
            z[0] = 1;

            for (int i = 1; i <= n; i++) {
                f = 1 - f;
                z[f] = (z[1 - f] + (b[i] == 0 ? x[1 - f] : 0)) % MOD;
                x[f] = (x[1 - f] + (b[i] == b[n] ? z[1 - f] : 0)) % MOD;
//                debug(x[f], z[f]);
            }

            System.out.println(z[f]);
        } else {
            long ans = 1;
            for (int i = 1; i <= c0[n] - 2; i++) ans = (ans * 2) % MOD;
            for (Map.Entry<Integer, ArrayList<Integer>> entry: map.entrySet()) {
                long[] z = new long[2];
                long[] x = new long[2];

                int f = 0;
                z[0] = 1;

                ArrayList<Integer> ps = entry.getValue();
                int len = ps.size();
                for (int i = 0; i < len; i++) {
                    f = 1 - f;
                    z[f] = z[1 - f];
                    x[f] = (x[1 - f] + z[1 - f]) % MOD;
//                    debug(entry.getKey(), z[f], x[f]);
                    if (i < len - 1 && c0[ps.get(i + 1)] - c0[ps.get(i) - 1] > 0) {
                        f = 1 - f;
                        z[f] = (z[1 - f] + x[1 - f] * (c0[ps.get(i + 1)] - c0[ps.get(i) - 1]) % MOD) % MOD;
                        x[f] = x[1 - f];
//                        debug(entry.getKey(), z[f], x[f]);
                    }
                }
//                debug(entry.getKey(), x[f], z[f]);
                ans = (ans + x[f]) % MOD;
            }
            System.out.println(ans);
        }

    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 221484
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  int N,D;
  cin>>N>>D;
  int x[50][50];
  rep(i,N){
    rep(j,D){
      cin>>x[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
     int dis=0;
     for(int k=0;k<D;k++){
       dis=dis+(x[j][k]-x[i][k])*(x[j][k]-x[i][k]);
     }
     for(int l=1;l*l<=16000;l++){
         if(dis==l*l){
           ans++;
           break;
         }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(void){
  int num,md,m,save[21],*now,max,min,l,i,j,k;
  while(1){
    scanf("%d %d",&num,&l);
    if(num==0&l==0) return 0;
    save[0]=num;
    //printf("%d\n",save[0]);
    now=(int *)calloc(l,sizeof(int));
    for(k=0;k<20;k++){
      //printf("save[%d]=%d\n",k,save[k]);
      for(i=l-1;i>=0;i--){
	now[i]=num%10;
	num/=10;
	//printf("%d",now[i]);
      }
      /*printf("save[%d]:",k);
      for(i=0;i<l;i++) printf("%d",now[i]);
      putchar('\n');*/
      max=0;
      min=0;
      for(i=0;i<l-1;i++){
	m=0;
	for(j=i;j<l;j++) if(m<now[j]){
	    m=now[j];
	    md=j;
	  }
	//printf("m:%d md:%d\n",m,md);
	for(j=md;j>i;j--) now[j]=now[j-1];
	now[i]=m;
	/*for(j=0;j<l;j++) printf("%d",now[j]);
	  putchar('\n');*/
      }
      int ten=1;
      for(j=0;j<l;j++,ten*=10){
	max+=now[l-j-1]*ten;
	min+=now[j]*ten;
      }
      //printf("%d max:%d,min:%d\n",k+1,max,min);
      save[k+1]=max-min;
      // printf("%d\n",save[k+1]);
      for(i=0;i<k+1;i++){
	if(save[i]==save[k+1]) goto clear;
      }
      num=save[k+1];
    }
  clear:
    printf("%d %d %d\n",i,save[k+1],k+1-i);
    free(now);
  }
  return 0;
}
    
    
  

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int N,K;
int main(){
    cin>>N>>K;
    int d[K];
    int ans[N]={0};
    int tmp;
    int cnt=0;
    for(int i=0;i<K;i++){
        cin>>d[i];
        for(int j=0;j<d[i];j++){
            cin>>tmp;
            ans[tmp-1]+=1;
        }
    }
    for(int k=0;k<N;k++){
        if(ans[k]==0)cnt++;
    }
    cout<<cnt;
    return 0;
}

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

int main() {
	long long int H, W, x, y,count=0;
	cin >> H >> W;

	if (H == 1) count = 1;
	else if (W == 1) count = 1;
	else if (H % 2 == 0) count = H / 2 * W;
	else if (H % 2 == 1) {
		x = (H / 2 + 1);
		y = H / 2;
		if (W % 2 == 1) {
			count = x * (W / 2 + 1) + y * (W/2);
			}
		else {
			count = (x + y) * W / 2;
		}

	}
	cout << count;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

total = sum(a)

for i in range(n):
  if b[i] > a[i]:
    b[i] -= a[i]
    a[i] = 0
    a[i+1] = max(0, a[i+1]-b[i])
  else:
    a[i] -= b[i]

print(total - sum(a))

Measured memory_bytes: 24164
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max({a * c, a * d, b * c, b * d}) << endl;
  return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;
public class Main {
	
	public static void Bomb(int Array[][],int x,int y){
		Array[x][y]=0;
		if(x>0&&Array[x-1][y]==1){
			Bomb(Array,x-1,y);
		}
		if(x>1&&Array[x-2][y]==1){
			Bomb(Array,x-2,y);
		}
		if(x>2&&Array[x-3][y]==1){
			Bomb(Array,x-3,y);
		}
		if(y>0&&Array[x][y-1]==1){
			Bomb(Array,x,y-1);
		}
		if(y>1&&Array[x][y-2]==1){
			Bomb(Array,x,y-2);
		}
		if(y>2&&Array[x][y-3]==1){
			Bomb(Array,x,y-3);
		}
		if(x<7&&Array[x+1][y]==1){
			Bomb(Array,x+1,y);
		}
		if(x<6&&Array[x+2][y]==1){
			Bomb(Array,x+2,y);
		}
		if(x<5&&Array[x+3][y]==1){
			Bomb(Array,x+3,y);
		}
		if(y<7&&Array[x][y+1]==1){
			Bomb(Array,x,y+1);
		}
		if(y<6&&Array[x][y+2]==1){
			Bomb(Array,x,y+2);
		}
		if(y<5&&Array[x][y+3]==1){
			Bomb(Array,x,y+3);
		}
		
	}
	
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int dataset;
		dataset=sc.nextInt();
		for(int i=0;i<dataset;i++){
			int board[][]= new int[8][8];
			for(int j=0;j<8;j++){
				int tmp;
				tmp=sc.nextInt();
				for(int k=0;k<8;k++){
					board[j][k]=(int) (tmp/(Math.pow(10, 7-k)));
					if(board[j][k]==1){
						tmp-=(int)Math.pow(10, 7-k);
					}
				}
			}
			int x,y;
			x=sc.nextInt();
			y=sc.nextInt();
			Bomb(board,y-1,x-1);
			System.out.println("Data "+(i+1)+":");
			for(int j=0;j<8;j++){
				for(int k=0;k<8;k++){
					System.out.print(board[j][k]);
					if(k==7){
						System.out.print("\n");
					}
				}
			}
		}
		
			
		
		
		
	}
}

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

int main(){
  int n; cin >> n;
  vector<vector<int>> to(n),cost(n);
  rep(i,n-1){
  int a,b,w; cin >> a >> b >> w;
  a--; b--;
  to[a].push_back(b); cost[a].push_back(w);
  to[b].push_back(a); cost[b].push_back(w);
  }
  vector<int> ans(n,-1);
  queue<int> q;
  ans[0]=0;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    rep(i,to[v].size()){
    int u=to[v][i]; int z = cost[v][i];
    if(ans[u] != -1) continue;
    ans[u] = (ans[v]+z) %2;
    q.push(u);
  }
  }
  rep(i,n) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 11904
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;

int main(int argc, char *argv[])
{
	string s;

	cin >> s;

	int ret;
	if (s=="SAT") ret=1;
	if (s=="FRI") ret=2;
	if (s=="THU") ret=3;
	if (s=="WED") ret=4;
	if (s=="TUE") ret=5;
	if (s=="MON") ret=6;
	if (s=="SUN") ret=7;

	cout << ret << endl;
	return 0;
}



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll n; cin >> n;
  ll k; cin >> k;
  // ll x, y, z; cin >> x >> y >> z;
  // string s; cin >> s;
  vector<ll> snk(n); REP(i, n) snk[i] = 0;
  vector<ll> d(k);
  ll a[110][110];
  REP(i, k) {
    cin >> d[i];
    REP(j, d[i]) {
      cin >> a[i][j];
      snk[a[i][j]-1] ++;
    }
  }
  ll ans = 0;
  REP(i, n) {
    //    cout << i << " " << snk[i] << endl;
    if(snk[i] == 0) ans++;
  }
  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


Measured memory_bytes: 3672
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    println!("{}", std::cmp::max(0, a - 2 * b));
}


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

#define rep(i,s,e) for (int i = s; i < e; ++i)
using namespace std;

int x[100001];
int y[100001];
int t[100001];
int main()
{
	int N; cin >> N;

	bool OK = true;
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	rep(i, 1, N + 1) {
		cin >> t[i] >> x[i] >> y[i];

		int diff_t = t[i] - t[i - 1];
		int diff_d = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		if (diff_t < diff_d) {
			OK = false;
			break;
		}
		else if (diff_t > diff_d) {
			if ((diff_t - diff_d) % 2 != 0) {
				OK = false;
				break;
			}
		}
	}
	cout << (OK ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
int main()
{
	ll a,b;
	cin>>a>>b;
	for(int i=0;i<=20;i++){
		ll tmp = a*i-i+1;
		if(tmp >= b)
		{
			cout<<i<<"\n";return 0;
		}
	}
	return 0;
}

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

set<int>s;

int main () {

int n;
cin >> n;
int a;
for (int i = 0; i < n; i ++) {
	cin >> a;
	int ss = s.size();
	s.insert(a);
	if (ss == s.size()) {s.erase(a);}
}
cout << s.size();

return 0;
}


Measured memory_bytes: 4864
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    int sum = 0;
    for (int i = 0;i < n;i++){
        cin >> s[i];
        sum += s[i];
    }

    if (sum % 10 != 0){
        cout << sum << endl;
        return 0;
    }
    sort(s.begin(), s.end());
    for (int i = 0;i < n;i++){
        if (s[i] % 10 != 0){
            cout << sum - s[i] << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}

Measured memory_bytes: 3640