akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vb vector<bool>
#define vs vector<string>
#define px(x) cout << x << endl
#define pfi(x) printf("%d\n", x)
#define pfs(x) printf("%s\n", x)
#define sfi(x) scanf("%d", &x)
#define sfs(x) scanf("%s", x)

int main() {
    string s;
    string t;
    cin >> s >> t;  
    int count = 0;

    for(int i=0; i<3; i++){
        if(s[i] == t[i]){
            count += 1;
        }   
    }
    cout << count << endl;
	return 0;
}

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

int arr[101] = {0};

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



Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
#define VI vactor<int>
#define VII vactor<vector<int>>
#define PII pair<int,int>

int main(){
  int A,B;
  cin>>A>>B;
  cout<<max({A+B,A-B,A*B})<<endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 2e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int H, W; cin >> H >> W;
    vs s(H); REP(i, H) cin >> s[i];
    REP(i, W+2) cout << "#"; cout << endl;
    REP(i, H)
    {
        cout << "#";
        cout << s[i];
        cout << "#" << endl;
    }
    REP(i, W+2) cout << "#"; cout << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int s,p;

int main(i){
	while(1){
		scanf("%d",&s);
		if(!s)break;
		i=1;
		for(;i<10;i++){
			scanf("%d",&p);
			s-=p;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int fib(int);
int F[45];
int main(){
  int i,v;
  for(i=0;i<45;i++){
    F[i]=0;
  }
  scanf("%d",&v);

  printf("%d\n",fib(v));
  
  return 0;
}

int fib(int n){
  if(n == 0 || n == 1)return 1;
  if(F[n] != 0)return F[n];
  F[n] = fib(n-1) + fib(n-2);
  return F[n];
}



Measured memory_bytes: 2104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String A = sc.next();
      String B = sc.next();
      String C = sc.next();
      if(A.equals(B)&&B.equals(C)&&C.equals(A)){
        System.out.println("No");
      }else if(!(A.equals(B)||B.equals(C)||C.equals(A))){
        System.out.println("No");
      }else{
        System.out.println("Yes");
      }
    }
}

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

using ll = long long;

int main() 
{
    int n; cin >> n;
    ll H[100010];
    for (int i = 0; i < n; i++)
    {
        cin >> H[i];
    }

    if (n == 1) {
        cout << "Yes" << "\n";
        return 0;
    }
    int threshold = 0;
    for (int i = 0; i < n-1; i++)
    {
        if (H[i]-H[i+1]>1) {
            cout << "No" << "\n";
            return 0;
        } else if (H[i] - H[i+1] == 1) {
            if (threshold == H[i] && i > 0) {
                cout << "No" << "\n";
                return 0;
            }
            H[i]--;
        } else {
            if (threshold != H[i] && i > 0) {
               H[i]--;
            }
            
        }

        threshold = H[i];
    }

    cout << "Yes" << "\n";
    
    

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
ifstream f("A.ni");

int main()
{
    int H1,H2,M1,M2,K;
    cin>>H1>>M1>>H2>>M2>>K;
    int tot=60*(H2-H1)+M2-M1;
    tot-=K;
    cout<<tot;


    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int a,b;
	cin >> a >> b;
	if(b%a == 0) cout << (a+b) << endl;
	else cout << (b-a) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N =1e6;
const int INF =1e18;

LL int dp[N], h[N];

int main(){
    int n, k;
    scanf("%d", &n);
    scanf("%d", &k);
    for(int i =0; i < n;i ++){
        scanf("%lld", &h[i]);
        dp[i] = INF;
    }
    dp[1] = abs(h[0]-h[1]);
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = i; j >= 0 && j >= i-k; j--)
            dp[i] = min(dp[i], (dp[j] + abs(h[i]-h[j])));
    }
    //for(int i = 0; i < n; i++)cout << dp[i] << " ";
    //cout << endl;
    printf("%lld\n", dp[n-1]);

}


Measured memory_bytes: 5120
#include<iostream>
#include<limits>
#include<string>
using namespace std;
int main()
{
	int num, distance;
	cin >> num >> distance;

	int ret = num / (distance * 2 + 1);
	if (ret * (distance * 2 + 1) < num)
	{
		ret++;
	}
	cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  int h,w;
  cin>>h>>w;
  int a[h][w];
  REP(i,h){
    string s;
    cin>>s;
    REP(j,w){
      if(s[j]=='.'){
        a[i][j] = 0;
      }else{
        a[i][j] = 1;
      }
    }
  }

  REP(i,h){
    bool b = false;
    REP(j,w){
      if(a[i][j]==1){
        b = true; 
        break;
      }
    }
    if(b==true){
      REP(j,w){
        bool b2 = false;
        REP(k,h){
          if(a[k][j]==1){
            b2 = true;
            break;
          }
        }
        if(b2==true){
          if(a[i][j]==1){
            cout<<"#";
          }else{
            cout<<".";
          }
        }
      }
      cout<<endl;
    }
  }


  return 0;
}

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

const int ALPHABET = 26;
int main() {
	int alpha[ALPHABET], H, W;
	for (int i = 0;i < ALPHABET;i ++)alpha[i] = 0;
	string s;
	cin >> H >> W;
	for (int i = 0;i < H;i ++) {
		cin >> s;
		W = s.length();
		for (int j = 0;j < W;j ++) {
			alpha[s[j] - 'a'] ++;
		}
	}
	int four, two = 0, one = 0;
	if (H % 2 == 1) {
		two += W / 2;
	}
	if (W % 2 == 1) {
		two += H / 2;
		if ((H + W) % 2 == 0) {
			one ++;
		}
	}
	four = (H * W - two * 2 - one) / 4;
	for (int i = 0;i < ALPHABET;i ++) {
		if (alpha[i] == 0) continue;
		four -= alpha[i] / 4;
		if (alpha[i] % 4 == 0);
		else if (alpha[i] % 2 == 0)	two --;
		else {
			if (alpha[i] % 4 == 3) two --;
			one --;
		};
		if (four < 0) two -= 2;
		if (two < 0 || one < 0) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""

"""



if __name__ == '__main__':
    n = int(input())
    data = [0 for _ in range(100000+2)]
    nums = [int(x) for x in input().split(' ')]
    for num in nums:
        data[num] += 1

    max_ans = 0
    for x in range(100000):
        temp = sum(data[x:x+3])
        if temp > max_ans:
            max_ans = temp
    print(max_ans)


Measured memory_bytes: 14708
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using namespace std;

void SolveA()
{
	int n, cnt = 0;
	scanf("%d", &n);

	while (n >= 3)
	{
		n = n - 3;
		cnt++;
	}

	printf("%d\n", cnt);
}

void SolveB()
{
	int n;
	scanf("%d", &n);

	string s = "";
	for (int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		s.append(str);
	}
	

	bool isPink = false;

	if (s.find('Y') != string::npos)
	{
		isPink = true;
	}

	if (isPink)
	{
		printf("Four\n");
	}
	else
	{
		printf("Three\n");
	}
}

void SolveC()
{
	long long int n;
	cin >> n;

	vector<string> strs;
	for (long long int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		strs.push_back(str);
	}
}

void SolveD()
{
	int H, W, D;
	scanf("%d %d %d", &H, &W, &D);
	
	int posx[90001], posy[90001];
	
	for (int h = 0; h < H; h++)
	{
		for (int w = 0; w < W; w++)
		{
			int A;
			scanf("%d", &A);
			posx[A] = w + 1;
			posy[A] = h + 1;
		}
	}

	//for (int q = 0; q < Q; q++)
	//{
	//	int L, R;
	//	scanf("%d %d", &L, &R);
	//	long long int mp = 0;
	//	if (L == R)
	//	{
	//		//cout << mp << "\n";
	//		printf("%d\n", mp);
	//		continue;
	//	}
	//	else
	//	{
	//		int sum = L + D;
	//		int prt = L;
	//		mp += abs(posx[sum] - posx[prt]) + abs(posy[sum] - posy[prt]);
	//		while (sum != R)
	//		{
	//			prt = sum;
	//			sum = sum + D;
	//			mp += abs(posx[sum] - posx[prt]) + abs(posy[sum] - posy[prt]);
	//		}
	//	}
	//	printf("%d\n", mp);
	//	//cout << mp << "\n";
	//}

	vector<int> d;
	d.resize(90001, 0);

	// 累積和の導出
	for (int i = D + 1; i <= H * W; i++)
	{
		d[i] = d[i - D] + abs(posx[i] - posx[i - D]) + abs(posy[i] - posy[i - D]);
	}

	int Q;
	scanf("%d", &Q);

	while (Q--)
	{
		int L, R;
		scanf("%d %d", &L, &R);
		printf("%d\n", d[R] - d[L]);
	}
}

void EditSolveC()
{

}

int main()
{
	//SolveA();
	//SolveB();
	//SolveC();
	SolveD();
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

vector<vector<pair<int,pair<int,int> > > >adj;
int dis[100005][2];
void dikstra(int ver,int x)
{
    dis[ver][x]=0;
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >qq;
    qq.push({0,ver});
    while (!qq.empty())
    {
        pair<int,int>pp=qq.top();
        qq.pop();
        if(dis[pp.second][x]<pp.first)
            continue;
        for(auto i:adj[pp.second])
        {
            int z=0;
            if(x==0)
                z=i.second.first;
            else
                z=i.second.second;
            if(dis[i.first][x]>pp.first+z)
            {
                dis[i.first][x]=pp.first+z;
                qq.push({dis[i.first][x],i.first});
            }
        }
    }    
}

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,m,s,t;
    cin>>n>>m>>s>>t;
    adj.resize(n+1);
    int x,y,a,b;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y>>a>>b;
        adj[x].push_back({y,{a,b}});
        adj[y].push_back({x,{a,b}});
    }

    for(int i=1;i<=n;i++)
        for(int j=0;j<2;j++)
            dis[i][j]=1e17;

    dikstra(s,0);
    dikstra(t,1);


    int mn=1e17;
    int z=1e15;
    vector<int>ans;
    for(int i=0;i<n;i++)
    {
        mn=min(mn,dis[n-i][0]+dis[n-i][1]);
        ans.push_back(z-mn);
    }        
    reverse(ans.begin(),ans.end());
    for(auto i:ans)
        cout<<i<<'\n';
} 
    


Measured memory_bytes: 15312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader buff = null;
		buff = new BufferedReader(new InputStreamReader(System.in));

		int A = Integer.parseInt(buff.readLine());
		int B = Integer.parseInt(buff.readLine());
		int C = Integer.parseInt(buff.readLine());
		int X = Integer.parseInt(buff.readLine());
		int count = 0;
		for(int i = 0; i <= A; ++i){
			for(int j = 0; j <= B; ++j){
				for(int k = 0; k <= C; ++k){
					int tmp = 500 * i + 100 * j + 50 * k;
					if(tmp == X){
						count++;
					}
				}
			}
		}

		System.out.println(count);
	}

	static long f() {
		long ans = 0;


		return ans;
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define WA cout<<"char134217728";exit(0)
#define RE throw
#define TLE sleep(1000)
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll a, b;
ll c(ll d, int g){
  ll f = d/bit(g+1)*bit(g) + ((d&bit(g)) ? d%bit(g)+1 : 0);
  return f%2;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;
  if(a==0&&b==0){
    cout << 0 << endl;
    return 0;
  }
  if(a==0) a++;
  if(b==0) b++;
  ll ans = 0;
  FOR(i, 0, 60){
    ans += (c(a-1, i)^c(b, i))*bit(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[105];
int n;
inline void read(int &x)
{
	int f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
inline int mn(int _x,int _y)
{
	return _x<_y?_x:_y;
}
inline int mx(int _x,int _y)
{
	return _x>_y?_x:_y;
}
inline int ab(int _x)
{
	if(_x<0) return -_x;
	else return _x;
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i]);
	for(int i=1;i<=n;i++)
	{
		if(a[i]%2!=0) continue;
		if(a[i]%3!=0&&a[i]%5!=0) 
		{
			printf("DENIED\n");
			return 0;
		}
	}
	printf("APPROVED\n");
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<map>
using namespace std;
int main(){
  int l, r,ans=2018;
  cin >> l >> r;
  if(r/2019>l/2019)ans=0;
  l%=2019;r%=2019;
  for(int i=r;i>l;i--){
    for(int j=l;j<i;j++){
      if(ans>(i*j)%2019)ans=(i*j)%2019;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[]
for i in range(n):
  b=int(input())
  c=[[] for _ in range(n)]
  for j in range(b):
    x,y=map(int,input().split())
    c[x-1]=y
  a.append(c)
ans=[]
for i in range(2**n):
  tr=bin(i)[2:].zfill(n)
  cnt=0
  for j in range(n):
    if tr[j]=='1':
      for k in range(n):
        if a[j][k]!=[] and a[j][k]!=int(tr[k]):
          break
      else:
        cnt+=1
  if sum(list(map(int,tr)))==cnt:ans.append(cnt)
print(max(ans))

Measured memory_bytes: 75536
#include <bits/stdc++.h>
#define max 1000000
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define lli long long int
#define endl '\n'
#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define InputArray(a,n) for(int i=0;i<n;i++) cin >> a[i];
#define CopyArray(a,temp,n) for(int i=0;i<n;i++) temp[i]=a[i];
#define PrintArray(a,n) for(int i=0;i<n;i++) cout << a[i] << " "; cout << endl;
using namespace std;


int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif

	set<string> st;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string x;
		cin >> x;
		st.insert(x);
	}

	cout << st.size() << endl;

	cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
	return 0;
}

Measured memory_bytes: 19224
import java.util.*;

public class Main{
    int[] parent;
    int[] size;

    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        parent = new int[n];
        size = new int[n];
        int[] p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scan.nextInt();
            parent[i] = i;
            size[i] = 1;
        }
        for(int i = 0; i < m; i++){
            int x = scan.nextInt() - 1;
            int y = scan.nextInt() - 1;
            unite(x, y);
        }
        int out = 0;
        for(int i = 0; i < n; i++){
            if(same(p[i] - 1, i)) out++;
        }
        System.out.println(out);
    }

    int root(int x){
        if(parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(size[x] < size[y]){
            parent[x] = y;
            size[y] += size[x];
        }else{
            parent[y] = x;
            size[x] += size[y];
        }
    }

    boolean same(int x, int y){
        return root(x) == root(y);
    }


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


Measured memory_bytes: 61144
#include<iostream>
using namespace std;
int main() {
   int x,y,z,tmp;

   cin >> x >> y >> z;

   if (x > y)
   {
       tmp = x;
       x = y;
       y = tmp;
   }
   if(y > z){
       tmp = y;
       y = z;
       z = tmp;
   }
   if(x > y){
       tmp = x;
       x = y;
       y = tmp;
   }

   cout << x<<" "<<y<<" "<<z<<endl;

}


Measured memory_bytes: 3104
n = gets.to_i
h = []
n.times do
  h << gets.split.map(&:to_i)
end
dp = Array.new(n+1) { Array.new(3, 0) }
dp[0] = [0, 0, 0]
n.times do |idx|
  3.times do |abc_idx|
    dp[idx+1][(abc_idx+1)%3] = dp[idx][abc_idx] + h[idx][abc_idx] if dp[idx+1][(abc_idx+1)%3] < dp[idx][abc_idx] + h[idx][abc_idx]
    dp[idx+1][(abc_idx+2)%3] = dp[idx][abc_idx] + h[idx][abc_idx] if dp[idx+1][(abc_idx+2)%3] < dp[idx][abc_idx] + h[idx][abc_idx]
  end
end

puts dp[n].max

Measured memory_bytes: 12028
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
using namespace std;

int top, S[1000];

void push(int x){
    S[++top] = x;
}

int pop() {
    top--;
    return S[top+1];
}

int main(){
    int a, b;
    top = 0;
    char s[100];
    while(scanf("%s", s) != EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        }else if(s[0] == '-'){
            b = pop();
            a = pop();
            push(a-b);
        }else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a*b);
        }else {
            push(atoi(s));
        }
    }
    
    printf("%d", pop());
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3224
def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False
    res = solve(i + 1, m) or solve(i + 1, m - A[i])
    return res


n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
for i in range(q):
    if sum(A) < M[i]:
        print("no")
    elif solve(0, M[i]):
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
#define REP(i, n) for (i64 (i) = 0; (i) < (n); ++(i))
#define FOR(i, a, b) for (i64 (i) = (a); (i) < (b); ++(i))
#define EACH(e, v) for(auto&e:v)

void func(vector<int> &v, int e) {
    vector<int> tmp;
    EACH(i, v) if (i != e) tmp.emplace_back(i);
    v = tmp;
}

bool dfs(int mn, int mx, bool turn, vector<int> a, vector<int> b) {
    if (a.size() == 0) return true;
    if (b.size() == 0) return false;
    if (turn) {
        bool ok = false;
        bool d = false;
        EACH(e, a) {
            if (e == mn - 1) {
                vector<int> c(a);
                func(c, e);
                ok |= dfs(mn - 1, mx, !turn, c, b);
                d = true;
            } else if (e == mx + 1) {
                vector<int> c(a);
                func(c, e);
                ok |= dfs(mn, mx + 1, !turn, c, b);
                d = true;
            }
        }
        if (not d) {
            return dfs(mn, mx, !turn, a, b);
        }
        return ok;
    } else {
        bool ok = true;
        bool d = false;
        EACH(e, b) {
            if (e == mn - 1) {
                vector<int> c(b);
                func(c, e);
                ok &= dfs(mn - 1, mx, !turn, a, c);
                d = true;
            } else if (e == mx + 1) {
                vector<int> c(b);
                func(c, e);
                ok &= dfs(mn, mx + 1, !turn, a, c);
                d = true;
            }
        }
        if (not d) {
            return dfs(mn, mx, !turn, a, b);
        }
        return ok;
    }
}

signed main() {

    int N;
    cin >> N;
    
    while (N--) {
        vector<int> p(6), q;
        REP(i, 6) cin >> p[i];
        vector<bool> has(14, false);
        EACH(e, p) has[e] = true;
        FOR(i, 1, 14) {
            if (i == 7) continue;
            if (has[i]) continue;
            q.emplace_back(i);
        }
        if (dfs(7, 7, true, p, q)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }

    }

}


Measured memory_bytes: 3176
// Dmitry _kun_ Sayutin (2020)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    string s;
    cin >> s;

    s = s;
    
    // PD
    vector<pair<int, int>> dp(SZ(s) + 1);
    dp[0] = make_pair(TYPEMIN(int), 0);

    for (int i = 0; i < SZ(s); ++i) {
        dp[i + 1] = make_pair(TYPEMIN(int), TYPEMIN(int));

        if (s[i] == 'P' or s[i] == '?') {
            dp[i + 1].first = max(dp[i].first, dp[i].second);
        }

        if (s[i] == 'D' or s[i] == '?') {
            dp[i + 1].second = max(dp[i].first + 2, dp[i].second + 1);
        }
    }

    char st = (dp.back().first >= dp.back().second ? 0 : 1);
    for (int i = SZ(s) - 1; i >= 0; --i) {
        s[i] = "PD"[st];

        if (st == 0) {
            st = (dp[i].first >= dp[i].second ? 0 : 1);
        } else {
            st = (dp[i].first + 1 >= dp[i].second ? 0 : 1);
        }
    }

    cout << s << "\n";

    return 0;
}


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

int get_time();
bool in_time(int class_start, int class_finish, int time_start, int time_finish);

int main()
{
  int class_num;
  cin >> class_num;
  int start[class_num], finish[class_num];
  for(int i = 0; i < class_num ; i++){
    start[i] = get_time();
    finish[i] = get_time();
    //    cout << start[i] << "-" << finish[i] << endl;
  }
  int active_teacher[class_num];
  for(int q = 0; q < class_num; q++){
    active_teacher[q] = 0;
  }
  int teacher_num;
  cin >> teacher_num;
  for(int i = 0; i < teacher_num; i++){
    int temp;
    cin >> temp;
    int str[temp];
    int fsh[temp];
    for(int j = 0; j < temp; j++){
      str[j] = get_time();
      fsh[j] = get_time();
      for(int k = 0; k < class_num; k++){
	if(in_time(start[k], finish[k], str[j], fsh[j])){
	    active_teacher[k]++;
	}
      }
    }
  }
  int active_student[class_num];
  for(int q = 0; q < class_num; q++){
    active_student[q] = 0;
  }
  int student_num;
  cin >> student_num;
  for(int i = 0; i < student_num; i++){
    int temp;
    cin >> temp;
    int str[temp];
    int fsh[temp];
    for(int j = 0; j < temp; j++){
      str[j] = get_time();
      fsh[j] = get_time();
      for(int k = 0; k < class_num; k++){
	if(in_time(start[k], finish[k], str[j], fsh[j])){
	  active_student[k]++;
	}
      }
    }
  }
  int class_number = 0;
  for(int i = 0; i < class_num; i++){
    if(active_teacher[i] < active_student[i]){
      class_number += active_teacher[i];
    } else {
      class_number += active_student[i];
    }
  }
  cout << class_number << endl;
  return 0;
}

int get_time()
{
  int a, b;
  cin >> a;cin.ignore();
  cin >> b;cin.ignore();
  return (a * 60 + b);
}

bool in_time(int class_start, int class_finish, int time_start, int time_finish)
{
  return ((time_start <= class_start) && (class_finish <= time_finish));
}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

int main(){
	lint n,m;cin>>n>>m;
	vector<pair<lint,lint> > a(n);rep(i,n)cin>>a[i].first>>a[i].second;sort(all(a));
	lint ans=0,cur=0,pos=0;
	while(m>0){
		if(a[pos].second<m){
			ans+=a[pos].first*a[pos].second;
			m-=a[pos].second;++pos;
		} else{
			cout<<ans+a[pos].first*m<<endl;
			return 0;
		}
	}cout<<ans<<endl;
}

//sub-EOF


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int x,y,z,a,b,c,t;
	int tle = 0,min;
	scanf("%d %d",&a,&b);
	min  = 0;
	for(x=0;x<a;x++)
	{
		scanf("%d %d",&c,&t);
		if (t <= b)
		{
			if (min ==0) min = c;
			if (min > c) min  =  c;
		}
	}
	if (min == 0) printf("TLE");
	else printf("%d",min);
	return 0;
}

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

int n, u;
int k[101], b[101], d[101], f[101];
int a[101][101];
int t = 1;

void dfs(int v){
    d[v] = t;
    t++;
    b[v]++;
    for(int l=0; l<k[v]; l++){
        if(b[a[v][l]] == 0){
            dfs(a[v][l]);
        }
    }
    f[v] = t;
    t++;
}


int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> u;
        cin >> k[u];
        for(int j=0; j<k[u]; j++){
            cin >> a[u][j];
        }
    }
    for(int v=1; v<=n; v++){
        if(b[v] == 0){
            dfs(v);
        }
        cout << v << " " << d[v] << " " << f[v] << endl;
    }
    return 0;
}

Measured memory_bytes: 3212
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int c[100005],b[100005],i,j,sum=0;
    for(i=0;i<n;i++)
        scanf("%d",&b[i]);
    for(i=0;i<n;i++)
        scanf("%d",&c[i]);
    for(i=0;i<n;i++)
    {
        if(b[i]>c[i])
            sum+=b[i]-c[i];
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(){
  long long int x,k,d;
  int p=0,m=0;
  scanf("%lld %lld %lld",&x,&k,&d);
  if(x<0){x=0-x;}
  if(x/d>k){
  	for(int i=0;i<k;i++){
      x-=d;
    }
  }
  else{
 	 for(int i=0;i<k;i++){
    if(p*m==1&&(k-i)%2==0){break;}
    
    if(x>=0){
      if(x==0){m=1;}
      p=1;
      x-=d;
    }else{
      x+=d;
      m=1;
    }
  }
  }
  if(x<0){x=0-x;}
  printf("%lld\n",x);
}
        

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

/*
Union-Find木はグループ分けをする際に用いる. 同じグループに属する=同じ木に属する.
2つの要素をまとめる(Union)ことと, 2つの要素が同じグループに属するかを判定(Find)
することができる.
「全ての人について同じグループの中に友達がいない」ようにグループ分けするための
最小グループ数は,　友達集合を作ったとき最も要素数の大きい集合の要素数.
このUnion-Find木ではrootを負数, childrenを非負数で表す. ひとつの集合の要素数は,
rootの値にマイナスをかけると得られる.
*/

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}  // 全要素-1で初期化
  int find_root(int x) {  // look for a root
    if (d[x] < 0) return x;  // マイナスなのでrootです
    return d[x] = find_root(d[x]);
  }
  bool unite(int x, int y) {  // 2つの要素を同じ集合にまとめる
    x = find_root(x);
    y = find_root(y);
    if (x == y) return false;  // rootが同じならこれ以上uniteする必要なし
    if (d[x] > d[y]) swap(x, y); // 要素数の小さい集合は大きい集合の子となる
    d[x] += d[y];  // uniteします(要素数が増えます)
    d[y] = x;  // この要素は非負なので誰かしらの子ですよ, を表す
    return true;
  }
  bool same(int x, int y) { return find_root(x) == find_root(y); }  // 同じ集合?
  int size(int x) { return -d[find_root(x)]; }  // 集合の要素数
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;  // 0-index化
    uf.unite(a, b);
  }
  
  int ans = 0;
  rep(i, n) ans = max(ans, uf.size(i));  // 最も要素数の大きい集合の要素数が答え
  cout << ans << endl;
}

Measured memory_bytes: 4032
#include <iostream>
#include <cstdio>
#include "bits/stdc++.h"
using namespace std;

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for(int i=0; i<N; i++){cin >> H[i];}
  vector<int> dp(N, INT_MAX);
  dp[0] = 0;
  int j;
  for(int i=0; i<N; i++){
    for(int j=1; j<=K; j++){
      if(i+j < N){
      	dp[i+j] = min(dp[i+j], dp[i]+abs(H[i]-H[i+j]));
      }else{
        break;
      }
    }
  }
  cout << dp[N-1] << endl;
  return 0;
}

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

long long arr[100000];

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

    for (long long i = 0; i < N; i++) {
        cin >> arr[i];
    }

    long long min = 1e10;
    for (long long i = 0; i <= N - K; i++) {
        long long s = i;
        long long e = i + K - 1;

        long long d1 = abs(arr[s] - 0);
        long long d2 = abs(arr[e] - 0);
        long long d = abs(arr[s] - arr[e]);

        long long dt = d + ((d1 < d2) ? d1 : d2);

        if (dt < min) {
            min = dt;
        }
    }

    cout << min << endl;
}

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

int main()
{
	int k;
	scanf("%d", &k);
	int ans = 0;
	for (int a=1; a<=k; a++){
		for (int b=1; b<=k; b++){
			for (int c=1; c<=k; c++){
				ans += __gcd(a, __gcd(b, c));
			}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3800
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn read_str_as_char_vec() -> Vec<char> {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().chars().collect()
}

fn read_str_as_T<T>() -> T
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().unwrap()
}

fn main() {
    let s = read_str_as_char_vec();
    let t = read_str_as_char_vec();

    for i in 0..s.len() {
        if s[i] != t[i] {
            println!("No");
            return;
        }
    }

    println!("Yes");
}


Measured memory_bytes: 2164
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#define ll long long
using namespace std;
int main(){
     int A,B,K;
     cin >> K >> A >> B;
     if (B/K - A/K > 0){
          cout << "OK" << endl;
     }else if(A%K == 0||B%K==0){
          cout << "OK" << endl;
     }
     else{
          cout << "NG" << endl;
     }
     return 0;
}

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

#define lint long long int

int main()
{
    lint n;
    cin >> n;
    
    int rt = int(sqrt(n)) + 1;
    
    int ans = 0;
    for (int i = 2; i <= rt; i++) {
        
        int k = 0;
        while ((n % i) == 0) {
            n /= i;
            k++;
        }
        
        int index = 1;
        while (k >= index) {
            ans++;
            k -= index++;
        }
    }
    
    if (n > 1) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
	
	int nn,aa, qq;
	ll sum=0;
	
	
	
	cin >> nn;
	
	//vector<int> aa(nn);
	//rep(i,nn) cin >> aa[i];
	//cin >> qq;
	
	
	vector<int> tmp(100005);
	
	rep(i,nn) {
		cin >> aa;
		tmp[aa]++;
		sum += aa;
	}
	
	int bb,cc;
	cin >> qq ;
	rep(i,qq){
		cin >> bb >> cc;
		
		tmp[cc] += tmp[bb];
		
		sum += (cc-bb) * tmp[bb];
		tmp[bb] = 0;
		
		
		printf("%lld\n",sum);
		
	}
	
	return 0;
}

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

int main() {
  int A,B; cin>>A>>B;
  string S; cin>>S;
  bool ans=true;
  rep(i,A+B+1){
    if(i==A&&S.at(i)!='-') ans=false;
    if(i!=A&&S.at(i)=='-') ans=false;
  }
  if(ans) cout<<"Yes";
  else cout<<"No";
}


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

int main(){
	int N;
	long ans = 0;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++){
		cin >> A[i];
		A[i] -= (i+1);
	}

	sort(A.begin(), A.end());
	int median = A[N/2];
	
	for(int i = 0; i < N; i++){
		ans += abs(A[i] - median);
	}
	cout << ans << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ll INF=1e9;
int main(){
      int dp[2][1000000];
      vector<int> V[2];
      REP(i,2)REP(j,1000000)dp[i][j]=INF;
      dp[0][0]=dp[1][0]=0;
      for(int i=1;i*(i+1)*(i+2)/6<=1000000;i++){
            V[0].PB(i*(i+1)*(i+2)/6);
            if((i*(i+1)*(i+2)/6)&1)V[1].PB(i*(i+1)*(i+2)/6);
      }
      REP(i,2){
            REP(j,1000000){
                  REP(k,V[i].size()){
                        if(j+V[i][k]>=1000000)break;
                        dp[i][j+V[i][k]]=min(dp[i][j+V[i][k]],dp[i][j]+1);
                  }
            }
      }
      int n;
      while(cin>>n&&n){
            cout<<dp[0][n]<<" "<<dp[1][n]<<endl;
      }
}

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

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

int main(void) {
    ios_base::sync_with_stdio(false);
    int cur=0,prev=0,i=1;
    int a,b; cin >> a >> b;
    for(;i<=999;i++) {
        prev=cur;
        cur+=i;
        if(cur-prev == b-a) {
            cout << prev-a << endl;
            break;
        }
    }

    return 0;
}


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

/// Defining variable types.
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

/// Defining usable key words
#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

/// Defining constant variables.
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

/// Defining some useful lines.
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);


/// Code of debugger.
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

const int mx=2e5+123;
int dp[mx];
int n,h[mx];

int solve(int i)
{
    if(i==n)
        return 0;

    if(dp[i]!=-1)
        return dp[i];

    int ret2=inf;
    int ret1=abs(h[i]-h[i+1])+solve(i+1);

    if(i+2<=n)
        ret2=abs(h[i]-h[i+2])+solve(i+2);

    dp[i]=min(ret1,ret2);

    return dp[i];
}

int main()
{
    optimize();

    cin>>n;

    for(int i=1; i<=n; i++)
        cin>>h[i];

    mem(dp,-1);

    cout<<solve(1)<<endl;


    return 0;
}


Measured memory_bytes: 9476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
 
public class Main {
	public static void main(String[] args) {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		String input1;
		String input2;
		try {
			input1 = br.readLine();
			input2 = br.readLine();
		} catch (IOException e) {
			return;
		}
		int N = Integer.valueOf(input1);
		String[] cardS = input2.split(" ");
		HashSet<String> hs = new HashSet<String>();
		for(String s : cardS)
			hs.add(s);
		int unique = hs.size();
		
		if((N - unique)%2 == 1)
			System.out.print(unique - 1);
		else
			System.out.print(unique);
	}
}

Measured memory_bytes: 34688
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

int solve(int n,int ans){
    int pp=1;//N????????°
    while(true) {
        if (pow(10,pp)>n) {
            break;
        }else{
            pp++;
        }
    }
    if (pp==1) {
        return ans;
    }else{
        ans++;
    }
   // cout << pp<<"|";
    
    int mm=0;
    for (int i=1; i<pp; i++) {
        int zen,go;
        go = n % (int)pow(10,i);
        zen =(n-go)/(int)pow(10,i);
       // cout << zen <<"^"<<go<<"~~";
        mm=max(mm,zen*go);
    }
   // cout << mm<<",";
    return solve(mm,ans);
}


int main(){
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        int N;
        cin >> N;
        cout << solve(N, 0) <<endl;
        continue;
    }
    
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1777777777ll
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read(a,n) rep(i,n)cin>>a[i]

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m, x;
li v[155];

int main() {
    cin >> n >> m >> x;
    read(v, m);

    auto pos = lower_bound(v, v + m, x);
    cout << min(v + m - pos, pos - v) << endl;


    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  int N;
  cin >> N;
  int A[N],B[N];
  rep(i,N) cin >> A[i] >> B[i];
  int ans=A[0]+B[0];
  rep(i,N) ans=min(ans,A[i]+B[i]);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
    int sum = 0;
    int N, L;
    cin >> N >> L;
    vector<int> R(N);
    for (int i = 1; i <= N; i++) {
        R[i-1] = L + i - 1;
        sum += R[i-1];
    }
    sort(R.begin(), R.end());
    
    int TTT = 1e9;
    int ans = 1e9;
    for (int i = 1; i <= N; i++) {
        int result = 0;
        for (int j = 1; j <= N; j++) {
            if (i == j) {
                continue;
            }
            result += R[j-1];
        }
        int AAA = abs(sum - result);
        if (AAA < TTT) {
            TTT = AAA;
            ans = result;
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int d[1000];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>s(n);
	rep(i, n) {
		cin >> s[i];
		d[s[i]]++;
	}
	vector<int>w, x;
	int ans = 0;
	FOR(i, 1, 12) {
		if (d[i] >= 3) {
			cout << 0 << endl; return 0;
		}
		if (d[i] == 1) {
			w.push_back(i);
		}
		if (d[i] == 2) {
			x.push_back(i);
			x.push_back(24 - i);
		}
	}
	x.push_back(0);
	if (d[0] >= 1) {
		cout << 0 << endl; return 0;
	}
	if (d[12] >= 2) {
		cout << 0 << endl; return 0;
	}
	if (d[12] == 1) {
		x.push_back(12);
	}
	rep(i, 1 << w.size()) {
		vector<int>y = x;
		rep(j, w.size()) {
			if ((i / (1 << j)) % 2 == 0)y.push_back(w[j]);
			else y.push_back(24 - w[j]);
		}
		sort(ALL(y));
		int minx = 24;
		rep(j, y.size()) {
			minx = min(minx, (y[(j + 1) % y.size()] - y[j] + 24) % 24);
		}
		ans = max(ans, minx);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256