akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 200000//頂点数
#define LOG 20
#define ROOT 0
class GRAPH
{
public:
	int num;//頂点数
	vector<int>pat[SIZE];
	vector<int>rev[SIZE];
	vector<int>etype[SIZE];//1:木辺 2:木辺の逆辺 -1:後退辺 -2:後退辺の逆辺 自己ループ非対応
	int ord[SIZE];
	int low[SIZE];
	int ordpt;
	bool flag[SIZE];
	bool isroot[SIZE];
	void undirectedadde(int s, int t)//s-t無向辺を追加
	{
		pat[s].push_back(t);
		pat[t].push_back(s);
		rev[s].push_back(pat[t].size() - 1);
		rev[t].push_back(pat[s].size() - 1);
		etype[s].push_back(0);
		etype[t].push_back(0);
	}
	void lowdfs(int node)
	{
		if (flag[node])return;
		flag[node] = true;
		ord[node] = ordpt++;
		for (int i = 0; i < pat[node].size(); i++)
		{
			if (!flag[pat[node][i]])
			{
				etype[node][i] = 1;
				etype[pat[node][i]][rev[node][i]] = 2;
				lowdfs(pat[node][i]);
			}
			else
			{
				if (etype[node][i] == 0)
				{
					etype[node][i] = -1;
					etype[pat[node][i]][rev[node][i]] = -2;
				}
			}
		}
	}
	void lowcalc(int node)
	{
		low[node] = ord[node];
		for (int i = 0; i < pat[node].size(); i++)
		{
			if (etype[node][i] == 1)
			{
				lowcalc(pat[node][i]);
				low[node] = min(low[node], low[pat[node][i]]);
			}
			if (etype[node][i] == -1)
			{
				low[node] = min(low[node], ord[pat[node][i]]);
			}
		}
	}
	bool isbridge(int node, int k)//node-pat[node][k]が橋かどうか
	{
		if (etype[node][k] <= 0)return false;
		if (etype[node][k] == 2)
		{
			int t = pat[node][k];
			k = rev[node][k];
			node = t;
		}
		if (low[pat[node][k]] > ord[node])return true;
		else return false;
	}
	bool isartic(int node)//nodeが関節点かどうか
	{
		if (isroot[node])
		{
			int cnt = 0;
			for (int i = 0; i < pat[node].size(); i++)if (etype[node][i] == 1)cnt++;
			if (cnt >= 2)return true;
			else return false;
		}
		else
		{
			for (int i = 0; i < pat[node].size(); i++)
			{
				if (etype[node][i] == 1)
				{
					if (low[pat[node][i]] >= ord[node])return true;
				}
			}
			return false;
		}
	}
};
GRAPH gr;
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		gr.undirectedadde(za, zb);
	}
	gr.num = num;
	gr.lowdfs(0);
	gr.lowcalc(0);
	int r = 0;
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j < gr.pat[i].size(); j++)r += gr.isbridge(i, j);
	}
	printf("%d\n", r / 2);
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if(C >= B || A >= D) cout << 0 << endl;
  else if (C >= A && B >= D) cout << D - C << endl;
  else if (A >= C && D >= B) cout << B - A << endl;
  else if (C >= A && D >= B) cout << B - C << endl;
  else if (A >= C && B >= D) cout << D - A << endl;
  
  
}

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

int main(){
    int h,w; cin >> h >> w;
    long count = 0;
    

    if(h > 1 && w > 1){
        if(w%2==0){
            count = floor(h/2.0)*w/2+ceil(h/2.0)*w/2;
        }else{
            count = floor(h/2.0)*floor(w/2.0)+ceil(h/2.0)*ceil(w/2.0);
        }
    }else{
        count = 1;
    }

    printf("%ld",count);
}

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

int main(void){
    int N,tmp,max=0,Alice=0,Bob=0;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        max=i;
        for(int j=i+1;j<N;j++){
            if(a[max]<a[j]){
                max=j;
            }
        }
        tmp=a[i];
        a[i]=a[max];
        a[max]=tmp;
    }
    for(int i=0;i<N;i++){
        if(i%2==0){
            Alice+=a[i];
        }else{
            Bob+=a[i];
        }
    }
    cout << Alice-Bob << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int N, A;
  cin >> N >> A;

  cout << (N % 500 <= A ? "Yes" : "No") << endl;

  return 0;
}


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int p, q, r;
    cin >> p >> q >> r;
    cout << min(p + q, min(q + r, r + p)) << endl;
}

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

