akhauriyash/Code-Regression huggingface dataset:
n=int(input())
h=list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0
for i in range(n-1):
      dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
      if i<n-2:
            dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]))
print(dp[-1])


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

using namespace std;

const int MOD = 1000000007;
int counter[100010];

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;

    int x;
    long long sol = 1;
    for(int i=0; i < n ;++i){
        cin >> x;
        if(counter[x] == 3) sol = 0; 
        if(!x)
            sol = (sol * (3 - counter[0])) % MOD;
        else{
            if(counter[x-1] == 2 and counter[x] == 0)
                sol = (sol * 2) % MOD;
            else if(counter[x-1] == 3 and counter[x] == 0)
                sol = (sol * 3) % MOD;
            else if(counter[x-1] == 3 and counter[x] == 1)
                sol = (sol * 2) % MOD;
            else if(counter[x-1] <= counter[x])
                sol = 0;
        }
        counter[x]++;
    }

    cout << sol << '\n';
    
    return 0;
}

Measured memory_bytes: 640
while True:
  try:
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    hit = blow = 0
    for i in range(len(A)):
      if A[i] == B[i]:
        hit += 1
    print(hit, end=" ")
    for b in B:
      if A.count(b) > 0:
        blow += 1
    print(blow - hit)
  except:
    break

Measured memory_bytes: 5596
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int l,x[11],i,a,n;
	char s[11];
	cin>>s;
	l=strlen(s);
	n=1000;
	for(i=0;i<l;i++) x[i]=s[i]-'0';
	for(i=0;i<l-2;i++){
		a=x[i]*100+x[i+1]*10+x[i+2];
		a=753-a;
		if(0>a) a=a*(-1);
		if(n>a) n=a;
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] a = new int[n];
    List<Integer> c = new ArrayList<Integer>();
    for(int i=0;i<n;i++){
        a[i]=sc.nextInt();
    }
    c.add(a[0]);
    for(int i=1;i<n;i++){
        int left=0;
        int right=c.size();
        while(true){
            if(left>right){
                break;
            }
            if(left==c.size()){
                right--;
                break;
            }
            int gaze=c.get((left+right)/2);
            if(gaze<=a[i]-1){
                left=(left+right)/2+1;
            }else if(gaze>a[i]-1){
                right=(left+right)/2-1;
            }
        }
        if(left==0){
            c.add(0,a[i]);
        }else{
            c.set(right,a[i]);
        }
    }
    System.out.println(c.size());
  }
}

