akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(' ')
	const int INF = 0x3f3f3f3f;
	typedef long long LL;
	typedef double DB;
	inline char gchar() {
		char ret = getchar();
		for(; (ret == '\n' || ret == '\r' || ret == ' ') && ret != EOF; ret = getchar());
		return ret; }
	template<class T> inline void fr(T &ret, char c = ' ', int flg = 1) {
		for(c = getchar(); (c < '0' || '9' < c) && c != '-'; c = getchar());
		if (c == '-') { flg = -1; c = getchar(); }
		for(ret = 0; '0' <= c && c <= '9'; c = getchar())
			ret = ret * 10 + c - '0';
		ret = ret * flg; }
	inline int fr() { int t; fr(t); return t; }
	template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
	template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
	template<class T> inline char wr(T a, int b = 10, bool p = 1) {
		return a < 0 ? pc('-'), wr(-a, b, 0) : (a == 0 ? (p ? pc('0') : p) : 
			(wr(a/b, b, 0), pc('0' + a % b)));
	}
	template<class T> inline void wt(T a) { wn(a); }
	template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
	template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
	template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
	template<class T> inline T gcd(T a, T b) {
		return b == 0 ? a : gcd(b, a % b); }
	template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
		for(; i; i >>= 1, b = b * b % _m)
			if(i & 1) r = r * b % _m;
		return r; }
};
using namespace my_header;

int a[555][555];

int main() {
#ifdef lol
	freopen("b.in", "r", stdin);
	freopen("b.out", "w", stdout);
#endif

	int n = fr(), c = n, t = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) {
			a[i][j] = gchar();
			if (a[i][j] == '#')
				t = 1;
		}
	if (!t) {
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= n; ++i) {
		int flg = true;
		for (int j = 1; j <= n; ++j) {
			if (a[j][i] == '.')
				flg = false;
		}
		c -= flg;
	}
	int ans = 2 * n;
	for (int i = 1; i <= n; ++i) {
		int x = 0;
		for (int j = 1; j <= n; ++j)
			if (a[i][j] == '.')
				++x;
		int flg = 1;
		for (int j = 1; j <= n; ++j)
			if (a[j][i] == '#')
				flg = 0;
		x += flg;
		ans = min(ans, x + c);
	}
	wt(ans);

	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
int main()
{
    int N;
    long long int c=0,i;
    scanf("%d",&N);
    if(N>=1&&N<=1000000)
    {
        for(i=0;i<=N;i++)
        {
            if(i%3!=0&&i%5!=0)
            {
                c=c+i;
            }
        }
        printf("%lld",c);
    }
}


Measured memory_bytes: 2064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            out.println(Math.max(0, A - B * 2));
        }

    }
}



Measured memory_bytes: 23124
eval"N,K="+`tr \\  ,`
I=r=s=1,1
2.upto([N,K+x=y=1].min){x=x*N*r%M=10**9+7
s+=x*y=y*r%M*N-=1
I<<r=M/_1*-I[M%_1]%M}
p s%M

Measured memory_bytes: 54976
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define Ans(s) cout << s << endl

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

typedef long long ll;
typedef vector<int> inv;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