// #define SIZE (200000)
#define SIZE (65536 * 4)
#define LEN (16)

int flag[SIZE];
char table[SIZE][LEN];

int hash(char *str)
{
        int i;
        int val;

        i = 0;
        val = 0;
        while(str[i] != '\0') {
                val = (val * 27 + (str[i] - 'a')) % SIZE;
                ++i;
        }

        return val;
}

main()
{
        int i;
        int n;
        int s;
        char buf[LEN];

        memset(table, 0x00, sizeof(table));

        s = 0;
        scanf("%d", &n);
        for(i = 0; i < n; ++i) {
                int j;

                scanf("%s", buf);
                j = hash(buf);
                while(1) {
#if 0
                        if(strcmp(buf, table[j]) == 0) {
                                break;
                        }
                        if(flag[j] == 0) {
                                flag[j] = 1;
                                s++;
                                break;
                        }
#endif
                        if(strcmp(buf, table[j]) == 0) {
                                break;
                        }
                        if(table[j][0] == '\0') {
                                strcpy(table[j], buf);
                                s++;
                                break;
                        }
                        j = (j + 1) % SIZE;
                }
        }
        printf("%d", s);
}

Measured memory_bytes: 5828
#include <iostream>
#define MOD 1000000007
using namespace std;

int N;

int main() {
    cin >> N;
    int cnt[N] = {};
    for (int i = 0; i < N; i++) {
        int t; cin >> t;
        cnt[t]++;
    }
    if ((N % 2 == 1 && cnt[0] != 1) || (N % 2 == 0 && cnt[0] != 0)) {
        cout << 0 << endl;
        return 0;
    }
    long long ans = 1;
    for (int i = N % 2 + 1; i < N; i+=2) {
        if (cnt[i] != 2) {
            cout << 0 << endl;
            return 0;
        }
        ans = ans * 2 % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.*;
import java.util.Arrays;

public class Main {
	static int[] isOk = new int[10000];
	static int x;
	static int a;
	static int b;
	public static void main(String[] args){
		Arrays.fill(isOk, 0);
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
		if(b-a<=0){
			System.out.println("delicious");
		}else if(b-a>x){
			System.out.println("dangerous");
		}else{
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n){
        cin>>v[i];
    }
    int l=0;int r=1;
    int ma=0;
    int k=0;
    for(int i=0;i<n-1;i++){
        if(v[i]>=v[i+1]){
            k++;
        }else{
            ma=max(k,ma);
            k=0;
        }
    }
    if(k!=0){
        ma=max(k,ma);
    }
    cout<<ma<<endl;






    return 0;
}


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

// {{{
#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        c: String,
    }

    let c = c.chars().next().unwrap();
    let ans = ((c as u8) + 1) as char;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main(){
    int H,W;
    while(1){
        cin >> H;
        cin >> W;
        if(H==0){
            break;
        }

        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if((i+j)%2 == 0){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
N, M = map(int, input().split())
A = [int(input()) for _ in range(N)]
B = [int(input()) for _ in range(M)]

vote = [0] * N
vote_max = 0
ans = -1
for b in B:
    for i in range(N):
        if A[i] <= b:
            vote[i] += 1
            if vote_max < vote[i]:
                vote_max = vote[i]
                ans = i
            break

print(ans + 1)


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

int main() {
	int A, B;
	cin >> A >> B;
	if((A + B) % 2 == 0){
		cout << (A + B) / 2 << endl;
	}
	else{
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A [] = new int[200001];
		int j = 0;
		
		for(int i =1; i<N; i++) {
			j = sc.nextInt();
			A[j] = A[j]+1;
			j++;
		}
		
		for(int i=1; i<N+1; i++) {
			if(A[i] > 0) {
				System.out.println(A[i]);
			}else{
				A[i] = 0;
				System.out.println(A[i]);
			}
		}
		
		sc.close();
	}
}

Measured memory_bytes: 70544
from math import ceil
time = [int(input()) for i in range(5)]
mod = []
for t in time:
    if t % 10 == 0: mod.append(10)
    else: mod.append(t % 10)

total = 0
for i in range(5):
    total += 10 * ceil(time[i]/10)
total -= (10 - min(mod))
print(total)

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int a, b, c;
	int i,num;

	while(scanf("%d %d %d", &a, &b, &c) == 3)
	{
		num = 0;
		for(i = a; i <= b; i++)
		{
			if(c % i == 0)
			{
				num = num + 1;
			}
		}
		printf("%d\n",num);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
#define lli long long int
int main(){
  lli i=1,n,q,j,flag=1;
  cin>>n>>q;
  string s;cin>>s;
  lli dp[n+1];
  dp[0]=0;
  while(i<n){
    if(s.substr(i-1,2)=="AC"){
      dp[i]=dp[i-1];
      dp[i+1]=dp[i]+1;
      i++;
    }
    else{
      dp[i]=dp[i-1];
    }
    i++;
  }
  if(dp[n]!=dp[n-1]+1)
    dp[n]=dp[n-1];
  for(i=0;i<q;i++){
    lli l,r;
    cin>>l>>r;
    cout<<dp[r]-dp[l]<<"\n";
  }
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long q = sc.nextInt();
        long h = sc.nextInt();
        long s = sc.nextInt();
        long d = sc.nextInt();
        long n = sc.nextInt();
        long money = 0;
        long v[] = new long[4];
        v[0] = q * 8;
        v[1] = h * 4;
        v[2] = s * 2;
        v[3] = d;
        if (v[0] <= v[1] && v[0] <= v[2] && v[0] <= v[3]) {
            money = n * 4 * q;
        } else if (v[1] <= v[2] && v[1] <= v[3]) {
            money = n * 2 * h;
        } else if (v[2] <= v[3]) {
            money = n * s;
        } else if (n % 2 == 0) {
            money = n / 2 * d;
        } else if (v[0] <= v[1] && v[0] <= v[2]) {
            money = n / 2 * d + q * 4;
        } else if (v[1] <= v[2]) {
            money = n / 2 * d + h * 2;
        } else {
            money = n / 2 * d + s;
        }
        System.out.println(money);
    }
}


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

#define PI 3.14159265358979323846

// #define ll long long int
#define ff first
#define ss second
// #define int long long int
#define pb push_back

#define N 10000010
#define MOD 1000000007

int bexp(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }   
    int dp[n] = {};
    dp[1] = abs(a[1] - a[0]);
    for (int i = 2; i < n; ++i)
     {
         dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2])); 
     } 
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 4360
using System;

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

            var n = a - (b * 2);
            Console.WriteLine(n > 0 ? n : 0);
        }
    }
}


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

