akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt64()
	m := nextInt64()

	if n == 0 || m == 0 {
		fmt.Println("IMPOSSIBLE")
		return
	}

	if int64(math.Abs(float64(n-m)))%2 == 1 {
		fmt.Println("IMPOSSIBLE")
		return
	}

	k := (math.Pow(float64(m), 2) - math.Pow(float64(n), 2)) / float64((2 * (n - m)))
	fmt.Println(int64(math.Abs(k)))
}


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

//var 
string a,b, ans;
int dp[3001][3001],n,m;

int main(){
	cin >> a >> b;
	n = a.size(); m = b.size();
	for(int i = 1; i<=n; i++){
		for(int j = 1; j<=m; j++){
			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			if(a[i-1] == b[j-1])dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
		}
	} int i = n, j = m; ans = "";
	while(i>0 && j>0){
		if(a[i-1] == b[j-1]) {
			ans += a[i-1];
			//cout << i << " " << j << endl;
			i--; j--;
		}else{
			if(dp[i-1][j]>dp[i][j-1])i--;
			else j--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 35456
#include<stdio.h>
int main() {
	int i,j,N,x;
	double  v[1001],t[1001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++)
		scanf("%lf", &v[i]);
	for (i = 1; i < N; i++) {
		for (j = i + 1; j <= N; j++) {
			if (v[i] > v[j]) {
				x = v[j];
				v[j] = v[i];
				v[i] = x;
			}
		}
	}
	for (i = 1; i < N; i++) {
		t[i] = (v[i] + v[i + 1]) / 2;
		v[i + 1] = t[i];
	}
	printf("%lf\n", v[N]);
	return 0;
}






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

typedef long long ll;

int main(void){
    ll N,M;
    cin >> N >> M;
    
    vector<bool> vec(100100,true);
    for(int i = 0; i < M; i++){
        ll tmp;
        cin >> tmp;
        vec[tmp] = false;
    }
    
    vector<ll> dp(100100,0);
    dp[0] = 1;
    for(int i = 0; i < N; i++){
        if(vec[i+1] == true) dp[i+1] += dp[i];
        if(vec[i+2] == true) dp[i+2] += dp[i];
        dp[i+1] %= 1000000007;
    }
    
    cout << dp[N] << endl;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MAX = 2e5+10;
ll n;
ll len;
ll u0,v0;
ll a[MAX];
ll ans[MAX];
vector<ll> adj[MAX];
vector< stack<ll> > dp(MAX);

void dfs(ll cur,ll par)
{
    bool flag = 0;
    ll ind;
    if(a[cur] <= dp[1].top())
    {
        dp[1].push(a[cur]);
        ind = 1;
    }
    else if(a[cur] > dp[len].top())
    {
        len++;
        flag = true;
        dp[len].push(a[cur]);
        ind = len;
    }
    else
    {
        ll left = 2;
        ll right = len;
        while(left<=right)
        {
            ll mid = (left+right)/2;
            if(dp[mid].top() >= a[cur])
            {
                right = mid-1;
            }
            else left = mid+1;
        }
        ind = right+1;
        dp[ind].push(a[cur]);
    }
    ans[cur] = len;
    for(ll i=0;i<adj[cur].size();i++)
    {
        if(adj[cur][i] == par)continue;
        dfs(adj[cur][i],cur);
    }
    dp[ind].pop();
    len-=flag;
}
int main()
{
    ///freopen("path_02.txt","r",stdin);
    ///freopen("path_02_out.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(ll i=1;i<n;i++)
    {
        cin>>u0>>v0;
        adj[u0].push_back(v0);
        adj[v0].push_back(u0);
    }
    dp[1].push(a[1]);
    len = 1;
    ans[1] = 1;
    for(ll j=0; j<adj[1].size(); j++)
    {
        dfs(adj[1][j],1);
    }
    for(ll j=1; j<=n; j++)
    {
        cout<<ans[j]<<endl;
    }
    return 0;
}


Measured memory_bytes: 164312
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define ALL(x)	(x).begin(), (x).end()
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7,N=1000010;
typedef long long ll;
int n,m;
vector<int>adj[MAXN+1];
int dp[MAXN+2];
bool visited[MAXN+1];
void dfs(int i){
	visited[i]=true;
	for(auto x:adj[i]){
		if (!visited[x])
			dfs(x);
		dp[i]=max(dp[i],1+dp[x]);
		}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	rep(i,0,m){
		int x,y;cin>>x>>y;
		adj[x].pb(y);
	}
	memset(dp,0,sizeof dp);
	memset(visited,false,sizeof visited);
	for(int i=1;i<=n;i++){
		if (!visited[i])
			dfs(i);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,dp[i]);
	cout<<ans<<"\n";
	
	
return 0;
}


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

int main()
{
    int n, k; cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    vector<int> t(n - k + 1);
    for (int i = 0; i < n - k + 1; i++) {
        t[i] = (x[i+k-1] - x[i]) + min(abs(x[i]), abs(x[i+k-1]));
    }

    int ans = *min_element(t.begin(), t.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <fstream>
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; }

const long long INF = 1LL << 60;
const long long MOD = 1000000007LL;
const long long MAX = 500000LL;
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	string s;
	cin >> s;
	if (s.size() < 3) {
		puts("Rabbit");
		return 0;
	}
	stack<char> st;
	for (ll i = 1; i < s.size() - 1; i++) {
		if (st.empty() || st.size() == 1) {
			st.push(s[i]);
		}
		else {
			char c1, c2;
			c1 = st.top();
			st.pop();
			c2 = st.top();
			st.pop();
			if (!(c2 == 'm' && c1 == 'e' && s[i] == 'w')) {
				st.push(c2);
				st.push(c1);
				st.push(s[i]);
			}
		}
	}
	//cout << st.size() << endl;


	if (st.size() == 1 && st.top() == 'e') {
		cout << "Cat" << endl;
	}
	else {
		cout << "Rabbit" << endl;
	}
	return 0;
}


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

#(1,1)から一番長く移動しないといけないのは(1,n)の時
ans = n - 1

for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        ans = min(ans, i + int(n/i) - 2)

print(ans)

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

int main() {
    int n;
    cin >> n;
    char s;
    bool four = false;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == 'Y') {
            cout << "Four" << endl;
            return 0;
        } 
    }
    if (!four) cout << "Three" << endl;
}

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

int main() {
  int n, p;
  string s;
  cin >> n;
  map<string, map<int, int>> m;
  rep(i, n) {
    cin >> s >> p;
    m[s][100-p] = i+1;
  }
  for(auto pr : m) for(auto x : pr.second) cout << x.second << endl;
}

Measured memory_bytes: 3612
X, Y = map(int, input().split())

mod = 10**9+7
def factorial(N):
    if N==1 or N==1:
        return 1
    else:
        ans = N
        for i in range(1, N):
            ans*=N-i
            ans%=mod
        return ans

if 2*Y-X>=0 and (2*Y-X)%3==0 and 2*X-Y>=0 and (2*X-Y)%3==0:
    s = (2*X-Y)//3
    t = (2*Y-X)//3
    if s==0 and t==0:
        print(0)
    elif s==0:
        print(1)
    elif t==0:
        print(1)
    else:
        a = factorial(s+t)
        b = pow(factorial(s), mod-2, mod)
        c = pow(factorial(t), mod-2, mod)
        #print(a, b, c)
        print((a*b*c)%mod)
else:
    print(0)

Measured memory_bytes: 63552
import java.util.*;
import java.lang.*;
import java.util.Scanner;

public class Main
{
	public static void main (String[] arg)
	{
		for(int i=1 ; i<10 ;i++)
		{
			for(int j=1 ; j<10 ;j++)
			{
				System.out.println(i+"x"+j+"="+(i*j));
			}
		}
	}
}

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

#define ran 3033

char s[ran], t[ran];
int slen, tlen;
int dp[ran][ran];
char ans[ran];
int la;

int main() {
	scanf("%s%s", s, t);
	slen = strlen(s);
	tlen = strlen(t);
	
	for(int i=1;i<=slen;i++)
		for(int j=1;j<=tlen;j++) {
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			if (s[i-1] == t[j-1])
				dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
		}
	int x = slen, y = tlen;
	la=0;
	while(x>0 && y>0) {
		if (dp[x][y] == dp[x-1][y]) x--;
		else 
		if (dp[x][y] == dp[x][y-1]) y--;
		else {
			ans[la++] = s[x-1];
			x--; y--;
		}
	}
	for(int i=la-1;i>=0;i--)
		putchar(ans[i]);
	puts("");
	
	return 0;
}

Measured memory_bytes: 35712
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i=0; i<n; i++) {
			a[i] = b[i] = in.nextInt();
		}
		Arrays.sort(b);
		int ans = 0;
		for (int i=0; i<n; i++) {
			if (i%2 != Arrays.binarySearch(b, a[i])%2) {
				ans++;
			}
		}
		out.println(ans/2);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 24392
#include <iostream>
using namespace std;
int main(){
   int d, n,ans;
   cin >> d >> n;
   if(d==0){
       ans =  n;
       if (n == 100){
           ans = n+1;
       }
   }else if(d==1){
       ans = 100 * n;
       if (n == 100){
           ans = 100 * (n+1);
       }
   }else if(d==2){
       ans = 100 * 100 * n;
       if (n == 100){
           ans = 100 * 100 * (n+1);
       }
       
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5)
    cout<<"YES";
else
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int N, K;
        cin >> N >> K;
        ll ans = K * pow(K - 1, N - 1);
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
#define ll long long int
using namespace std;
int main(void) {
  int a, b;
  cin>>a>>b;
  cout<<(b-a)*(b-a+1)/2-b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int a, b;
  cin >> a >> b;
  if (a >= 13) P(b);
  else if (a >= 6) P(b / 2);
  else P(0);
  return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);

	ll a, v, b, w, t;
	cin >> a >> v;
	cin >> b >> w;
	cin >> t;
	if (w >= v) {
		cout << "NO\n";
		return 0;
	}
	ll d = abs(b - a);
	if (t * (v - w) >= d) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    int h, w;
    char a[100][100];
    int b[100]={0}, c[100]={0};
    
    cin >> h >> w;

    for (int i = 0; i < h; i++){
        for (int j=0; j < w; j++){
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (a[i][j] == '#') {
                b[i] = 1;
                c[j] = 1;
            }
        }
    }

    for (int i = 0; i < h; i++){
        if (b[i] > 0) {
            for (int j = 0; j < w; j++){
                if (c[j] > 0) cout << a[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}

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

using namespace std;

int main(void){
	int x;
	int i = 0;
	while(cin >> x){
		if(x == 0)
		break;
		i++;
		printf("Case %d: %d\n", i, x);
	}
	return 0;
}

Measured memory_bytes: 1140
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()

b = readl()
p = max(b)
a = [p] * (n + 1)

for i in range(n - 1):
    t = b[i]
    if t <= a[i]:
        a[i] = t
    if t <= a[i + 1]:
        a[i + 1] = t
ans = 0
for i in range(n):
    ans += a[i]
print(ans)

Measured memory_bytes: 6736
//https://atcoder.jp/contests/abc118/tasks/abc118_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> v(M+1);
    REP( i, N ){
        int K;
        cin >> K;
        vector<int> A(K);
        for( int i = 0; i < K; ++i ){
            cin >> A[ i ];
            v[A[i]]++;
        }
    }
    cout << count( ALL(v), N ) << endl;
    return 0;
}

Measured memory_bytes: 256
/*
    Author: Mohit Saini
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define pb push_back
typedef long double ld;
typedef vector<ll> vll;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll n; cin >> n;
        string s; cin >> s;
        vector<vector<ll>> a(n,vector<ll>(3,0));
        ll ans =0;
        ll r=0,g=0,b=0;
       
        repD(i,n-1,0){
            a[i][0] = r; a[i][1] = g; a[i][2] = b;
            if(s[i]=='R') r++;
            else if(s[i]=='G') g++;
            else b++;

        }
       
        ll f=0;
        for(ll i=0;i<n-1;i++){
            for(ll j=i+1;j<n;j++){
                f=0;
                ll t=j+j-i;
                if(s[i]==s[j]) {
                    continue;
                }
                map<char,ll> help;
                help[s[i]]++;
                help[s[j]]++;
                if(t<=n-1) f=1;

                if(help['R']==0){
                    ans += a[j][0];
                    if(f and s[t]=='R') ans --;
                }
                 if(help['G']==0){
                    ans += a[j][1];
                    if(f and s[t]=='G') ans --;
                }
                 if(help['B']==0){
                    ans += a[j][2];
                    if(f and s[t]=='B') ans --;
                }
            }

        }
        cout << ans << endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	ll ans = c - a - b;
	if(ans > 0 && ans*ans > 4*a*b) cout << "Yes";
	else cout << "No";

}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define forup(i,a,b) for(int i=(a); i<(b); ++i)
#define fordn(i,a,b) for(int i=(a); i>(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)

#define gi(x) scanf("%d",&x)
#define gl(x) cin>>x
#define gd(x) scanf("%lf",&x)
#define gs(x) scanf(" %s",x)

#define D(x) cout << #x << " : " << x << endl

#define fs first
#define sc second

#define pb push_back
#define mp make_pair

const int inf=numeric_limits<int>::max();
const LL linf=numeric_limits<LL>::max();

const int max_n=100001;

int n, a[max_n], dp[max_n];

int main() {
    gi(n);
    rep(i, n){
        gl(a[i]);
    }

    dp[n-1] = 0;
    dp[n-2] = abs(a[n-1]-a[n-2]);

    fordn(i, n-3, -1){
        dp[i] = min(abs(a[i+1]-a[i])+dp[i+1], abs(a[i+2]-a[i])+dp[i+2]);
    }

    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 1024
use std::iter;
use std::u32;

fn main(){
    let d: u32 = read_one();
    let g: u32 = read_one();
    let pc: Vec<(u32, u32)> = read2_lines(d as usize);
    
    let mut v: Vec<u32> = Vec::new();
    
    for i in 0..(u32::pow(2, d)) {
        let (mut s, mut n) = pc.iter().enumerate()
            .filter(|&(index, _item)| {((i >> index) & 1) == 1})
            .map(|(index, &(p, c))| {(p * (index + 1) as u32 * 100 + c, p)})
            .fold((0, 0), |x, y| {(x.0 + y.0, x.1 + y.1)});
        for (index, &(p, c)) in pc.iter()
            .enumerate()
            .filter(|&(index, _item)| {((i >> index) & 1) != 1})
            .rev() 
        {
            if g <= s {break;}
            let need = (g - s - 1) / ((index + 1) as u32 * 100) + 1;
            if need <= p - 1 {
                n += need;
                s += need * (index + 1) as u32 * 100;
                break;
            } else {
                n += p - 1;
                s += (p - 1) * (index + 1) as u32 * 100;
            }
        }
        if g <= s {
            v.push(n);
        }
    }
    println!("{}", v.iter().min().unwrap())
}

use std::io::*;
use std::str::*;

fn read_one<T: std::str::FromStr>() -> T {
    let mut s = stdin().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.trim().parse().ok().unwrap()
}

fn read2<T: FromStr, T2: FromStr>() -> (T, T2) {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut iter = s.trim().split_whitespace();
    (iter.next().unwrap().parse().ok().unwrap(), iter.next().unwrap().parse().ok().unwrap())
}

fn read2_lines<T: FromStr, T2: FromStr>(n: usize) -> Vec<(T, T2)> {
    (0..n).map(|_| read2()).collect()
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int wa(int n)
{
	int num = 0;

	while (n > 0)
	{
		num += n % 10;
		n /= 10;
	}
	return num;
}
int main()
{
	int N, A, B,ans = 0;

	cin >> N >> A >> B;

	int n;
	for (int i = 1; i <= N; i++)
	{
		n = wa(i);
		if (n >= A && n <= B)
			ans += i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    sequence =list(map(int, "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(', ')))
    kth = int(input())
    print(sequence[kth - 1])
       

main()

Measured memory_bytes: 2940
read = lambda:list(map(int, input().split()))

def calc(a, b):
    dt = a ** 2 + b ** 2
    return pow(dt, 0.5)
n, d = read()
ans = 0
for _ in range(n):
    x, y = read()
    if calc(x, y) <= d:
        ans += 1
print(ans)

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

typedef pair<double, double> pd;
typedef vector<pd> vpd;


#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

bool is_runrun(ll N){
  ll tmp = N%10;
  while(N>0){
    N/=10;
    if(N==0) return true;
    if(abs(N%10-tmp)>1) return false;
    tmp = N%10;
  }
  return true;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll K;
  IN(K);

  ll val = 0;
  ll k = 0;
  while(k<K){
    val++;
    ll p = 1;
    while(p*10<val){
      if(val>p*10 && (val/p)%10>(val/p/10)%10+1) val += p*10-val%(p*10);
      p *= 10;
    }
    if(is_runrun(val)) k++;
    if(k==K){
      OUT(val);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 256
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll a,b;
		cin>>a>>b;
		cout<<max(a+b,max(a-b,a*b));
	}
	return 0;
}

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

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b){
  ll p=1;
  for(int i=0;i<b;i++){
    p*=a;
  }
  return p;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll binom1(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  ll i,ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

int main(){
  int i,j,k,cnt=0;
  ll n,m;
  cin>>n>>m;
  int p=(int)round(sqrt(m));
  int q=p;
  int a[q+1];
  for(i=0;i<=p;i++)a[i]=0;
  for(i=2;i<=p;i++){
    if(m%i==0){
      a[i]++;
      m/=i;i=1;
      p=(int)round(sqrt(m));
    }
  }
  if(m!=1){
    if(m>q)a[0]=1;
    else a[m]++;
  }
  ll ans=1;
  for(i=0;i<=q;i++){
    if(a[i]!=0){
      ans=(ans*binom1(n+a[i]-1,a[i]))%MOD;
    }
  }
  cout<<ans<<endl;
}

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

int main(){

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

    vector<pair<int,int>> pairs(n);

    for(int i=0; i<n; i++){
        int a,b; cin>>a>>b;
        pairs[i] = make_pair(a,b);
    }

    sort(pairs.begin(),pairs.end());

    int count=0;
    ll sum=0;

    for(int i=0; i<n; i++){
        if(m == count)break;
        while(m>count){
            if(pairs[i].second == 0)break;
            sum += pairs[i].first;
            pairs[i].second--;
            count++;
        }
    }

    cout<<sum<<endl;

    return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int ct[100];
main(){
 string st;
cin >> st;
for (int i = 0; i < (int)st.size(); i++)
ct[st[i] - 'a'] = 1;
bool flag = 1;
int offBit = -1;
for (int i = 0; i < 26; i++) if (!ct[i]){
flag = 0;
offBit = i;
break;
}
if (!flag){
cout << st << char(offBit + 'a'); exit(0);
}
string tmp = st;
if (next_permutation(tmp.begin(), tmp.end()) ){
for (int i = 0; i < (int)tmp.size(); i++)
if (tmp[i] == st[i]) cout << st[i];
else  { cout << tmp[i]; exit(0);}
}
else cout << -1;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <vector>
#include <stdio.h>
#include <iostream>
#include <unordered_set>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <cassert>


#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd
#define index asdklnas
#define right sld
#define left sldl
using namespace std;

typedef long long ll;
typedef long double dbl;

template<class T>
void print(vector<T> s){
    for (T x : s)
        cout << x << " ";
    cout << endl;
}

mt19937 mrand(random_device{} ());
int rnd() {
	return mrand();
}

const int maxn = 1e5 + 7;

vector<int> getFactor(int x){
	vector<int> s;
	if (x < 0){
		s.push_back(-1);
		x *= -1;
	}
	for (int i = 2; i * i <= 1e8; i++){
		if (x % i == 0){
			int cnt = 0;
			while (x % i == 0){
				cnt++;
				x /= i;
			}
			if (cnt & 1)
				s.push_back(i);
		}
	}
	if (x > 1)
		s.push_back(x);
	return s;
}

vector<int> compress(vector<vector<int> > s){
	int n = s.size();
	vector<vector<int> > ss(n);
	// print(s[0]);
	for (int i = 0; i < n; i++){
		sort(s[i].begin(), s[i].end());
		for (int j : s[i])
			ss[i].push_back(j);
	}
	// print(s[0]);
	sort(ss.begin(), ss.end());
	ss.resize(unique(ss.begin(), ss.end()) - ss.begin());
	// cout << ss.size() << endl;
	vector<int> answer(n);
	for (int i = 0; i < n; i++){
		// print(s[i]);
		answer[i] = lower_bound(ss.begin(), ss.end(), s[i]) - ss.begin();
	}
	return answer;
}

int main(){
    srand(17);
 	ios_base::sync_with_stdio(0);
 	ll r;
 	cin >> r;
 	cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  ans += min(n, m / 2);
  n -= ans;
  m -= ans * 2;
  cout << ans + m / 4 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <sstream>
#include <complex>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using iii = pair<int, ii>;
using viii = vector<iii>;

using ll = long long int;
using vc = vector<char>;
using vb = vector<bool>;
using ib = pair<int, bool>;
using vib = vector<ib>;

#define MOD 1000 * 1000 * 1000 + 7
#define INF 1000 * 1000 * 1000

bool resuelveCaso() {
	string s;
	cin >> s;
	if (!cin) return false;
	ll k;
	cin >> k;

	int pos = 1;
	if (k == 1) cout << s[0] << '\n';
	else {
		while (s[pos - 1] == '1' && pos < k) ++pos;
		cout << s[pos - 1] << '\n';
	}

	return true;
}

int main() {
	while (resuelveCaso()) {}
	return 0;
}

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

int main() {
  int yen;
  cin >> yen;
  int ans=0;
  int temp=yen/500;
  ans+=(temp*1000);
  temp=yen%500;
  temp=temp/5;
  ans+=(temp*5);
  cout << ans << endl;





}

Measured memory_bytes: 3612
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let k: usize = read();
    let (a, b) = read_touple::<usize>();

    let mut ans = "NG";
    for i in 1..10000 {
      if a <= i * k && i * k <= b {
        ans = "OK";
      }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2108
import Control.Monad
import Data.List

main = sol <$> get >>= print

get = map (map read . words) . lines <$> getContents

sol ([w,h,_]:ps) = area $ foldl' f (0,w,0,h) ps

area (l,r,b,t) = max 0 (r-l)*max 0 (t-b)

f (l,r,b,t) [x,y,a]
  | a == 1    = (max l x,r,b,t)
  | a == 2    = (l,min r x,b,t)
  | a == 3    = (l,r,max b y,t)
  | a == 4    = (l,r,b,min t y)
  | otherwise = undefined

Measured memory_bytes: 1020
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n = 3;
    vector<int> v(n); cin >> v;
    sort(v.rbegin(), v.rend());
    cout << (v[0] * 10 + v[1] + v[2]) << '\n';
}


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

void digi(int x, int *a, int *b) {
  *b = x % 10;
  while (x) {
    *a = x;
    x /= 10;
  }
}

int main() {
  int n,ini=0,last=0,aux=0; cin>>n;
  vector<vector<int>> arr(10, vector<int>(10, 0));

  for (int i=1; i<=n; i++) {
    digi(i,&ini,&last);
    //cout<<ini<<" "<<last<<endl;
    arr[ini][last]++;
  }
 
  int ans = 0;
  for (int i=1; i<10; i++) {
    for (int j=1; j<10; j++) {
      ans += arr[i][j] * arr[j][i];}}
 
  cout<<ans<<endl;
  return 0;}

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

typedef long long ll;
ll N, M;

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

    ll c_max = M / 2;

    // c をそのまま使う
    ll ans = min(c_max, N);

    // c を2つ使って sを作る
    // c4つで1セット
    ans += (M - ans * 2) / 4;

    cout << ans << endl;
}

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



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

	for (int i = 0; i < 300; i++) {
		N = N.substr(0, N.size() - 1);
		if (N.size() % 2 == 0) {
			if (N.substr(0, N.size() / 2) == N.substr(N.size() / 2, N.size() / 2)) {
				cout << N.size() << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n; cin >> n;
	vector<int> a(n+2,0);
	rep(i,1,n+1) cin >> a[i];
	ll sum = 0;
	rep(i, 0, n + 1){ 
		sum +=abs(a[i] - a[i + 1]);
	}
	rep(i,1, n+1) {
		ll ans = 0;
		ans = sum + abs(a[i - 1] - a[i + 1]) - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <cctype>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int m; in(), m = in();) {
		unordered_multimap<int, int> g;
		while (m--) {
			int a = in(), b = in();
			g.insert({a, b});
			g.insert({b, a});
		}
		unordered_set<int> c{1};
		queue<pair<int, int>> q;
		q.push({1, 0});
		while (!q.empty()) {
			auto n = q.front();
			q.pop();
			auto i = g.equal_range(n.first);
			for_each(i.first, i.second, [&](auto a) {
					 if (!c.count(a.second)) {
						c.insert(a.second);
						if (n.second < 1)
							 q.push({a.second, n.second + 1});}});
		}
		outl(c.size() - 1);
	}
}


Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
int ROW_INDEX = 1;
//[min_range, max_range]からn_ints個の整数の組をすべてとりだしcomb[組][整数]に格納する
void AllCombs_ints(int min_range, int max_range, int depth, int n_ints, int **comb){
	if(depth > 0){
		for(int x = min_range; x <= max_range; x++){
			//comb[0]を一時的な格納場所として使っている。気持ち悪い。
			comb[0][depth-1] = x;
			if(depth == 1){
				for(int num_i = 1; num_i <= n_ints; num_i++)
					comb[ROW_INDEX][num_i-1] = comb[0][n_ints-num_i];
				ROW_INDEX++;
			}
			AllCombs_ints(x + 1, max_range, depth - 1, n_ints, comb);
		}
	}
	if(depth == n_ints)
		ROW_INDEX = 1;
}
int Factorial(int upto){
	if(upto == 0)
		return 1;
	return upto * Factorial(upto-1);
}

int main(){
	int H, W, K;
	scanf("%d %d %d", &H, &W, &K);
	int mat[H+1][W+1], temp[H+1][W+1];
	for(int i = 1; i <= H; i++){
		char s[10];
		scanf("%s", &s);
		for(int j = 0; j < W; j++){
			if(s[j] == '.')
				mat[i][j+1] = temp[i][j+1] = 0;
			if(s[j] == '#')
				mat[i][j+1] = temp[i][j+1] = 1;
		}
	}
	int ans = 0;
	for(int n_row = 0; n_row <= H; n_row++){
		int n_rcomb = Factorial(H) / Factorial(n_row) / Factorial(H-n_row);
		int **pt_rslice;
		pt_rslice = (int **) malloc(sizeof(int *) * (n_rcomb+1));
		for(int pt_i = 0; pt_i <= n_rcomb; pt_i++)
			pt_rslice[pt_i] = (int *) malloc(sizeof(int) * (n_row > 0 ? n_row : 1));
		AllCombs_ints(1, H, n_row, n_row, pt_rslice);

		for(int n_col = 0; n_col <= W; n_col++){
				int n_ccomb = Factorial(W) / Factorial(n_col) / Factorial(W-n_col);
				int **pt_cslice;
				pt_cslice = (int **) malloc(sizeof(int *) * (n_ccomb+1));
				for(int pt_j = 0; pt_j <= n_ccomb; pt_j++)
					pt_cslice[pt_j] = (int *) malloc(sizeof(int) * (n_col > 0 ? n_col : 1));
				AllCombs_ints(1, W, n_col, n_col, pt_cslice);

				for(int i = 1; i <= n_rcomb; i++){
					for(int j = 1; j <= n_ccomb; j++){

						for(int k = 0; k < n_row; k++){
							for(int m = 1; m <= W; m++){
								temp[pt_rslice[i][k]][m] = 0;
							}
						}
						for(int k = 0; k < n_col; k++){
							for(int m = 1; m <= H; m++){
								temp[m][pt_cslice[j][k]] = 0;
							}
						}
						int total = 0;
						for(int k = 1; k <= H; k++){
							for(int m = 1; m <= W; m++){
								total += temp[k][m];
							}
						}
						//printf("%d\n", total);
						if(total == K)
							ans++;
						for(int k = 1; k <= H; k++){
							for(int m = 1; m <= W; m++){
								temp[k][m] = mat[k][m];
							}
						}
					}
				}
            	for(int pt_i = 0; pt_i <= n_ccomb; pt_i++)
		free(pt_cslice[pt_i]);
	free(pt_cslice);



		}
      	for(int pt_i = 0; pt_i <= n_rcomb; pt_i++)
		free(pt_rslice[pt_i]);
	free(pt_rslice);
	}
	printf("%d", ans);
	return 0;
}

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

int N; long long A, B;

int p[5005];
int rev[5005];

// Second indx:
/*
1: (-inf, 1]
2: (1, 2]
3: (2, 3]
4: (3, 4] and so on.
N+1: (N, N+1]
*/
//long long memo[5005][5005];
long long dp[5005][5005];

// Sort from 1 to i inclusive
// The element i+1 is in k
/*long long dp(int i, int k){
    if(i == 0){
        return 0;
    }else if(memo[i][k] != -1){
        return memo[i][k];
    }else{
        // shift left
        long long ans = 1LL << 61;

        for(int j = 1; j <= k; j ++){
            if(j < rev[i]){
                ans = min(ans, B + dp(i-1, j));
            }else if(j == rev[i]){
                ans = min(ans, B*(j==k) + dp(i-1, j));
            }else{
                ans = min(ans, A + dp(i-1, j));
            }
        }

        //printf("dp(%d, %d)=%lld\n", i, k, ans);
        return memo[i][k] = ans;
    }
}*/

int main(){
    scanf("%d%lld%lld", &N, &A, &B);

    for(int i = 1; i <= N; i ++){
        scanf("%d", &p[i]);
        rev[p[i]] = i;
    }

    for(int j = 1; j <= N+1; j ++){
        dp[0][j] = 0;
    }

    for(int i = 1; i <= N; i ++){
        long long ans = 1LL << 61;
        for(int j = 1; j <= N+1; j ++){

            if(j < rev[i]){
                ans = min(ans, B + dp[i-1][j]);
            }else if(j == rev[i]){
                ans = min(ans, dp[i-1][j]);
            }else{
                ans = min(ans, A + dp[i-1][j]);
            }

            dp[i][j] = ans;
            if(j == rev[i]){
                dp[i][j] = min(ans, dp[i-1][j]);
            }
        }
    }

    printf("%lld", dp[N][N+1]);
    return 0;
}


Measured memory_bytes: 195840
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

const long long mod = 1e9+7;

int main()
{
  vector<int> dp(2004);
  int s;
  cin >> s;
  dp[0] = 1;
  for(int i = 1; i <= s; i++){
    for(int j = 0; j <= i-3; j++){
      dp[i] += dp[j];
      dp[i] %= mod;
    }
  }
  cout << dp[s] << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
	int n;cin>>n;
	map<int,int> mm;
	for(int i=0;i<n;i++){
		int t;cin>>t;
		mm[t]++;
	}
	if(mm.size()==1){
		if(mm[0]!=0)
		cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		return 0;
	}
	if(mm.size()==2){
		if(mm[0]!=0){
			for(auto it:mm){
				if(it.first!=0){
					int sec=it.second;
					if(sec==n*2/3&& (n*2%3==0) && mm[0]==(n/3) && (n%3==0)){
						cout<<"Yes"<<endl;return 0;
					}else{
						cout<<"No"<<endl;return 0;
					}
				}
			}
		}
	}
	if(mm.size()!=3){
		cout<<"No"<<endl;return 0;
	}
	set<int> ms;
	vector<int> mv;
	for(auto it:mm){
		ms.insert(it.second);
		mv.push_back(it.first);
	}
	if(ms.size()!=1){
		cout<<"No"<<endl;return 0;
	}
	if(mv[0] != (mv[1] ^ mv[2])){
		cout<<"No"<<endl;return 0;
	}
	cout<<"Yes"<<endl;return 0;
}

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

int main(){
  int n,m,i,j;
  cin>>n>>m;
  int a[m],b[m];
  for(i=0;i<m;i++){
    cin>>a[i]>>b[i];
  }
  int p[n];
  for(i=0;i<n;i++){
    p[i]=0;
    for(j=0;j<m;j++){
      if(a[j]==i+1)p[i]++;
      if(b[j]==i+1)p[i]++;
    }
  }
  for(i=0;i<n;i++){
    cout<<p[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)1<<30)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class T,typename I=typename T::iterator>auto&operator<<(ostream&os,T t){bool b=1;for(auto s:t)os<<(abi::__cxa_demangle(typeid(decltype(*declval<I>())).name(),0,0,0)[2]=='d'||exchange(b,0)?"":" ")<<s;return os<<endl;}

int main(){
	int n,c;
	cin>>n>>c;
	vvi f(3,vi(c,0));
	vvi cost(c,vi(c));
	rep(i,c)rep(j,c)cin>>cost[i][j];
	rep(i,n){
	    rep(j,n){
	        int t; cin>>t;
	        f[(i+j)%3][t-1]++;;
	    }
	}
	int ans=INF;
	rep(q,c)rep(w,c)rep(e,c){
	    if(q==w or q==e or w==e) continue;
	    vi color={q,w,e};
	    int p=0;
	    rep(i,3)rep(j,c){
	        p+=cost[j][color[i]]*f[i][j];
	    }
	    ans=min(ans,p);
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, S;
  cin >> K >> S;
  int N = 0; 
  for (int i = 0; i <= K; i++) {
   for (int j = 0; j <= K; j++) {
  if(i + j <= S && i + j + K >= S)
  N ++;  
   }
  }
  cout << N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

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

	int n; cin >> n;
	ll d; cin >> d;
	int result = 0;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		ll res = x * x + y * y;
		if (res <= d * d)
			result++;
	}
	cout << result << '\n';

	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<map>
#include<queue>
#include<algorithm>
#include<deque>
#include<string.h>
#define ll long long
//#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        ll num[200005];
        for(int i=0; i<n; i++)
            scanf("%lld",&num[i]);
        int r=0;
        ll sum0 = 0,sum1 = 0,ans = 0;
        for(int l=0; l<n; l++)
        {
            //r=l;
            while((sum0^num[r])==(sum1+num[r])&&r<n)
            {
                sum0 ^= num[r];
                sum1 += num[r++];
            }
            ans+=(r-l);
            sum0 ^= num[l];
            sum1 -= num[l];
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int b = 2;
        int[]a = new int[b];
        for(int i = 0; i < b; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        //result(a)でa[]を送れる
        int re = result(a);
        System.out.println(re);
    }

    //判定
    private static int result(int a[]){
        int re = 0;
        if(a[0] < a[1]){
            re = 0;
        }else{
            re = 10;
        }
        return re;
    }
}

Measured memory_bytes: 21844