akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var rank = IntArray(n + 1) { 1 }
    val cities=(1..m).map {
        val (p, y) = readLine()!!.split(" ").map { it.toInt() }
        return@map Triple(it, p, y)
    }.sortedBy { it.third }

    val sb=StringBuilder()
    cities.map {
        Pair(it,rank[it.second]++)
    }.sortedBy {
        it.first.first
    }.forEach {
        sb.append(it.first.second.toString().padStart(6,'0'))
        sb.append(it.second.toString().padStart(6,'0'))
        sb.append("\n")
    }
    println(sb)
}


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

long long ans=0;
int a[55], d[55], n;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &d[i]);
		a[i] = a[i-1]+d[i];
	}
	for(int i = 1; i <= n; i++) 
		ans += d[i] * (a[n]-a[i]);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if (N == 7 || N == 5 || N == 3) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}
	}
}

Measured memory_bytes: 22740
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h, a;
    cin>>h>>a;
    ll ans = h/a;
    if(h % a != 0) {
    	ans++;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
typedef pair<double,double> pd;

pd D[100];
int A[100];
int n;

int side(pd p1, pd p2){
	double dy=p2.first-p1.first,dx=p2.second-p1.second;
	for(int i=0;i<n;i++){
		pd p3=D[i];
		if (p1==p3||p2==p3)continue;
		if ((p3.second-p1.second)*dy-dx*(p3.first-p1.first)<0) return 0;
	}
    return 1;
}

int main(){
	while (1){
		int i,s;
		pd p,p1,p2;
		char c;
		cin>>n;
		if (n==0) break;
		for (i=0;i<n;i++){
			cin>>D[i].first>>c>>D[i].second;
			A[i]=0;
		}
		sort(D,D+n);
		p=D[0];
		p1=p;
		s=0;
		while (1){
			for (i=0;i<n;i++){
				p2=D[i];
				if (A[i]==0 && p1!=p2 && side(p1,p2)) break;
			}
			p1=p2;
			A[i]=1;
			s++;
			if (p2==p) break;
		}
		std::cout<<n-s<<"\n";
		for (i=0;i<n;i++){
			D[i]=make_pair(0,0);
			A[i]=0;
		}
	}
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
int64_t H, W, K, ans = pow(10, 6);
vector<string> A(10);

int main()
{
  cin >> H >> W >> K;
  for (int i = 0; i < H; i++)
    cin >> A[i];
  for (int bit = 0; bit < (1 << (H - 1)); bit++)
  {
    vector<pair<int, int>> parts(0);
    int start = 0;
    for (int j = 0; j < H; j++)
    {
      if (j == H - 1)
      {
        parts.push_back(make_pair(start, H - 1));
      }
      else if (bit & (1 << j))
      {
        parts.push_back(make_pair(start, j));
        start = j + 1;
      }
    }
    int64_t cnt = parts.size() - 1;
    vector<int> tmp1(parts.size(), 0);
    for (int w = 0; w < W; w++)
    {
      vector<int> tmp2(parts.size(), 0);
      for (int j = 0; j < parts.size(); j++)
      {
        for (int h = parts.at(j).first; h <= parts.at(j).second; h++)
        {
          if (A.at(h).at(w) == '1')
            tmp2.at(j)++;
        }
      }
      for (int j = 0; j < parts.size(); j++)
      {
        if (tmp1[j] + tmp2[j] <= K)
        {
          tmp1.at(j) += tmp2.at(j);
          continue;
        }
        if (tmp2.at(j) > K)
          cnt += pow(10, 6);
        else if (tmp1[j] + tmp2[j] > K)
          tmp1 = tmp2, cnt++;
        break;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

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


int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  sort(x.begin(),x.end());
  int minv = INF;
  for(int p = x[0]; p <= x[n-1]; ++p){
    int sum = 0;
    rep(i,n){
      sum += (x[i]-p)*(x[i]-p);
    }
    minv = min(sum,minv);
  }
  cout << minv << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,w;
bool solve(int id,vector<string>& s){
    if(id==h/2){
        vector<int> flag(w,false);
        for(int j=0;j<w;j++){
            if(flag[j]) continue;
            for(int k=j+1;k<w;k++){
                bool isok=true;
                for(int i=0;i<h;i++){
                    if(s[i][j]!=s[h-1-i][k]){
                        isok=false;
                        break;
                    }
                }
                if(isok){
                    flag[j]=flag[k]=true;
                    break;
                }
            }
        }
        int cnt=count(flag.begin(),flag.end(),false);
        if(cnt>=2) return false;
        if(cnt==0) return true;
        for(int j=0;j<w;j++){
            if(!flag[j]){
                for(int i=0;i<h;i++){
                    if(s[i][j]!=s[h-1-i][j]) return false;
                }
                return true;
            }
        }        
        assert(false);
    }
    for(int i=id+1;i<h-id;i++){
        if(h%2==1 && i==h/2) continue;
        assert(i<=h-id-1);
        if(i!=h-id-1) swap(s[i],s[h-id-1]);
        if(solve(id+1,s)) return true;
        if(i!=h-id-1) swap(s[i],s[h-id-1]);
    }
    return false;
}

int main(){
    cin>>h>>w;
    vector<string> s(h);
    for(int i=0;i<h;i++) cin>>s[i];
    vector<int> flag(h);
    bool isok=false;
    if(h%2==1){
        for(int i=0;i<h;i++){
            swap(s[i],s[h/2]);
            isok=isok || solve(0,s);
            swap(s[i],s[h/2]);
        }
    }else{
        isok=solve(0,s);
    }
    cout<<(isok? "YES" : "NO")<<endl;
    return 0;
}


Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = input()
def is_a(x, y):
  for i in range(x, y-1):
    if s[i]==s[i+1]=="#":
      return False
  return True
def is_f(x, y):
  for i in range(x, y+1):
    if s[i-1]==s[i]==s[i+1]==".":
      return True
  return False

ans = "No"
if is_a(a, b) and is_a(c, d):
  if c < d or is_f(b, d):
    ans = "Yes"
print(ans)

Measured memory_bytes: 3572
a, b, k = input().split()
a, b, k = int(a), int(b), int(k)

if k < a:
  a = a-k

else:
  k = k-a
  a = 0
  if k < b:
    b = b-k
  else:
    b = 0
  
print(a,b)

Measured memory_bytes: 38256
H,W = map(int,input().split())
Data = []

for _ in range(H):
    Data.append(input())

hdata = set()
wdata = set()

for h in range(H):
    for w in range(W):
        if Data[h][w] == '#':
            hdata.add(h)
            wdata.add(w)

for h in range(H):
    output = False
    for w in range(W):
        if h in hdata and w in wdata:
            print(Data[h][w],end='')
            output = True
    if output:
        print('')


Measured memory_bytes: 4468
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f(i,a,b) for(int i=a; i<b; i++)
using namespace std;

int main()
{
    IOS
    int a, b;
    cin>>a>>b;
    if(a > 9 || b > 9) cout<<"-1";
    else cout<<a*b;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
char s[100001],t[100001];
int gcd(int a,int b){
    if(a<b)return gcd(b,a);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int main(){
    int n,m;
    scanf("%d%d%s%s",&n,&m,s,t);
    int g=gcd(n,m);
    for(int i=0;i<g;i++){
        if(s[n/g*i]!=t[m/g*i]){
            printf("-1");
            return 0;
        }
    }
    printf("%lld",(long long)n*m/g);
    return 0;
}

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

using namespace std;

void make_lower(string &s) {
	for (auto &c: s) {
		if (c >= 'A' && c <= 'Z') {
			c -= 'A';
			c += 'a';
		}
	}
}

int main() {
	string W, T;
	cin >> W;
	make_lower(W);

	int count = 0;
	while (cin >> T && T != "END_OF_TEXT") {
		make_lower(T);
		if (T == W) ++count;
	}
	cout << count << endl;
}


Measured memory_bytes: 3144
N = int(input())
SP_str = [list(input().split()) for i in range(N)]
SP = [[i[0],int(i[1])] for i in SP_str]


SP_sort = sorted(SP,key=lambda x: (x[0],-x[1]))
for i in range(N):
    a = SP.index(SP_sort[i])
    print(a+1)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
const ll longinf=1LL<<60 ;
ll dist(ll x,ll y){
    return abs(x)+abs(y);
}

bool odd,even;
int main(){
    string s="RLUD";
    int n;cin>>n;
    ll x[n],y[n];
    rep(i,n){
        cin>>x[i]>>y[i];
        if(abs(x[i]+y[i])%2)odd=true;
        else even=true;
    }
    if(even&&odd){
        cout<<"-1"<<endl;
        return 0;
    }
    ll a[40],m=40;
    if(even)a[0]=1LL<<38;
    else a[0]=1LL<<39;
    rep(i,m-1)a[i+1]=(a[i]+1)/2;
    cout<<m<<endl;
    rep(i,m)cout<<a[i]<<" ";
    cout<<endl;
    rep(i,n){
        rep(j,m){
            ll mi=longinf;
            int ret=-1;
            if(dist(x[i]-a[j],y[i])<mi){mi=dist(x[i]-a[j],y[i]);ret=0;}
            if(dist(x[i]+a[j],y[i])<mi){mi=dist(x[i]+a[j],y[i]);ret=1;}
            if(dist(x[i],y[i]-a[j])<mi){mi=dist(x[i],y[i]-a[j]);ret=2;}
            if(dist(x[i],y[i]+a[j])<mi){mi=dist(x[i],y[i]+a[j]);ret=3;}
            if(ret==0)x[i]-=a[j];
            if(ret==1)x[i]+=a[j];
            if(ret==2)y[i]-=a[j];
            if(ret==3)y[i]+=a[j];
            cout<<s[ret];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void){
  int a[3];
  int i,j;
  int min;

  for(i=0;i<3;i++)
    scanf("%d",&a[i]);

  for(i=0;i<2;i++){
    min = a[i];
    for(j=i+1;j<3;j++){
      if(min > a[j]){
        min = a[j];
        a[j] = a[i];
        a[i] = min;
      }
    }
  }
  for(i=0;i<3;i++)
    if(i<2)
      printf("%d ",a[i]);
    else
      printf("%d\n",a[i]);

  return 0;
}

Measured memory_bytes: 596
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln endl
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inp freopen("input.txt", "r", stdin)
#define outp freopen("output.txt", "w", stdout)
#define dbgm(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 2e5+5, MOD = 1e9+7, EPS = 1e-9;
int t,n,m,k,x,y;
int main(){
	fastio;
	int n,w;
	cin>>n>>w;
	ll poss[w+1] = {0};
	forn(i,w+1) poss[i] = -1;
	poss[0] = 0;
	ll x,y;
	forn(i,n){
		cin>>x>>y;
		for(int j = w;j>=0;j--){
			if(poss[j]!=-1 && j+x<=w) poss[j+x] = max(poss[j+x],y+poss[j]);
		}
	}
	// forn(i,w+1){
	// 	cout<<i<<" "<<poss[i]<<ln;
	// }

	ll ma=0;
	forn(i,w+1) ma = max(ma,poss[i]);
	cout<<ma<<ln;
	return 0;
}

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

int main(){
 int N;
 cin >> N;
 string a,b,c;
 cin >> a >> b >> c;
 int counter = 0;
 
 for(int i = 0;i < N; i++){
  if(a.at(i) == b.at(i)){
   if(a.at(i) != c.at(i)) counter++;
  }
  else{
   if(a.at(i) == c.at(i) || b.at(i) == c.at(i)) counter++;
   else counter+=2;
   }
  }
  
  cout << counter << endl;
  }

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

# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"

using namespace std;

# 1 "../IO/io.h" 1
inline int readInt() {
    int v;
    int r = scanf("%d", &v);
    return v;
}

inline long long readLong() {
    long long v;
    int r = scanf("%lld", &v);
    return v;
}

inline vector<int> readVecInt(int n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = readInt();
    }
    return a;
}


inline void printLine(int v) {
    printf("%d\n", v);
}

inline void printLine(long long v) {
    printf("%lld\n", v);
}

inline void printLine(const vector<int> &a) {
    for (int v: a) {
        printf("%d ", v);
    }
    printf("\n");
}

inline void printLine(const string &s) {
    printf("%s\n", s.c_str());
}
# 5 "<stdin>" 2

int main() {
    int n = readInt();
    auto a = readVecInt(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i%2 == 0 && a[i]%2 == 1) {
            ans++;
        }
    }
    printLine(ans);
}


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

#define Bye return 0
#define ll long long

using namespace std;

void solve(){
    int n; cin>>n;
    
    map<int, int> a;
    for (int i=0; i<n; i++){
        int e; cin>>e;
        a[e]++;
    }

    for (auto i : a){
        if(i.second == 2){
            cout<<"NO"<<endl;
            return;
        }
    }
    
    cout<<"YES"<<endl;
}

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

Measured memory_bytes: 12924
// template ///////////////////////////////////////////////////////////
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <sys/resource.h>
#include <iostream>
using namespace std;

class timer{
	enum KIND{ REAL, CPU }; // real_time or cpu_time 
	double t0; // start
	double t1; // end
	KIND kind_of_time; // default is real_time
	double get_realtime(){struct timeval tv; gettimeofday(&tv, NULL);
		return tv.tv_sec + (double)tv.tv_usec*1e-6;}
	double get_cputime(){struct rusage RU; getrusage(RUSAGE_SELF, &RU); 
		return RU.ru_utime.tv_sec + (double)RU.ru_utime.tv_usec*1e-6;}
public:
	timer(){kind_of_time = REAL;}
	void set(KIND k){kind_of_time = k;}
	void start(){t0 = get_realtime();}
	void stop(){t1 = get_realtime();}
	void print(){printf("TotalTime : %.3fsec\n", t1-t0);}
};
////////////////////////////////////////////////////////////////////////
typedef long long int ll;

ll pow(ll x, int n);
ll rem(ll x, ll n, int mod);

#define MOD 1000000007

int main()
{
	timer T;
    int m, n;
    cin >> m >> n;
	
	ll r;
	T.start();
	r = rem(m, n, MOD);
	T.stop();

    cout << r << endl;
	//T.print();

    return 0;
}

ll rem(ll x, ll n, int mod)
{
	if(!n) return 1;
	long long res;
	res = rem(x*x%mod, n/2, mod);
	if(n%2) res = res*x%mod;
	return res;
}

ll pow(ll x, int n)
{
	if(!n) return 1;
	ll res;
	res = pow(x*x, n/2);
	if(n%2) res *= x;
	return res;
}

Measured memory_bytes: 1156
#include <cstdio>
int main() {
	int n,pm,pe,pj;
	while (scanf("%d",&n)&&n!=0) {
		for (int i=0; i<n;i++) {
			scanf("%d%d%d",&pm,&pe,&pj);
			if ((pm==100||pe==100||pj==100)||((pm+pe)/2>=90)||((pm+pe+pj)/3>=80)) {
				printf("A\n");
			} else if ((pm+pe+pj)/3>=70) {
				printf("B\n");
			} else if (((pm+pe+pj)/3>=50)&&(pm>=80||pe>=80)) {
				printf("B\n");
			} else {
				printf("C\n");
			}
		}
	}
} 

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  string s, t;
  cin >> s >> t;
  int mx = 0;
  for (int i = 0 ; i <= s.size() - t.size(); i++) {
    int c = 0;
    for (int j = 0 ; j < t.size(); j++) {
      c += s[i + j] == t[ j];
    }
    mx = max(mx, c);
  }
  cout << t.size() - mx << "\n";
}

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

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

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

    return gcd(b, a % b);
}

int gcd(int a, int b, int c)
{
    int ab;
    ab = gcd(a, b);
    return gcd(ab, c);
}

int main()
{
    int n;
    int64_t ans = 0;
    cin >> n;
    
    rep(i, n)
    {
        rep(j, n)
        {
            rep(k, n)
            {
                ans += gcd(i + 1, j + 1, k + 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define db long double
# define IOS ios_base :: sync_with_stdio(0)
# define halt(...) {fo << (__VA_ARGS__) << '\n';exit(0);}
# define pp(n) cerr << #n << " = " << n << '\n'
# define ppp(v) for (auto it : v) cerr << it << ' ';cerr << '\n'
int sz[1 << 20];
int has[1 << 20];
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    has[1] = 1;
    int n,m;
    fi>>n>>m;
    for (int i = 1;i <= n;++i) sz[i] = 1;
    while (m --)
    {
        int x,y;
        fi>>x>>y;
        ++sz[y];
        --sz[x];
        has[y] |= has[x];
        if (!sz[x]) has[x] = 0;
    }
    int ans = 0;
    for (int i = 1;i <= n;++i) ans += has[i];
    fo << ans << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int n, x,y,z;
    scanf("%d", &n);
    x = n / 100;
    y = ((n-(x*100))/10);
    z = n-(x*100)-(y*10);
    if(x == 7 | y == 7 | z == 7){
        puts("Yes");
    }
    else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 1620
N = int(input())

ans = 'Yes'

tt, tx, ty = 0, 0, 0,
for _ in range(N):
    t, x, y = map(int, input().split())
    ct = t-tt
    cx = abs(x-tx)
    cy = abs(y-ty)
    if ct < (cx+cy):
        ans = 'No'
        break
    if cx+cy == 0:
        ans = 'No'
        break
    if ct%2 != (cx+cy)%2:
        ans = 'No'
        break
    tt, tx, ty = t, x, y

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	vector<int>A(12);
	int B[] = { 1,3,5,7,8,10,12 }, C[] = { 4,6,9,11 }, D[] = { 2 };
	int l = 0, j = 0, k = 0;
	for (int i = 0; i < 12; i++) {
		if (i + 1 == B[j]) {
			A[i] = 1;
			j++;
		}
		else if (i + 1 == C[k]) {
			A[i] = 2;
			k++;
		}
		else {
			A[i] = 3;
			l++;
		}
	}
	int X, Y; cin >> X >> Y;
	if (A.at(X - 1) == A.at(Y - 1))cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100

int n, pos, c=0;
int pre[MAX], in[MAX], post[MAX];

void rec(int l, int r){
    if(l>=r){
        return;
    }
    int root=pre[pos++];
    int m;
    for(int i=0; i<n; i++){
        if(root==in[i]){
            m=i;
            break;
        }
    }
    rec(l,m);
    rec(m+1, r);
    post[c++]=root;
}


int main(void){
    int i;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &pre[i]);
    }
    for(i=0; i<n; i++){
        scanf("%d", &in[i]);
    }

    rec(0,n);
    for(i=0; i<n; i++){
        scanf("%d", &post[i]);
    }
    for(i=0; i<n-1; i++){
        printf("%d ", post[i]);
    }
    printf("%d\n", post[i]);
    
    return 0;


}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;

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

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

class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Split(' ');
        int[] H = new int[N];
        for (int i = 0; i < N; i++)
            H[i] = int.Parse(s[i]);

        int ctr = 1;
        for(int i = 1; i < N; i++)
        {
            bool b = true;
            for(int j = 0; j < i; j++)
            {
                if (H[j] > H[i])
                {
                    b = false;
                    break;
                }
            }
            if (b)
                ctr++;
        }

        Console.WriteLine(ctr);
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <stdbool.h>

int N,a=4,b=7;
int main()
{
    scanf("%d",&N);
    bool yes=false;

    for(int i=0;i<=25;i++){
	for(int j=0;j<=15;j++){
	    if(i*a+j*b==N){
		yes=true;
		break;
	    }
	}
	if(yes==true)
	    break;
    }
    if(yes==true)
        printf("Yes\n");
    else
        printf("No\n");
    

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
long long a[51];
long long p[51];
long long f(int n , long long x)
{
    if(n == 0)
        if(x <= 0)
            return 0;
        else
            return 1;
    else if(x <= 1 + a[n - 1])
        return f(n - 1, x - 1);
    else
        return p[n - 1] + 1 + f(n - 1 , x - 2 - a[n - 1]);
}
int main()
{
    int n;
    long long x;
   // freopen("burgers.in" , "r" , stdin);
    //freopen("burgers.out" , "w" , stdout);
    scanf("%d%lld" , &n , &x);
    p[0] = 1;
    a[0] = 1;
    for(int i = 1; i <= n ; i ++)
    {
        a[i] = a[i - 1] * 2 + 3;
        p[i] = p[i - 1] * 2 + 1;
    }
    printf("%lld" , f(n , x));
    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    long double rad = (double)(H*30 + M*0.5 - M*6%360)*M_PI/180.0;
    long double ans = sqrt(A*A + B*B -2.0*A*B*cos(rad));
    printf("%10.10Lf\n", ans);

    return 0;
}

Measured memory_bytes: 4152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String n = in.nextLine();
		for (int i = 0; i < n.length(); ++i) {
			if (n.charAt(i) == '1') {
				System.out.print('9');
			} else {
				System.out.print('1');
			}
		}
		System.out.println("");
		in.close();
	}
}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
    int N; SCD(N);
    int x[102];
    int y[102];
    int h[102];

    REP(i,N){
        SCD3(x[i],y[i],h[i]);
    }

    

    FORq(Cx,0,100){
        FORq(Cy,0,100){
            int nowH;
            REP(i,N){
                if (h[i] == 0) continue;
                nowH = abs(x[i] - Cx) + abs(y[i] - Cy) + h[i];
                break;
            }
            bool chk = true;
            REP(i,N){
                if (h[i] != max(nowH - abs(x[i] - Cx) - abs(y[i]-Cy),0)){
                    chk = false;
                }
            }

            if (chk){
                printf("%d %d %d\n",Cx,Cy,nowH);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		String S = sc.get();
		int left = Integer.parseInt(S.substring(0, 2), 10);
		int right = Integer.parseInt(S.substring(2), 10);
		if (isYear(left) && isYear(right)) {
			System.out.println("NA");
		} else if (isYear(left)){
			System.out.println("YYMM");
		} else if (isYear(right)) {
			System.out.println("MMYY");
		} else {
			System.out.println("AMBIGUOUS");
		}
	}
	
	boolean isYear(int n) {
		return n > 12 || n <= 0;
	}
}

class Main {
	public static void main(String... args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				try {
					return (line = line != null && line.hasMoreTokens() ? line : new StringTokenizer(reader.readLine())).nextToken();
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
		});
	}
}

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

namespace ConsoleApp1
{
    public class Program
    {
        static void Main(string[] args)
        {
            string[] nK = Console.ReadLine().Trim().Split(' ');
            int n = int.Parse(nK[0]), k = int.Parse(nK[1]), high = 0, low = 0, mid = 0;
            int[] ls = new int[n];
            for (int i = 0; i < n; i++) { ls[i] = int.Parse(Console.ReadLine()); high += ls[i]; }
            while (high - low > 1)
            {
                mid = (high + low) / 2;
                int pos = check(ls, k, mid);
                if (pos >= n) high = mid; else low = mid;
            }
            Console.WriteLine(high);

        }
        public static int check(int[] ls, int k, int mid)
        {
            int pos = 0;
            for (int i = 0; i < k; i++)
            {
                int sum = 0;
                while(ls[pos] + sum <= mid)
                {
                    sum += ls[pos]; pos++;
                    if (ls.Length == pos) return pos;
                }
            }
            return pos;
        }
    }
}





Measured memory_bytes: 20056
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 1e5;
typedef long long LL;

int sum;
int n, V;
int w[105], v[105];
int a[105];
int dp[105][105][405];
//表示前i个物品中选j个容量为k
int main()
{
	while(scanf("%d %d", &n, &V) != EOF)
	{
		sum = 0;
		memset(dp, 0, sizeof(dp));
		for(int i = 1; i <= n; i++)
		{
			scanf("%d %d", &w[i], &v[i]);
			a[i] = w[i] - w[1];
			sum = sum + a[i];
		}
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= i; j++)
			{
				for(int k = 0; k < a[i]; k++)
					dp[i][j][k] = dp[i - 1][j][k];
			}
			for(int j = 1; j <= i; j++)
			{
				for(int k = a[i]; k <= sum; k++)
					dp[i][j][k] = max(dp[i - 1][j][k], dp[i - 1][j - 1][k - a[i]] + v[i]);
			}
		}
		int ans = 0;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= i; j++) {
				if(w[1] * j > V) break;
				for(int k = 0; k <= min(sum, V - w[1] * j); k++) ans = max(ans, dp[i][j][k]);
			}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 17664
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
const int64 INF = 1LL << 59;
 
struct edge
{
  int to, cost;
};
struct node
{
  int now, time, type;
};
 
int N, M, X, T[10000];
vector< edge > g[10000];
int64 min_cost[10000][202][3];
 
int bfs()
{
  queue< node > qs[202];
  fill_n(**min_cost, 10000 * 202 * 3, INF);
  qs[0].emplace((node){0, 0, 1});
  min_cost[0][0][1] = 0;
   
  for(int t = 0; true; t++) {
    auto& que = qs[t % 202];
    while(!que.empty()) {
      const node p = que.front();
      que.pop();
      if(t != min_cost[p.now][p.time][p.type]) continue;
      if(p.now == N - 1) return(t);
      for(auto e : g[p.now]) {
        node q = (node){e.to, p.time, p.type};
        if(q.type + T[e.to] == 3) {
          if(q.time + e.cost < X) continue;
          q.time = 0;
          q.type = T[e.to];
        } else if(q.type == T[e.to]) {
          q.time = 0;
        } else {
          q.time = min(X, q.time + e.cost);
        }
        if(t + e.cost >= min_cost[q.now][q.time][q.type]) continue;
        min_cost[q.now][q.time][q.type] = t + e.cost;
        qs[(t + e.cost) % 202].push(q);
      }
    }
  }
}
 
int main()
{   
  cin >> N >> M >> X;
  for(int i = 0; i < N; i++) {
    cin >> T[i];
    if(T[i] == 0) T[i] = 1;
    else if(T[i] == 1) T[i] = 0;
  }
  for(int i = 0; i < M; i++) {
    int A, B, D;
    cin >> A >> B >> D;
    --A, --B;
    g[A].emplace_back((edge){B, D});
    g[B].emplace_back((edge){A, D});
  }
  cout << bfs() << endl;
}

Measured memory_bytes: 51504
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[200][200];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            a[n][j]=a[n][j]+a[i][j];
            a[i][m]=a[i][m]+a[i][j];
            a[n][m]=a[n][m]+a[i][j];
        }
    }
    
    for(int i=0;i<n+1;i++){
        for(int j=0;j<m+1;j++){
            if(j!=0)cout<<" ";
            cout<<a[i][j];
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
signed main() {
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        ans += i;
    }
    cae
    r0
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using DII = tuple<double, int, int>;

struct	UnionFind {
	int		size;
	int		*par;
	int		*rank;
	int		num_group;
	UnionFind(int size): size(size), par(NULL), rank(NULL), num_group(size) {
		assert(size > 0);
		par = new int[size];
		rank = new int[size];
		assert(par != NULL && rank != NULL);
		for (int i = 0; i < size; ++i) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	~UnionFind() {
		delete [] par;
		delete [] rank;
		par = NULL;
		rank = NULL;
	}
	int		find(int idx) {
		if (par[idx] == idx)
			return idx;
		return (par[idx] = find(par[idx]));
	}
	bool	same(int lhs, int rhs) {
		if (find(lhs) == find(rhs))
			return true;
		return false;
	}
	void	unite(int lhs, int rhs) {
		int	par_l = find(lhs), par_r = find(rhs);
		if (par_l == par_r)
			return;
		if (rank[par_l] < rank[par_r]) {
			par[par_l] = par_r;
			--num_group;
		} else {
			par[par_r] = par_l;
			if (rank[par_l] == rank[par_r])
				++rank[par_l];
			--num_group;
		}
	}
};

double	calc_dist(const vector<double> &x_vec,
			const vector<double> &y_vec, const vector<double> &z_vec,
			int i, int j)
{
	double dx2 = (x_vec.at(i) - x_vec.at(j)) * (x_vec.at(i) - x_vec.at(j));
	double dy2 = (y_vec.at(i) - y_vec.at(j)) * (y_vec.at(i) - y_vec.at(j));
	double dz2 = (z_vec.at(i) - z_vec.at(j)) * (z_vec.at(i) - z_vec.at(j));
	return sqrt(dx2 + dy2 + dz2);
}

double	solve(int n, const vector<double> &x_vec,
			const vector<double> &y_vec, const vector<double> &z_vec,
			const vector<double> &r_vec)
{
	UnionFind	uf(n);
	vector<DII>	edge_vec;

	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			double	dist = calc_dist(x_vec, y_vec, z_vec, i, j);
			double	cost = dist - r_vec.at(i) - r_vec.at(j);
			if (cost <= 0) {
				uf.unite(i, j);
			} else {
				edge_vec.push_back(make_tuple(cost, i, j));
			}
		}
	}
	if (edge_vec.size() == 0 || uf.num_group == 1) 
		return 0.;
	sort(edge_vec.begin(), edge_vec.end());
	int i, j;
	double cost;
	double sum_cost = 0;
	for (auto tpl : edge_vec) {
		tie(cost, i, j) = tpl;
		if (uf.same(i, j))
			continue;
		uf.unite(i, j);
		sum_cost += cost;
		if (uf.num_group == 1)
			break;
	}
	return sum_cost;
}

int	main()
{
	int	n;
	while (cin >> n) {
		if (n == 0) break;
		vector<double>	x_vec(n), y_vec(n), z_vec(n), r_vec(n);
		for (int i = 0; i < n; ++i)
			cin >> x_vec.at(i) >> y_vec.at(i) >> z_vec.at(i) >> r_vec.at(i);
		double result = solve(n, x_vec, y_vec, z_vec, r_vec);
		cout << fixed << setprecision(3) << result << endl;
	}
}



Measured memory_bytes: 3408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===
template<class OperatorMonoid,
         class Merge = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)> >
struct DualSegmentTree {
    int sz, height;
    const OperatorMonoid e;
    const Merge merge_operator;
    vector<OperatorMonoid> lazy;
 
    DualSegmentTree(OperatorMonoid e, const Merge &h):
        e(e), merge_operator(h) {};
    void init(int nmemb) {
        sz = nmemb;
        lazy.assign(sz << 1, e);

        height = -1;
        while (nmemb) nmemb >>= 1, height++;
    };
 
    inline void propagate(int k) {
        if (k >= sz || lazy[k] == e) return;
        lazy[(k << 1) | 0] = merge_operator(lazy[(k << 1) | 0], lazy[k]);
        lazy[(k << 1) | 1] = merge_operator(lazy[(k << 1) | 1], lazy[k]);
        lazy[k] = e;
    };
    void push_down(int k) {
        for (int i = height; i > 0; i--) {
            propagate(k >> i);
        }
    };
 
    // [l, r)
    void update(int l, int r, OperatorMonoid op) {
        l += sz; r += sz;
        push_down(l);
        push_down(r - 1);
         
        while (l < r) {
            if (l & 1) lazy[l] = merge_operator(lazy[l], op), l++;
            if (r & 1) --r, lazy[r] = merge_operator(lazy[r], op);
 
            l >>= 1;
            r >>= 1;
        }
    };
 
    OperatorMonoid operator [] (int k) {
        k += sz;
        push_down(k);
        return lazy[k];
    };
};
//===

vector<llong> v;
DualSegmentTree<llong> dst(-1, [](auto l, auto r){ return r; });
vector<tuple<llong, llong, llong>> a;
vector<llong> d;

llong idx(int x)  {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main() {
    llong n, q;
    cin >> n >> q;
    dst.init(2 * n + q + 5);

    for (int i = 0; i < n; i++) {
        llong s, t, x;
        cin >> s >> t >> x;
        a.push_back(tie(x, s, t));
        v.push_back(s - x);
        v.push_back(t - x);
    }

    for (int i = 0; i < q; i++) {
        llong x;
        cin >> x;
        d.push_back(x);
        v.push_back(x);
    }

    sort(a.rbegin(), a.rend());
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    for (int i = 0; i < n; i++) {
        llong s, t, x;
        tie(x, s, t) = a[i];

        dst.update(idx(s - x), idx(t - x), x);
    }

    for (int i = 0; i < q; i++) {
        cout << dst[idx(d[i])] << endl;
    }

    return 0;
}


Measured memory_bytes: 27420
#include<stdio.h>
#include<string.h>
int main(void){
    char S[100];
    scanf("%s",&S);
    if(S[0]=='1'){
        printf("Heisei");
    }else if(S[1]!='0'){
        printf("TBD");
    }else if(S[2]=='0'){
        printf("Heisei");
    }else if(S[2]!='1'){
        printf("TBD");
    }else if(S[3]!='9'){
        printf("Heisei");
    }else if(S[5]!='0'){
        printf("TBD");
    }else if((S[6]=='1')||(S[6]=='2')||(S[6]=='3')||(S[6]=='4')){
        printf("Heisei");
    }else{
        printf("TBD");
    }
    return 0;
}

Measured memory_bytes: 128
a,b,c = map(int, input().split())
amalist = []

i = 0
while True:
    i = i+a
    if i%b == c:
        print("YES")
        break
    else:
        if i%b not in amalist:
            amalist.append(i%b)
        else:
            print("NO")
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int a[510],amari[510];

vector<int> yaku(int x){
	vector<int> ret;
	for(int i = 1;i * i <= x;i++){
		if(x % i == 0){
			ret.pb(i);
			if(i * i != x) ret.pb(x / i);
		}
	}
	sort(all(ret));
	return ret;
}

signed main(){
	int n,k,sum = 0,ma = 1;
	cin >> n >> k;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		sum += a[i];
	}
	vector<int> yakus = yaku(sum);
	for(int v : yakus){
		if(v == 1) continue;
		int sumamari = 0,sa;
		for(int i = 0;i < n;i++){
			amari[i] = a[i] % v;
			sumamari += amari[i];
		}
		if(sumamari % v == 0){
			int sa = sumamari / v;
			sort(amari,amari + n,greater<int>());
			for(int i = 0;i < n && sa;i++){
				if(amari[i]){
					sa--;
					sumamari -= amari[i];
				}
			}
		}
		if(sumamari <= k) chmax(ma,v);
	}
	cout << ma << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
	int a, b,c ,d ,e;
	cin >> a >> b;
	c =a/b;
	d =a%b;
	e =100000 * d/b;
	cout << c << " " << d << " " << c << "."<< e << endl;
	return 0;
}



Measured memory_bytes: 3084
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

#define NUM_MAX 100

struct prod {
    int weight;
    int value;
};

int desc(const void *a1, const void *a2) {
    return *(int*)a2 - *(int*)a1;
}

#define RANGE_MAX 3
int main(void) {
    int num, ulimit;
    get_int2(&num, &ulimit);
    static struct prod prods[NUM_MAX];
    int i, j;
    for(i = 0; i < num; i++) {
        get_int2(&prods[i].weight, &prods[i].value);
    }
    int base = prods[0].weight;
    static int map[RANGE_MAX+1];
    static int cum[RANGE_MAX+1][NUM_MAX+1];
    static int vidx[RANGE_MAX+1];
    for(i = 0; i < RANGE_MAX+1; i++) vidx[i] = 1;

    for(i = 0; i < num; i++) {
        int idx = prods[i].weight-base;
        map[idx]++;
        cum[idx][vidx[idx]++] = prods[i].value;
    }

    for(i = 0; i <= RANGE_MAX; i++) {
        qsort(&cum[i][1], vidx[i], sizeof(int), desc);
        for(j = 1; j <= NUM_MAX; j++) {
            cum[i][j] += cum[i][j-1];
        }
    }

    int k0, k1, k2, k3;
    int cnt_max = ulimit/base;
    int ans = 0;
#ifdef DEBUG
    printf("cnt_max: %d\n", cnt_max);
    for(i = 0; i < RANGE_MAX+1; i++) printf(" %d", vidx[i]-1);
    putchar('\n');
#endif
    for(k0 = 0; k0 < vidx[0]; k0++) {
        for(k1 = 0; k1 < vidx[1]; k1++) {
            for(k2 = 0; k2 < vidx[2]; k2++) {
                for(k3 = 0; k3 < vidx[3]; k3++) {
                    int ks[RANGE_MAX+1] = {k0, k1, k2, k3};
                    // 1-indexed -> 0-indexed
                    int cnt_sum = 0;
                    for(i = 0; i < RANGE_MAX+1; i++) cnt_sum += ks[i];
                    if(cnt_sum > cnt_max) continue;
                    int w = cnt_sum * base;
                    for(i = 0; i < RANGE_MAX+1; i++) {
                        w += ks[i]*i;
                    }
                    if(w > ulimit) break;
                    int res = 0;
                    for(i = 0; i < RANGE_MAX+1; i++) {
                        res += cum[i][ks[i]];
                    }
                    ans = max(ans, res);
                }
            }
        }
    }

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

Measured memory_bytes: 128
n = int(input())
H = [0] + list(map(int, input().split()))

dp = [0] * (n+1)
#dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, n+1):
  dp[i] = min(dp[i-1] + abs(H[i] - H[i-1]), dp[i-2] + abs(H[i] - H[i-2]))
print(dp[n])

Measured memory_bytes: 52208
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define val first
#define place second
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18;
const int N = (int)2e5 + 100;
const int MAXA = (int)3e6;
int arr[N],cnt[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ifstream cin("input.txt");
    // ofstream cout("output.txt");
    int n;
    cin >> n;
    bool ok = 1;
    for(int i = 1;i <= n;i++){
        cin >> arr[i];
    }
    sort(arr + 1,arr + 1 + n);
    int num = 0;
    for(int i = 1;i <= n;i++){
        if((arr[i] - (arr[n] / 2)) < 0)ok = 0;
    }
    if(arr[1] == arr[2] && arr[2] == arr[3])ok = 0;
    if(arr[1] == arr[2] && ((arr[1] - (arr[n] / 2)) != 1))ok = 0;
    if(arr[1] != arr[2] && (arr[1] != (arr[n] / 2)))ok = 0;
    for(int i = 1;i <= n;i++)cnt[arr[i]]++;
    for(int i = 1;i <= n;i++){
        if(!(cnt[arr[i]] >= 2 || arr[i] == arr[1]))ok = 0;
    }
    int st = -1;
    if(arr[1] == arr[2])st = 1; else st = 0;
    for(int i = st + 1;i <= (arr[n] / 2);i++){
        if(cnt[i + (arr[n] / 2)] < 2){
                ok = 0;
                break;
        }
    }
    if(ok)cout << "Possible"; else cout << "Impossible";
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : " ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ';
constexpr char newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll res = 0;
    if (k < a) {
        res += k;
    } else {
        res += a;
        k -= a;
        if (k >= b) {
            k -= b;
            res -= k;
        }
    }
    cout << res << newl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cmath>
#include<list>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 8;
int n,q,x,num;
int s[maxn];


bool is_find(int x)
{
    int left,right,mid;
    left = 0;
    right = n;
    while(left < right)
    {
        mid = (left + right) / 2;
        if(s[mid] == x) return true;
        else if(s[mid] > x)
        {
            right = mid;
        }
        else if(s[mid] < x)
        {
            left = mid + 1;
        }
    }
    return false;
}
int main()
{
    scanf("%d",&n);
    num = 0;
    fill(s,s+maxn,0);
    for(int i = 0; i < n; ++i) scanf("%d", &s[i]);
    sort(s,s+n);
    scanf("%d",&q);
    for(int i = 0; i < q; ++i)
    {
        scanf("%d", &x);

            if(is_find(x))
            {
                num++;

            }

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

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int n = 0; 
		
		while(n*(n+1)/2 < x) {
			n++;
		}
		System.out.println(n);

	}

}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
using namespace std;
int main(){
	long long a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	if ((a+b)>2*c){
		if (x>y){
			long long d=2*c*y;
			long long e=a*(x-y);
			if (a>2*c)
			cout<<2*c*x<<endl;
			else cout<<d+e<<endl;
		}
		else {
			long long d=2*c*x;
			long long e=b*(y-x);
			if (b>2*c)
			cout<<2*c*y<<endl;
			else cout<<d+e<<endl;
		}
	}
	else
	cout<<a*x+b*y<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

int n, ans = 0;

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

void exgcd(int a, int b, int &x, int &y) {
    if (!b) {
        x = 1, y = 0;
        return;
    }
    int _x, _y;
    exgcd(b, a%b, _x, _y);
    x = _y, y = _x-a/b*_y;
}

int inverse(int x, int mod) {
    int k, l;
    exgcd(x, mod, k, l);
    k %= mod;
    if (k < 0) k += mod;
    return k;
}

int cal(int s, int x, int K) {
    int d = gcd(x, K);
    if (s % d) return 0;
    else {
        int s_ = s / d, x_ = x / d, K_ = K / d;
        int k = 1ll * s_ * inverse(x_, K_) % K_;
        return s - k * x;
    }
}

int SG(int A, int K) {
    if (K == 1) return A;
    if (A < K) return 0;
    int x = A / K + 1;
    int t = cal(A, x, K);
    if (t / K == A / K) return t / K;
    int l = A / K * K;
    // A - kx < l
    // kx > A - l
    int k = (A - l + x - 1) / x;
    return SG(A - k * x, K);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int a, k; scanf("%d%d", &a, &k);
        ans ^= SG(a, k);
    }
    if (ans) puts("Takahashi");
    else puts("Aoki");
    return 0;
}

Measured memory_bytes: 256
let N = Int(readLine()!)!

var a = [[Int]]()
for _ in stride(from: 0, to: N, by: 1) {
    let row = readLine()!.split(separator: " ").map { Int($0)! }
    a.append(row)
}

/// arrayOfScore[combination] = score
/// うさぎのうちのcombinationがグループになっている時に得られる得点score
var arrayOfScore = [Int]()
for combination in stride(from: 0, to: 1 << N, by: 1) {
    var score = 0
    for i in stride(from: 0, to: N, by: 1) {
        for j in stride(from: i + 1, to: N, by: 1) {
            if (combination >> i) & 1 == 1, (combination >> j) & 1 == 1 {
                score += a[i][j]
            }
        }
    }
    arrayOfScore.append(score)
}

/// dp[combination] = score
/// うさぎのうちのcombinationがどこかしらに所属している時の得点score
var dp = Array(repeating: 0, count: 1 << N)
for combination in stride(from: 0, to: 1 << N, by: 1) {
    /// 未所属のうさぎ
    let rabbitsNotBelonging = combination ^ (1 << N - 1)
    var subset = rabbitsNotBelonging
    /// 未所属うさぎ集団の全ての部分集合について
    while subset > 0 {
        let nextCombination = subset | combination
        dp[nextCombination] = max(dp[nextCombination], dp[combination] + arrayOfScore[subset])
        subset = (subset - 1) & rabbitsNotBelonging
    }
}

print(dp[1 << N - 1])


Measured memory_bytes: 9436