using namespace std;
int g[100005];
int x[100005][2];
int u[100005];
vector<pair<long long,pair<int,int> > >v;
int FIND(int p){
	if(g[p]==p)return p;
	else return g[p]=FIND(g[p]);
}
void UNION(int p,int q){
	g[FIND(p)]=FIND(q);
}
bool cmp1(int a,int b){
	return x[a][0]<x[b][0];
}
bool cmp2(int a,int b){
	return x[a][1]<x[b][1];
}
int main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)cin>>x[i][0]>>x[i][1]; 
	for(int i=1;i<=n;i++)u[i]=g[i]=i;
	sort(u+1,u+n+1,cmp1);
	for(int i=1;i<n;i++){
		v.push_back(make_pair(x[u[i+1]][0]-x[u[i]][0],make_pair(u[i],u[i+1])));
	}
	sort(u+1,u+n+1,cmp2);
	for(int i=1;i<n;i++){
		v.push_back(make_pair(x[u[i+1]][1]-x[u[i]][1],make_pair(u[i],u[i+1])));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		if(FIND(v[i].second.first)==FIND(v[i].second.second))continue;
		ans+=v[i].first;
		UNION(v[i].second.first,v[i].second.second);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

vector<int> no;
vector<int> nore;

int main()
{
    int m,K;
    cin >> m >> K;

    if(K == 0){
        for(int i = 0;i < (1<<m);i++) {
            if(i) printf(" %d",i);
            else printf("%d",i);
        }
        for(int i = (1<<m)-1;i>=0;i--){
            printf(" %d",i);
        }
        printf("\n");
        return 0;
    }

    int max_m = (1 << m)-1;

    if(max_m + 1 <= K || (m == 1 && K == 1)) {printf("-1\n");return 0;}

    if(max_m == K) max_m--;

    int another = K ^ max_m;

    for(int i = 0;i < (1<<m);i++){
        if(i!= K && i!=max_m && i != another) no.push_back(i);
    }

    nore = no;
    reverse(ALL(nore));

    int blank = 0;
    printf("%d",K);
    blank = 1;

    _for(i,0,no.size()){
        printf(" %d",no[i]);
    }

    printf(" %d %d",max_m,another);
    printf(" %d",K);
    printf(" %d %d",another,max_m);

     _for(i,0,nore.size()){
        printf(" %d",nore[i]);
    }

    printf("\n");
    return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, m;
  cin >> n >> m;
  vector<set<int>> to(n);
  REP(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].insert(b);
    to[b].insert(a);
  }
  vector<int> p(n);
  REP(i, n) p[i] = i;
  int ans = 0;
  do{
    if(p[0] != 0) break;
    bool ok = true;
    REP(i, n-1){
      if(to[p[i]].count(p[i+1]) == 0) ok = false;
    }
    if(ok) ans++;
  }while(next_permutation(ALL(p)));
  cout << ans << endl;
  return 0;
}

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



