akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll a, b;
    cin >> a >> b;

    if((a*b)%2 == 0) {
        out("Even");
    }
    else {
        out("Odd");
    }
    
    re0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int T = sc.nextInt();
		int S = sc.nextInt();
		if (S*T>=D) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 35624
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3
    ^lb   ^ub */
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)

#define DumpArray(cont,from,to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

using namespace std;
typedef long long ll;
typedef long double ld;
int N;
vector<int> b;
int main() {
    cin >> N;
    b.resize(N);
    REP(i,N)
        cin >> b[i];
    REP(i,N) {
        if (b[i]>i+1) {
            cout << -1 << endl;
            exit(0);
        }
    }
    vector<int> Ans;
    REP(cnt,N) {
        for (int i = b.size() - 1; i >= 0; --i) {
            if (b[i]==i+1) {
                Ans.pb(i+1);
                b.erase(b.begin()+i);
                break;
            }
        }
    }
    reverse(ALL(Ans));
    REP(i,N) {
        cout << Ans[i] <<endl;
    }
    return 0;
}


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

int main() {
  bool trick[100];
  for (int i = 0; i < 100; i++) trick[i] = true;
  int n, k;
  std::cin >> n >> k;

  for (int i = 0; i < n; i++) {
    int d;
    std::cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      std::cin >> a;
      trick[a - 1] = false;
    }
  }
  int res{0};
  for (int i = 0; i < n; i++) res += trick[i];
  std::cout << res << std::endl;
}

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

