akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <queue>
#include <utility>

using namespace std;

int main()
{
        int n;
        map < int, int >m1, m2;
        priority_queue < pair < int, int >>q1, q2;
        cin >> n;
        for (int i = 0; i < n; i++) {
                int buf;
                map < int, int >*p;
                if (i % 2 == 0) {
                        p = &m1;
                } else {
                        p = &m2;
                }
                cin >> buf;
                if (!p->insert( {
                               buf, 1}
                    ).second)
                        p->at(buf) = p->at(buf) + 1;
        }
 for (auto z:m1)
                q1.push(make_pair(z.second, z.first));
 for (auto z:m2)
                q2.push(make_pair(z.second, z.first));

        if (q1.top().second == q2.top().second) {
                pair < int, int >p1, p2;
                p1 = q1.top();
                p2 = q2.top();
                q2.pop();
                q1.pop();
                if (q1.top().first + p2.first > q2.top().first + p1.first)
                        q2.push(p2);
                else
                        q1.push(p1);
        }

        q2.push(make_pair(0, 0));
        q1.push(make_pair(0, 0));

        cout << n - q2.top().first - q1.top().first << endl;

        return 0;
}

Measured memory_bytes: 6136
#include<iostream>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;

    if(A == 1){
        A = 14;
    }
    if(B == 1){
        B = 14;
    }

    if(A == B){
        cout << "Draw" << endl;
        return 0;
    }
    else if(A > B){
        cout << "Alice" << endl;
        return 0;
    }
    else if(B > A){
        cout << "Bob" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local S = (read.l()):totable()
if S[3] == S[4] and S[5] == S[6] then
    print("Yes")
else
    print("No")
end

Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200010
ll a[N],b[N],c[N],d[N],e[N],f[N],n;
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[i]=c[i]=d[i]=e[i]=f[i]=1e17;
  }
  b[0]=0;
  for(int i=0;i<n;i++){
    ll xs,ys;
    if(a[i]==0)xs=2,ys=1;
    else if(a[i]%2==1)xs=1,ys=0;
    else xs=0,ys=1;
    b[i+1]=b[i]+a[i];
    c[i+1]=min(b[i],c[i])+xs;
    d[i+1]=min(min(b[i],c[i]),d[i])+ys;
    e[i+1]=min(d[i],e[i])+xs;
    f[i+1]=min(min(c[i],d[i]),min(e[i],f[i]))+a[i];
  }
  ll ans=min(min(b[n],c[n]),min(min(d[n],e[n]),f[n]));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9600
type t = { v : int; w : int }

let solve a n w =
  let dp = Array.make_matrix (n + 1) (w + 1) 0 in
  for i = 1 to n do
    for j = 1 to w do
      dp.(i).(j) <-
        if j - a.(i-1).w < 0 || dp.(i-1).(j - a.(i-1).w) + a.(i-1).v <= dp.(i-1).(j)
        then dp.(i-1).(j)
        else dp.(i-1).(j - a.(i-1).w) + a.(i-1).v;
    done
  done;
  dp.(n).(w)

let () =
  let (n, w) = Scanf.scanf "%d %d " (fun n w -> n, w) in
  let a = Array.init n (fun _ -> Scanf.scanf "%d %d " (fun v w -> { v; w })) in
  solve a n w |> Printf.printf "%d\n"

Measured memory_bytes: 10440
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(a > 0 and c > 0){
        c-=b;
        if(c <= 0){break;}
        a-=d;
    }
    if(a<=0){cout << "No";}
    else {cout << "Yes";}
    return 0;
}

Measured memory_bytes: 3628
<?php
$str = trim(fgets(STDIN));
$k = (int)trim(fgets(STDIN));
$len = strlen($str);
$count = 0;
for($i = 0;$i <= $len; $i++){
	$n = $str[$i];
	if($n == "1"){
		$count ++;
		if($count == $k){
			echo "1";
			return;
		}
	}else{
		echo $n;
		return;
	}
}

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

int main(){
//srandom((unsigned long)time(NULL));

long long n;
cin>>n;
vector<long long> t,x,y;
t.emplace_back(0);
x.emplace_back(0);
y.emplace_back(0);
for(long long i=0;i<n;i++){
    long long a,b,c;
    cin>>a>>b>>c;
    t.emplace_back(a);
    x.emplace_back(b);
    y.emplace_back(c);
}
bool plan=true;
for(long long i=0;i<n;i++){
    long long d=abs(x[i]-x[i+1])+abs(y[i]-y[i+1]);
    if(d>abs(t[i]-t[i+1])){
        plan=false;
    }else{
        if((abs(t[i]-t[i+1])-d)%2==1){
            plan=false;
        }
    }

}
if(plan){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}


return 0;
}