int main()
{
	int n, k;
	cin >> n >> k;

	inv v(n);
	rep(i, n) cin >> v[i];

	int ans = 0;

	for(int l = 0; l <= k; l++)
	{
		for(int r = 0; r <= k - l; r++)
		{
			if (l + r > n) continue;

			int d = k - l - r;
			int score = 0;
			inv s;

			rep(i, l)
			{
				score += v[i];
				s.push_back(v[i]);
			}

			for (int i = n - r; i < n; i++)
			{
				score += v[i];
				s.push_back(v[i]);
			}

			sort(ASC(s));

			for (int i = 0; i < d; i++)
			{
				if (i >= s.size()) break;
				if (s[i] > 0) break;
				score -= s[i];
			}
			ans = max(ans, score);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
C = [list(map(int, input().split())) for i in range(3)]
A = []
B = []
for i in range(3):
  A.append([C[0][i] - C[1][i], C[1][i] - C[2][i], C[2][i] - C[0][i]])
for i in range(3):
  B.append([C[i][0] - C[i][1], C[i][1] - C[i][2], C[i][2] - C[i][0]])
ans = 'Yes'
if A[0] != A[1]:
  ans = 'No'
elif A[1] != A[2]:
  ans = 'No'
elif B[0] != B[1]:
  ans = 'No'
elif B[1] != B[2]:
  ans = 'No'
print(ans)

Measured memory_bytes: 3064
'use strict'

function main(s) {
  
  s = s.split('\n')[0].split(' ').map(n => Number(n));
  const A = s[0];
  const B = s[1];
  const C = s[2];

  const abc_sum = A + B + C;
  let same_sum = Math.max(...[A, B, C]) * 3;

  if (abc_sum % 2 !== same_sum % 2) same_sum += 3;

  const answer = (same_sum - abc_sum) / 2;
  console.log(answer);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
s = gets.chomp
if s.size.odd?
  s.slice!(-1)
elsif s.size == 2
  puts 1
  exit
else
  s.slice!(-2, 2)
end
until (s.scan(s.slice(0, s.size / 2)).size == 2)
  s.slice!(-2, 2)
end
puts s.size

Measured memory_bytes: 1916
#include <iostream>
#include <map>

using namespace std;



int main() {
    int n;
    string name;
    map<char, unsigned long long> mp;

    cin >> n;

    char cc[] = {'M', 'A', 'R', 'C', 'H'};

    mp['M'] = 0;
    mp['A'] = 0;
    mp['R'] = 0;
    mp['C'] = 0;
    mp['H'] = 0;

    for (int i = 0; i < n; i++) {
        cin >> name;

        if (name[0] == 'M' || name[0] == 'A' || name[0] == 'R' || name[0] == 'C' || name[0] == 'H') {
            mp[name[0]]++;
        }
    }

    unsigned long long sum = 0;

    for (int i = 0; i < 3; i++) {
        for (int j = i + 1; j < 4; j++) {
            for (int k = j + 1; k < 5; k++) {
                unsigned long long a = mp[cc[i]] * mp[cc[j]] * mp[cc[k]];
                sum += a;
            }
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int ans = 0;
		int start_with_B = 0;
		int end_with_A = 0;
		int B_any_A = 0;
		for(int i=0;i<n;i++) {
			String s = in.next();
			for(int j=0;j<s.length()-1;j++) {
				if(s.substring(j, j+2).equals("AB")) ans++;
			}
			if(s.charAt(0)=='B') start_with_B++;
			if(s.charAt(s.length()-1)=='A') end_with_A++;
			if(s.charAt(0)=='B' && s.charAt(s.length()-1)=='A') B_any_A++;
		}
		ans += Math.min(end_with_A, start_with_B);
		if(B_any_A!=0 && Math.max(end_with_A, start_with_B)==B_any_A) ans--;
		System.out.println(ans);
		in.close();
	}

}


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

using namespace std;

int main() {
    int n, x, maxi;
    
    scanf("%d", &n);

    long long resp = 0;
    for (int i=0; i<n; ++i) {
        scanf("%d", &x);
        if (i == 0) {
            maxi = x;
            continue;
        }

        if (x < maxi)
            resp += maxi-x;
        maxi = max(maxi, x);
    }

    printf("%lld\n", resp);

    return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int N;

void solve() {
    cin >> N;
    vector<P> G[N];
    for (int i = 0; i < N-1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--; w %= 2;
        G[u].push_back(P(v, w));
        G[v].push_back(P(u, w));
    }
    vector<int> C(N, 0);
    queue<int> q;
    q.push(0);
    vector<bool> memo(N, false);
    memo[0] = true;
    while(!q.empty()) {
        int n = q.front(); q.pop();
        for (P p : G[n]) {
            if (memo[p.first]) continue;
            memo[p.first] = true;
            int parentC = C[n];
            C[p.first] = p.second == 0 ? parentC : (parentC + 1) % 2;
            q.push(p.first);
        }
    }
    for (int i = 0; i < N; ++i) {
        cout << C[i] << endl;
    }
}

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


Measured memory_bytes: 6784
N,S = map(int,input().split())
MOD = 998244353
A = list(map(int,input().split()))
dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
	a = A[i-1]
	for j in range(0, S+1):
		if a > j:
			dp[i][j] = 2*dp[i-1][j] % MOD
		else:
			dp[i][j] = (2*dp[i-1][j] + dp[i-1][j-a]) % MOD
print(dp[N][S])

Measured memory_bytes: 147012
import java.util.Scanner;

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

      int a = scan.nextInt();
      int b = scan.nextInt();

      if(a < b){
        System.out.println("a < b");
      }else if(a > b){
        System.out.println("a > b");
      }else{
        System.out.println("a == b");
      }
  }
}

Measured memory_bytes: 25932
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    const char White = '.';
    const char Black = '#';

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ab = new Dictionary<int, List<int>>();
        var cc = new Dictionary<int, int>[n];

        for (int i = 0; i < n; i++) {
            ab[i] = new List<int>();
            cc[i] = new Dictionary<int, int>();
        }

        for (int i = 0; i < n - 1; i++) {
            var spl = input.ReadLine().Split(' ');
            var a = int.Parse(spl[0]) - 1;
            var b = int.Parse(spl[1]) - 1;
            var c = int.Parse(spl[2]);

            ab[a].Add(b);
            ab[b].Add(a);

            cc[Math.Min(a, b)][Math.Max(a, b)] = c;
        }

        var splx = input.ReadLine().Split(' ');
        var q = int.Parse(splx[0]);
        var k = int.Parse(splx[1]) - 1;

        var box = new long[n];
        Search(n, ab, cc, k, -1, box);

        var sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            var spl = input.ReadLine().Split(' ');
            var x = int.Parse(spl[0]) - 1;
            var y = int.Parse(spl[1]) - 1;

            sb.AppendLine((box[x] + box[y]).ToString());
        }

        return sb;
    }

    static void Search(int n, Dictionary<int, List<int>> ab, Dictionary<int, int>[] cc, int p, int from, long[] box) {
        //Debug.WriteLine(x);

        if (from != -1) {
            box[p] = box[from] + cc[Math.Min(from, p)][Math.Max(from,p)];
        }

        //次の再帰
        foreach (var to in ab[p]) {
            if (to == from) continue;
            Search(n, ab, cc, to, p, box);
        }
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 97188
#include <iostream>
#include <algorithm>
using namespace std;
int n, k, a;
int tot = 0;
int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		tot += 2 * (min(k - a, a));
	}
	cout << tot << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
    string s,ans;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]!='B')ans.push_back(s[i]);
        else if(s[i]=='B'&&ans.size()!=0) ans.pop_back();
    }
    cout<<ans<<endl;
    return 0;
}


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