Measured memory_bytes: 50872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
      string S;
	  cin >> S;
  
  	  int start, end; 
  	  bool can =true;
  
  	  for(int i=0;i<S.size();i++){
        if(S[i] == 'A' && can){
          start = i;
          can = false;
        }
        if(S[i] == 'Z' && !can){
          end = i;
        }
      }
  cout << end - start + 1<<endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++) cin >> a[i];

	int ans=0, m=n+1;
	for(int i=0; i<n; i++){
		m=min(m, a[i]);
		if(a[i]<=m) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

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

	ArrayList<ArrayList<Integer>> g = new ArrayList<>();
	int V = 100005;
	boolean used[];
	int cnt[];
	private void dfs(int n) {
		ArrayDeque<Integer> st = new ArrayDeque<>();
		st.add(n);
		used[n]=true;
		cnt[n/V]++;
		while(!st.isEmpty()) {
			int s = st.pop();
			ArrayList<Integer> l = g.get(s);
			for(int i=0; i<l.size(); i++) {
				int t = l.get(i);
				if(!used[t]) {
					used[t]=true;
					cnt[t/V]++;
					st.add(t);
				}
			}
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		for(int i=0; i<V*2; i++) g.add(new ArrayList<>());
		used = new boolean[V*2];
		for(int i=0; i<n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			y += V;
			g.get(x).add(y);
			g.get(y).add(x);
		}

		long ans = 0;
		for(int i=0; i<V*2; i++) {
			if(!used[i]) {
				used[i]=true;
				cnt = new int[2];
				dfs(i);
				ans += (long)cnt[0]*cnt[1];
			}
		}
		ans -= n;
		System.out.println(ans);
		sc.close();
	}


}


Measured memory_bytes: 76820
def prime_factorize(N):
    res = [0] * (N+1)
    for n in range(2,N+1):
        a = 2
        while a*a <= n:
            if n % a == 0:
                ex = 0
                while n % a == 0:
                    ex += 1
                    n //= a
                #res.append((a, ex))
                res[a] += ex
            a += 1
        if n != 1:
            res[n] += 1
    return res

N = int(input())
prime = prime_factorize(N)

mod = 10 ** 9 + 7
ret = 1
for i in prime:
    ret *= (i+1)
    ret %= mod

print(ret)


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

int main(){
    int n,y;
    cin >> n >> y;
    int a = -1;
    int b = -1;
    int c = -1;
    bool flag = false;
    for(int i = 0;i<=20000;i++){
        for(int j = 0;j<= 20000;j++){
            if(y/1000 - n == 4*i+9*j && (y-5000*i-10000*j)/1000 >= 0){
                a = j;
                b = i;
                c = (y-5000*i-10000*j)/1000;
                
            }
        }
        
    }

    cout << a << " " << b << " " << c << endl;
}



Measured memory_bytes: 256
#include <utility>
#include <vector>
#include <iostream>
#include <cstdlib>
#include<bits/stdc++.h>
#include <limits>
#include <set>
#include <map>
#include <string>
#include <sstream>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
ull gcd(ull a, ull b){return b? gcd(b, a%b):a;}
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	ull H;
	cin >> H;

	ull count = 0;
	while(H > 0){
		H = (ull)(floor(H / 2));
		count += 1;
	}

	ull ans = pow(2, count) - 1;
    cout <<ans<< endl;
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
typedef complex<int> point;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

#define watch(x) cerr << (#x) << " = " << (x)    << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}


void smain() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    set<int> kek = {a, b, c, d};

    if (kek.count(1) && kek.count(9) && kek.count(4) && kek.count(7) ) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
        if(res>INT_MAX){
            return INT_MAX;
        }
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,a;
    cin>>n>>k;
    vector<ll> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll pos=-1;
    for(int i=0;i<n-1;i++){
        if(arr[i]+arr[i+1]>=k){
            pos=i+1;
            break;
        }
    }
    if(pos==-1) cout<<"Impossible";
    else{
        cout<<"Possible"<<endl;
        for(int i=1;i<pos;i++) cout<<i<<endl;
        for(int i=n-1;i>=pos;i--) cout<<i<<endl;
    }
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int num = 0;
  for (int i = A; i <= B; i++){
    int s, t, u, v;
    s = i % 10;
    t = i/10000 % 10;
    u = i/10 % 10;
    v = i/1000 % 10;
    if (s == t && u == v){
      num++;
    }
  }
  cout << num << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>

using namespace std;

int main() {
  int N,x;
  cin >> N >> x;
  int a[N];
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long int ans = 0;
  for(int i = 0; i < N; i++) {
    if(i != N-1) {
      int tmp = max(0, a[i] + a[i+1] - x);
      if(tmp > a[i+1]) {
        ans += tmp;
        tmp -= a[i+1];
        a[i+1] = 0;
        a[i] -= tmp;
      } else {
        ans += tmp;
        a[i+1] -= tmp;
      }
    } else {
      int tmp = max(0, a[i] - x);
      ans += tmp;
      a[i] -= tmp;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int n,m,p;
char code[1010][1010];
bool ma[1010][1010];
bool pattern[1010][1010];
ull ha[1010][1010],tmp[1010][1010];
ull mh[1010][1010];
bool tm1[1010][1010];
void compute_hash(bool a[1010][1010],int n,int m)
{
	const ull B1=9983;
	const ull B2=100000007;
    ull t1=1;
    for(int j=0;j<p;j++) t1*=B1;
		for(int i=0;i<n;i++)
		{
            ull e=0;
            for(int j=0;j<p;j++)
				e=e*B1+a[i][j];
			for(int j=0;j+p<=m;j++)
			{
				tmp[i][j]=e;
				if(j+p<m)e=e*B1-t1*a[i][j]+a[i][j+p];
			}
		}
		ull t2=1;
		for(int i=0;i<p;i++) t2*=B2;
		for(int j=0;j+p<=m;j++)
		{
			ull e=0;
			for(int i=0;i<p;i++)
				e=e*B2+tmp[i][j];
			for(int i=0;i+p<=n;i++)
			{
				ha[i][j]=e;
				if(i+p<n)
					e=e*B2-t2*tmp[i][j]+tmp[i+p][j];
			}
		}
}
int getbit(char ch)
{
	if(ch>='A'&&ch<='Z')return 0+ch-'A';
	if(ch>='a'&&ch<='z')return 26+ch-'a';
	if(ch>='0'&&ch<='9')return 52+ch-'0';
	if(ch=='+') return 62;
	return 63;
}
void  decode(bool mat[1010][1010],int h,int w)
{
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<(w+5)/6;j++)
		{
			int bit=getbit(code[i][j]);
			for(int k=0;k<6;k++)
				mat[i][j*6+k]=((bit>>(5-k))&1)==1;
		}
	}
}
void init()
{
	for(int i=0;i<n;i++)
		scanf("%s",code[i]);
	decode(ma,n,m);
	for(int i=0;i<p;i++)
		scanf("%s",code[i]);
	decode(pattern,p,p);
}
void rotate()
{
    for(int i=0;i<p;i++)
		for(int j=0;j<p;j++)
		{tm1[i][j]=pattern[j][p-1-i];
		}

	for(int i=0;i<p;i++)
		for(int j=0;j<p;j++)
		pattern[i][j]=tm1[i][j];
}
void mirror()
{
    for(int i=0;i<p;i++)
		for(int j=0;j<p;j++)
		tm1[i][j]=pattern[i][p-1-j];
	for(int i=0;i<p;i++)
		for(int j=0;j<p;j++)
		pattern[i][j]=tm1[i][j];
}
set<ull> seen;
void solve()
{
	seen.clear();
    int ans=0;
	compute_hash(pattern,p,p);
	ull hp=ha[0][0];
	seen.insert(hp);
	compute_hash(ma,n,m);
	for(int i=0;i+p<=n;i++)
	{
		for(int j=0;j+p<=m;j++)
		{
			if(ha[i][j]==hp)ans++;
		mh[i][j]=ha[i][j];
		}

	}
	for (int k=0;k<7;k++)
	{
		if(k==3)mirror();
		else rotate();
		compute_hash(pattern,p,p);
		hp=ha[0][0];
		if(seen.find(hp)!=seen.end())continue;
		seen.insert(hp);
		for(int i=0;i+p<=n;i++)
			for(int j=0;j+p<=m;j++)
			if(mh[i][j]==hp)ans++;
	}
	printf("%d\n",ans);
}
int main()
{
	for(;;)
	{
		scanf("%d%d%d",&m,&n,&p);
		if(n==0&&m==0&&p==0)break;
		init();
		solve();
	}
	return 0;
}

Measured memory_bytes: 28184
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq

logging.basicConfig(level=logging.DEBUG)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n,m = map(int,input().split())
	a = list(map(int,input().split()))
	priority = []
	for i in a:
		heapq.heappush(priority,-i)
	for _ in range(m):
		mx = heapq.heappop(priority)
		heapq.heappush(priority,-(-mx//2))
	print(-sum(priority))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


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

signed main(){
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if(A + B >= C){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    char a[101][101];
    int h, w; cin >> h >> w;

    rep(i, h){
        rep(j, w){
            cin >> a[i][j];
        }
    }

    vector<bool> row(h, false);
    vector<bool> col(w, false);

    rep(i, h){
        rep(j, w){
            if(a[i][j] == '#'){
                row[i] = true;
                col[j] = true;
            }
        }
    }

    rep(i, h){
        if(row[i]){
            rep(j, w){
                if(col[j]){
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3608
/* AOJ 0038*/

#include<iostream>
#include<queue>

using namespace std;

void Swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void BabbleSort(int *data,int n){

	int i,j;
	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){
			if(data[j] <= data[j-1]){
				Swap(&data[j],&data[j-1]);
			}
		}
	}

}

//onePair or threeCards or fourCards
int isSameCard(int *data){
	
	int tmp[13];

	for(int i=0;i<13;i++){
		tmp[i] = 0;
	}

	for(int i=0;i<5;i++){
		tmp[data[i]-1]++;
	}

	BabbleSort(tmp,13);

	if(tmp[12]==3 && tmp[11] == 2){
		return 6;//フルハウス
	}
	else if(tmp[12] == 4){
		return 7;//フォーカード
	}
	else if(tmp[12] == 3){
		return 4;
	}
	else if(tmp[12] == 2 && tmp[11] == 2){
		return 3;
	}
	else if(tmp[12] == 2){
		return 2;
	}
	else{
		return 1;
	}
}

int isStraight(int *data){
	
	int tmp[13];

	for(int i=0;i<13;i++){
		tmp[i] = 0;
	}

	for(int i=0;i<5;i++){
		tmp[data[i]-1]++;
	}

	if(tmp[9] == 1 && tmp[10] == 1 && tmp[11] == 1 && tmp[12]==1 && tmp[0]==1){
		return 5;
	}
	else{
		for(int i=0;i<=13-5;i++){
			if(tmp[i]==1&&tmp[i+1]==1&&tmp[i+2]==1&&tmp[i+3]==1&&tmp[i+4]==1){
				return 5;
			}
		}
	}

	return 1;
}

int main(){

	int data[5];
	char tmp;

	queue<int> ans;

	while(cin>>data[0]){
		if(data[0]==0){
			break;
		}
		cin>>tmp;
		cin>>data[1];
		cin>>tmp;
		cin>>data[2];
		cin>>tmp;
		cin>>data[3];
		cin>>tmp;
		cin>>data[4];

		BabbleSort(data,5);

		if(isSameCard(data)>=2){
			ans.push(isSameCard(data));
		}
		else{
			ans.push(isStraight(data));
		}

	}

	int size=ans.size();

	for(int i=0;i<size;i++){
		switch(ans.front()){
		case 7:
			cout<<"four card"<<endl;
			break;
		case 6:
			cout<<"full house"<<endl;
			break;
		case 5:
			cout<<"straight"<<endl;
			break;
		case 4:
			cout<<"three card"<<endl;
			break;
		case 3:
			cout<<"two pair"<<endl;
			break;
		case 2:
			cout<<"one pair"<<endl;
			break;
		case 1:
			cout<<"null"<<endl;
			break;
		}
		ans.pop();
	}

	return 0;
}

Measured memory_bytes: 1192
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>

using namespace std;

int k[256];
int x[256][16], d[256][16];
int memo[256][16][128];
int n, m;

int getMin(int nowY, int idx, int left)
{
	if (nowY == n) return (0);
	if (~nowY && memo[nowY][idx][left] >= 0) return (memo[nowY][idx][left]);
	
	int res = INT_MAX;
	
	for (int i = 0; i < k[nowY + 1]; i++){
		int bad = (nowY == -1 || nowY == n - 1 ? 0 : (d[nowY][idx] + d[nowY + 1][i]) * abs(x[nowY][idx] - x[nowY + 1][i]));
		res = min(res, getMin(nowY + 1, i, left) + bad);
	}
	
	if (left && nowY + 2 <= n){
		for (int i = 0; i < k[nowY + 2]; i++){
			int bad = (nowY == -1 || nowY == n - 2 ? 0 : (d[nowY][idx] + d[nowY + 2][i]) * abs(x[nowY][idx] - x[nowY + 2][i]));
			res = min(res, getMin(nowY + 2, i, left - 1) + bad);
		}
	}
	
	if (~nowY) memo[nowY][idx][left] = res;
	return (res);
}

int main()
{
	while (scanf("%d %d", &n, &m) && n){
		
		for (int i = 0; i < n; i++){
			scanf("%d", k + i);
			for (int j = 0; j < k[i]; j++){
				scanf("%d %d", &x[i][j], &d[i][j]);
			}
		}
		k[n] = 1;
		
		memset(memo, -1, sizeof(memo));
		
		printf("%d\n", getMin(-1, 0, m));
		
	}
	return (0);
}

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

int main()
{
    int N, M, t;
    std::scanf("%d", &N);
    std::vector<int> v;
    v.reserve(N);
    for (int i = 0; i < N; i++) {
        std::scanf("%d", &t);
        v.push_back(t);
    }
    std::sort(v.begin(), v.end());
    std::vector<int>::iterator it;
    int sum = 0;

    std::scanf("%d", &M);
    for (int i = 0; i < M; i++) {
        std::scanf("%d", &t);
        it = std::lower_bound(v.begin(), v.end(), t);
        if (it != v.end() && v[it-v.begin()] == t) sum++;
    }
    std::cout << sum << std::endl;
    return 0;
}



Measured memory_bytes: 3220
N, K = map(int, input().split())
H = list(map(int, input().split()))

inf = float('inf')
dp = [inf] * (N + 1)
dp[1] = 0

for i in range(1, N):
    for j in range(1, K + 1):
        if i + j <= N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(H[i - 1] - H[i + j - 1]))

print(dp[N])
# print(dp)


Measured memory_bytes: 55264
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	int s[110];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>s[i];
		sum+=s[i];
	}
	sort(s,s+n);
	if(sum%10==0){
		for(int i=0;i<n;i++){
			if(s[i]%10!=0){
				sum-=s[i];
				cout<<sum<<endl;
				return 0;
			}
		}
		cout<<0<<endl;
		return 0;
	}
	else{
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    rrep(i, 1000) {
        if(k * i >= a && k * i <= b) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;


    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        for(int i = n - 1; i >= 0; i--){
            System.out.print(a[i]);
            if(i != 0){
                System.out.print(" ");
            }else{
                System.out.println();
            }    
        }
    }
}

Measured memory_bytes: 26340
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>

int main()
{
    std::string s, p;
    std::cin >> s >> p;

    std::string ringString = std::move(s + s);

    std::vector<std::string> list;
    for (std::size_t i = 0; i < s.length(); ++i) {
        std::stringstream oss;
        for (std::size_t j = i; j < i + p.length(); ++j) {
            oss << ringString[j];
        }
        list.push_back(oss.str());
    }

    if (std::find(list.begin(), list.end(), p) != list.end()) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;

}


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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

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

    cout << (n[0]==n[2] ? "Yes" : "No") << 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 A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		int X = Integer.parseInt(sc.next());
		sc.close();

		int count = 0;
		for(int a = 0; a <= A; a++) {
			for(int b = 0; b <= B; b++) {
				for(int c = 0; c <= C; c++) {

					int check = 500 * a + 100 * b + 50 * c;
					if(check == X) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21972
def main():
    n, m = map(int, input().split())
    p = [0] * m
    y = [0] * m
    dic = {}
    cities = [[] for _ in range(n)]
    x = [0] * m
    for i in range(m):
        p[i], y[i] = map(int, input().split())
        cities[p[i] - 1].append(y[i])
        dic[y[i]] = i
    for i in cities:
        for ind, j in enumerate(sorted(i), 1):
            x[dic[j]] = ind
    for i in range(m):
        print("{:06}{:06}".format(p[i],x[i]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 34572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=5003;
const ll INF=1LL<<30;

bool compare(pair<ll,ll> a,pair<ll,ll> b){
    return atan2(a.first,a.second)<atan2(b.first,b.second);
}

int main(){
    
    int N;cin>>N;
    vector<pair<ll,ll>> P(N);
    for(int i=0;i<N;i++){
        cin>>P[i].first>>P[i].second;
    }
    
    sort(all(P),compare);
    for(int i=0;i<N;i++){
        P.push_back(P[i]);
    }
    
    vector<ll> xsum(2*N+1,0.0),ysum(2*N+1,0.0);
    ll ans=0;
    
    for(int i=1;i<=2*N;i++){
        xsum[i]+=xsum[i-1]+P[i].first;
        ysum[i]+=ysum[i-1]+P[i].second;
    }
    
    for(int i=0;i<N;i++){
        for(int j=i;j<i+N;j++){
            ll X=xsum[j+1]-xsum[i];
            ll Y=ysum[j+1]-ysum[i];
            ans=max(ans,X*X+Y*Y);
        }
    }
    
    long double left=0.0,right=2000000000.0,mid;
    for(int i=0;i<300;i++){
        mid=(left+right)/2.0;
        if(mid*mid>=ans) right=mid;
        else left=mid;
    }
    
    cout<<setprecision(25)<<mid<<endl;
}





Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int H, W, K;

  cin >> H >> W >> K;
  vector<string> G(H);
  cin >> G;
  int cnt = 0;
  vector<vector<int>> ans(H, vector<int>(W));
  for (int i = 0; i < H; ++i) {
    if (!count(G[i].begin(), G[i].end(), '#')) {
      if (cnt)
        ans[i] = ans[i - 1];
    } else {
      for (int j = 0; j < W; ++j)
        if (G[i][j] == '#')
          ans[i][j] = ++cnt;
        else if (j)
          ans[i][j] = ans[i][j - 1];
      for (int j = W - 1; j >= 0; --j)
        if (!ans[i][j])
          ans[i][j] = ans[i][j + 1];
    }
  }
  for (int i = H - 1; i >= 0; --i)
    if (!ans[i][0])
      ans[i] = ans[i + 1];
  for (int i = 0; i < H; ++i) {
    cout << ans[i] << '\n';
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception{
        // Your code here!
     		Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int i =a*b;
            if(i%2==0){
                System.out.println("Even");
                
            }
            if(i%2!=0){
                System.out.println("Odd");
                
            }
        
    }
}

Measured memory_bytes: 35748
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class UnionFind:
    """ Union-Find木 """

    def __init__(self, n):
        self.n = n
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)
        # あるノードを根とする集合に属するノード数
        self.size = [1] * (n+1)
        # あるノードを根とする集合が木かどうか
        self.tree = [True] * (n+1)

    def find(self, x):
        """ 根の検索(グループ番号と言えなくもない) """
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """ 併合 """
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 木かどうかの判定用
        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def is_same(self, x, y):
        """ 同じ集合に属するか判定 """
        return self.find(x) == self.find(y)

    def get_size(self, x=None):
        if x is not None:
            """ あるノードの属する集合のノード数 """
            return self.size[self.find(x)]
        else:
            """ 集合の数 """
            res = set()
            for i in range(self.n+1):
                res.add(self.find(i))
            # グループ0の分を引いて返却
            return len(res) - 1
    
    def is_tree(self, x):
        """ 木かどうかの判定 """
        return self.tree[self.find(x)]

N, M, K = MAP()
uf = UnionFind(N)
ans = [0] * N
for i in range(M):
    a, b = MAP()
    a -= 1; b -= 1
    uf.union(a, b)
    ans[a] -= 1
    ans[b] -= 1
for a in range(N):
    ans[a] += uf.get_size(a) - 1
for i in range(K):
    a, b = MAP()
    a -= 1; b -= 1
    if uf.is_same(a, b):
        ans[a] -= 1
        ans[b] -= 1
print(*ans)


Measured memory_bytes: 91424
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;
 
int main(void){
    long long int L, R;
    cin >> L >> R;
    if(R-L>2019)
       R=L+2019;
    long long int w = 2019;
    long long int ans = 10000;
    int checkl, checkr;
    for(long long int i = L; i <= R-1; i++){
        for(long long int j = L+1; j <= R; j++){
            ans = min(ans, ((i%w)*(j%w)%w));
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define rrep(i,s,e) for(int (i) = (s);(i) >= (e);(i)--)

signed main() {
    int n,x;cin>>n>>x;
    vector<int> a(n);
    rep(i,0,n-1) cin >> a[i];
    sort(a.begin(),a.end());   
    rep(i,0,n-1)
    {
        if(x<a[i])
        {
            cout << i << endl;
            return 0;
        }
        x -= a[i];
    }

    if(x == 0)cout << n << endl;
    else cout << n-1 << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<P>> graph(n, vector<P>());
	vector<set<int>> st(n);
	rep(i, m) {
		int u, v, c;
		cin >> u >> v >> c;
		u--; v--;
		graph[u].pb({ c,v });
		graph[v].pb({ c,u });
		st[u].insert(c);
		st[v].insert(c);
	}
	rep(i, n) {
		sort(all(graph[i]));
		graph[i].pb({ inf,inf });
	}
	map<P, int> dp;
	dp[{0, 0}] = 0;
	deque<P> que;
	que.push_back({ 0,0 });
	while (!que.empty()) {
		P p = que.front(); que.pop_front();
		int v = p.first; int c = p.second;
		int idx = lower_bound(all(graph[v]), P(c, 0)) - graph[v].begin();
		while (graph[v][idx].first == c) {
			int nxt = graph[v][idx].second;
			if (!dp.count({ nxt,c }) || dp[{nxt, c}] > dp[{v, c}]) {
				dp[{nxt, c}] = dp[{v, c}];
				que.push_front({ nxt,c });
			}
			idx++;
		}
		for (int i : st[v]) {
			if (!dp.count({ v,i }) || dp[{v, i}] > dp[{v, c}] + 1) {
				dp[{v, i}] = dp[{v, c}] + 1;
				que.push_back({ v,i });
			}
		}
		st[v].clear();
		//cout << v << ' ' << c << ' ' << dp[{v, c}] << '\n';
	}
	int ans = inf;
	for (auto i : dp) {
		if (i.first.first == n - 1) {
			chmin(ans, i.second);
		}
	}
	cout << (ans == inf ? -1 : ans) << '\n';
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) cin >> a[i];

    int ans = INF;
    for (int i = -100; i <= 100; i++) {
        int tmp = 0;
        rep (j, n) {
            tmp += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

void kansu(int,int);

int main(void)
{
	int a,b;
	
	scanf("%d %d",&a,&b);
	while(a!=0 && b!=0){
		kansu(a,b);
		scanf("%d %d",&a,&b);
	}
	return 0;
}
void kansu(int a,int b)
{
	int i,j,x,y,n;
	int suu[17][17];
	int kouji[17][17];
	
	scanf("%d",&n);
	for(i=1;i<=a;i++){
		for(j=1;j<=b;j++){
			kouji[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		kouji[x][y]=1;
	}
	for(i=1;i<=a;i++){
		for(j=1;j<=b;j++){
			if(kouji[i][j]==1){
				suu[i][j]=0;
			}
			else {
				if(i==1 && j==1){
					suu[i][j]=1;
				}
				else {
					if(i==1){
						suu[i][j]=suu[i][j-1];
					}
					else if(j==1){
						suu[i][j]=suu[i-1][j];
					}
					else {
						suu[i][j]=suu[i][j-1]+suu[i-1][j];
					}
				}
			}
		}
	}
	printf("%d\n",suu[a][b]);
}
					

Measured memory_bytes: 604
///int ->(-2147483648<->2147483647)
///unsigned int(0<->4294967295)
///long long int (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
///unsigned long long int (0 to 18,446,744,073,709,551,615)
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<math.h>
#include<algorithm>
#include<string>
#include<utility>
#include<stack>
#include<cstring>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<iomanip> ///setprecision
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define INF 1000000000
#define ll long long
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define pdd pair<double,double>
#define vi vector<int>
#define vll vector<long long>
#define vc vector<char>
#define vd vector<double>
#define sci(value) scanf("%d%*c",&value)
#define scl(value) scanf("%lld%*c",&value)
#define pi  (2*acos(0))
#define pb push_back
#define valid(value123,value234,limitrow,limitcol) value123>=0&&value123<limitrow&&value234>=0&&value234<limitcol
//int fx[]= {0,0,1,-1,-1,1,-1,1};//kings move
//int fy[]= {1,-1,0,0,-1,1,1,-1};//kings move
//int fx[]={-2,-2,-1,-1, 1,1, 2,2};  // Knights Move
//int fy[]={-1, 1,-2, 2,-2,2,-1,1}; // Knights Move
//ll powFunction(ll a,ll b){if(b==0)return 1;ll re=powFunction(a,b/2);re=(re*re);if(b&1)re=(re*a);return re;}
///ll digitSum(ll a){ll ans=0;while(a){ans+=(a%10);a/=10;}return ans;}

#define MX 100005
#define mod 1000000007
vector<int>graph[MX];
vector<pii>vec;
map<pii,int>mp;
bool visit[MX];
int mark[MX];
int ans=0;

void bfs(int src)
{
    queue<int>qu;
    qu.push(src);
    visit[src]=1;
    while(!qu.empty())
    {
        int u=qu.front();
        qu.pop();
        int x=1;
        for(int i=0;i<graph[u].size();i++)
        {
            int v=graph[u][i];
            if(!visit[v])
            {
                visit[v]=1;
                qu.push(v);
                if(mark[u]==x)
                    x++;
                mark[v]=x;
                mp[{u,v}]=x;
                mp[{v,u}]=x;
                x++;
            }
        }
        if(ans<x)
            ans=x;
    }
}

int main()
{
    /*
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","r",stdin);
    #endif // ONLINE_JUDGE*/
    int n,a,b;
    sci(n);
    for(int i=1;i<n;i++)
    {
        sci(a),sci(b);
        graph[a].push_back(b);
        graph[b].push_back(a);
        vec.push_back({a,b});
    }
    bfs(1);
    printf("%d\n",ans-1);
    for(int i=0;i<(n-1);i++)
    {
        printf("%d\n",mp[{vec[i].first,vec[i].second}]);
    }

}




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

long long int diff(int *a, int n, int x)
{
	long long int ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]<x)
			ans = ans+x-a[i];
		else
			ans = ans+a[i]-x;
	}
	return ans;
}

int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		a[i] = a[i] - (i+1);
	sort(a, a+n);
	int mid = n/2;
	cout<<diff(a,n,a[mid])<<endl;
	return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int nmax = 15;
const int pmax = 1100;
int n;
ll g;
int p[nmax], c[nmax];
ll f[nmax][pmax];
int sum = 0;
int main() {
    IO;
    scanf("%d %lld", &n, &g);
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &p[i], &c[i]);
        sum += p[i];
    }
    ll res = INF;
    for (int i = 0; i <= n; i++)
    for (int j = 0; j <= sum; j++)
        f[i][j] = -LINF;
    f[0][0] = 0ll;
    for (int i = 1; i <= n; i++)
    for (int j = 0; j <= sum; j++) {
        for (int jx = 0; jx <= j; jx++) 
        if (j - jx <= p[i]) {
            if (j - jx == p[i]) 
                f[i][j] = max(f[i][j], f[i - 1][jx] + 1ll * (j - jx) * 100 * i + 1ll * c[i]);
            else 
                f[i][j] = max(f[i][j], f[i - 1][jx] + 1ll * (j - jx) * 100 * i);
        }
        if (f[i][j] >= g) {
            res = min(res, 1ll * j);
            //cout << f[i][j] << " " << i << " " << j << "\n";
        }
    }
    printf("%d", res);
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static int cnt=0;
	
	public static int[] L=new int[500000/2+2];
	public static int[] R=new int[500000/2+2];
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan =new Scanner(System.in);
		int n=scan.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++){
			arr[i]=scan.nextInt();
		}
		long sum=mergeSort(arr,n,0,n);
		System.out.println(sum);
		//arrPrint(arr);
		//System.out.println(cnt);
	}

	private static long mergeSort(int[] arr, int n, int low, int high) {
		// TODO Auto-generated method stub
		if(low+1<high){
			int mid=(low+high)/2;
			long v1=mergeSort(arr, n, low, mid);
			long v2=mergeSort(arr, n, mid, high);
			long v3=merge(arr, n, low, mid,high);
			return v1+v2+v3;
		}
		else return 0;
	}

	private static long  merge(int[] arr, int n, int low, int mid,int high){
		// TODO Auto-generated method stub
		long res=0;
		int n1=mid-low;
		int n2=high-mid;
		for(int i=0;i<n1;i++) L[i]=arr[low+i];
		for(int i=0;i<n2;i++) R[i]=arr[mid+i];
		L[n1]=R[n2]=2000000000;
		int i=0,j=0;
		for(int k=low;k<high;k++){
			cnt++;
			if(L[i]<=R[j]){
				arr[k]=L[i++];
				
			}
			else{
				arr[k]=R[j++];
				res+=n1-i;
			}
		}
		return res;
	}

	public static void arrPrint(int[] arr){
		int i=0;
		for(i=0;i<arr.length-1;i++)
			System.out.print(arr[i]+" ");
		System.out.println(arr[i]);
	}
}



Measured memory_bytes: 105492
N,A,B,C = map(int,input().split())

import sys
sys.setrecursionlimit(500000)

s = []

for i in range(N):

    S = input()
    s.append(S)

def dfs(dep,A,B,C):

    if dep == N:
        return []

    if s[dep] == "AB":

        if A == B == 0:
            return None
        if A >= B:
            cat = dfs(dep+1,A-1,B+1,C)
            if cat != None:
                cat.append("B")
                return cat
        if A <= B:
            cat = dfs(dep+1,A+1,B-1,C)
            if cat != None:
                cat.append("A")
                return cat

    elif s[dep] == "BC":
        
        if B == C == 0:
            return None
        if B >= C:
            cat = dfs(dep+1,A,B-1,C+1)
            if cat != None:
                cat.append("C")
                return cat
        if B <= C:
            cat = dfs(dep+1,A,B+1,C-1)
            if cat != None:
                cat.append("B")
                return cat

    else:

        if A == C == 0:
            return None
        if A >= C:
            cat = dfs(dep+1,A-1,B,C+1)
            if cat != None:
                cat.append("C")
                return cat
        if A <= C:
            cat = dfs(dep+1,A+1,B,C-1)
            if cat != None:
                cat.append("A")
                return cat

    return None

       
rev = dfs(0,A,B,C)

if rev == None:
    print ("No")
else:
    print ("Yes")
    for i in range(N-1,-1,-1):
        print (rev[i])
    
    

Measured memory_bytes: 110028
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main()
{
    int n; cin >> n;
    vector<ll> a(n);
    ll ans = 1LL;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (!a[i]) {
            ans = 0LL;
            goto end;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (a[i] > 1000000000000000000LL / ans) {
            ans = -1LL;
            break;
        }
        ans *= a[i];
    }

    end:;
        cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4040
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358

int main(void){
    double a, b, hour, min, radh, radm, rad, ans;
    scanf("%lf %lf %lf %lf", &a, &b, &hour, &min);
    
    radh = 2*PI * (hour + min / 60) / 12;
    radm = 2*PI * min / 60;
    rad = (radh - radm < PI) ? radh - radm : radm - radh;
    
    ans = sqrt(a*a + b*b - 2*a*b*cos(rad));
    printf("%.10lf", ans);
    
    return 0;
}


Measured memory_bytes: 2520
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;

    vector<vector<int> > table(n+1, vector<int>(n+1));
    for (int i = 0; i < n; ++i) {
      int sum = 0;
      for (int j = 0; j < n; ++j) {
	scanf("%d", &table[i][j]);
	sum += table[i][j];
      }
      table[i][n] = sum;
    }

    for (int i = 0; i < n+1; ++i) {
      int sum = 0;
      for (int j = 0; j < n; ++j)
	sum += table[j][i];
      table[n][i] = sum;
    }

    for (int i = 0; i < n+1; ++i) {
      for (int j = 0; j < n+1; ++j)
	printf("%5d", table[i][j]);
      puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
int main(){
	long A[100][100], b[100], c[100];
	int m, n;
	scanf("%d%d", &m, &n);
	int i, j = 0;
	while(i++ < m){
		j = 0;
		while(j++ < n) scanf("%d", &A[i-1][j-1]);
	}
	i = 0;
	while(i++ < n) scanf("%d", &b[i-1]);
	i = 0;
	while(i++ < m){
		c[i-1], j = 0;
		while(j++ < n) c[i-1] += A[i-1][j-1]*b[j-1];
	}
	for(int i = 0; i < m; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}


Measured memory_bytes: 2800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int A[N];
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  
  int count[N] = {};
  int test;
  for(int i = 0; i < N; i++){
    test = A[i] - 1;
    count[test]++;
  }
  sort(count, count + N);
  
  int integ;
  for(int i = 0; i < N - K; i++){
    integ += count[i];
  }
  
  cout << integ << endl;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    string S;
    cin >> S;
    cout << (S[2] == S[3] && S[4] == S[5] ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			int h = scan.nextInt();
			int w = scan.nextInt();
			if (h == 0 && w == 0) break;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (i == 0 || i == h - 1 || j == 0 || j == w - 1) {
						System.out.print("#");
					} else System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 34612