akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int>pa;

const int N=2e5+100;
const int mod=1e9+7;

ll solve(ll x,ll y,ll z)
{
    if(x<y) swap(x,y);
    if(x<z) swap(x,z);
    if(y<z) swap(y,z);
    return x-z;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    ll h,w;
    cin>>h>>w;
     if(h%3==0 || w%3==0 ) {
        cout<<0<<endl;
        return 0;
     }
    if(h<w) swap(h,w);
    ll ans=1e18;
    ll s2,s3;
    for(int i=1;i<=h;i++){
        ll ww=w;
        ll l=h-i;
        ll s1=i*ww;
        if(l<ww) swap(l,ww);
        if(l*ww%2==0) s2=s3=l*ww/2;
        else {
            s2=(l-1)*ww/2;
            s3=s2+min(l,ww);
        }
      // cout<<s1<<" "<<s2<<" "<<s3<<endl;
       ans=min(ans,solve(s1,s2,s3));
    }
    swap(h,w);
    for(int i=1;i<=h;i++){
        ll ww=w;
        ll l=h-i;
        ll s1=i*ww;
        if(l<ww) swap(l,ww);
        if(l*ww%2==0) s2=s3=l*ww/2;
        else {
            s2=(l-1)*ww/2;
            s3=s2+min(l,ww);
        }
      // cout<<s1<<" "<<s2<<" "<<s3<<endl;
       ans=min(ans,solve(s1,s2,s3));
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> pl;
ll a=1000000000+7;
map<int,ll> m;

void pf(int n){
  for(int i=2;i*i<=n;i++){
    if(n%i) continue;
    while(n%i==0){
      m[i]++;
      m[i]%=a;
      n/=i;
    }
  }
  if(n!=1) m[n]++;
}
int main(){
  int n; cin>>n;

  ll ans=1;
  for(int i=1;i<=n;i++){
    pf(i);
    // cout<<"i "<<i<<endl;
    // for(auto iter=m.begin();iter!=m.end();iter++)
    // cout<<iter->first<<" "<<iter->second<<endl;
  }

  for(auto iter=m.begin();iter!=m.end();iter++){
    // cout<<iter->first<<" "<<iter->second<<endl;
    if(((iter->second)+1)%a==0) continue;
    ans*=((iter->second)+1);
    ans%=a;
    // cout<<ans<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define sync_cin                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0)
using namespace std;

#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;



int main()
{
    sync_cin;
    string s; cin >> s;

    string a, b;
    for (int i = 0; i < s.length(); i++)
        if (i & 1) 
        {
            a.push_back('0');
            b.push_back('1');
        }
        else
        {
            a.push_back('1');
            b.push_back('0');
        }
    
    int ans = s.length();
    int sol1 = 0, sol2 = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] != a[i]) sol1++;
        if (s[i] != b[i]) sol2++;
    }


    ans = min(sol1, sol2);

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

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;


int main(){
    int ac=0,wa=0,tle=0,re=0;
    int n; cin >> n;
    for(int i=0;i<n;i++){
        string s; cin >> s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if(s=="RE") re++;
    }
    cout << "AC x " << ac << endl; 
    cout << "WA x " << wa << endl; 
    cout << "TLE x " << tle << endl; 
    cout << "RE x " << re << endl; 
    return 0;
}

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

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

using namespace std;

const int INF=1<<29;

int main(){
	int n; scanf("%d",&n);
	char B[500][501];
	rep(i,n) scanf("%s",B[i]);

	bool ok=false;
	int fil=0;
	rep(j,n){
		int c=0;
		rep(i,n) if(B[i][j]=='#') ok=true, c++;
		if(c==n) fil++;
	}
	if(!ok) return puts("-1"),0;

	long ans=INF;
	rep(i,n){
		bool ok=false;
		rep(k,n) if(B[k][i]=='#') ok=true;
		ans=min(ans,count(B[i],B[i]+n,'.')+(ok?0:1));
	}
	ans+=n-fil;
	printf("%ld\n",ans);

	return 0;
}


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

X = inputI()

l = [pow(i,5) for i in range(-500,500)]

for i in l:
  for j in l:
    if i-j == X:
      if i!=0 and j!= 0:
        print(int(pow(abs(i),0.2)*i/abs(i)) ,int(pow(abs(j),0.2)*j/abs(j)))
        exit()
      elif i==0 and j!=0:
        print(0 ,int(pow(abs(j),0.2)*j/abs(j)))
        exit()
      elif i!=0 and j==0:
        print(int(pow(abs(i),0.2)*i/abs(i)) ,0)
        exit()
      else:
        print(0,0)
        exit()

Measured memory_bytes: 73388
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
mint dp[100005][13];
int main(){
string s;
cin>>s;
dp[0][0]=1;
reverse(all(s));
ll now=1;
int n=s.size();
for(int i=0;i<n;i++){
    if(s[i]!='?'){
        ll d=s[i]-'0';
        for(int j=0;j<13;j++){
            dp[i+1][(d*now+j)%13]+=dp[i][j];
        }
    }
    else{
        for(int d=0;d<10;d++){
       for(int j=0;j<13;j++){
            dp[i+1][(d*now+j)%13]+=dp[i][j];
           }
        }
    }
    now*=10;
    now%=13;
}
cout<<dp[n][5]<<endl;
}

Measured memory_bytes: 10704
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
const LL INF = 1LL << 60;
const int MaxN = 1e5;

int n, q, k;
int all;
int pre[2 * MaxN + 5], last[2 * MaxN + 5], other[2 * MaxN + 5];
LL cost[2 * MaxN + 5];
LL dis[MaxN + 5];
bool vis[MaxN + 5];

void build(int x, int y, LL w)
{
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
	cost[all] = w;
}

void BFS(int s)
{
	for(int i = 1; i <= n; i++)
		dis[i] = INF;
	dis[s] = 0;
	vis[s] = 1;
	queue <int> q;
	q.push(s);
	int now, ed, dr;
	while(!q.empty()) {
		now = q.front();
		q.pop();
		ed = last[now];
		while(ed != -1) {
			dr = other[ed];
			if(dis[now] + cost[ed] < dis[dr]) {
				dis[dr] = dis[now] + cost[ed];
				if(!vis[dr]) {
					q.push(dr);
				}
			}
			ed = pre[ed];
		}
		vis[now] = 0;
	}
}

int main()
{
	while(scanf("%d", &n) != EOF)
	{
		all = -1; memset(last, -1, sizeof(last));
		for(int i = 1; i < n; i++) {
			int u, v;
			LL w;
			scanf("%d %d %lld", &u, &v, &w);
			build(u, v, w);
			build(v, u, w);
		}
		scanf("%d %d", &q, &k);
		BFS(k);
		for(int i = 1; i <= q; i++) {
			int u, v;
			scanf("%d %d", &u, &v);
			printf("%lld\n", dis[u] + dis[v]);
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define rep(i, j, k) for (int i = j; i < k; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define mt make_tuple

#define iv inline void
#define ii inline int
#define ill inline ll

template <typename S, typename T>
inline bool smin(S &l, T r) {
  return r < l ? l = r, 1 : 0;
}
template <typename S, typename T>
inline bool smax(S &l, T r) {
  return l < r ? l = r, 1 : 0;
}

constexpr int MOD = 998244353;

template <typename S>
inline S mod(S &l) {
  return l = (l % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}
ill po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

void fileIO(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

constexpr int N = 5e5 + 10;

int n, k;
ll res, f[N << 1];

iv input() { cin >> n >> k; }

iv init() {
  f[0] = 1;
  rep(i, 1, N << 1) add(f[i], f[i - 1] * i);
}

ill ente(int x, int y) {
  return f[x + y] * po(f[x] * f[y] % MOD, MOD - 2) % MOD;
}

ill catalan(int x, int y, int l) {
  if (l <= 0) return 0;
  ll local = ente(x, y);
  if (y - l >= 0) add(local, -ente(x + l, y - l));
  return local;
}

iv faze_0() {
  rep(R, 0, k + 1) {
    int B = k - R;
    if (max(n, B) > R) continue;
    if (B == R)
      add(res, catalan(R, B - 1, B - n + 1));
    else
      add(res, catalan(R, B, R - n + 1));
  }
}

int main() {
#ifndef LOCAL
  // fileIO("");
#endif

  input();

  init();

  faze_0();

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 8064
import java.util.*;

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

    public static void main(String[]$) {
        long a = scanner.nextLong() - 1;
        long b = scanner.nextLong();
        long x = scanner.nextLong();
        System.out.println(a == -1 ? b / x + 1 : b / x - a / x);
    }
}

Measured memory_bytes: 23124
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();

        string S = cin.nextString();
        string T = cin.nextString();

        int[] s = getNum(S);
        int[] t = getNum(T);

        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] != t[i])
            {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }

    int[] getNum(string S)
    {
        int N = S.Length;
        int[] s = new int[N];
        var d1 = new Dictionary<int, int>();
        int cur = 0;
        for (int i = 0; i < N; i++)
        {
            if (d1.ContainsKey(S[i]))
            {
                s[i] = d1[S[i]];
            }
            else
            {
                d1.Add(S[i], cur);
                s[i] = cur;
                cur++;
            }
        }

        return s;
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 17888
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    X=list(zip(A,B))
    X.sort(lambda x:x[1])
    B.sort()

    C=[(x[0],i) for i,x in enumerate(X)]
    C.sort()
    A=[C[i][0] for i in range(n)]
    perm=[C[i][1] for i in range(n)]

    # A <= B を満たしていなければ不可能
    if(any(A[i]>B[i] for i in range(n))):
        print("No")
        return

    # 自由度が1つあれば可能
    if(any(A[i+1]<=B[i] for i in range(n-1))):
        print("Yes")
        return

    # permのYoung図が[n]かどうかで判断
    cnt=0
    visited=[0]*n
    def dfs(v)->int:
        if(visited[v]): return 0
        visited[v]=1
        stack=[v]
        cnt=0
        while(stack):
            cnt+=1
            v=stack.pop()
            nv=perm[v]
            if(visited[nv]):break
            visited[nv]=1
            stack.append(nv)
        return cnt

    if(dfs(0)==n):
        print("No")
    else:
        print("Yes")

resolve()

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

int main() 
{
  string A, B, C;
  cin >> A >> B >> C;
  int a = A.size(), b = B.size(), c = C.size();
  
  string ans;
  if (A.at(a - 1) == B.at(0) && B.at(b - 1) == C.at(0)) ans = "YES";
  else ans = "NO";
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[][][] xy = new int[N][][];
            for (int i = 0; i < N; i++) {
                int A = in.nextInt();
                xy[i] = new int[A][2];
                for (int j = 0; j < A; j++) {
                    xy[i][j][0] = in.nextInt();
                    xy[i][j][1] = in.nextInt();
                }
            }
            int ans = 0;
            for (int mask = 0; mask < (1 << N); mask++) {
                if (check(mask, xy)) {
                    int sum = 0;
                    for (int i = 0; i < 15; i++) {
                        if ((mask & (1 << i)) > 0) {
                            sum++;
                        }
                    }
                    ans = Math.max(sum, ans);
                }
            }
            out.println(ans);
        }

        boolean check(int mask, int[][][] xy) {
            boolean[] t_true = new boolean[xy.length];
            for (int id = 0; id < xy.length; id++) {
                t_true[id] = ((mask & (1 << id)) > 0);
            }
            for (int id = 0; id < xy.length; id++) {
                if ((mask & (1 << id)) > 0) {
                    for (int[] test : xy[id]) {
                        if (t_true[test[0] - 1]) {
                            if (test[1] == 0) return false;
                        } else {
                            if (test[1] == 1) return false;
                        }
                    }
                }
            }
            return true;
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21588
str_line = [i for i in input()]
a_place = []
z_place = []
result1 = 0
result2 = 10000000
for i, stri in enumerate(str_line):
    if stri == "A":
        a_place.append(i)  
for i, stri in enumerate(str_line):
    if stri == "Z":
        z_place.append(i)   
for i in z_place:
    if i >= result1:
        result1 = i
for i in a_place:
    if i <= result2:
        result2 = i
print(result1 - result2 + 1)        

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

DIVIDER = 1000000007

memo = [{} for _ in range(N + 1)]

tab_pow4 = [1]
tab_tmp = 1
for i in range(N):
    tab_tmp *= 4
    tab_pow4.append(tab_tmp)

def dp(Nlen, end):
    if Nlen < len(end):
        return 0
    elif memo[Nlen].setdefault(end, None) != None:
        return memo[Nlen][end]
    #
    if end in ('AGC', 'GAC', 'ACG'):
        ret = 0
    elif Nlen == len(end):
        ret = 1
    else:
        ret = 0
        if end not in ('AGC', 'TGC', 'CGC', 'GGC', 'GAC', 'GTC', 'GCC', 'GGC'):
            ret = (ret + dp(Nlen - 1, 'A' + end[:2])) % DIVIDER
        ret = (ret + dp(Nlen - 1, 'C' + end[:2])) % DIVIDER
        ret = (ret + dp(Nlen - 1, 'G' + end[:2])) % DIVIDER
        ret = (ret + dp(Nlen - 1, 'T' + end[:2])) % DIVIDER
    #
    memo[Nlen][end] = ret
    return ret

import itertools

ans = 0
for end in itertools.product('ACGT', repeat=3):
    if end in ('AGC', 'CAG', 'ACG'): continue
    ans = (ans + dp(N, ''.join(end))) % DIVIDER

# for i in range(N + 1):
#     print("#", memo[i], sum(memo[i].values()))
print(ans)

Measured memory_bytes: 3940
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define rep(i,n) for(int i = 0 ; i < n ; i++)

using namespace std;

int a[4];

int calc(int a,char c,int b){
  if(c == '+'){
    return a + b;
  } else if(c == '-'){
    return a - b;
  }
  return a * b;
}

bool t(int res){
  if(res == 10){
    return true;
  }
  return false;
}

string op = "+-*";

void solve(bool &found){
  bool check[3][3][3];
  memset(check,false,sizeof(check));

  rep(i,3) rep(j,3) rep(k,3){
	if(check[i][j][k]) continue;
	check[i][j][k] = true;

	if(t(calc(calc(a[0],op[i],calc(a[1],op[j],a[2])),op[k],a[3]))){
	  printf("((%d %c (%d %c %d)) %c %d)\n" 
		 ,a[0],op[i],a[1],op[j],a[2],op[k],a[3]);

	  found = true;
	  return;
	} 
	if(t(calc(calc(a[0],op[i],calc(a[1],op[j],a[2])),op[k],a[3]))){
	  printf("(%d %c (%d %c %d) %c %d)\n" 
		 ,a[0],op[i],a[1],op[j],a[2],op[k],a[3]);

	  found = true;
	  return;
	} 
	if(t(calc(calc(a[0],op[i],a[1]),op[j],calc(a[2],op[k],a[3])))){
	  printf("((%d %c %d) %c (%d %c %d))\n" 
		 ,a[0],op[i],a[1],op[j],a[2],op[k],a[3]);

	  found = true;
	  return;
	}
  }

}

int main(){
  while(true){
    rep(i,4){
      cin >> a[i]; 
    }

    if(a[0] == 0) break;
    sort(a,a+4);

    bool found = false;

    do{
      found = false;
      solve(found);
      if(found) break;
    } while(next_permutation(a,a+4));    

    if(!found){
      cout << "0" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int h[100005] = { 0 };
int main()
{
	char c,d;
	int n, q;
	cin >> n >> q;
	cin >> d;
	for (int i = 2; i <= n;i++) {
		cin >> c;
		if (c == 'C'&&d == 'A')h[i]++;
		h[i] += h[i - 1];
		d = c;
	}
	int a, b;
	for (int i = 1; i <= q; i++) {
		cin >> a >> b;
		cout << h[b]-h[a] << endl;
	}
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

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

int main(int argc, char **argv)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int p[3] = {a, b, c};
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2-i; ++j) {
            if (p[j] > p[j+1]) {
                swap(&p[j], &p[j+1]);
            }
        }
    }
    printf("%d\n", (p[0] + p[1]));
    return 0;
}

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

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

void selectionsort(int array[],int number){
    int cnt = 0;
    int min;
    for(int i = 0;i < number;i++){
        min = i;
        for(int j = i+1;j < number;j++){
            if(array[j] < array[min]){
                min = j;
            }
        }
        if(i != min){
            swap(array[i],array[min]);
            cnt++;
        }
    }
    for(int i = 0;i < number;i++){
        if(i != 0) printf(" ");
        printf("%d",array[i]);
    }
    printf("\n%d\n",cnt);
}

int main(){
    int num;
    int origin[100];
    cin >> num;
    for(int i = 0;i < num;i++) cin >> origin[i];
    selectionsort(origin,num);
    return 0;
}


Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
#include <map>
#define MAX 1010
#define INF 1e+5
using namespace std;

int Minimum_Cost_Sort(int A[], int n)
{
	int B[MAX], visited[MAX], x = INF, ans = 0;
	map<int, int> M;
	
	for (int i = 0;i < n;i++)
	{
		B[i] = A[i];
		visited[i] = false;
		x = min(x, A[i]);
	}
	
	sort(B, B+n);
	
	for (int i = 0;i < n;i++)
	{
		M[B[i]] = i;
	}
	
	for (int i = 0;i < n;i++)
	{
		int tmp = i;
		int circle_size = 0;
		int weight = 0;
		int mini = INF;
		
		do
		{
			visited[tmp] = true;
			weight += A[tmp];
			mini = min(mini, A[tmp]);
			tmp = M[A[tmp]];
			circle_size++;
		}while(!visited[tmp]);
		
		ans += min(weight + (circle_size-2) * mini, weight + (circle_size+1) * x + mini);
	}
	return ans;
}

int main ()
{
	int n, A[MAX];
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> A[i];
	}
	
	int mini_cost = Minimum_Cost_Sort(A, n);
	
	cout << mini_cost << endl;
	
	return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
int main() 
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        for(int i=0;i<s.size()-1;i++)
        {
            if(s[i]==s[i+1])
            {
                cout<<"Bad";
                return 0;
            }
        }
        cout<<"Good";
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

type Edge struct {
	from, to int
}

func main() {
	defer stdout.Flush()

	N := readInt()
	K := readInt()

	es := make([]Edge, 0, N*2)
	for i := 2; i <= N; i++ {
		es = append(es, Edge{1, i})
	}

	fs := make([]Edge, 0, N*2)
	for i := 2; i < N; i++ {
		for j := i + 1; j <= N; j++ {
			fs = append(fs, Edge{i, j})
		}
	}
	if len(fs) < K {
		println(-1)
		return
	}
	for i, j := 0, len(fs); K < j; i, j = i+1, j-1 {
		es = append(es, fs[i])
	}
	println(len(es))
	for _, e := range es {
		println(e.from, e.to)
	}
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 1408
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: usize,
        b: usize,
        xx: [usize; n],
    }

    let mut cost = 0;

    for i in 1..n {
        let dist = xx[i] - xx[i-1];
        if dist * a > b {
            cost += b;
        } else {
            cost += dist * a;
        }
    }

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


Measured memory_bytes: 3680
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define all(x) (x).begin(),(x).end()
#define V vector<int>
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

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


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

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



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s, t; cin >> s >> t;
	rep(i, s.size() + t.size()) {
		if (i % 2 == 0) {
			cout << s[i/2];
		}
		else {
			cout << t[i / 2];
		}
	}
	cout << endl;
	return 0;
}

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

li=[]

for i in range(0,n):
  s,p=input().split()
  p=int(p)
  li.append((i+1,s,p))


new_li=sorted(li,key=lambda x:x[2] , reverse=True)
new2_li=sorted(new_li,key=lambda x:x[1])


for j in range(0,n):
  print(new2_li[j][0])


Measured memory_bytes: 3060
//***Bismillahir Rahmanir Rahim***//
 
//*********************************//
//******Ashraful Haque Toni********//
//********Dept. of CSE,JnU*********//
//email:ashrafulhaquetoni@gmail.com//
//*******contact:01640690531*******//
//*********************************//
 
 
#include<bits/stdc++.h>
 
using namespace std;
 
#define         ash ios_base::sync_with_stdio(0);
#define         pb push_back
#define         sc(n) scanf("%d",&n);
#define         scl(n) scanf("%I64d",&n);
#define         sc2(m,n) scanf("%d %d",&m,&n);
#define         sc2l(m,n) scanf("%I64d %I64d ",&m,&n);
#define         pf printf
#define         Big(x,y) max(x,y);
#define         Small(x,y) min(x,y);
#define         input(array,size) for(int i=0;i<size;i++)cin>>array[i];
#define         newline pf("\n");
#define         f(s,l,in) for(ll i=s;i<l;i+=in)
#define         Max INT_MAX
#define         Min INT_MIN
#define         pi acos(-1.0)
#define         Memset(a,val) memset(a,val,sizeof(a));
 
typedef long long ll;
 
 
int main()
{
    ash;
    int s,c;
    sc2(s,c);
    
    c+=s*3;
    pf("%d\n",c/2);
 
 
 
 
    return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        s: Chars,
    }

    let mut abc: Vec<usize> = vec![0;3];
    for i in 0..s.len() {
        match s[i] {
            'a' => abc[0]+=1,
            'b' => abc[1]+=1,
            'c' => abc[2]+=1,
            _ => return,
        }
    }

    abc.sort();
    if abc[2]<=abc[0]+1 {
        println!("YES");
    } else {
        println!("NO");
    }

}


Measured memory_bytes: 2540
S=input()
Q=int(input())
x=0
A=[]
B=[]
for i in range(0,Q):
    query=list(input().split())
    if query[0]=='1':
        x+=1
    else:
        if query[1]=='1':
            if x%2==1:
                B.append(query[2])
            else:
                A.append(query[2])
        else:
            if x%2==1:
                A.append(query[2])
            else:
                B.append(query[2])

if x%2==1:
    B=[B[len(B)-1-i] for i in range(0,len(B))]
    S=[S[len(S)-1-i] for i in range(0,len(S))]
    a=''.join(A)
    b=''.join(B)
    S=''.join(S)
    print(b+S+a)
else:
    A=[A[len(A)-1-i] for i in range(0,len(A))]
    a=''.join(A)
    b=''.join(B)
    print(a+S+b)

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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 888
import java.util.*;

public class Main{
	public static void main(String[] args){
      	Scanner sc = new Scanner(System.in);
    	int n = Integer.parseInt(sc.next());
      	int[] list = new int[n];
      	int count = 0;
      	for(int cnt = 0;cnt < list.length;cnt++){
        	list[cnt] = Integer.parseInt(sc.next());
        }
      	for(int cnt = 0;cnt < list.length;cnt += 2){
        	if(list[cnt] % 2 != 0){
				count++;
            }
        }
      	System.out.println(count);
    }
}


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

int main()
{
long long int n;
cin>>n;
long long int arr[n],i,t=0,temp1,temp2;
for(i=0;i<n;i++)
{
    scanf("%lld",&arr[i]);
    
}
sort(arr,arr+n);
n--;
if(arr[n/2]==arr[n/2 +1])
t=0;
else
{temp1=arr[n/2];
temp2=arr[n/2 +1];
t=temp2-temp1;
}
cout<<t;
return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int>ii;
typedef vector<int>vi;
typedef pair<int,ii>iii;
const int N=1e5+5;
vector<ii>a,b;
map<ii,int>check;
vi pset,s;
bool cmp(ii a,ii b )
{
    return a.second<b.second;
}
void init(int n)
{
    pset.assign(n+1,-1);
    s.assign(n+1,1);
    for(int i=1;i<=n;i++){
        pset[i]=i;
    }
}
int findset(int i)
{
    if(pset[i]==i)return i;
    else return pset[i]=findset(pset[i]);
}
void unionset(int i,int j)
{
    int x=findset(i),y=findset(j);
    if(s[x]>s[y]){
        pset[y]=x;
        s[x]+=s[y];
    }
    else{
        pset[x]=y;
        s[y]+=s[x];
    }
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
    int n,cnt=0,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x,y;
        cin>>x>>y;
        if(check[ii(x,y)])continue;
        else{
            a.push_back(ii(x,y));
            b.push_back(ii(x,y));
            check[ii(x,y)]=++cnt;
        }
    }
    init(a.size()+1);
    sort(a.begin(),a.end());
    sort(b.begin(),b.end(),cmp);
    priority_queue<iii,vector<iii>,greater<iii> >q;
    //for(int i=1;i<=a.size();i++)cout<<pset[i]<<endl;
    for(int i=0;i<a.size()-1;i++){
        int x=a[i].first,y=a[i].second;
        q.push(iii(a[i+1].first-x,ii(check[a[i]],check[a[i+1]])));
    }
    for(int i=0;i<a.size()-1;i++){
        int x=b[i].first,y=b[i].second;
        q.push(iii(b[i+1].second-y,ii(check[b[i]],check[b[i+1]])));
    }
    while(!q.empty()){
        int c=q.top().first,u=q.top().second.first,v=q.top().second.second;
        q.pop();
        if(findset(u)!=findset(v)){
            ans+=c;
            unionset(u,v);
        }
    }
    cout<<ans;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

using P = Point<long double>;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);
	P p1, p2;
	cin >> p1.x >> p1.y >> p2.x >> p2.y;
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		P p;
		cin >> p.x >> p.y;
		P proj = p1 + (p2 - p1).unit() * (p - p1).dot((p2-p1).unit());
		cout << proj.x << " " << proj.y << '\n';
	}
}


Measured memory_bytes: 3260
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    char a,b;
    cin >> a;
    if (a=='A')b='T';
    if (a=='T')b='A';
    if (a=='C')b='G';
    if (a=='G')b='C';
    cout << b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <stdlib.h>

using namespace std;



int main(){
    vector<int>A;
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int req;
        cin >> req;
        if (req==0){
            int x;
            cin >> x;
            A.push_back(x);
        }else if(req==1){
            int p;
            cin >> p;
            cout << A[p] << endl;
        }else{
            A.pop_back();
        }
    }

}



Measured memory_bytes: 3936
#include<stdio.h>
#define MAX 2000000
#define K 10010

int A[MAX], B[MAX];

void CountingSort(int A[], int N, int B[]) {
	int C[K] = { 0 };
	for (int i = 0; i < N; i++) {
		C[A[i]]++;
	}
	for (int i = 1; i < K; i++) {
		C[i] += C[i - 1];
	}
	for (int i = N - 1; i >= 0; i--) {
		C[A[i]]--;
		B[C[A[i]]] = A[i];
	}

}

int main() {
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	CountingSort(A, N, B);
	for (int i = 0; i < N; i++) {
		if (i)printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 17404
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  int N,M,p;
  cin >> N >> M >> p;
  vector<pair<int,P>> E(M);
  for(int i=0; i<M; i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    c -= p;
    E[i] = pair<int,P>(c,P(a,b));
  }
  vector<vector<int>> G(N);
  for(int i=0; i<M; i++){
    G[E[i].second.second].emplace_back(E[i].second.first);
  }
  vector<bool> can(N,false);
  can[N-1] = true;
  queue<int> que;
  que.emplace(N-1);
  while(que.size()){
    int v = que.front();
    que.pop();
    for(int nv: G[v]){
      if(can[nv]) continue;
      can[nv] = true;
      que.emplace(nv);
    }
  }
  vector<ll> dist(N,-INF);
  vector<ll> one(N,-INF);
  dist[0] = 0;
  for(int i=0; i<2*N; i++){
    for(int e=0; e<M; e++){
      int cost = E[e].first;
      int v,nv;
      tie(v,nv) = E[e].second;
      if(dist[v] == -INF) continue;
      chmax(dist[nv],dist[v] + cost);
    }
    if(i == N-1){
      for(int j=0; j<N; j++){
        if(can[j]){
          one[j] = dist[j];
        }
      }
    }
  }
  bool fin = true;
  for(int i=0; i<N; i++){
    if(one[i] == -INF) continue;
    if(dist[i] != one[i]) fin = false;
  }
  if(!fin){
    cout << -1 << "\n";
  }else{
    cout << max(0LL,dist[N-1]) << "\n";
  }
  return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	
	string S;
	cin>>S;
	int n=S.size();
	int a=0,b=0;
	FDS(i,n){
		if(S[i]=='0'){
			a++;
		}
		if(S[i]=='1'){
			b++;
		}
	}
	int k=min(a,b);
	cout<<k*2<<endl;
}

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

int main(){
    int N, X;
    int L[N]; 
    int D[N+1];
	cin >> N >> X;
  	for(int i = 0; i <= N; i++){
    	cin >> L[i];
    }
  	int count = 0;
    D[0] = 0;
  	count++;
    for(int i = 1; i <= N; i++){
  		D[i] = D[i-1] + L[i-1];
        if(D[i] <= X) count++;
    }
    cout << count << endl;
}

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

bool isprime[300000];

void eratos(){
  
  for(int i=6 ; i < 300000 ; i++){
    if(isprime[i]){
      int x=i+i;
      while(x < 300000){
	isprime[x]=false;
	x+=i;
      }
    }
  }
  
}
int main(){
  
  int n;
  
  
  while(1){
    
    cin >>n;
    if(n==1)break;
    
    for(int i=0 ; i < 300000 ; i++)isprime[i]=false;
    
    int a=6;
    
    for(int i=1 ; a <= n ; i++){
      if(n%a == 0){
	isprime[a]=true;
      }
      if(i%2 == 1){
	a+=2;
      }else{
	a+=5;
      }
    }
    
    eratos();

    cout <<n<<":";
    for(int i=6 ; i < 300000 ; i++){
      if(isprime[i]){
	cout <<" "<<i;
      }
    }
    cout <<endl;    
    
  }
  
  return 0;
}

Measured memory_bytes: 1452
/*
 
                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 

signed main()
{
 
    fast;
     int a,b,c,k;
     cin >> a >> b >> c >> k;
     if(a+b>=k){
     	if(a>=k) cout<<k<<endl;
     	else
     	cout<<a<<endl;
     }
     else
     cout<<a-min(c,k-a-b)<<endl;;
    return 0;
}
 
/* Pooja Yadav */

Measured memory_bytes: 3612
#include<iostream>
#include<cmath>
using namespace std;
int dp[100005];
int h[100005];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>h[i];
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pa pair<int,int>
#define pb push_back
#define ms(x,y) memset(x,y,sizeof(x))
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mod 1000000007
#define N 100010
using namespace std;
inline ll read() {
	ll x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int n,a[N],t[N];
int main() {
	n=read();
	for (int i=1; i<=n; i++) a[i]=read(),t[a[i]-1]++,t[a[i]]++,t[a[i]+1]++;
	int ans=0;
	for (int i=0; i<=1e5+1; i++) ans=max(ans,t[i]);
	cout << ans << endl;
}

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

int main(){
  int n,k;
  cin >> n>>k;
  
  vector<int> h(n);
  
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  
  sort(h.begin(), h.end());
  
  long long sum = 0;
  
  for(int i=0; i<(int)h.size()-k; i++){
    sum += h[i];
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 1152
#define		_CRT_SECURE_NO_WARNINGS

#include <cstdio>

int main()
{
	int		a, b;
	int		d, r;
	double	f;

	scanf("%d %d", &a, &b);

	d = a / b;
	r = a % b;
	f = static_cast<double>(a) / b;


	printf("%d %d %0.5f\n", d, r, f);

	return 0;
}

Measured memory_bytes: 2732
n, x = gets.split(" ").map(&:to_i)
points = gets.split(" ").map(&:to_i)

if n == 1
    puts (x - points[0]).abs
    exit
end

d = []
for i in 0..n-1
  d << (x - points[i]).abs
end
puts d.inject{|a, b| a.gcd(b)}


Measured memory_bytes: 9348
def insertion_sort(a, n)
  for i in (1..n-1)
    v = a[i]
    j = i - 1
    while j >= 0 && a[j] > v
      a[j+1] = a[j]
      j -= 1
    end
    a[j+1] = v
    puts a.join(" ")
  end
end

n = gets.to_i
ary = gets.chomp.split(" ").map(&:to_i)
puts ary.join(" ")
insertion_sort(ary, n)

Measured memory_bytes: 8744
def babble_sort(A, N):
    cnt = 0
    flag = 1
    while flag:
      flag = 0
      i = 0
      for j in reversed(range(i + 1, N)):
        if A[j] < A[j-1]:
          c = A[j]
          A[j] = A[j -1]
          A[j-1] = c
          cnt += 1
          flag = 1
      i += 1
    for b in range(N):
      print(A[b], end=" \n"[b + 1 == N])
    print(cnt)


N = int(input())
A = list(map(int, input().split()))

babble_sort(A, N)


Measured memory_bytes: 5616