int main() {
    string s;
    cin >> s;
    
    rep(i,s.size()) {
        cout << "x";
    }
    cout << endl;
    
    
    return 0;
}


Measured memory_bytes: 3564
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int X,t;
	cin >> X >> t;
	int ans = X-t;
	if(ans<0) ans=0;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int maxn=10000;
using namespace std;
char a[200][200];
int main(){
	int i,j;
	int k,l;
	long long  n,m;
//	freopen("in.txt","r",stdin);
    scanf("%lld",&n);
	int ans=0;
	for(i=sqrt(n);i>0;i--){
		if(n%i==0)
		 {
		 	 m=n/i;
		 	 break;
		 }
	}
	while(m>0){
		ans++;
		m/=10;
	}
	cout << ans;
}

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

int main(){
	int A,B;
	cin>>A>>B;
	
	int wa=A+B;
	int sa=A-B;
	int seki=A*B;
	
	int max=wa;
	if(max<sa)
		max=sa;
	if(max<seki)
		max=seki;
	cout<<max;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int h[n+1];
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    int dp[n+1];
    dp[1]=0; dp[2] = abs(h[2]-h[1]);
    for(int i = 3; i <= n; i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n];
}

Measured memory_bytes: 4292
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()

  l=[]
  for _ in range(m):
    a=LI()
    l.append(a[1:])

  l2=LI()

  pattern=[]
  for i in range(1<<n):
    _l=[]
    for j in range(n):
      _l.append(1 if i&(1<<j) else 0)
    pattern.append(_l)

  ans=0
  for x in pattern:
    f=True
    for i,y in enumerate(l):
      on_num=0
      for z in y:
        on_num+=x[z-1]

      if not f:
        break
      if f and l2[i]!=on_num%2:
        f=False
        break

    if f:
      ans+=1

  return ans

# main()
print(main())