Measured memory_bytes: 2912
#include<bits/stdc++.h>
#define N 17
using namespace std;
int n,m;
int mp[N][N],sum[1<<15],f[1<<15][N];
int main()
{
	scanf("%d%d",&n,&m);int t1,t2,t3;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&t1,&t2,&t3);
		mp[t1][t2]=mp[t2][t1]=t3;
	}
	for(int i=0;i<1<<n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i&(1<<(j-1)))
			{
				for(int k=j+1;k<=n;k++)
				{
					if(i&(1<<(k-1)))
					{
						sum[i]+=mp[j][k];
					}
				}
			}
		}
	}
	memset(f,0xcf,sizeof(f));
	for(int i=1;i<1<<n;i++)if(i&1)f[i][1]=sum[i];
	for(int i=1;i<1<<n;i++)
	{
		for(int k=1;k<=n;k++)
		{
			if(i&(1<<(k-1)))
			{
				for(int j=(i-1)&i;j;j=(j-1)&i)
				{
					if(j&(1<<(k-1)))continue;
					for(int l=1;l<=n;l++)
					{
						if((j&(1<<(l-1)))&&mp[l][k])
						{
							f[i][k]=max(f[i][k],f[j][l]+mp[l][k]+sum[i^j]);
						}
					}
				}
			}
		}
	}
	printf("%d\n",sum[(1<<n)-1]-f[(1<<n)-1][n]);
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    int n; cin >> n;
    vector<int> p(n), q(n);
    vector<int> v(n);
    rep(i, n) cin >> p.at(i);
    rep(i, n) cin >> q.at(i);
    rep(i, n) v.at(i) = i+1;
    int a, b, count = 1;
    do{
        if(v == p) a = count;
        if(v == q) b = count;
        count++;
    }while(next_permutation(v.begin(), v.end()));
    cout << abs(a - b) << endl;
    return 0;
}


Measured memory_bytes: 3572
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

int64_t GreatestCommonDivisor(const int64_t a, const int64_t b) {
  // GCD. O(log(min(a, b))). 最大公約数.
  int64_t result = -1LL;
  if (a < 0) {
    std::cerr << "ERROR: GreatestCommonDivisor(): a is out of range: " << a << std::endl;
    throw 1;
  } else if (b < 0LL) {
    std::cerr << "ERROR: GreatestCommonDivisor(): b is out of range: " << b << std::endl;
    throw 1;
  } else if (a == 0LL) {
    result = b;
  } else if (b == 0LL) {
    result = a;
  } else {
    const int64_t new_a = std::min(a, b);
    const int64_t new_b = std::max(a, b) % new_a;  // Euclidean Algorithm
    result = GreatestCommonDivisor(new_a, new_b);
  }
  return result;
}

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

  int64_t N, X;
  cin >> N >> X;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int64_t D = abs(X - A[0]);
  for (int64_t i = 1; i < N; ++i) {
    D = GreatestCommonDivisor(D, abs(X - A[i]));
  }
  cout << D << endl;
  return 0;
}


Measured memory_bytes: 3916
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, cnt = 0;
    cin >> N;
    vector<int> p(N);
    for (int& i : p) cin >> i;
    for (int i = 1; i < N - 1; i++) {
        vector<int> v = {p[i-1], p[i], p[i+1]};
        int t = p[i];
        sort(v.begin(), v.end());
        if (t == v[1]) cnt++;
    }
    cout << cnt << endl;
}

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