signed main() {
  int N, A ,B;
  cin >> N >> A >> B;
  int X = 0;
  
  for (int i = 1; i <= N; i++){
    int sum = 0;
    int j = i;
    while(j > 0){
      sum += j % 10;
      j /= 10;
    }
    if(A <= sum && sum <= B){
      X += i;
    }
  }
  cout << X << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int N, X, Y;
	cin >> N >> X >> Y;
	--X, --Y;
	vector<vector<int>> vi(N, vector<int>(N, -1));

	for (int st = 0; st < N; ++st)
	{
		int len = 0;
		queue<int> que;
		que.push(st);
		vi[st][st] = 0;

		while (!que.empty())
		{
			vector<int> nd;
			int c = que.front(); que.pop();

			// 次の行き先
			if (c > 0) nd.push_back(c - 1);
			if (c < (N-1)) nd.push_back(c + 1);
			if (c == X) nd.push_back(Y);
			if (c == Y) nd.push_back(X);

			// 行先に応じて探索
			for (auto nc : nd)
			{
				if (vi[st][nc] == -1)
				{
					vi[st][nc] = vi[st][c] + 1;
					que.push(nc);
				}
			}
		}
	}

	// 結果を数える
	vector<int> rec(N, 0);
	for (int i = 0; i < N; ++i)
	{
		for (int j = i + 1; j < N; ++j)
		{
				rec[vi[i][j]] += 1;
		}
	}

	for (int i = 1; i < N; ++i)
	{
		cout << rec[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 19004
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#include<iterator>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


struct v_t
{
	int p;
	vi c;
};


using vvt=vector<v_t>;


void vmove(vvt&v, int a, int b)
{
	for(int mbc:v[b].c)
	{
		v[mbc].p=a;
	}
	copy(v[b].c.begin(), v[b].c.end(), back_inserter(v[a].c));
	v[b].c.clear();
}


ll uni(vvt&v, ll ans, int n, int a, int b)
{
	ll ret=ans;

	if(v[a].p==v[b].p) return ret;

	int ap=v[a].p;
	int bp=v[b].p;
	ll an=v[ap].c.size();
	ll bn=v[bp].c.size();

	if(an>bn)
	{
		vmove(v, ap, bp);
	}
	else
	{
		vmove(v, bp, ap);
	}
	ret-=an*(n-an)+bn*(n-bn);
	ret+=(an+bn)*(n-(an+bn));
	return ret;
}


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vi a(m), b(m);
		vector<v_t> v(n+1);
		vll ans(m+1);

		for(int i=1;i<=n;i++)
		{
			v[i].p=i;
			v[i].c.push_back(i);
		}

		for(int i=0;i<m;i++)
		{
			scanf("%d%d", &a[i], &b[i]);
		}

		ans[m]=(ll)n*(n-1);
		for(int i=m-1;i>=0;i--)
		{
			ans[i]=ans[i+1];
			ans[i]=uni(v, ans[i+1], n, a[i], b[i]);
		}
		for(int i=1;i<=m;i++)
		{
			printf("%lld\n", ans[i]/2);
		}
	}

	return 0;
}


Measured memory_bytes: 12920
#include<bits/stdc++.h>
using namespace std;
char a[1000001],s[1000001];
int main()
{
    int b,sum=0,l=0;
    cin>>a;
    b=strlen(a);
    for(int i=b-1;i>=0;i--) 
	{
        s[sum]=a[i];
        if(s[sum]=='b') s[sum]='d';
        else if(s[sum]=='d') s[sum]='b';
        else if(s[sum]=='p') s[sum]='q';
        else if(s[sum]=='q') s[sum]='p';
        sum++;
    }
    for(int i=0;i<=b-1;i++) 
	{
        if(a[i]!=s[i])
		{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 384
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

int licznik[100005];

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	string s;
	cin >> s;
	for(int i = 0; i < 3; i++){
		licznik[(int)s[i]]++;
	}
	
	char a = 'a';
	char b = 'b';
	char c = 'c';
	
	if(licznik[(int)a] == 1 && licznik[(int)b] == 1 && licznik[(int)c] == 1){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;









	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;

const int INF = 1LL << 40;
const int N = 101;
const int M = 100001;
int dp[M];
int w[N], v[N];
 
signed main() {
 
    int n, c; cin >> n >> c;
    for(int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    
    for(int i = 0; i < M; i++) dp[i] = INF;
    dp[0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = M - 1; j >= v[i]; j--) {
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    
    int ans = 0;
    for(int i = 0; i < M; i++)
        if(dp[i] <= c)
            ans = i;
    
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n,m;
  	cin >> n >> m;
  	vector<int> a(n);
  	double sum = 0;
  	for(int i=0;i<n;i++){
    	cin >> a.at(i);
      	sum += a.at(i);
    }
  	double min = sum / (4*m);
  	sort(a.begin(),a.end());
  	reverse(a.begin(),a.end());
  	bool e = true;
  	for(int i=0;i<m;i++){
    	if(a.at(i) < min){
        	e = false;
          	break;
        }
    }
      if(e==true) cout << "Yes" << endl;
      else cout << "No" << endl;
 
    
}

Measured memory_bytes: 3596
<?php
fscanf(STDIN, "%d", $n);

$format = '';
for ($i = 0; $i < $n; $i++) {
    if ($i > 0) {
        $format .= ' ';
    }
    $format .= '%d';
}

$nums = fscanf(STDIN, $format);
insertionSort($nums, $n);

function insertionSort($A, $N)
{
    for ($i = 0; $i < $N; $i++) {
        $val = $A[$i];
        $j = $i - 1;

        while ($j >= 0 && $A[$j] > $val) {
            $A[$j+1] = $A[$j];
            $j--;
        }
        $A[$j+1] = $val;

        echo join(' ', $A)."\n";
    }

    return $A;
}

Measured memory_bytes: 6628
#include <cstdio>
#include <functional>
#include <vector>
#include <algorithm>

int testcase_ends() {
  int w, h;
  scanf("%d %d", &w, &h);
  if (w == 0 && h == 0)
    return 1;

  int xs, ys;
  scanf("%d %d", &xs, &ys);

  int xg, yg;
  scanf("%d %d", &xg, &yg);

  std::vector<std::vector<int>> g(h+2, std::vector<int>(w+2));

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

  for (int i=0; i<n; ++i) {
    int c, d, x, y;
    scanf("%d %d %d %d", &c, &d, &x, &y);

    int dh=2, dw=2;
    (d? dh:dw) += 2;

    for (int j=0; j<dh; ++j)
      for (int k=0; k<dw; ++k)
	g[y+j][x+k] = c;
  }

  // for (int i=0; i<h; ++i)
  //   for (int j=0; j<w; ++j)
  //     fprintf(stderr, "%d%c", g[i][j], j+1<w? ' ':'\n');

  if (g[ys][xs] != g[yg][xg])
    return !printf("NG\n");

  const int dy[]={-1, 0, 1, 0};
  const int dx[]={0, -1, 0, 1};
  std::function<bool (int, int)> dfs=[&](int x, int y) {
    if (x == xg && y == yg) return true;

    int cs=g[y][x];
    g[y][x] = -cs;  // mark visited
    for (int k=0; k<4; ++k) {
      int cd=g[y+dy[k]][x+dx[k]];
      if (cs == cd && dfs(x+dx[k], y+dy[k]))
	return true;
    }
    return false;
  };

  printf("%s\n", dfs(xs, ys)? "OK":"NG");
  return 0;
}      

int main() {
  while (!testcase_ends()) {}
}



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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string ans;
  auto move = [&](int h, int w) {
    rep(i, abs(h)) ans += (h > 0 ? 'U' : 'D');
    rep(i, abs(w)) ans += (w > 0 ? 'R' : 'L');
  };

  int h1 = ty - sy, w1 = tx - sx;
  move(h1, w1);

  int h2 = sy - ty, w2 = sx - tx;
  move(h2, w2);

  int h3 = ty - sy, w3 = tx - sx;
  ans += (w3 > 0 ? 'L' : 'R');
  h3 += (h3 > 0 ? 1 : -1);
  w3 += (w3 > 0 ? 1 : -1);
  move(h3, w3);
  ans += (h3 > 0 ? 'D' : 'U');

  int h4 = sy - ty, w4 = sx - tx;
  ans += (w4 > 0 ? 'L' : 'R');
  h4 += (h4 > 0 ? 1 : -1);
  w4 += (w4 > 0 ? 1 : -1);
  move(h4, w4);
  ans += (h4 > 0 ? 'D' : 'U');

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


Measured memory_bytes: 3580
#include<stdio.h>
#include<stdlib.h>
typedef long long int ll;
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int main(){
    static int n,a[200000];
    int flg=0;

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

    for(int i=0;i<n;i++){
        if(a[i]!=0){
            flg=1;
            break;
        }
    }

    if(!flg){
        printf("Yes\n");
        return 0;
    }
    qsort(a,n,sizeof(int),asc);

    if(n%3!=0){
        printf("No\n");
        return 0;
    }

    
    if(a[0]!=a[n/3-1]||a[n/3]!=a[2*n/3-1]||a[2*n/3]!=a[n-1]){
        printf("No\n");
        return 0;
    }

    if((a[0]^a[2*n/3])==a[n/3]){
        printf("Yes\n");
        return 0;
    }
    printf("No\n");




    return 0;

}

Measured memory_bytes: 892
n=int(input())
l=[]
for i in range(1,201):
    if i%2==0:
        l.append(0)
        continue
    c=0
    for j in range(1,i+1):
        if i%j==0:
            c+=1
    if c==8:
        l.append(1)
    else:
        l.append(0)
print(sum(l[:n]))


Measured memory_bytes: 2940
N, K = map(int, input().split())

D = list(map(str, input().split()))

while True:
    n = str(N)
    nn = str(N)

    for o in nn:
        if o in D:
            N += 1
            nn = str(N)
            break

    if n == nn:
        break

print(N)

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


typedef long long ll;
typedef double db;
int main(){
	char a[200005] , b[200005];
	scanf("%s %s",a,b);
	int book[26];
	int len = strlen(a);
	memset(book,0,sizeof(book));
	for(int i = 0 ; i < len ; i ++){
		if(a[i] == b[i]) {
			book[a[i]-'a'] = 1;
			continue;
		}
		else{
			if(book[a[i]-'a'] != 1){
				// book[b[i]-'a'] = 1;
				char ta = a[i],tb = b[i];
				for(int j = 0 ; j < len ; j ++){
					if(a[j] == ta) {
						if(j < i){
							printf("No");return 0;
						}
						a[j] = tb;
					}
					else if(a[j] == tb){
						if(j < i){
							printf("No");return 0;
						}
						a[j] = ta;
					} 
				}
				book[a[i]-'a'] = 1;
				// cout << a << " " << b << endl;
				// for(int j = 0 ; j < 26 ; j ++){
				// 	cout << book[j] << " ";
				// }
				// cout << endl;
			}
		}
	}
	if(!(strcmp(a,b))){
		printf("Yes");
	}else{
		printf("No");
	}
	












	return 0;
}

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

int main() {
  int a;
  cin>>a;
  int b=a%10;
  a/=10;
  int c=a%10;
  a/=10;
  int d=a%10;
  a/=10;
  int e=a%10;
  if(c==d){
    if(b==c||d==e)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */
// const int NIL = -1;
const int INF = 1 << 30;
const int MAX = 500000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
struct Node {
    Node *parent, 
         *left, 
         *right;
    int key;
};

Node *root, *NIL;

/* function */
void insert(int z);
void preorder(Node* v);
void inorder(Node* v);

/* main */
int main(){

    // main
    int n, key;
    cin >> n;
    string man;
    for (int i = 0; i < n; i++) {
        cin >> man;
        if (man == "print") {
            inorder(root); cout << '\n';
            preorder(root); cout << '\n';
        }
        else {
            cin >> key;
            insert(key);
        }
    }

}

void insert(int key) {

    // init new node
    // Node *z = (Node *)malloc(sizeof(Node));
    Node *z = new Node();
    z->left = NIL;
    z->right = NIL;
    z->parent = NIL;

    Node *y = NIL;  // parent of x(root)
    Node *x = root; // root of 'T'

    while (x != NIL) {
        y = x;  // set parent
        if (key < x->key) {
            x = x->left;
        }
        else {
            x = x->right;
        }
    }

    z->parent = y;
    z->key = key;

    if (y == NIL) {  // 'T' is empty
        root = z;
    }
    else if (key < y->key) {
        y->left = z;  // z is y's left
    }
    else if (key >= y->key) {
        y->right = z;  // z is y's right
    }
}

void preorder(Node* v) {
    cout << ' ' << v->key;
    if (v->left != NIL) 
        preorder(v->left);
    if (v->right != NIL) 
        preorder(v->right);

}

void inorder(Node* v) {
    if (v->left != NIL) 
        inorder(v->left);
    cout << ' ' << v->key;
    if (v->right != NIL) 
        inorder(v->right);

}



Measured memory_bytes: 26644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,a,b;
  cin>>k>>a>>b;
  if((b-a)>=(k-1)){
    cout<<"OK"<<endl;
  }else if(b%k<a%k||b%k==0||a%k==0){
    cout<<"OK"<<endl;
  }else{
    cout<<"NG"<<endl;
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ll Q, H, S, W, N;
  cin >> Q >> H >> S >> W >> N;
  chmin(H, Q*2);
  chmin(S, H*2);
  chmin(W, S*2);
  if (N%2)
    cout << N/2*W+S << endl;
  else
    cout << N/2*W << endl;
  return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    auto xs = readints;

    auto deque = Deque!int(n);
    for (int i = 0; i < xs.length; i++) {
        if ((i & 1) == (n & 1)) {
            deque.insertBack(xs[i]);
        }
        else {
            deque.insertFront(xs[i]);
        }
    }

    for (int i = 0; i < n; i++) {
        if (i > 0) write(' ');
        write(deque[i]);
    }
    writeln();
}

struct Deque(T) {
    private T[] _buffer;
    private int _front;
    private int _back;

    this(int size) {
        _buffer = new int[size * 3];
        _front = _back = (size * 3) / 2;
    }

    bool empty() @property { return  _front == _back; }
    int length() @property { return _back - _front; }

    void insertFront(T value) {
        if (empty) {
            _buffer[_front] = value;
            _back++;
            return;
        }

        _buffer[--_front] = value;
    }

    void insertBack(T value) {
        if (empty) {
            _buffer[_front] = value;
            _back++;
            return;
        }

        _buffer[_back++] = value;
    }

    void removeFront() {
        assert(!empty);
        ++_front;
    }

    void removeBack() {
        assert(!empty);
        --_back;
    }

    T opIndex(int index) {
        return _buffer[_front + index];
    }
}


Measured memory_bytes: 13552
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var m = int.Parse(line[0]);
            var n = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var a = new int[n];
            for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
            Console.WriteLine(m >= n ? a.Max() : getAns(a, m));
        }
    }
    static int getAns(int[] a, int m)
    {
        var ng = 1; var ok = 100000000;
        while (ok - ng > 1)
        {
            var mid = ng + (ok - ng) / 2;
            if (check(a, m, mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
    static bool check(int[] a, int m, int t)
    {
        var aL = a.Length;
        var mcount = 1;
        int bcount = 0;
        var p = 0;
        while (p < aL)
        {
            bcount += a[p];
            if (bcount > t)
            {
                mcount++;
                bcount = a[p];
                if (mcount > m | bcount > t) return false;
            }
            p++;
        }
        return true;
    }
}




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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X, Y;
  cin >> X >> Y;
  if (X % Y == 0) {
    cout << -1 << '\n';
  } else {
    cout << X << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  DV(dp,lli,1010,(1<<N)+10,INF);//dp[i][j]:=i個目の鍵まで見たとき，箱{集合j}が開いているような鍵の買い方の値段の最小値
  Vec(key,pint,M,pint(0,0));//値段,その鍵で開く箱の集合
  rep(i,0,M){
    cin >> key[i].first >> A;
    while(A--){
      cin >> B;
      B--;
      key[i].second+=(1<<B);
    }
  }
  dp[0][0]=0;
  rep(i,0,M)rep(j,0,1<<N){
    if(i>0)chmin(dp[i][j],dp[i-1][j]);
    chmin(dp[i][j|key[i].second],dp[i][j]+key[i].first);//j|key[i].second 集合jと集合key[i].secondの和集合
  }
  if(dp[M-1][(1<<N)-1]==INF)Out(-1);
  else Out(dp[M-1][(1<<N)-1]);
}


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

ans = n//100

if ans <= 5:
    print(8)
    exit()
elif ans >= 6 and ans <= 7:
    print(7)
    exit()
elif ans >= 8 and ans <= 9:
    print(6)
    exit()
elif ans >= 10 and ans <= 11:
    print(5)
    exit()
elif ans >= 12 and ans <= 13:
    print(4)
    exit()
elif ans >= 14 and ans <= 15:
    print(3)
    exit()
elif ans >= 16 and ans <= 17:
    print(2)
    exit()
elif ans >= 18 and ans <= 19:
    print(1)
    exit()


Measured memory_bytes: 9200
import sys
sys.setrecursionlimit(10**9)

def BF(edges,n,s):
    inf=float("inf")
    d=[inf for i in range(n+1)]
    d[s]=0
    update=True
    for i in range(n+1):
      update=False
      for v,u,cost in edges:
        if cand[v]!=1 or cand[u]!=1:
          continue
        if d[v]!=inf and d[u]>d[v]+cost:
          d[u]=d[v]+cost
          update=True
      if update==False:
        break
      if i==n:
        return inf
    return -d[-1]

def DFS_1toN(v):
  for u in to[v]:
    if toflag[u]==0:
      toflag[u]=1
      DFS_1toN(u)
      
def DFS_Nto1(v):
  for u in ot[v]:
    if otflag[u]==0:
      otflag[u]=1
      DFS_Nto1(u)
    
n,m=map(int,input().split())
g=[]
to=[[] for _ in range(n+1)]
ot=[[] for _ in range(n+1)]
for _ in range(m):
  a,b,c=map(int,input().split())
  g.append([a,b,-c])
  to[a].append(b)
  ot[b].append(a)
toflag=[0]*(n+1)
toflag[1]=1
DFS_1toN(1)
otflag=[0]*(n+1)
otflag[n]=1
DFS_Nto1(n)
cand=[0]*(n+1)
for i in range(1,n+1):
  cand[i]=toflag[i]*otflag[i]
ans=BF(g,n,1)
if ans==float('inf'):
  print('inf')
else:
  print(ans)

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

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

			String in = br.readLine();
			String chr[] = in.split(" ");
			int x = Integer.parseInt(chr[0]);
			int a = Integer.parseInt(chr[1]);

			 System.out.println(x<a?0:10);
		}
	}
}

Measured memory_bytes: 25344
// Chain matrix multiplication (DP)

#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;

  int a, b;
  vector<int> A, B;
  while (cin >> a >> b) {
    A.push_back(a);
    B.push_back(b);
  }

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

  // len=0 => cost = 0, the default value
  for (int len = 1; len < n; ++len) {
    for (int i = 0; i < n - len; ++i) {
      int j = i + len;
      int best = numeric_limits<int>::max();
      for (int k = i; k < j; ++k) {
        best = min(best, cost[i][k] + cost[k + 1][j] + A[i] * B[k] * B[j]);
      }
      cost[i][j] = best;
    }
  }

  cout << cost[0][n - 1] << endl;
}


Measured memory_bytes: 3156
#include <cstdio>

int main()
{
  int x,y;
  scanf("%d%d",&x,&y);
  int c=0;
  c+=(x==1?300000:x==2?200000:x==3?100000:0);
  c+=(y==1?300000:y==2?200000:y==3?100000:0);
  if(x==1&&y==1){
    c+=400000;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int gcd(int x,int y){
    return y ? gcd(y,x%y) : x;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<int> l(n);
    rep(i,0,n){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int res = 0;
    rep(i,0,n){
        rep(j,i+1,n){
            rep(k,j+1,n){
                if(l[k] < l[i]+l[j])res++;
            }
        }
    } /*
    rep(i,0,n){
        i = 0;
        int t=i+1;
        if(t == n)break;
        bool flag=false;
        rep(j,i+2,n){
            if(i==n-1)goto end;
            if(i==j)break;
            if(t==j){
                i++;
                t=i+1;
                continue;
            }
            cout<<l[i]<<" "<<l[t]<<" "<<l[j]<<endl;            
            if(l[i]+l[t] > l[j]){
                res++;
                //printf("l[%d]=%d,l[%d]=%d,l[%d]=%d\n",i,l[i],t,l[t],j,l[j]);
            }else{
                t++;
                j--;
            }
        }
    } */
    end:
    /*
    rep(i,2,n){
        if(l[i] < l[i-1]+l[i-2]){
            int k=1;
            for(int t=i;t >= i-2;t--){
                if(t==0)break;
                k *= t;
            }
            cout << k << endl;
            res += k/2;
        }
    } */
    cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int max(int a, int b)
{
	return (a > b) ? a : b;
}

int main()
{
	long long int A, B, N;
	scanf("%lld%lld%lld", &A, &B, &N);

	long long int ans = 0;
	if (N < B) {
		ans = (A * N) / B - A * (N / B);
	}
	else {
		ans = (A * (B - 1)) / B - A * ((B - 1) / B);
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 1728
A, B = map(int,input().split())
S = input()
r = 'Yes'
for i in range(len(S)):
  if i == A:
    jo = ['-']
  else:
    jo = ['0','1','2','3','4','5','6','7','8','9']
  
  if not S[i] in jo:
    r = 'No'
    break
print(r)
    

Measured memory_bytes: 9136
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

// n個の寿司があり, i個目の種類はt_i, 美味しさはd_iである
// この中からk個選び, 美味しさd_iの挿話とt_iの種類数の2乗の話を最大化したい
// 最大値を求めよ

// 選ぶ種類数をcとすると,
// c個選び, 残りをその種類の中でk-c個選んだ時が最適である
// cは1..(種類数の最大値)のforループ(高々O(N))
// 残りの要素は, 大きい方からk-c個選べば良い
// (大きい要素じゅんに並べるpriority_queueが有効)

signed main() {
  INIT;
	VAR(int,n,k);
	map< int,vector<int> > ds; 
	REP(i,n) {
		VAR(int,t,d);
	  ds[t].push_back(d);
	}

  // 種類ごとの最大値と, 種類ごとの残りの要素を別に保管
  vector<int> mxs, others;
	EACH(di,ds){
		vector<int> nums = di.second;
		sort(ALL(nums));
		reverse(ALL(nums));
		mxs.push_back(nums[0]);
		FOR(i,1,nums.size()) {
			others.push_back(nums[i]);
		}
	}

	sort(ALL(mxs));
	reverse(ALL(mxs));
	sort(ALL(others));
	reverse(ALL(others));
	EACH(mi,mxs){
		debug(mi);
	}
	EACH(oi, others){
		debug(oi);
	}

	vector<int> mxs_sm(n+1,0), others_sm(n+1,0);
	REP(i,mxs.size()){
		mxs_sm[i+1] = mxs_sm[i] + mxs[i];
	}
	REP(i,others.size()){
		others_sm[i+1] = others_sm[i] + others[i];
	}
	EACH(mi,mxs_sm){
		debug(mi);
	}
	EACH(oi, others_sm){
		debug(oi);
	}

	int c = min((int)ds.size(), k);
	debug(c);
	int ans = 0;
	FOR(i,1,c+1){
		int res = mxs_sm[i] + others_sm[k-i] + i*i;
		debug(mxs_sm[i]);
		debug(others_sm[k-1]);
		debug(i);
		debug(res);
		ans = max(ans,res);
	}
	OUT(ans)BR;
	
  return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    int A, B, C;
    ll X, Y;
    cin >> A >> B >> C >> X >> Y;

    if (A + B < C * 2) {
        cout << A * X + B * Y << endl;
        return 0;
    }

    ll ans = 0;

    const auto tmp_min = std::min(X, Y);
    ans += tmp_min * C * 2;
    X -= tmp_min;
    Y -= tmp_min;

    if (X == 0) {
        ans += B > C * 2 ? Y * C * 2 : Y * B;
    } else {
        ans += A > C * 2 ? X * C * 2 : X * A;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  map<int,int> mp;
  rep(i,N) {
    mp[A[i]]++;
  }
  int cnt = 0;
  for(auto x: mp) {
    int k = x.first;
    int c = x.second;
    if(c<k) {
      cnt += c;
    } else {
      cnt += c-k;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 5120
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))

m = max(A)
c = A.count(m)
if c == 1:
    m2 = sorted(set(A),reverse=True)[1]
    for i in A:
        print (m) if i != m else print(m2)
else:
    for _ in range(n):
        print (m)


Measured memory_bytes: 17188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = 0, y = 0, z = 0;
        for (int i = 0; i < n; i++) {
            int temp = sc.nextInt();
            if (temp <= a)
                x += 1;
            else if (temp <= b)
                y += 1;
            else
                z += 1;
        }

        System.out.println(Math.min(Math.min(x, y), z));
        sc.close();
    }
}

Measured memory_bytes: 36004
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;

int main(void){
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    
}

Measured memory_bytes: 3592
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
m = S // N
C = [
  sum((A[i] - m)**2 for i in range(N)), 
  sum((A[i] - m - 1)**2 for i in range(N)),
  sum((A[i] - m + 1)**2 for i in range(N))
]
print(min(C))

Measured memory_bytes: 3060
n = gets.chomp.to_i
list, zeros = n.times.map { gets.chomp.split(' ').map(&:to_i) }.partition { |nums| nums[2] != 0 }

targets = []

0.upto(100).each do |x|
  0.upto(100).each do |y|
    ch = -1
    result = list.all? do |nums|
      x1, y1, h1 = nums
      ch_tmp = h1 + (x1 - x).abs + (y1 - y).abs
      if ch == -1
        ch = ch_tmp
        true
      else
        ch == ch_tmp
      end
    end
    targets << [x, y, ch] if result
  end
end

if targets.size == 1
  x, y, h = targets[0]
  puts "#{x} #{y} #{h}"
  exit
end

answer = targets.find do |nums|
  x, y, h = nums
  zeros.all? do |zero_nums|
    x1, y1, _h = zero_nums
    (h - (x - x1).abs - (y - y1).abs) <= 0
  end
end
x, y, h = answer
puts "#{x} #{y} #{h}"


Measured memory_bytes: 2684
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const lint INF=1e18;
int n,m,S,T;
vector<pi> g1[100005],g2[100005];
lint dist1[100005],dist2[100005],dist3[100005];

const lint BASE=1000000000000000ll;

void ijk(vector<pi>* g,lint* dist,int source){
  REP(i,n) dist[i]=INF;
  dist[source]=0;
  priority_queue<pair<lint,int>,vector<pair<lint,int> >,greater<pair<lint,int> > >pq;
  pq.push({0,source});
  while(!pq.empty()){
    lint co=pq.top().fr;
    int v=pq.top().sc;
    pq.pop();
    for(auto e:g[v]){
      if(co+e.sc<dist[e.fr]){
        dist[e.fr]=co+e.sc;
        pq.push({dist[e.fr],e.fr});
      }
    }
  }
}
lint res[100005];
int main(){
  cin>>n>>m>>S>>T;
  --S;--T;
  REP(i,m){
    int u,v,a,b;
    scanf("%d%d%d%d",&u,&v,&a,&b);--u;--v;
    g1[u].pb({v,a});
    g1[v].pb({u,a});
    g2[u].pb({v,b});
    g2[v].pb({u,b});
  }

  ijk(g1,dist1,S);
  ijk(g2,dist2,T);

  REP(i,n){
    res[i]=dist1[i]+dist2[i];
  }
  res[n]=INF;
  for(int i=n-1;i>=0;--i) res[i]=min(res[i+1],res[i]);

  REP(i,n) printf("%lld\n",BASE-res[i]);
  return 0;
}





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

int main() {
  int m;
  cin >> m;
  ll sum, n;
  sum = 0; n = 0;
  rep(i, m) {
    ll d, c;
    cin >> d >> c;
    sum += d*c;
    n += c;
  }
  cout << n-1 + (sum-1)/9LL << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define ll long long

int cnt(int n){
    int c = 0;
    for(int i=1;i<=n;i++){
        if(n%i == 0){
            c++;
        }
    }
    return c;
}

int main(){

    int n; cin >> n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i%2 == 0) continue;
        if(cnt(i) == 8){
            //cout << i << endl;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256