int main(void){
    int a[3];
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    int K;
    cin>>K;
    sort(a,a+3);
    int sum=0;
    for(int i=0;i<K;i++){
        a[2]*=2;
    }
    for(int i=0;i<3;i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int main() {
    ll i, n, a, b, c, d, x1, x2, ok=0;
    scanf("%lld%lld%lld%lld%lld",
        &n, &a, &b, &c, &d);
    for(i=0; i<=n-1; i++) {
        x1=a+d*i-c*(n-1-i);
        x2=a+c*i-d*(n-1-i);
        if(b<=x1 && b>=x2) ok=1;
    }
    printf(ok? "YES\n" : "NO\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j) for(int i;i<j;i++)
#define print(t) cout<<t<<endl
typedef long long ll;
typedef string str;

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << x2 + y1 - y2 << ' ';
	cout << y2 + x2 - x1 << ' ';
	cout << x1 + y1 - y2 << ' ';
	cout << y1 + x2 - x1 << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int P[202020];
int H[202020];
int HS[202020];
string S;

template<class V,int NV> class SegTree_1 {
public:
	vector<V> val;
	static V const def=-(1<<30);
	V comp(V l,V r){ return max(l,r);};
	
	SegTree_1(){val=vector<V>(NV*2,def);};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=v; //上書きかチェック
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};

SegTree_1<int,1<<20> st[2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	S.resize(N,'0');
	int ma=0;
	FOR(i,N) {
		cin>>P[i];
		if(P[i]>ma) {
			H[i]=1;
			ma=P[i];
		}
		HS[i+1]=HS[i]+H[i];
	}
	FORR(v,st[0].val) v=0;
	FORR(v,st[1].val) v=-1<<30;
	
	for(i=N-1;i>=0;i--) {
		int e=st[0].getval(P[i]+1,N+2);
		int o=st[1].getval(P[i]+1,N+2);
		
		if(e>=0) st[H[i]^1].update(P[i],e+H[i]+1);
		if(o>=0) st[H[i]].update(P[i],o+H[i]+1);
	}
	
	
	
	int Hx=0,Hy=0,Cx=0,Cy=0;
	FOR(i,N) {
		int Q=HS[N]-HS[i+1];

		st[0].update(P[i],0);
		st[1].update(P[i],-1<<30);
		
		S[i]='1';
		// a=Q-k, b=k+m, T=Cx-Cy+Q;
		{
			int T=(Cx+(P[i]>Hx))-Cy+Q;
			int num=st[T&1].getval(Hy+1,N+2);
			if(num>=T && T>=0) S[i]='0';
		}
		// a=k+m, b=Q-k, T=Cy-Cx+Q;
		{
			int T=Cy-(Cx+(P[i]>Hx))+Q;
			int num=st[T&1].getval(max(Hx,P[i])+1,N+2);
			if(num>=T && T>=0) S[i]='0';
		}
		if(S[i]=='0') {
			if(Hx<P[i]) Cx++, Hx=P[i];
		}
		else {
			if(Hy<P[i]) Cy++, Hy=P[i];
		}
		
	}
	
	
	if(Cx!=Cy) cout<<-1<<endl;
	else cout<<S<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 20480
def readinput():
    n,k=map(int,input().split())
    s=input()
    return n,k,s

def main(n,k,s):
    nl=s.count('L')
    nr=n-nl
    if nl==0 or nr==0:
        return n-1
    
    c=['L','R']

    # happyの初期値を計算
    flip=[]
    happy=0
    if s[0]=='L':
        ci=0
    else:
        ci=1
    l=0
    for i in range(n):
        #print(s[i],c[ci])
        if s[i]==c[ci]:
            l+=1
            #print(l)
        else:
            #print(l)
            happy+=max(l-1,0)
            flip.append(ci)
            l=1
            ci=(ci+1)%2
    else:
        happy+=max(l-1,0)
    #print(flip,happy)
    return happy+min(2*k,len(flip))

if __name__=='__main__':
    n,k,s=readinput()
    ans=main(n,k,s)
    print(ans)


Measured memory_bytes: 9920
#include <stdio.h>

int main(){
  int n;  scanf("%d", &n);
  long sum = 0;
  int a[100005] = {0};
  for(int i=0; i<n; i++){
    int t;  scanf("%d", &t);
    a[t]++;
    sum += t;
  }

  int q;  scanf("%d", &q);
  while(q--){
    long b, c;  scanf("%ld %ld", &b, &c);
    long num = a[b];
    sum -= b*num;
    sum += c*num;
    a[b] = 0;
    a[c] += num;
    printf("%ld\n", sum);
  }

  return 0;
}
  


Measured memory_bytes: 2124
from itertools import permutations
import math

n = int(input())
xy = []
for i in range(n):
    xy.append([int(i) for i in input().split()])

a = range(n)
ans = 0
b = list(permutations(a, n))
for i in range(len(b)):
    for j in range(1, n):
        ans += math.sqrt((xy[b[i][j]][0] - xy[b[i][j - 1]][0])**2 + (xy[b[i][j]][1] - xy[b[i][j - 1]][1])**2)
ans /= len(b)
print(ans)


Measured memory_bytes: 8100
#include <bits/stdc++.h>
#define INF 1234567891
#define MAXS 100007

#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define INP freopen("input.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll lista[MAXS];
int a, b, c;

int main(){
  cin >> a >> b >> c;
  lista[0] = c;
  for(int i = 0; i < 10; ++i){
    lista[i+1] = lista[i] * a - b;
    cout << lista[i+1] << endl;
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int M = 1000000;
        IntStack stack = new IntStack(M);

        long n = in.l();
        for (int i = 2; i < M; i++) {
            if (n % i == 0) {
                int c = 0;
                while (n % i == 0) {
                    c++;
                    n /= i;
                }
                stack.push(c);
            }
        }
        if (n > 1) {
            stack.push(1);
        }

        int ans = 0;
        while (!stack.isEmpty()) {
            int c = stack.pop();
            int i = 1;
            for (int s = 0; s + i <= c; s += i++);
            ans += i - 1;
        }

        out.println(ans);
    }
}

class IntStack {
    final int MAX;
    int[] array;
    int head = 0;

    IntStack(int N) {
        MAX = N;
        array = new int[N];
    }

    void push(int n) {
        array[head++] = n;
    }

     int pop() {
        return array[--head];
    }

    boolean isEmpty() {
        return head == 0;
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 36688
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split(" ");

const A = parseInt(input[0], 10);
const B = parseInt(input[1], 10);
const T = parseInt(input[2], 10);

let ans = 0;

for (let t = A; t < T + 0.5; t += A) {
  ans += B;
}

console.log(ans);

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

int main(void){
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) h-=a[i];
    if(h<=0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll unsigned long long
#define db double
#define inf 301
#define INF (int)1e8 
#define mod (int)(1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
typedef pair<int,int> P;

int n,m;
vector <P> a[inf];
int f[2][inf][inf];

int main(){
	rd(n) rd(m)
	int x,y,z;
	for (int i=1;i<=m;i++){
		rd(x) rd(y) rd(z)
		if (z>y-x+1){
			puts("0");
			return 0;
		}
		a[y].push_back(make_pair(x,z));
	}
	int now=0;
	f[0][0][0]=1;
	for (int i=1;i<n;i++){
		now^=1;
		memset(f[now],0,sizeof(f[now]));
		for (int j=0;j<=i;j++){
			for (int k=j;k<=i;k++){
				f[now][j][k]=(f[now][j][k]+f[now^1][j][k])%mod;
				if (j==0 && k==0){
					f[now][j][i]=(f[now][j][i]+f[now^1][j][k])%mod;
				}
				else{
					f[now][j][i]=(f[now][j][i]+f[now^1][j][k])%mod;
					f[now][k][i]=(f[now][k][i]+f[now^1][j][k])%mod;
				}
			}
		}
		if (i==2){
			i=2;
		}
		for (int pos=0;pos<a[i+1].size();pos++){
			int l=a[i+1][pos].first;
			for (int j=0;j<=i;j++){
				for (int k=j;k<=i;k++){
					int cnt=1+(j>=l)+(k>=l);
					if (cnt!=a[i+1][pos].second){
						f[now][j][k]=0;
					}
				}
			}
		}
	}
	ll ans=0;
	for (int j=0;j<n;j++){
		for (int k=j;k<n;k++){
			if (!j && !k){
				ans=(ans+((ll)f[now][j][k])*3LL%mod)%mod;
			}
			else{
				ans=(ans+((ll)f[now][j][k])*6LL%mod)%mod;
			}
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
using System.Numerics;
class MainClass
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        Solve();
        Out.Flush();
        Read();
    }
    //ここにプログラムを入力
    static void Solve()
    {
        int N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Array.Sort(A);
        BigInteger total = 1;
        bool frag = true;
        for (int i = 0; i < N&&frag; i++)
        {
            total *= A[i];
            if (total == 0)
            {
                WriteLine(0);
                return;
            }
            else if (total > 1000000000000000000)
            {
                frag = false;
                break;
            }
        }
        WriteLine(frag?total:-1);
    }
}


Measured memory_bytes: 41684
N, M = map(int,input().split())
L = []
R = []
for i in range(M):
    tmp_L, tmp_R = map(int,input().split())
    L.append(tmp_L)
    R.append(tmp_R)

left = max(L)
right = min(R)

if right - left < 0:
    print(0)
else:
    print(right - left + 1)

Measured memory_bytes: 11052
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

n_bit = 2**n

# １の立つ数で仕分けしておく
flag_num = {}
log2_num = {}
for i in range(n+1):
    flag_num[i] = []
    log2_num[2**i] = i

for i in range(n_bit):
    num = str(bin(i)).count('1')
    flag_num[num].append(i)

#bit演算
# https://www.slideshare.net/KMC_JP/slide-www

# いくつかのウサギを同じグループにした時の点数を計算しておく
g = [0]*n_bit
for i in range(2,n+1):
    for j in flag_num[i]:
        #1になっている一番下の桁の取得
        left_flag = j & (-j)
        #一番左の1だけ反転
        right_flags = j - left_flag

        g[j] = g[right_flags]
        left = log2_num[left_flag]
        for k in range(n+1):
            if( ((right_flags >> k) & 1)  > 0):
                g[j] += a[left][k]

#dpを更新する
init = -1 * 150 * 10**10
dp = [init] * n_bit
dp[0] = 0
for i in range(1,n+1):
    for j in flag_num[i]:
        temp = init
        k = (j-1) & j
        while( k >= 0):
            ### ここに処理を描く ###
            temp = max(temp, dp[k] + g[j-k] )

            # k==0ならbreak
            if(k==0):
                break
            #kの更新
            k = (k-1) & j
        dp[j] = temp

print(dp[n_bit - 1])

Measured memory_bytes: 46556
from collections import deque

def BellmanFord(adjList, vSt, INF):
    numV = len(adjList)
    negINF = -INF
    costs = [INF] * numV
    costs[vSt] = 0
    vNows = set([vSt])

    for _ in range(numV):
        vChangeds = set()
        for vFr in vNows:
            costFr = costs[vFr]
            for vTo, wt in adjList[vFr]:
                c2 = costFr + wt
                if c2 < costs[vTo]:
                    costs[vTo] = c2
                    vChangeds.add(vTo)
        if not vChangeds:
            return costs
        vNows = vChangeds

    for v in vNows:
        costs[v] = negINF

        Q = deque(vNows)
    while Q:
        vFr = Q.popleft()
        for vTo, wt in adjList[vFr]:
            if costs[vTo] == negINF: continue
            costs[vTo] = negINF
            Q.append(vTo)

    return costs


N, M, P = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(M):
    A, B, C = map(int, input().split())
    A, B = A-1, B-1
    adjL[A].append((B, -(C-P)))

costs = BellmanFord(adjL, 0, float('inf'))

if costs[N-1] == -float('inf'):
    print(-1)
else:
    print(max(0, -costs[N-1]))


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

#define int long long

using namespace std;

int a[100001];
int b[100001];

 main () {
	int n, ans = 0;
	cin >> n;
	int k = 0;
	for (int i = 1;i <= n;i ++) {
	    cin >> a[i];
		if (a[i] != a[i - 1]) b[++ k] = a[i];
	}
	n = k;
    int i = 1;
    while (i <= n) {
    	ans ++;
    	int j = i;
    	if (b[i + 1] > b[i]) {
    		while (b[j + 1] > b[j]) {
    			j ++;
    		}
    	}
    	if (b[i + 1] < b[i]) {
    		while (b[j + 1] < b[j]) {
    			j ++;
    		}
    	}
    	i = j + 1;
    }
    cout << ans;
    return 0;           		
}

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

int main () {
  int n = 0 , k = 0 ;
  cin >> n >> k ;
  
  int x = 0 , y = 0 ;
  cin >> x >> y ;
  
  int answer = 0 ;
  
  answer = n * x ;
  
  if ( n > k ){
    answer = answer + ( y - x ) * ( n - k ) ;
  }
  cout << answer << endl ;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, tmp int
	sum := 0
	max := 0
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > max {
			sum += max
			max = tmp
		} else {
			sum += tmp
		}
	}
	if max < sum {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define ll long long
#define M 100000007
#define fr first
#define sc second
#define endl "\n"
#define vc vector
#define pb push_back
#define pii pair<ll, ll>
#define psi pair<string, ll>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265
#define r0 return 0
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;


int main() {
  fast
  ll n,k,move=0;
  cin>>n>>k;
  ll a[n];
  rep(i,0,n) cin>>a[i];
  if(n<=k){
      cout<<"0";
  }
  else{
      sort(a,a+n);
      for(int i=0;i<n-k;i++){
          move+=a[i];
      }
      cout<<move;
  }
}



Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define double long double
const double PI = acos(-1.0);
struct point {
	double x, y;
	int num;
	point operator +(const point &p)const {
		return { x + p.x, y + p.y };
	}
	point operator -(const point &p)const {
		return { x - p.x, y - p.y };
	}
	point Rotate(double Angle) {
		Angle = Angle*PI / 180;
		double ss = sinl(Angle), cc = cosl(Angle);
		return { x*cc - y*ss, x*ss + y*cc };
	}
	point operator *(const double &k)const {
		return { x*k,y*k };
	}
}P[4], RD, LD, RR;
point Get() {
	char p[3];
	int d, l;
	scanf("%s%d%d", p,&d,&l);
	if (strcmp(p, "BC") == 0) {
		return P[1].Rotate(d)*l;
	}
	if (strcmp(p, "BD") == 0) {
		return P[1].Rotate(-d)*l;
	}
	if (strcmp(p, "CB") == 0) {
		return P[2].Rotate(-d)*l;
	}
	if (strcmp(p, "CD") == 0) {
		return P[2].Rotate(d)*l;
	}
	if (strcmp(p, "DB") == 0) {
		return (P[0]-P[3]).Rotate(d)*l;
	}
	if (strcmp(p, "DC") == 0) {
		return P[3].Rotate(-d)*l;
	}
}
double ccw(point a, point b, point c) {
	return (b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x);
}
bool Inside(point a, point b, point c, point d) {
	if (ccw(a, b, d) < 0 && ccw(b, c, d) < 0 && ccw(c, a, d) < 0)return true;
	if (ccw(a, b, d) > 0 && ccw(b, c, d) > 0 && ccw(c, a, d) > 0)return true;
	return false;
}
int Loc(point a) {
	int i, j, k;
	for (i = 0; i < 30; i+=2) {
		for (j = 0; j < 30; j += 2) {
			for (k = -30; k <= 30; k += 2) {
				point tp = P[0] + RR * k + RD * i + LD * j;
				point P1 = tp;
				point P2 = tp+RR;
				point P3 = tp+RR+RR;
				point P4 = tp+RD;
				point P5 = tp+RD+RR;
				point P6 = tp + RD + RR+RR;
				point P7 = tp+RD+RD;
				point P8 = tp+RD+RD+RR;
				point P9 = tp + RD + RD + RR + RR;
				if (Inside(P1, P2, P4, a) || Inside(P6, P8, P9, a))return 1;
				if (Inside(P2, P3, P5, a) || Inside(P5, P7, P8, a))return 2;
				if (Inside(P2, P4, P5, a) || Inside(P5, P6, P8, a))return 3;
				if (Inside(P3, P5, P6, a) || Inside(P4, P5, P7, a))return 4;
			}
		}
	}
	return 0;
}
int main() {
	RD = { 0.5 , -sqrtl(3)*0.5L };
	LD = { -0.5 , -sqrtl(3)*0.5L };
	RR = { 1.0, 0.0 };
	P[0] = { 0.0, 0.0 };
	P[1] = P[0] + LD;
	P[2] = P[0] + RD;
	P[3] = P[0] + RR;
	point A = Get(), B = Get();
	if (Loc(A) == Loc(B))printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 3016
// https://atcoder.jp/contests/arc079/tasks/arc079_a

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define int long long
#define all(x) (x).begin(), (x).end()

const int maxn = 200500;

vector<int> G[maxn];
int N, M;

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

    cin >> N >> M;

    while(M--) {
        int u, v;
        cin >> u >> v;

        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    string ans = "IMPOSSIBLE";
    for(int adj: G[1]) {
        for(int adj2: G[adj]) {
            if(adj2 == N) {
                ans = "POSSIBLE";
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 15668
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int n; cin >> n;
    deque<int> deq;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        if (i & 1) deq.push_front(a);
        else deq.push_back(a);
    }
    
    if (n & 1) reverse(deq.begin(), deq.end());
    for (auto e : deq) cout << e << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  string a = "abcdefghijklmnopqrstuvwxyz";

  for (int i = 0; i < 26; i++) {
    for (int j = 0, l = S.size(); j < l; j++) {
      if (S[j] == a[i]) {
        break;
      }
      if (j == l - 1 && S[j] != a[i]) {
        cout << a[i] << endl;
        return 0;
      }
    }
  }

  cout << "None" << endl;
}

Measured memory_bytes: 3704
#include<cstdio>
inline int max(int a,int b){return a>b?a:b;}
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",a+b+c-max(a,max(b,c)));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n,m;
    cin >> n >> m;
    int h[n+1];
    vector <int> g[n+1];
    for(int i=1;i<=n;i++)
    	cin >> h[i];
    for(int i=0;i<m;i++){
    	int u,v;
    	cin >> u >> v;
    	g[u].push_back(v);
    	g[v].push_back(u);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
    	int mx=0;
    	for(auto j:g[i])
    		mx=max(mx,h[j]);
    	if(h[i]>mx)ans++;
    }
    cout << ans;
}

Measured memory_bytes: 10252
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=3050;
const int mod=1e9+7;
int pow(int x, int k){ int ans=1;for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ans=(ll)ans*x%mod;return ans;}
int inv(int x){ return pow(x,mod-2);}
int x[N],y[N],a[N],p[N],sum[N];
int main()
{
	int n,i,q,j;
	scanf("%i %i",&n,&q);
	vector<int> id;
	for(i=1;i<=n;i++) scanf("%i",&a[i]),id.pb(a[i]);
	sort(id.begin(),id.end());id.resize(unique(id.begin(),id.end())-id.begin());
	for(i=1;i<=n;i++) a[i]=lower_bound(id.begin(),id.end(),a[i])-id.begin()+1;
	for(i=1;i<=q;i++) scanf("%i %i",&x[i],&y[i]);
	int ans=0;
	for(j=id.size();j>=1;j--)
	{
		for(i=1;i<=n;i++) p[i]=a[i]==j;
		for(i=1;i<=q;i++) p[x[i]]=p[y[i]]=(ll)(p[x[i]]+p[y[i]])*inv(2)%mod;
		int hi=0;
		for(i=1;i<=n;i++)
		{
			ans+=(ll)hi*p[i]%mod;ans%=mod;
			ans+=(ll)sum[i]*p[i]%mod*inv(2)%mod;ans%=mod;
			hi+=sum[i];hi%=mod;
			sum[i]+=p[i];sum[i]%=mod;
		}
	}
	for(i=1;i<=q;i++) ans=ans*2%mod;
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		int goal = scan.nextInt();

		// check
		int pos = 0;
		int answer = 0;
		for(int i = 1; i < 1000000000; i++) {
			pos += i;
			if(pos >= goal) {
				answer = i;
				break;
			}
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> N;
}

bool isok(string s){
    if(s.length()<=2) return false;
    if(stoi(s)>N) return false;
    unordered_map<int,int> cnt;
    for (int i = 0; i < s.length(); i++) cnt[s[i]-'0']++;
    if(cnt[7]&&cnt[5]&&cnt[3]) return true;
    else return false;    
}

int solve(){
    string s=to_string(N);
    vector<string> kouho={""};
    for (int i = 0; i < s.length(); i++)
    {
        vector<string> tmp=kouho;
        for(auto s:kouho){
            tmp.push_back(s+'7');
            tmp.push_back(s+'5');
            tmp.push_back(s+'3');
        }
        kouho = tmp;
    }
    set<string> ans;
    for(auto s:kouho){
        if(isok(s)) ans.insert(s);
    }
    // DBG(ans)
    cout << ans.size() << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


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

int main() {

  int map[32][32];

  int N;
  int M;
  int xi, yi;
  int x, y;
  

  for(;;) {

    for(int i = 0; i < 32; ++i) {
      for(int j = 0; j < 32; ++j) {
	map[i][j] = 0;
      }
    }

    x = y = 10;
    
    std::cin >> N;
    if( N == 0 ) break;

    for(int i = 0; i < N; ++i) {
      std::cin >> xi >> yi;
      map[xi][yi] = 1;
    }

    std::cin >> M;
    for(int i = 0; i < M; ++i) {
      char d;
      int l;
      std::cin >> d >> l;
      if( d == 'N' ) {
	for(int ny = y; ny <= y+l; ++ny) {
	  map[x][ny] = 0;
	}
	y = y+l;
      }
      if( d == 'E' ) {
	for(int nx = x; nx <= x+l; ++nx) {
	  map[nx][y] = 0;
	}
	x = x+l;
      }
      if( d == 'S' ) {
	for(int ny = y; ny >= y-l; --ny) {
	  map[x][ny] = 0;
	}
	y = y-l;
      }
      if( d == 'W' ) {
	for(int nx = x; nx >= x-l; --nx) {
	  map[nx][y] = 0;
	}
	x = x-l;
      }
    }

    bool ans = true;
    for(int i = 0; i < 20; ++i) {
      for(int j = 0; j < 20; ++j) {
	if( map[i][j] != 0 ) {
	  ans = false;
	}
      }
    }
    if( ans ) {
      std::cout << "Yes" << std::endl;
    }
    else {
      std::cout << "No" << std::endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a) )
#define M 1000000007

ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	int n;
	cin>>n;
	unordered_map<int,int>m;
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		m[x]++;
		ans+=x;
	}
	int q;
	cin>>q;
	while(q--)
	{
		ll p,q;
		cin>>p>>q;
		if(m.find(p)!=m.end())
		{
			ans=ans-p*m[p]+q*m[p];
			m[q]+=m[p];
			m.erase(p);
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 6624
n = int(input())
D = {}
for i in range(n):
    D[i + 1] = int(input())
ans = 0
button = 1
pushed = set()
while button not in pushed:
    pushed.add(button)
    button = D[button]
    ans += 1
    if button == 2:
        print(ans)
        break
else:
    print(-1)


Measured memory_bytes: 22240
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int A, V;
  Int B, W;
  cin>>A>>V;
  cin>>B>>W;
  Int T;
  cin>>T;

  Int ans = 0;
  if(A < B){
    Int a = A + V * T;
    Int b = B + W * T;
    if(a >= b) ans = 1;
  }
  else{
    Int a = A - V * T;
    Int b = B - W * T;
    if(a <= b) ans = 1;
  }

  cout<<(ans? "YES":"NO")<<endl;

  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include <iomanip>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll combi[51][51];

int main()
{
	REP(i,51)
	{
		combi[i][0] = combi[i][i] = 1;
	}
	REP(i,51)
	{
		for(int j = 1;j < i;j++)
		{
			combi[i][j] = combi[i-1][j-1] + combi[i-1][j];
		}
	}
	
	//SHOW2d(combi,6,6);
	
	int n,a,b;
	cin >> n >> a >> b;
	
	vector<ll> v;
	REP(i,n)
	{
		ll t;
		cin >> t;
		v.PB(t);
	}
	
	sort(ALL(v),greater<ll>());
	
	
	int cou = 0;
	for(;v[cou] == v[cou+1];cou++);
	cou++;
		
	if(cou >= a)
	{
		long double ret = v[0];
		ll kazu = 0;
		for(int i = a;i <= min(cou,b);i++)
		{
			kazu = kazu + combi[cou][i];
		}
		cout << fixed << setprecision(7) << ret << endl;
		cout << kazu << endl;
	}
	else
	{
		long double ret = 0;
		int tmp = 0;
		int num = 0;
		REP(i,n)
		{
			if(v[i] == v[a-1])tmp++;
		}
		REP(i,a)
		{
			ret += v[i];
			if(v[i] == v[a])num++;
		}
		ret /= a;
		ll kazu = 0;
		kazu = kazu + combi[tmp][num];
		cout << fixed << setprecision(7) << ret <<endl;
		cout << kazu << endl;
	}
		
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


class UnionFind {
	vector<int> data;
	int num;
public:
	UnionFind(int size) : data(size, -1), num(size) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			num--;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
	int numSet() {
		return num;
	}
};

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

	ll n;
	cin >> n;
	UnionFind uni(n);
	vector<P> x(n), y(n);
	REP(i, n) {
		cin >> x[i].first >> y[i].first;
		x[i].second = i;
		y[i].second = i;
	}

	sort(all(x));
	sort(all(y));

	vector<pair<ll, P>> es;
	REP(i, n-1) {
		es.push_back(make_pair(abs(x[i + 1].first - x[i].first), make_pair(x[i].second, x[i + 1].second)));
		es.push_back(make_pair(abs(y[i + 1].first - y[i].first), make_pair(y[i].second, y[i + 1].second)));
	}

	sort(all(es));
	ll sum = 0;
	for (auto e:es) {
		ll mon = e.first;
		ll u = e.second.first;
		ll v = e.second.second;
		if (!uni.findSet(u, v)) {
			uni.unionSet(u, v);
			sum += mon;
			if (uni.size(u) == n) break;
		}
	}

	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 12144
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main (String [] args){
		List <Integer> list = new ArrayList<Integer>();
		HashMap <Integer, Integer>hm = new HashMap<Integer, Integer>();
		int v1 = Integer.parseInt(sc.next());
		int v2 = Integer.parseInt(sc.next());		
		int v3 = Integer.parseInt(sc.next());
		String ans_str = "";
		int ans_int = 0;
		ans_int = (v1-v2)%v3;
		System.out.println(ans_int);
		System.out.flush();
		sc.close();
	}
}

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

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

const int mod = 1000000007;
#define PI 3.14159265359;

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

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


int main() {
  char a, b;
  cin >> a >> b;
  if (a == 'H') {
    if (b == 'H') P('H');
    else P('D');
  } else {
    if (b == 'H') P('D');
    else P('H');
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	void main(){
		try(Scanner sc = new Scanner(System.in)){
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.printf("%d %d\n", a*b, 2*a+2*b);
			
		}
	}

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

}



Measured memory_bytes: 26208
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var ringyou = new long[N + 1, N + 1];
            for (var i = 1; i <= N; ++i)
            {
                var ukv = Sarray();
                for (var j = 2; j < ukv.Length; ++j)
                {
                    ringyou[i, ukv[j]] = 1;
                }
            }
            var d = new long[N + 1];
            var f = new long[N + 1];
            StringBuilder ans = new StringBuilder();
            Action<long> dfs = null;
            var time = 1L;
            dfs = (long n) =>
                 {
                     for (var j = 1; j <= N; ++j)
                     {
                         if (ringyou[n, j] == 1 && d[j] == 0)
                         {
                             d[j] = time++;
                             dfs(j);
                             f[j] = time++;
                         }
                     }

                 };
            for (var i = 1; i <= N; ++i)
                if (d[i] == 0)
                {
                    d[i] = time++;
                    dfs(i);
                    f[i] = time++;
                }
            for(var i=1;i<=N;++i)
            {
                WriteLine($"{i} {d[i]} {f[i]}");
            }
        }
    }
}


Measured memory_bytes: 20412
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Array

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    fs <- replicateM n getIntList
    ps <- array ((1,0),(n,10)) . zip [(i,j) | i <- [1..n], j <- [0..10]] . concat <$> replicateM n getIntList
    let result = maximum [calc fs ps open|open <- replicateM 10 [0,1], any (== 1) open]
    print result

calc fs ps open = sum . map (ps !) . zip [1..] $ map (sum . zipWith (*) open) fs

Measured memory_bytes: 5088
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
int main(){
   int n;
   long long s=0;
   cin >> n;
   vector<int> l(2*n);
   for(int i=0; i<2*n; i++){
       cin >> l.at(i);
   }
   sort(l.begin(),l.end());
    for(int i=0; i<n; i++){
           s+=l[2*i];
    }
   cout << s << endl;
}

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

const int MAXN = 200000 + 10;

int n;
int a[MAXN];
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    int p, q, r;
    p=q=r=0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i]%4 == 0) p++;
        else if (a[i]%2 == 0) q++;
        else r++;
    }

    if (r > p) { 
        if (r == p + 1 && q == 0) {
            cout << "Yes\n";
        } else 
        cout << "No\n"; 
    }
    else { cout << "Yes\n"; }
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		for (int i = 0; i < k; i++) {
			String a = in.next();
			String b = in.next();
			int l = find_LCS(a,b);
			System.out.println(l);
		}
		in.close();
	}
	
	public static int find_LCS(String a, String b) {
		int m = a.length();
		int n = b.length();
		int[][] lcs = new int[m+1][n+1];
		
		
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				lcs[i][j] = Math.max(lcs[i-1][j], lcs[i][j-1]);
				if (a.charAt(i-1) == b.charAt(j-1)) {
					lcs[i][j] = 1 + lcs[i-1][j-1];
				}
			}
		}
		
		return lcs[m][n];
	}
}



Measured memory_bytes: 64348
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int[] NA = ReadLineParseIntArray();
        long N = NA[0];
        long A = NA[1];
        long[] X = ReadLine().Split(' ').Select(x => int.Parse(x) - A).ToArray();
        long max = Abs(X.Max());
 
        long[] dp = new long[2 * max * N + 1];
        dp[N * max] = 1;
        for(int i = 0; i < N; i++)
        {
            long first = Max(0, X[i]);
            long last = Min(dp.Length, dp.Length + X[i]);
            if (X[i] <= 0)
                for (long t = first; t < last; t++)
                    dp[t] += dp[t - X[i]];
            else
                for (long t = last - 1; t >= first; t--)
                    dp[t] += dp[t - X[i]];
        }
        WriteLine(dp[N * max] - 1);    }

    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

Measured memory_bytes: 13496