int main(){
    int n;
    cin>> n;
    int r=0;
    for(int i=0;i<=n;i++){
        if(getchar()=='R'){
            r++;
        }
    }
    if(r>(n-r)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int a, b; cin >> a >> b;
  string ans;
  if (a*b%2 == 0) {
    ans = "No";
  } else {
    ans = "Yes";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int> 
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--) 
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

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

int min(int a, int b) { return (a < b)? a : b; }


   
 /*************************************************************************/

vi ar[100010];
int vis[100010],dist[10001];
char grid[1010][1010];
vector<vector<int>> dp(1010,vector<int>(1010,-1));
// int dp[1010][1010];
/*
vi a;
int n,m;
*/
int solve()
{
    
    return 0;
}

int cc;
/*
void dfs(int node )
{
	vis[node]=1;
	cc++;
	for(int child : ar[node])
	{
		if(vis[child]==0)
		{
			dfs(child);			
		}		
	}
}
*/
int n,m;

int solve(int i, int j)
{
	if(dp[i][j]!=-1)
		return dp[i][j];
	if(i>n || j>m)
		return 0;
	if(grid[i][j]=='#')
	{
		dp[i][j]=0;
		return 0;
	}
	if(i==n-1 && j==m-1)
	{
		dp[i][j]=1;
		return 1;
	}
	if(i==n-1)
		return dp[i][j] = solve(i,j+1) % mod;
	if(j==m-1)
		return dp[i][j] = solve(i+1,j) % mod;
	return dp[i][j] = (solve(i+1,j) % mod + solve(i,j+1) % mod) % mod;
		
}



int32_t main()
{
	FIO
    // testcase
	{
        // int n,m;
        cin>>n>>m;
        // memset(dp,-1,sizeof(dp));
        for(int i=0;i<n;i++)
        {
        	for(int j=0;j<m;j++)
        	{
        		cin>>grid[i][j];
        	}
        }
        cout<<solve(0,0);       
    }
    return 0;
}




Measured memory_bytes: 11648
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> v(n), c(n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}


	for (int i = 0; i < n; i++) {
		if (v[i] - c[i] > 0) {
			ans += v[i] - c[i];
		}
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main(void){
	int n,m;
	cin>>n;
	set<string> uids;
	for(int i=0;i<n;++i){
		string s;
		cin>>s;
		uids.insert(s);
	}
	bool locked=true;
	cin>>m;
	for(int i=0;i<m;++i){
		string s;
		cin>>s;
		if(uids.find(s)!=uids.end()){
			cout<<((locked)?"Opened by ":"Closed by ")<<s<<endl;
			locked=!locked;
		}
		else cout<<"Unknown "<<s<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
const int N=1<<14;
int v[N];
bool ok(int x)
{
	while(x)
	{
		if(v[x%10]) return 0;
		x/=10;
	}
	return 1;
}
int main()
{IOS;
	int n,k;cin>>n>>k;
	for(int i=0,x;i<k;++i)
		cin>>x,v[x]=1;
	for(int i=n;;++i)
		if(ok(i))
			return cout<<i<<Endl,0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a1(n), a2(n);

    REP(i,n){
        cin >> a1.at(i);
    }
    REP(i,n){
        cin >> a2.at(i);
    }

    int max = 0;
    REP(i,n){
        int sum = 0;
        for(int j=0; j<n; j++){
            if(j == i) sum += a1.at(j) + a2.at(j);
            else if(j>i) sum += a2.at(j);
            else sum += a1.at(j); 
        }
        if(sum > max) max = sum;
    }
    cout << max << '\n';

}

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

using State = string::const_iterator;

bool equation(State &itr);
int expr(State &itr);
int term(State &itr);
int factor(State &itr);
int number(State &itr);


bool valid;

void error(State &itr){
    valid = false;
    while(*itr){
        itr++;
    }
}

void next_char(State &itr, char expected){
    if(*itr == expected){
        itr++;
    }else{
        error(itr);
    }
}

bool equation(State &itr){
    int lhs = expr(itr);
    next_char(itr, '=');
    int rhs = expr(itr);
    return lhs == rhs;
}

int expr(State &itr){
    int res = term(itr);
    while(1){
        if(*itr == '+'){
            itr++;
            res += term(itr);
        }else if(*itr == '-'){
            itr++;
            res -= term(itr);
        }else{
            break;
        }
    }
    return res;
}
int term(State &itr){
    int res = factor(itr);
    while(1){
        if(*itr == '*'){
            itr++;
            res *= factor(itr);
        }else{
            break;
        }
    }
    return res;
}

int factor(State &itr){
    int res;
    if(*itr == '-'){
        itr++;
        res = -factor(itr);
    }else if(*itr == '('){
        next_char(itr, '(');
        res = expr(itr);
        next_char(itr, ')');
    }else{
        res = number(itr);
    }
    return res;
}

int number(State &itr){
    if(isdigit(*itr)){
        if(*itr == '0'){
            itr++;
            return 0;
        }
        int res = 0;
        while(isdigit(*itr)){
            res <<= 1;
            res |= *itr-'0';
            itr++;
        }
        return res;
    }else{
        error(itr);
        return 0;
    }
}

constexpr char chs[] = {'=','+','-','*','(',')','0','1'};
map<char,int> mp;
string s;
vector<char> v;
vector<bool> used;
string formula;

int rec(int n){
    if(n==0){
        State begin = formula.begin();
        valid = true;
        valid &= equation(begin);
        valid &= begin == formula.end();
        return (valid ? 1 : 0);
    }
    int res = 0;
    if(isalpha(s[n-1])){
        int idx = mp[s[n-1]];
        if(v[idx] == '#'){
            for(int i=0;i<8;i++){
                if(!used[i]){
                    used[i] = true;
                    v[idx] = chs[i];
                    formula[n-1] = chs[i];
                    res += rec(n-1);
                    used[i] = false;
                    v[idx] = '#';
                }
            }
        }
        else{
            formula[n-1] = v[idx];
            res += rec(n-1);
        }
    }else{
        formula[n-1] = s[n-1];
        res = rec(n-1);
    }
    return res;
}

int main(){
    cin >> s;
    int n = 0;
    for(auto c : s){
        if(isalpha(c) && mp.find(c) == mp.end()){
            mp[c] = n;
            n++;
        }
    }
    v.resize(n, '#');
    used.resize(n, false);
    formula.resize(s.size());
    cout << rec(int(s.size())) << endl;
    return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  string s[3];
  REP(i, 3) {
    cin >> s[i];
  }
  cout << s[0][0] << s[1][1] << s[2][2] << endl;;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[]x = new int[N];
		int[]y = new int[N];
		int[]h = new int[N];
		for(int i = 0; i < N; i++) {
			x[i] = scan.nextInt();
			y[i] = scan.nextInt();
			h[i] = scan.nextInt();
		}
		scan.close();
		for(int cx = 0; cx <= 100; cx++) {
			for(int cy = 0; cy <= 100; cy++) {
				int t = 0;
				for(int i = 0; i < N; i++) {
					boolean flag = true;
					if(h[i] > 0) {
						t = h[i] + Math.abs(x[i] - cx) + Math.abs(y[i] - cy);
						if(t == 6) {
							//System.out.println(cx + " " + cy);
						}
						for(int j = 0; j < N; j++) {
							int k = Math.max(0, t - Math.abs(x[j] - cx) - Math.abs(y[j] - cy));
							if(k != h[j]) {
								flag = false;
								break;
							}else {

							}
						}
						if(flag) {
							System.out.println(cx + " " + cy  + " " + t);
							System.exit(0);
						}
					}
				}

			}
		}
	}
}

Measured memory_bytes: 23380
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int ans = 0;
    if (n >= 9) {
        ans += 9;
        if (n >= 999) {
            ans += 900;
            if (n >= 99999)ans += 90000;
            else ans += max(n - 9999, 0);
        }
        else ans += max(n - 99, 0);
    }
    else ans += n;

    cout << ans << "\n";
}

Measured memory_bytes: 256
n,d = map(int,input().split())

x_list = []
for i in range(n):
    x_list.append(list(map(int,input().split())))

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        dis = 0
        for k in range(d):
            dis = dis + (x_list[i][k] - x_list[j][k])**2
        dis = dis **0.5
        if dis.is_integer():
            cnt = cnt + 1
        else:
            pass
print(cnt)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#include<functional>
#define int long long
using namespace std;

vector<int>book[20];
int dp[15][3000]{};
signed main() {
	int a, b; cin >> a >> b;
	for (int c = 0; c < a; c++) {
		int d, e; cin >> e >> d;
		book[d - 1].push_back(e);
	}
	for (int c = 0; c < 10; c++) {
		if (book[c].size()) {
			sort(book[c].begin(), book[c].end());
			reverse(book[c].begin(), book[c].end());
			for (int d = 1; d < book[c].size(); d++) {
				book[c][d] += book[c][d - 1] + d * 2;
			}
		}
	}
	for (int c = 0; c < 10; c++) {
		for (int d = 1; d <= b; d++) {
			dp[c + 1][d] = dp[c][d];
			for (int e = 1; e <= book[c].size() && e <= d; e++) {
				dp[c + 1][d] = max(dp[c + 1][d], dp[c][d - e] + book[c][e - 1]);
			}
		}
	}
	int MAX = 0;
	for (int x = 0; x <= 10; x++) {
		MAX = max(MAX, dp[x][b]);
	}
	cout << MAX << endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  if(SZ(s) == 2) cout << s << endl;
  else {
    reverse(s.begin(), s.end());
    cout << s << endl;
  }
  
}


Measured memory_bytes: 256
n,a,b,c,d=map(int, input().split(' '))
a -= 1
b -= 1
c -= 1
d -= 1
s = input()
if c == d:
    ans = 'No'
elif c < d:
    n0 = s[a:d].count('##')
    if n0 != 0:
        ans = 'No'
    else:
        ans = 'Yes'
else:
    n0 = s[a:c].count('##')
    n1 = s[b-1:d+2].count('...')
    if n0 == 0 and n1 != 0:
        ans = 'Yes'
    else:
        ans = 'No'
print(ans)

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long K = sc.nextLong();
		long D = sc.nextLong();

		if (Math.abs(X) / D >= K) {
			System.out.println(Math.abs(X) - K * D);
		}else {
			K -= Math.abs(X) / D ;
			if (K % 2 == 0) {
				System.out.println(Math.abs(X) % D);
			}else {
				System.out.println(Math.abs(Math.abs(X) % D - D));
			}

		}
	}
}

Measured memory_bytes: 35688
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var allWords = new List<(int person, int word)>[N];

            for (var i = 0; i < N; i++)
            {
                var a = int.Parse(Console.ReadLine());
                allWords[i] = new List<(int, int)>();
                for (var j = 0; j < a; j++)
                {
                    var inputs = Console.ReadLine().Split(' ');
                    var x = int.Parse(inputs[0]) - 1;
                    var y = int.Parse(inputs[1]);
                    allWords[i].Add((x, y));
                }
            }

            var ans = 0;

            // a << n で2^n乗を計算することですべてのパターンをチェック
            for (var bits = 0; bits < 1 << N; bits++)
            {
                var hasNoContradiction = true;
                var honestCount = 0; // 正直者カウント

                for (int i = 0; i < N; i++)
                {
                    // i番目の人が不親切な人(0)の場合は、次の番号の人へ
                    if (((bits >> i) & 1) == 0) continue;

                    honestCount++;

                    // i番目の人の証言に矛盾がないか確認
                    for (var j = 0; j < allWords[i].Count; j++)
                    {
                        // 現在調査しているパターン(bits)から証言に出てきた人が正直者か不親切な人かの値 != 証言から正直者か不親切な人かの値
                        if ((bits >> (allWords[i][j].person) & 1) != allWords[i][j].word)
                        {
                            hasNoContradiction = false;
                        }
                    }
                }

                if (hasNoContradiction)
                {
                    ans = Math.Max(ans, honestCount);
                }
            }

            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 27772
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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(void){
    string s; cin >> s;
    int n = s.size()-2;
    cout << s[0] << n << s[s.size()-1] << endl;
    return 0;
}

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

static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int solve(){
    int ans = 0;

    bool V[MAX];
    for(int i=0; i<n; ++i){
        B[i] = A[i];
        V[i] = false;
    }
    sort(B, B+n);
    for(int i=0; i<n; ++i) T[B[i]] = i;
    for(int i=0; i<n; ++i){
        if(V[i]) continue;
        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while(true){
            V[cur] = true;
            ++an;
            int v = A[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if(V[cur]) break;
        }
        ans += min(S + (an - 2)*m, m + S + (an + 1)*s);
    }

    return ans;
}

int main(){
    cin >> n;
    s = VMAX;
    for(int i=0; i<n; ++i){
        cin >> A[i];
        s = min(s, A[i]);
    }

    cout << solve() << endl;
}



Measured memory_bytes: 3160
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n, t;
    cin >> n >> t;
    int right = t;
    ll ans=0;
    REP(i,n){
        int ti;
        cin >> ti;
        ans+=max(0, ti-right);
        right = ti+t;
    }
    cout << right-ans << endl;
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    # 横だけ、縦だけ
    ans = min(W, H)
    for w in range(1, W):
        ans = min(ans, max(w * H, (W - w) * -(-H // 2))
                  - min(w * H, (W - w) * (H // 2)))
    for h in range(1, H):
        ans = min(ans, max(h * W, (H - h) * -(-W // 2))
                  - min(h * W, (H - h) * (W // 2)))
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 5005
using namespace std;
int n,fa[N],ft[N],a[N],b[N];
vector<int>e[N];
void biu()
{
	puts("IMPOSSIBLE");
	exit(0);
}
void dfs(int x)
{
	int fl[N];
	memset(fl,0,sizeof fl);
	fl[0]=1;
	int sum=0;
	for (int i=0;i<e[x].size();i++)
	{
		dfs(e[x][i]);
		sum+=a[e[x][i]]+b[e[x][i]];
		memset(ft,0,sizeof ft);
		for (int j=0;j<=a[x];j++)
			ft[j]=(j>=a[e[x][i]]&&fl[j-a[e[x][i]]])||(j>=b[e[x][i]]&&fl[j-b[e[x][i]]]);
		memcpy(fl,ft,sizeof fl);
	}
	int now=a[x];
	for (;now>=0&&!fl[now];now--);
	if (now==-1) biu();
	sum-=now;
	b[x]=sum;
}
int main()
{
	scanf("%d",&n);
	for (int i=2;i<=n;i++)
	{
		scanf("%d",&fa[i]);
		e[fa[i]].push_back(i);
	}
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	dfs(1);
	puts("POSSIBLE");
}

Measured memory_bytes: 8832
#include <algorithm>
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using P = std::pair<int, int>;

std::string s;
bool fl;

int main()
{
  std::cin >> s;

  rep( i, s.size()-1 )
  {
    if( s[i] == s[i+1] )
    { std::cout << i+1 << ' ' << i+2 << std::endl, fl = true; break; }
    else if( i+2 < s.size() && s[i] == s[i+2] )
    { std::cout << i+1 << ' ' << i+3 << std::endl, fl = true; break; }
  }

  if( !fl )
    std::cout << -1 << ' ' << -1 << std::endl;

  return 0;
}

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

int main() {
    //
    int num;
    int sNum, mNum;
    int Min = 0;
    int Max = 0;

    cin >> num;
    long long kin = 1000;
    vector<int> vec(num);
    for (int i = 0; i < num; i++) cin >> vec.at(i);

    for (int i = 0; i < num - 1; i++) {
        if (vec.at(i) < vec.at(i + 1)) {
            long long has;
            has = kin % vec.at(i);
            kin = kin / vec.at(i);
            kin = kin * vec.at(i + 1) + has;

        }
    }

    cout << kin;
    //
}


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

N, K = [int(i) for i in input().split()]
h = [int(input()) for i in range(N)]

sorted_tree = sorted(h)
sorted_tree2 = sorted_tree[K-1:]

min_diff = 1e9
for (min_h, max_h) in zip(sorted_tree, sorted_tree2):
    if (max_h - min_h) < min_diff:
        min_diff = max_h - min_h

print(min_diff)


Measured memory_bytes: 8652
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n, m, p, total, ans;
  while(true){
    cin >> n >> m >> p;
    if(n == 0 && m == 0 && p == 0){
      break;
    }
    vector<int> x(n, 0);	
    for(int i = 0; i < n; i++){
      cin >> x[i];
    }
    total = 0;
    for(int i = 0; i < n; i++){
      total = total + x[i];
    }	
    total = total * 100;
    if(x[m - 1] == 0){ 
      cout << 0 << endl;
      continue;
    }
    int rem = (total * (100 - p)) / 100;
    cout << rem / x[m-1] << endl;
  }
  return 0;
}	

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = 0;
        int g=0;
      for (int i=1;i<=5;i++)
      {
          a=in.nextInt();
          if (a==0)
          {
           g=i;
          }
         


        }
      System.out.print(g);

    }
}

Measured memory_bytes: 35644
n,m = map(int, input().split())
from collections import defaultdict
G = defaultdict(dict)
for i in range(1,n):
    G[i+1] = {}
for i in range(m):
    a,b,c = map(int, input().split())
    G[a][b] = c
start_vertex = 1
def bellmanford(G, start_vertex):
    if start_vertex not in G:
        return -1, -1
    distances = {}
    parents   = {}
    for node in G:
        distances[node] = float('-inf')
        parents[node]   = None
    distances[start_vertex] = 0
    for _ in range(len(G)-1):
        for node in G.keys():
            for neighbor in G[node]:
                if distances[neighbor] < distances[node] + G[node][neighbor]:
                    distances[neighbor] = distances[node] + G[node][neighbor]
                    parents[neighbor]   = node
    pathnode = n
    while pathnode != start_vertex:
        for neighbor in G[pathnode]:
            if distances[neighbor] < distances[pathnode] + G[pathnode][neighbor]:
                print('inf' , flush=True)
                return -1,-1
        pathnode = parents[pathnode]
    return distances, parents
distances, parents = bellmanford(G, start_vertex)
if distances != -1:
    print(distances[n] , flush=True)


Measured memory_bytes: 9712
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


// initialization
const int MAX = int(2e5)+10;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// binom mod MOD
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  // initialize
  COMinit();

  ll n, m, k;
  cin >> n >> m >> k;

  ll ans = 0;
  ll a = ((m*m)%MOD * COM(n+1, 3)) % MOD;
  ll b = ((n*n)%MOD * COM(m+1, 3)) % MOD;
  ans = (a + b) % MOD;
  ans *= COM(m*n-2, k-2);
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */
namespace utils{

    class Repeater{
        int st;
        int ed;
        int d;
    public:
        class rep_iterator{
            int i; int d;
        public:
            rep_iterator(int x, int pd) :i(x), d(pd) {}

            int& operator*(){ return i; }
            bool operator==(const rep_iterator& k) const { return i == k.i; }
            bool operator!=(const rep_iterator& k) const { return i != k.i; }
            rep_iterator& operator++(){ i+=d; return *this; }
        };

        explicit Repeater(int N) :st(0), ed(N), d(1) {}
        Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }

        rep_iterator begin() const{ return rep_iterator(st, d); }
        rep_iterator end() const{ return rep_iterator(ed, d); }

    };

    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    int x;
    is >> x;
    if(!is) return;
    int a = x / 100;
    int b = x % 100;
    if(a > 12 or a == 0){
        if(b > 12 or b == 0){
            cout << "NA\n";
        }
        else{
            cout << "YYMM\n";
        }
    }
    else{
        if(b > 12 or b == 0){
            cout << "MMYY\n";
        }
        else{
            cout << "AMBIGUOUS\n";
        }

    }

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_B.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> sum;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    if(i == 0)sum.pb((ll)x);
    else sum.pb((ll)x + sum[i - 1]);
  }
  ll res = linf;
  for(int i = 0; i < n - 1; i++){
    res = min(res, abs(sum[n-1] - 2 * sum[i]));
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 2420
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <vector>
#include <queue>


typedef long long llong;
using namespace std;

int main() {
	int n;
	llong maxim;
	int input_num;
	int stock_sum;
	int reserve_max_neg;
	while (1) {
		cin >> n;
		if (!n)break;
		maxim = -100010;
		stock_sum = 0;
		for (int i = 0; i < n; i++) {

			cin >> input_num;
			stock_sum += input_num;
			if (stock_sum > maxim)maxim = stock_sum;
			if (stock_sum < 0)stock_sum = 0;
		}
		cout << maxim << endl;
	}
	return 0;
}
 


Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;cin>>n>>m;
    vector<long long> a(n),b(n);
    vector<long long> c(m),d(m);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<m;i++){
        cin>>c[i]>>d[i];
    }
    vector<long long> ans(n,1),kyori(m);
    for(int i=0;i<n;i++){
        long long saitan = abs(a[i]-c[0])+abs(b[i]-d[0]);
        for(int j=1;j<m;j++){
            kyori[j] = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(saitan>kyori[j]){
                ans[i] = j+1;
                saitan = kyori[j];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 256
S = input()

op = ['+','+','+']

for bit in range(2**3):
  sum = int(S[0])
  for i in range(3):
    if (bit >> i) & 1:
      sum += int(S[i+1])
      op[i] = '+'
    else:
      sum -= int(S[i+1])
      op[i] = '-'

  if sum == 7:
    print(f'{S[0]}{op[0]}{S[1]}{op[1]}{S[2]}{op[2]}{S[3]}=7')
    break

Measured memory_bytes: 9136
from collections import defaultdict


def main():
    N = int(input())
    i = 2
    primes = defaultdict(int)
    while i**2 <= N:
        while N % i == 0:
            primes[i] += 1
            N //= i
        i += 1
    if N > 1:
        primes[N] = 1
    elements = list(primes.values())
    ans = 0
    for i in range(len(elements)):
        for j in range(1, 10):
            if elements[i] >= j:
                elements[i] -= j
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 68236
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x)   (x.begin(),x.end()) 
#define sz(v)     ((int)(v.size()))
#define INF 1e9+7
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 

int32_t main(){
  fast; 

  int n ; cin>>n; 
  map<int, int > mp; 
  vi a(n); 
  for(int i=0;i<n;i++){
    int x ; cin>>a[i]; x=a[i]; 
    if(mp.find(x)!=mp.end()) mp[x]++; 
    else mp[x]=1; 
  
  }
  int sum=0; 
  for(auto it=mp.begin();it!=mp.end();it++){
      int co=it->sec; //cout<<co<<endl; 
      sum+=(co*(co-1)/2);// cout<<sum<<endl;
  }


  for(int i=0;i<n;i++){
        
        int count=mp[a[i]]; 
        int val=(count-1)*(count-2)/2; 
        val-=(count)*(count-1)/2; 
        cout<<sum+val<<endl;    
  }
}

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

int main(){
    bool a[30] = {};
    int n;
    for(int i = 0;i<30;i++) a[i] = false;
    while(cin >> n){
        a[n-1] = true;
    }
    for(int i = 0;i<30;i++){
        if(!a[i]) cout << i+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3112
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef pair<int,int> P;
int main(){
  P p;
  vector<P> ar;
  int n,c1,m1,s1,m2,s2,m3,s3,m4,s4;
  while(1){
    cin >> n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      p.first = ((m1 + m2 + m3 + m4)*60) + (s1+s2+s3+s4);
      p.second = c1;
      ar.push_back( p );
    }
    sort( ar.begin() , ar.end() );
    cout << ar[0].second << endl;
    cout << ar[1].second << endl; 
    cout << ar[n-2].second << endl;
    ar.clear();
  }
}

Measured memory_bytes: 1304
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
using namespace std;
long long INF = 1000000009;
map<int, int> mp;
int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	vector<int> a(n), b(m);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < m; i++) cin >> b[i];
	sort(a.rbegin(), a.rend());
	sort(b.begin(), b.end());
	bool tmp = false;
	for (int i = x + 1; i <= y; i++) {
		if (a.at(0) < i && b.at(0) >= i) tmp = true;
	}
	if (tmp) cout << "No War" << endl;
	else cout << "War" << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n+1);
  int tmp;
  for(int i = 1;i<n+1;i++){
    for(int j = 0;j<n-1;j++){
      cin >> tmp;
      a[i].push_back(tmp);
    }
  }
  int c = n*(n-1)/2;
  ll day = 0;
  int t;
  int flg = 0;
  int upd = 0;
  while(c >0){
    upd = 0;
    int used[n+1] = {};
    for(int i = 1;i<n+1;i++){
      t = a[i][0];
      if(a[i].size() > 0 && a[t].size() >0){
        if(used[i] == 0 && used[t] == 0 && a[t][0] == i ){
          a[i].erase(a[i].begin());
          a[t].erase(a[t].begin());
          used[i] = 1;
          used[t] = 1;
          c--;
          upd = 1;
        }
      }
    }
    if(upd == 0){
      flg = 1;
      break;
    }
    day++;
  }
  
  if(flg == 1){
    cout << -1;
  }else{
    cout << day;
  }
  
}

Measured memory_bytes: 7636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int M, K; cin >> M >> K;

  if (M < 2) {
    if (K != 0) {
      cout << -1 << endl;
      return 0;
    }

    if (M == 1) cout << 1 << ' ' << 1 << ' ';
    cout << 0 << ' ' << 0 << endl;
    return 0;
  }

  if (K >= (1<<M)) {
    cout << -1 << endl;
    return 0;
  }

  rep(i,(1<<M)) {
    if (i == K) continue;
    cout << i << ' ';
  }
  cout << K << ' ';

  for (int i=(1<<M)-1; i>=0; --i) {
    if (i == K) continue;
    cout << i << ' ';
  }
  cout << K << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
const ll P = 1048576;
const int N = 205;
string s,ss[N];
ll gcd(ll a,ll b)
{
    return b == 0 ? a : gcd(b , a%b);
}
ll pp[N];
int main()
{
    pp[1] = 2;
    repu(i,2,21)
    pp[i] = pp[i-1] * 2ll;
    while(cin >> s)
    {
        if(s == "#")
        {
            break;
        }
        int len = s.length();
        int st = 0,i = 0;
        while(1)
        {
            string a = s.substr(st,4);
            if(a == "west")
                ss[i] = a,st += 4;
            else
                ss[i] = s.substr(st,5),st += 5;
            if(st > len)
                break;
            i++;
        }
        ll sum = 0;
        if(ss[i-1] == "north")
            sum = 0;
        if(ss[i-1] == "west")
            sum = 90 * P;
        for(int j = i-2; j >= 0; j--)
        {
            if(ss[j] == "north")
                sum -= (90ll * pp[20 - i + j + 1]);//cout<<20-i+j+1<<endl;
            else
                sum += (90ll * pp[20 - i + j + 1]);//cout<<20-i+j+1<<endl;
        }
        //printf("%lld*********\n",sum);
        ll p = gcd(sum,P);
        printf("%lld",sum/p);
        if(P/p != 1)
            printf("/%lld",P/p);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1216
N = int(input())
s = str(input())

a = 0
b = 0

for i in range(N):
    if s[i] == 'R':
        a = a + 1
ans = max(a,b)
for i in range(N):
    if s[i] == 'R':
        a = a - 1
    else:
        b = b + 1
    now = max(a,b)
    ans = min(ans, now)
print(ans)


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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  return 0;
}

/* convert a string into an integer value */
int getKey(char str[]){
  int sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  int i,h,key;
  key = getKey(str);
  for(i=0;1;i++){
    h =(h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;    
  }
  return 0;
}

int insert(char str[]){
  int i,h,key;
  key = getKey(str);
  for(i=0;1;i++){
    h =(h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 15408