Measured memory_bytes: 6828
#include "bits/stdc++.h"
using namespace std;

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

    int sum = 0;
    for(int i =0;i<N;i++){
        int x,distance;
        cin >> x ;

        if(x<(K-x)) distance = 2*x;
        else distance = 2*(K-x);

        sum += distance;
    } 
    cout << sum << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

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

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    int N;
    cin >> N;

    vector<string> w(N);
    REP(i, N) cin >> w[i];

    bool f = true;

    char c = w[0].back();
    FOR(i, 1, N) {
        if (w[i].front() != c) {
            f = false;
            break;
        }

        c = w[i].back();
    }


    sort(ALL(w));
    if (unique(ALL(w)) - w.begin() != w.size()) f = false;

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a,b,c,d;
	cin >> a >> b >> c >>d;
	while(1) {
		c -= b;
		if (c <=0) {
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if (a <=0) {
			cout << "No" << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3056
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

double solve(int y,int x){
	return sqrt(x*x+y*y);
}

int main(){
	int d,e;
	while(cin>>d>>e&&(d||e)){
		double ans = INF;
		rep(x,d+1){
			int y = d-x;
			double res = solve(y,x);
			ans = min(abs(e-res),ans);
		}
		printf("%.10lf\n",ans);
	}
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second

int main(){
    int w,h;
    while(cin>>w>>h,w){
        vs f(h+2,string(w+2,'#'));
        bool isExist=true;
        rep(i,h){
            cin>>f[i+1];
            isExist&=count(all(f[i+1]), '.')==f[i+1].length();
            f[i+1]="#"+f[i+1]+"#";
        }
        if(isExist){
            cout<<"0 0"<<endl;
            continue;
        }
        
        int ans;
        vs b;
        
        ans=0;
        b=f;
        range(y,1,h+1)range(x,1,w+1){
            if(b[y][x]!='.')continue;
            b[y][x]='B';
            int isEnable=1;
            stack<pii> bfs;
            bfs.emplace(y,x);
            while(!bfs.empty()){
                auto p=bfs.top();
                bfs.pop();
                vi v={1,0,-1,0,1};
                rep(i,4){
                    int ty=p.fs,tx=p.sc;
                    switch(b[ty+v[i]][tx+v[i+1]]){
                        case 'W':
                            isEnable=-100000;
                            break;
                        case '.':
                            isEnable++;
                            bfs.emplace(ty+v[i], tx+v[i+1]);
                            b[ty+v[i]][tx+v[i+1]]='B';
                    }
                }
            }
            if(isEnable>0) ans+=isEnable;
        }
        cout<<ans<<" ";
        
        ans=0;
        b=f;
        range(y,1,h+1)range(x,1,w+1){
            if(b[y][x]!='.')continue;
            b[y][x]='W';
            int isEnable=1;
            stack<pii> bfs;
            bfs.emplace(y,x);
            while(!bfs.empty()){
                auto p=bfs.top();
                bfs.pop();
                vi v={1,0,-1,0,1};
                rep(i,4){
                    int ty=p.fs,tx=p.sc;
                    switch(b[ty+v[i]][tx+v[i+1]]){
                        case 'B':
                            isEnable=-100000;
                            break;
                        case '.':
                            isEnable++;
                            bfs.emplace(ty+v[i], tx+v[i+1]);
                            b[ty+v[i]][tx+v[i+1]]='W';
                    }
                }
            }
            if(isEnable>0) ans+=isEnable;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3168
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;
 
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed parsing")
}
 
use std::cmp::{min, max};
use std::num;
use std::collections::HashMap;
 
 
fn main() {
    
    let n = read::<usize>();
    let q = read::<usize>();
    let mut tree : Vec<Vec<usize>> = vec![Vec::new(); n];
    
    let mut scores = vec![0u64; n];
    
    for _ in 0..n-1 {
        let a = read::<usize>();
        let b = read::<usize>();
        
        tree[a-1].push(b-1);
    }
    
    
    for _ in 0..q {
        let parent = read::<usize>() - 1;
        let val = read::<u64>();
        
        scores[parent] += val;
    }
    
    for i in 0..tree.len() {
        for item in &tree[i] {
            scores[*item] += scores[i];
        }
    }
    
    
    for i in 0..n {
        print!("{} ", scores[i]);
    }
    
    
}

Measured memory_bytes: 20732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {

       


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = int.Parse(line);
                if (ints[0] == 0) { break; }
                int a = ints[0]; int b = ints[1], c = ints[2];

                int n = int.Parse(Console.ReadLine());
                List<Kensa> okKensa = new List<Kensa>();
                List<Kensa> badKensa = new List<Kensa>();
                bool[] okParts = new bool[a + b + c + 1];
                bool[] badParts = new bool[a + b + c + 1];

                for (int i = 0; i < n; i++) {
                    ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    if (ints[3] == 1) {
                        okKensa.Add(new Kensa(ints[0], ints[1], ints[2]));
                    }
                    else {
                        badKensa.Add(new Kensa(ints[0], ints[1], ints[2]));
                    }
                }
                //OK kakutei.
                foreach (Kensa ken in okKensa) {
                    okParts[ken.a] = true;
                    okParts[ken.b] = true;
                    okParts[ken.c] = true;
                }
                //Bad kakutei.
                foreach (Kensa ken in badKensa) {
                    if (okParts[ken.a] && okParts[ken.b]) {
                        badParts[ken.c] = true;
                    }
                    if (okParts[ken.b] && okParts[ken.c]) {
                        badParts[ken.a] = true;
                    }
                    if (okParts[ken.c] && okParts[ken.a]) {
                        badParts[ken.b] = true;
                    }
                }


                for (int i = 1; i <= (a + b + c); i++) {
                    if (okParts[i]) { Console.WriteLine(1); }
                    else if (badParts[i]) { Console.WriteLine(0); }
                    else { Console.WriteLine(2); }
                }


            }
        }

        
    }

    class Kensa {
        public int a;
        public int b;
        public int c;
        public Kensa(int n1, int n2, int n3) {
            a = n1; b = n2; c = n3;
        }
    }

    
}

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

int main() {
  int N,Y;
  
  bool ao = false;

  cin >> N >> Y;//札の数、金額

  int x=-1,y=-1,z=-1;//10000,5000,1000円札の枚数

  for(int i=0;i<=N;i++){
     for(int j=0;j<=N-i;j++){
          int c=N-i-j;     
          int sum = 10000*i + 5000*j + 1000*c;

          if(sum == Y){
            x=i;y=j;z=c;
            ao=true;
            break;
          }
      }
    if(ao){break;}
  }//枚数制約の中で、全パターンを探り、Yと比較。i:10000 j:5000円に対応
  //一つ見つけた瞬間にfor文を停止する。


  cout<<x<<" "<<y<<" "<<z<<endl;//バリエーションの一つを出力
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 200001;
ll h[MAX] = {};
ll a[MAX] = {};
ll pos[MAX] = {};
int main() {
    

    ll n;
    cin >> n;
    for (ll i=1;i<=n;i++) {
        ll p;
        cin >> p;
        a[i] = p;
        pos[p] = i;
    }
    set <ll> s;
//    for(ll i=1;i<=n;i++){
//        cout << i << " " << pos[i] << endl;
//    }
    ll ans = 0;
    ll left = 0;
    ll right = n;
    s.insert(0);
    s.insert(n+1);
    for (ll i=1;i<=n;i++){
        left = *(--s.lower_bound(pos[i]));
        right = *(s.upper_bound(pos[i]));
//        cout << left << " " << right << endl;
        s.insert(pos[i]);
        ans += i * (right-pos[i]) * (pos[i] - left);
//        cout << ans << endl;
    }
    cout << ans << endl;



}




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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, m, a[5],b[5];
int POW(int a, int b){
	if(b < 1) return 1;
	int c = a;
	while(--b) c *= a;
	return c;
}
int num(int a, int b){
	return a/POW(10,b)%10;
}
void solve(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = (n==1?0:POW(10,n-1)); i < POW(10,n); i++){
		bool ok = 1;
		for(int j = 0; j < 5; j++){
			if(num(i,n-a[j]) == b[j]) continue;
			ok = 0;
			break;
		}
		if(ok){
			cout << i << endl;
			return;
		}
	}
	cout << -1 << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int a,b,c,sum,time;
	scanf("%d %d %d",&a,&b,&c);
	sum=0;
	time=0;
	while(sum<a)
	{
		sum=sum+b;
		time=time+c;
	}
	printf("%d",time);
}



Measured memory_bytes: 1704
if __name__ == "__main__":
    # 入力パターン．
    # 先に要素数Nが与えられて，その数読み込むパターン
    ### N
    ### a_1 a_2 a_3 ... a_N
    N = input()
    msg = "No"
    for n in N:
        if n == '7':
            msg = "Yes"
  
    print(msg)

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

const int MAX = 1000001; 

struct Query 
{ 
	int l, r, idx; 
}; 

bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

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

int main() 
{ 
	int n,q,aman,shlok;
	cin>>n>>q;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	Query queries[q];
	for(int i=0;i<q;i++){
		int left,right;
		cin>>left>>right;
		queries[i].l=(left-1);
		queries[i].r=(right-1);
		queries[i].idx=i;
	} 
	//int q = sizeof(queries)/sizeof(queries[0]); 
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
}

Measured memory_bytes: 19316
#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()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    string n; cin >> n;
    cout << "ABC" + n << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
 using namespace std;
 
 // #define  int           long long
 #define pb                push_back
 #define ppb               pop_back
 #define pf                push_front
 #define ppf               pop_front
 #define all(x)            (x).begin(),(x).end()
 #define uniq(v)           (v).erase(unique(all(v)),(v).end())
 #define sz(x)             (int)((x).size())
 #define fr                first
 #define sc                second
 #define pint              pair<int,int>
 #define rep(i,a,b)        for(int i=a;i<b;i++)
 #define mem1(a)           memset(a,-1,sizeof(a))
 #define mem0(a)           memset(a,0,sizeof(a))
 #define ppc               __builtin_popcount
 #define ppcll             __builtin_popcountll
 #define vint			   vector<int>
 #define vpint			   vector<pair<int,int>>
 #define mp                make_pair


 void reader() 
 { 
 #ifndef ONLINE_JUDGE 
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout); 
 #endif
 }
 
 void fastIO() {ios_base::sync_with_stdio(false); cin.tie(NULL);}
 
 
 
 void solve()
 {
 int a,b,c;
 int k;
 
 cin>>a>>b>>c>>k;
 int cnt=0;
 while(a>=b)
 {
 	b*=2;
 	cnt++;
 }

 while(b>=c)
 {
 	c*=2;
 	cnt++;
 }
 
 if(k<cnt)
 	cout<<"No";
 else
 	cout<<"Yes";
 
 
 
 cout<<"\n";
 }
 
 
 
 signed main()
 {
 	reader(); fastIO();
 	long long t=1;
 	//cin>>t;
 	while(t--) solve();
 	return 0;
 }

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define G 1111
#define N 111
using namespace std;
#define LL long long
#define mod 1000000007
inline LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while (ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while (ch>='0' && ch<='9'){
        x=x*10+ch-'0';ch=getchar();
    }
    return x*f;
}
LL fastpow(LL x,LL y){
	LL res=1;
	for (;y;y>>=1){
		if (y&1) res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
LL n,m,k;
LL ans=1,fac[G],inv[G];
LL C(LL m,LL n){
	if (m>n || n<0 || m<0) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
LL gcd(LL x,LL y){
	if (x%y==0) return y;
	else return gcd(y,x%y);
}
LL polya(LL n){
	LL res=0;
	for (LL i=1;i<=n;++i){
		res=(res+fastpow(k,gcd(n,i)))%mod;
	}
	return res*fastpow(n,mod-2)%mod; 
}
set <LL> dat;
LL ea[N*2],eb[N*2],ec[N],tot,top;
LL dfn[N],low[N],stk[N],idx;
void tarjan(LL u,LL fa){
	dfn[u]=low[u]=++idx;
	stk[++top]=u;
	for (LL i=ec[u];i;i=eb[i]){
		LL v=ea[i];
		if (!dfn[v]){
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
			if (low[v]>=dfn[u]){
				dat.clear();
				LL n=0,m=0,lst;
				do{
					lst=stk[top--];
					dat.insert(lst);
					n++;
				}while (lst!=v);
				dat.insert(u);n++;
				for (LL x:dat){
					for (LL j=ec[x];j;j=eb[j]){
						LL v=ea[j];
						if (dat.count(v)) m++; 
					}
				}
				m>>=1;
				if (m<n) ans=ans*k%mod;
				if (m==n) ans=ans*polya(n)%mod;
				if (m>n) ans=ans*C(k-1,m+k-1)%mod;
			} 
		}else{
			low[u]=min(low[u],dfn[v]);
		}
	}
	if (!fa) top--;
}
void add(LL x,LL y){
	tot++;ea[tot]=y;eb[tot]=ec[x];ec[x]=tot;
}
int main(){
	n=read(),m=read(),k=read();
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for (LL i=2;i<G;++i) fac[i]=fac[i-1]*i%mod;
	for (LL i=2;i<G;++i) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for (LL i=2;i<G;++i) inv[i]=inv[i]*inv[i-1]%mod;
	for (LL i=1;i<=m;++i){
		LL u=read(),v=read();
		add(u,v);add(v,u);
	}
	for (LL i=1;i<=n;++i){
		if (!dfn[i]) tarjan(i,0);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << n/3 << endl;
  return 0;
}

Measured memory_bytes: 256
nm = [0,31,29,31,30,31,30,31,31,30,31,30]
while True:

    m,d = map(int,raw_input().split(" "))

    if m == 0:
        break
    else:
        nd = 0
        for i in range(m):
           nd += nm[i]

        nd += d
        n = nd%7
        if n == 1:
            print "Thursday"
        elif n == 2:
            print "Friday"
        elif n == 3:
            print "Saturday"
        elif n == 4:
            print "Sunday"
        elif n == 5:
            print "Monday"
        elif n == 6:
            print "Tuesday"
        else:                                                                                                                                                                                                
            print "Wednesday"

Measured memory_bytes: 4244
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int num = 0;
  int w = 0;
  int r = 0;
  rep(i,n-1){
    if(s[i] == 'W' && s[i+ 1] == 'R')num++;
  }
  if(num == 0){
    cout << 0 << endl;
    return 0;
  }
  rep(i, n){
    if(s[i] == 'W')w++;
    else r++;
  }
  int ans = 0;
  rep(i, r){
    if(s[i] == 'W')ans++; 
  }
  cout << ans << endl;
}

Measured memory_bytes: 3732
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, A);
    IN(ll, B);
    OUT(A * B);
}

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

using namespace std;

const int INF = 1e9 + 5;

int main() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);

  vector<int> h(n);

  for(int &x: h) scanf("%d", &x);


  vector<int> dp(n, INF);
  dp[0] = 0;
  
  for(int i = 0; i < n; i++) {
  	for(int j = i + 1; j <= i + k; j++) {
		if(j < n) dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
	}
  }
  printf("%d", dp[n-1]);
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll s = llabs(a - b);
    if (s % 2 == 0)
    {
        cout << s / 2 << endl;
    }
    else
    {
        cout << min(min(llabs(1 - a), llabs(1 - b)) + (s - 1) / 2 + 1, min(llabs(n - a), llabs(n - b)) + (s - 1) / 2 + 1) << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
//	freopen("SNOOKER.inp","r",stdin);
//	freopen("SNOOKER.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}

using ll =  long long;
#define endl "\n"
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define what_is(x)  cerr << #x << " is :" << (x) << endl
#define what_are(x,y) cerr << #x <<" is : " << (x) <<" ; " << #y <<" is: " <<y << endl
#define pii pair<int,int>
#define fi first
#define se second

const int MOD =  1e9+7;
const int inf = INT_MAX;
const int MAX_N = 1e5 + 7;

int n;
ll dp[3007][3007], a[3007] ,total = 0;

void solve()
{
	
	
	cin >> n;
	for(int i = 1; i <= n; i ++) 
	{
		cin >> a[i];
		total += a[i];
	}
	
	for(int l = n; l > 0; l --)
	{
		for(int r = l; r <= n; r ++)
		{
			if(l == r) dp[l][r] = a[l];
			else if(l +1 == r) dp[l][r] = max(a[l], a[r]);
			else
			{
				dp[l][r] = max(a[l] + min(dp[l+2][r], dp[l+1][r-1]) ,
								a[r] + min(dp[l][r-2], dp[l+1][r-1])
								);
			}
		}
	}
	
	cout << 2*dp[1][n] - total ;
}
/*----------------------------------------------------------------------

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

Measured memory_bytes: 70016
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner (System.in);
		int a = sc.nextInt();
		a+=sc.nextInt();
		int b = sc.nextInt();
		b+=sc.nextInt();
		sc.close();

		if (a != b) {
			System.out.println(a>b ? "Left" : "Right");
		} else {
			System.out.println("Balanced");
		}
	}
}


Measured memory_bytes: 35668
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}




int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    string s;
    cin>>n>>s;
    int res=0;
    for(int i=0;i<n;i++){
        if(n-(i+1)<2)break;
        if(s[i]=='A'&& s[i+1]=='B' && s[i+2]=='C'){
            res++;
        }
    }
    cout<<res<<endl;
    return 0;

}


Measured memory_bytes: 256
def main(argv)
  n = gets.chomp.to_i
  p = gets.chomp.split(' ').map(&:to_i)
  
  swapped = false
  flag = true
  index_pair = [-1, -1]
  n.times do |i|
    if p[i] != (i + 1) then
      if swapped then
        if i != index_pair[1] then
          flag = false
          break
        end
      else
        j = p[i] - 1
        index_pair = [i, j]
        if p[j] == (i + 1) then
          swapped = true
        else
          flag = false
          break
        end
      end
    end
  end
  
  puts (flag ? 'YES' : 'NO')
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int main() {
  int N, x;
  std::cin >> N >> x;
  std::vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> a[i];
  }

  int cnt = 0;
  std::sort(a.begin(), a.end());
  for (int i = 0; i < N - 1; ++i) {
    x -= a[i];
    if ( x > 0 ) ++cnt;
    else if ( x == 0 ) {
      ++cnt;
      break;
    }
    else x += a[i];
  }
  if ( x == a[N - 1] ) ++cnt;
  std::cout << cnt << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			while (true) {
				int n = sc.nextInt();
				if (n == 0) {
					break;
				}
				int[] scores = new int[n];
				for (int i = 0; i < scores.length; i++) {
					scores[i] = sc.nextInt();
				}
				double average = 0, variance = 0;
				for (int i = 0; i < scores.length; i++) {
					average += scores[i];
				}
				average /= n;
				for (int i = 0; i < scores.length; i++) {
					variance += (scores[i] - average) * (scores[i] - average);
				}
				variance /= n;
				System.out.println(Math.sqrt(variance));
			}
			sc.close();
		}
	}
}



Measured memory_bytes: 31772