akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

const int MAXN = 3000001;

int A[MAXN];
int N;

bool done[MAXN];

pair<int, int> I[MAXN];

int Ilen(pair<int, int> p) {
	if (p.first >= p.second)
		return p.first - p.second + 1;
	return N - p.second + p.first + 1;
}

bool used[MAXN];


int main() {
	ios_base::sync_with_stdio(false);
	
	cin >> N;
	FOR (i, N) {
		cin >> A[i];
		A[i]--;
	}

	int idx = 0, val = A[0];
	while (idx < N && A[idx] == val)
		idx++;
	idx--;
	int last = idx;
	
	FOR (i, N)
		I[i].first = I[i].second = -1;
		
	SET(done, 0);
		
	while (true) {
		val = A[idx];
		if (done[val]) {
			cout << "0" << endl;
			return 0;
		}
		int j = idx;
		while (true) {
			j--;
			if (j < 0)
				j = N - 1;
			if (j == last || A[j] != val)
				break;
		}
		
		j = (j + 1) % N;
		
		I[val].first = idx;
		I[val].second = j;
		done[val] = true;
		idx = j - 1;
		if (idx < 0)
			idx = N - 1;
		if (idx == last)
			break;
	}
	
	int len0 = Ilen(I[0]);
	LL ret = 1LL;
	SET(used, 0);
	int numI = 0, marked = 0, taken = 0;
	
	FOR (i, N) {
		if (I[i].first == -1) {
//			cout << "entered" << endl;
//			cout << ret << " " << (marked - taken - (len0 - 1) * numI) << endl;
			ret *= (marked - taken - (len0 - 1) * numI);
//			cout << marked << " " << taken << " " << numI << " " << ret << endl;
			ret %= 998244353LL;
			taken++;
			continue;
		}

		int len = Ilen(I[i]);
		if (len > len0) {
			cout << "0" << endl;
			return 0;
		}
		
		int idx = I[i].first;
		used[idx] = true;
		while (idx != I[i].second) {
			idx--;
			if (idx < 0)
				idx = N - 1;
			used[idx] = true;
		}
		
		int before = (I[i].first + 1) % N;
		int after = I[i].second - 1;
		if (after < 0)
			after = N - 1;

		marked += len;
		taken++;
		if (!used[before] && !used[after]) {
			if (len < len0) {
				cout << "0" << endl;
				return 0;
			}
			numI++;
		}
		else {
			if (used[before] && used[after]) {
				ret *= (len0 - len + 1);
				ret %= 998244353LL;
				numI--;
			}
		}
		
		if (marked == N)
			numI = 0;
		if (marked == N && i == 0)
			ret = N;
	}
	
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 12544
import java.util.*;
import java.io.*;

public class Main {
    public static int firstExplosion(String S){
        for(int i=0;i<S.length();i++){
        	if(S.charAt(i)!='1') return i;
        }
        return 10000000;
    }
    public static char solve(String S, long K){
        if(firstExplosion(S)<K) return S.charAt(firstExplosion(S));
        else return S.charAt((int)K-1);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        System.out.println(solve(S,K));
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

void ABC173B()
{
	int N;
	cin >> N;
	vector<string> S(N);
	for (auto& x : S)
		cin >> x;
	int nAC = 0;
	int nWA = 0;
	int nTLE = 0;
	int nRE = 0;
	for (int i = 0; i < N; ++i)
	{
		if (S[i] == "AC")
			++nAC;
		else if (S[i] == "WA")
			++nWA;
		else if (S[i] == "TLE")
			++nTLE;
		else
			++nRE;
	}
	cout << "AC x " << nAC << endl;
	cout << "WA x " << nWA << endl;
	cout << "TLE x " << nTLE << endl;
	cout << "RE x " << nRE << endl;
}


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


Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll n,m,h,w,k;
string s[310];
ll a[100010],b[100010],c[100010];
ll dp[100010];
V<ll> v[310];
ll ans[310][310];
ll t=1,fr=0,lw=0,ue=0;

void f(ll x0,ll x1,ll y0,ll y1,ll z){
	reg(i,y0,y1)reg(j,x0,x1)ans[i][j]=z;
}

int main(void){
	cin>>h>>w>>k;
	rep(i,h)cin>>s[i];
	rep(i,h)rep(j,w)if(s[i][j]=='#'){
		v[i].push_back(j);
		ue=max(ue,i);
	}
	rep(i,ue){
		bool ex=false;
		fr=0;
		rep(j,v[i].size()){
			if(j!=v[i].size()-1){
				f(fr,v[i][j],lw,i,t);
			}else{
				f(fr,w-1,lw,i,t);
			}
			t++;
			ex=true;
			fr=v[i][j]+1;
		}
		if(ex)lw=i+1;
	}
	fr=0;
	rep(j,v[ue].size()){
		if(j!=v[ue].size()-1){
			f(fr,v[ue][j],lw,h-1,t);
		}else{
			f(fr,w-1,lw,h-1,t);
		}
		fr=v[ue][j]+1;
		t++;
	}
	rep(i,h){
		rep(j,w)cout<<ans[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 2816
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= putStrLn . which "AC" "WA" . and . ( <*> ) [ f1, f2, f3 ] . pure

f1 = ( == 'A' ) . head
f2 = ( == 1 ) . length . filter ( == 'C' ) . drop 2 . reverse . drop 1 . reverse
f3 = ( == 2 ) . length . filter isUpper

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define ll long long;
int main()
{
    int n,k,a,b;
    cin>>n>>k;
    a=((n-2)*(n-1))/2;
    if(a<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    vector<pair<int,int>>v;
   	for(int i=2;i<=n;i++)
    {
		v.push_back({1,i});
	}
    b=(((n-2)*(n-1))/2)-k;
	for(int i=2;i<=n-1;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(b<=0)
                break;
			v.push_back({i,j});
			b--;
		}
	}
    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

int main()
{
    int n,m;
    cin >> n >> m;
    int ind[n] = {};
    vector<int> e[n] = {};
    for(int i=0; i<n+m-1; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        e[a].push_back(b);
        ind[b]++;
    }

    int root = -1;
    for(int i=0; i<n; i++){
        if(ind[i] == 0 ) root = i;
    }
    
    stack<int> s;
    s.push(root);
    pair<int, int> pp[n] = {};
    while(!s.empty()){
        int a = s.top();
        // cout << "turn: "<< a << endl;
        s.pop();
        for(auto c: e[a]){
            ind[c]--;
            if(ind[c] == 0) s.push(c);
            int candidate = pp[a].first + 1;
            // cout << c << ": " << pp[c].first << ","<< pp[c].second << "<" << candidate << endl;
            if(pp[c].first < candidate){
                pp[c].first = candidate;
                pp[c].second = a + 1;
            }
        }
    }
    
    for(auto p: pp) cout << p.second << endl;
    return 0;
}

Measured memory_bytes: 7424
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N>>K) {
		ll ans=K;
		REP(i, N-1) ans*=K-1;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
Sa = list(input())
Sb = list(input())
Sc = list(input())
word = Sa.pop(0)
while True:
    if word == 'a':
        if len(Sa) ==0:
            print('A')
            exit()
        word = Sa.pop(0)

    elif word == 'b':
        if len(Sb) ==0:
            print('B')
            exit()
        word = Sb.pop(0)
    elif word == 'c':
        if len(Sc) ==0:
            print('C')
            exit()
        word = Sc.pop(0)


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

int main() {
    int64_t n, m, ans;
    cin >> n >> m;
    if (n >= 3 && m >= 3) ans = (n-2) * (m-2);
    else if (n == 1 && m == 1) ans = 1;
    else if (n == 1 || m == 1) ans = max(n, m) - 2;
    else ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<M;i++){
			int a1 = int.Parse(str2[i]);
			N -= a1;
		}
		if(N<=-1){
			N = -1;
		}
		Console.WriteLine(N);
	}
}

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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

pll norm(ll x,ll y)
{
  ll g=__gcd(abs(x),abs(y));
  x/=g;
  y/=g;
  if(x<0)return mp(-x,-y);
  else return mp(x,y);
}


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


string s,t;
cin>>s>>t;
sort(all(s));
sort(all(t),greater<>());

if(s<t)cout<<"Yes"<<"\n";
else cout<<"No"<<"\n";


return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=800+10,M=1500,INF=0x3f3f3f3f;
int main()
{
    int n,m,a,b,c;
    char s[N];
    while(~scanf("%s",s)){
        bool flag=0;
        for(int i=0;i<strlen(s);i++){
            if((s[i]=='a'||s[i]=='A')&&(s[i+1]=='c'||s[i+1]=='C')){
                flag=1;break;
            }

        }
        if(flag) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
 }


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll div(ll &n) {
    ll ret = abs(n) % 2;
    if (n < 0) {
        n = (abs(n) + ret) / 2LL;
    }
    else {
        n = -(n - ret) / 2LL;
    }
    return ret;
}

string solve(ll n) {
    string ret = "";
    while (n != 0) {
        ret.push_back(div(n) + '0');
    }
    reverse(ret.begin(), ret.end());
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    if (N == 0)
        cout << 0 << endl;
    else
        cout << solve(N) << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
class c
{
    static void Main()
    {
        var LR = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int L = LR[0] % 2019, R = LR[1] % 2019;
        int ans = int.MaxValue;
        if (LR[1] - LR[0] >= 2019 || L >= R) Console.WriteLine(0);
        else
        {
            for (int i = L; i < R; i++)
            {
                for (int j = i + 1; j <= R; j++)
                {
                    ans = Math.Min(ans, i * j % 2019);
                }
            }
            Console.WriteLine(ans);
        }
    }
}

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

namespace AtCoder.ABC074
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());
            var x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int total = 0;
            for (int i = 0; i < n; i++)
            {
                if (x[i] <= Math.Abs(k - x[i]))
                {
                    total += x[i] * 2;
                }
                else
                {
                    total += Math.Abs(k - x[i]) * 2;
                }
            }
            Console.WriteLine(total);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


int main(){
  int N;cin>>N;
  vint a(N);
  int xa=0;
  repeat(i,N){
    cin>>a[i];
    xa ^= a[i];
    a[i] ^= a[i]-1;
  }
  debug(xa);
  debugArray(a,N);
  ll ans=0;
  sort(a.begin(),a.end());
  for(int i=31;i>=0;i--){
    if(!((xa>>i)&1))continue;
    int j=lower_bound(a.begin(),a.end(),(1<<i))-a.begin();
    if(a[j]!=(1<<(i+1))-1){
      ans = -1;
      break;
    }
    ans++;
    xa ^= a[j];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){

    string s;
    cin >> s;
    vector<int> b,w;
    for (int i = 0; i < (int)s.size(); i++){
        if (s[i] == 'B'){
            b.push_back(i);
        } else {
            //w.push_back(i);
        }
    }
    for (int i = 0; i < b.size(); i++){
        w.push_back((int)s.size() - 1 - i);
    }
    sort(b.rbegin(), b.rend());
    ll sum = 0;
    for (int i = 0; i < (int)b.size(); i++){
        sum += w[i] - b[i];
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2808
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <queue>

int main(){
    int N, D, A;
    std::cin >> N >> D >> A;
    std::vector<std::pair<int, int>> XH;
    for (int i=0; i<N; i++) {
        int x,y;
        std::cin >> x >> y;
        XH.push_back(std::make_pair(x, y));
    }
    
    auto comp = [](std::pair<int, int> a, std::pair<int, int> b) {
        return a.first < b.first;
    };
    std::sort(XH.begin(), XH.end(), comp);
    for (int i=0; i<N; i++) {
        XH[i].second = (XH[i].second-1)/A+1;
    }
    
    size_t answer=0;
    size_t tot = 0;
    std::queue<std::pair<size_t, size_t>> q;
    for (int i=0; i<N; i++) {
        int x = XH[i].first;
        int h = XH[i].second;
        while (q.size() && x>q.front().first) {
            tot -= q.front().second;
            q.pop();
        }
        h -= tot;
        if (h>0) {
            answer += h;
            tot += h;
            q.push(std::make_pair(x+2*D, h));
        }
    }
    
    std::cout << answer << std::endl;
  return 0;
}


Measured memory_bytes: 3440
// AtCoder Beginner Contest 123 - Problem D: Cake 123 (https://atcoder.jp/contests/abc123/tasks/abc123_d)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAX { 1010 };

ll as[MAX], bs[MAX], cs[MAX], xs[MAX*MAX], ans[MAX*MAX];

ll amount(ll m, ll X, ll Y, ll Z)
{
    ll res = 0;

    for (int i = 0; i < X; ++i)
    {
        auto j = lower_bound(xs, xs + Y*Z, m - as[i]) - xs;
        res += (Y*Z - j);
    }

    return res;
}

void solve(ll X, ll Y, ll Z, ll K)
{
    ll pos = 0;

    for (int i = 0; i < Y; ++i)
        for (int j = 0; j < Z; ++j)
            xs[pos++] = bs[i] + cs[j];

    sort(as, as + X);
    sort(xs, xs + Y*Z);

    ll a = xs[0] + as[0], b = xs[Y*Z - 1] + as[X - 1], k = a;

    while (a <= b)
    {
        auto m = a + (b - a)/2;
//cout << "a = " << a << ", b = " << b << ", m = " << m << ", amount = " << amount(m, X, Y, Z) << '\n';
        if (amount(m, X, Y, Z) >= K)
        {
            k = m;
            a = m + 1;
        } else
            b = m - 1;
    }

//cout << "k = " << k << ", amount = " << amount(k, X, Y, Z) << '\n';

    pos = 0;

    for (ll i = 0; i < X; ++i)
    {
        ll j = lower_bound(xs, xs + Y*Z, k - as[i]) - xs;

        while (j < Y*Z)
        {
            ans[pos++] = (-(as[i] + xs[j]));
            ++j;
        }
    }

    sort(ans, ans + pos);
}

int main()
{
    ios::sync_with_stdio(false);

    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    for (int i = 0; i < X; ++i)
        cin >> as[i];

    for (int i = 0; i < Y; ++i)
        cin >> bs[i];

    for (int i = 0; i < Z; ++i)
        cin >> cs[i];

    solve(X, Y, Z, K);

    for (int i = 0; i < K; ++i)
        cout << -ans[i] << '\n';

    return 0;
}


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

using namespace std;

long long INF=1e15;

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

    int n;
    cin>>n;
    vector<int> a(3*n);
    for(int i=0;i<3*n;i++)cin>>a[i];

    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    long long ans=0,sum=0;

    for(int i=1;sum<n;i+=2){
        ans+=a[i];
        sum++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main(){
    string str;
    cin >> str;
    unsigned long ans = 0;
    int len = str.size()-1;
    int bit = 0;
    for(;bit < (1<<len);++bit){
        int digit = 0;
        for(int j = len;j >= 0;j--){
            int value = str[j] - '0';
            ans += value * long(pow(10,digit));
            if(bit & (1 << (len-j))) digit = 0;
            else ++digit;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define sd second
#define ll long long

using namespace std;

const int maxn = 3010;
const int oo = 1e9;

int n,res0=oo,res1=oo;
string t;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 //   freopen("in.txt","r",stdin);
    cin>>t;
    n = t.length();
    for (int i=0;i<t.length();i++) if (t[i]=='0') res0 = min(res0, max(i,n-i-1));
    for (int i=0;i<t.length();i++) if (t[i]=='1') res1 = min(res1, max(i,n-i-1));
    if (res0==oo || res1==oo) cout<<n;
    else cout<<max(res0,res1);

}


Measured memory_bytes: 512
N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")
 
for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if N-1<k:
      break
 
    if S[j]!=S[i] and S[j]!=S[k] and S[k]!=S[i]:
        ans-=1
        
print(ans)

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

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

    string s, t;
    cin >> s >> t;

    int res = 0;
    for (int i = 0; i < 3; ++i){
        if(s[i] == t[i]) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

ll k;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> k;
    int n = 50;
    vector <ll> a(n);
    for(int i = 0 ; i < n ; i++){
        a[i] = i;
    }
    ll f = k / n;
    for(auto &i : a) i += f * n;
    for(auto &i : a) i -= f * (n - 1);
    for(int itt = 0 ; itt < k % n ; itt++){
        int mn = 0;
        for(int j = 0 ; j < n ; j++){
            if(a[j] < a[mn]) mn = j;
        }
        for(int j = 0 ; j < n ; j++){
            if(j == mn) a[j] += n;
            else a[j]--;
        }
    }
    cout << n << endl;
    for(auto &i : a) cout << i << " ";
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using vpii = vector<pair<int, int>>;
using ll = long long;

string ans = "Yes";

void	check(string s)
{
	int j = s.size() - 1;
	for (int i = 0; i < s.size() / 2; i++)
	{
		if (s[i] != s[j])
			ans = "No";
		j--;		
	}
}

int		main(void)
{
	string s;

	cin >> s;
	check(s);
	int N = s.size();
	check(s.substr(0, N / 2));
	check(s.substr((N + 3) / 2 - 1));
	
	cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, k) = i.read2::<usize, usize>();

    writeln!(o, "{}", n - k + 1).unwrap();
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4352
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def how_many_times(p):
    i = 0
    while True:
        if i * (i + 1) // 2 > p:
            break
        i += 1

    return i - 1


n = int(input())
factors = Counter(prime_factorize(n))

ans = 0
for f, p in factors.items():
    ans += how_many_times(p)

print(ans)


Measured memory_bytes: 9464
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int>a(n), cnt(n, 0);
    rep(i, n)cin >> a[i];
    int i = 0, w = 0, r = 0, cnk = 0, str = 0;//iは行った町のNo、wはワープした回数、rはループに入るまで
    if (n < k) {
        while (cnt[i] < 2) {//二回ループさせる
            cnt[i]++;
            if (cnt[i] == 2) {
                cnk++;
                w++;
                if (cnk == 1)str = i;
            }
            i = a[i] - 1;
            r++;
        }
        r = r - 2 * w;
        ll q = (ll)(k - r) % w;
        i = str;
        while (q > 0) {
            q--;
            i = a[i] - 1;
        }
    }
    else {
        while (k > 0) {
            k--;
            i = a[i] - 1;
        }
    }
    cout << i + 1 << endl;

    return 0;
}

Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, K;
    cin >> N >> K;
    VL a(N), f(N);
    rep(i, 0, N) cin >> a[i];
    rep(i, 0, N) cin >> f[i];
    sort(ALL(a));
    sort(ALL(f), greater<ll>());
    ll L = -1, R = 1e18;
    while(R - L > 1){
        // cerr << L << " " << R << endl; 
        bool flag = true;
        ll M = L + (R - L) / 2;
        ll k = K;
        rep(i, 0, N){
            if(a[i] * f[i] > M){
                ll rem = a[i] * f[i] - M;
                k -= (rem + f[i] - 1) / f[i];
            }
            if(k < 0){
                flag = false;
                break;
            }
        }
        if(flag) R = M;
        else L = M;
    }
    cout << max(0LL, R) << endl;
    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    ll now = 1;
    for(ll i = 1;i<=N;++i){
        now*=i;
        now%=(ll)(1e9+7);
    }
    cout << now << '\n';
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define md 1000000007
#define mx 1e18
#define pb push_back
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pii pair<ll int,ll int>
#define ff first
#define ss second


int main()
{
	// fastio
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt" , "r" , stdin);
	// freopen("output.txt" , "w" , stdout);
	// #endif

	ll int n;
	cin>>n;

	ll int ar[n+1][n+1];
	for(ll int i=0;i<n;i++)
		for(ll int j=0;j<n;j++)
			cin>>ar[i][j];

	ll int dp[(1<<n)+1];
	memset(dp,0,sizeof(dp));

	dp[0]=1LL;

	// for(ll int i=0;i<n;i++)
	// {
		for(ll int j=0;j<(1<<n);j++)
		{
			ll int i = __builtin_popcount(j);
			for(ll int k=0;k<n;k++)
			{
				if(ar[i][k] && !(j&(1LL<<k)))
				{
					ll int nm = j^(1LL<<k);
					dp[nm]+=dp[j];
					dp[nm]%=md;
				}
			}
		}
	// }	

	cout<<dp[(1<<n)-1]<<endl;

	return 0;
}


Measured memory_bytes: 16640
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int month,day,count=0,week;
    
    while(1){
        scanf("%d %d",&month,&day);
        if(month==0)
            break;
        if(month==2)
            count+=31;
        if(month==3)
            count+=31+29;
        if(month==4)
            count+=31+29+31;
        if(month==5)
            count+=31+29+31+30;
        if(month==6)
            count+=31+29+31+30+31;
        if(month==7)
            count+=31+29+31+30+31+30;
        if(month==8)
            count+=31+29+31+30+31+30+31;
        if(month==9)
            count+=31+29+31+30+31+30+31+31;
        if(month==10)
            count+=31+29+31+30+31+30+31+31+30;
        if(month==11)
            count+=31+29+31+30+31+30+31+31+30+31;
        if(month==12)
            count+=31+29+31+30+31+30+31+31+30+31+30;
        
        count+=day;
        
        week=count%7;
        if(week==0)
            printf("Wednesday\n");
        if(week==1)
            printf("Thursday\n");
        if(week==2)
            printf("Friday\n");
        if(week==3)
            printf("Saturday\n");
        if(week==4)
            printf("Sunday\n");
        if(week==5)
            printf("Monday\n");
        if(week==6)
            printf("Tuesday\n");
        
        count=0;
        
        
    }
    return 0;
}

Measured memory_bytes: 584
int main (void){
  int N;
  scanf("%d",&N);
  int A[N];
  for(int i=0;i<N;i++){
  scanf("%d",&A[i]);
  }

  for(int j=0;j<N;j++){
    if(A[j]%2==0){
      if(A[j]%3==0||A[j]%5==0){
      }else{
        printf("DENIED\n");
        return 0;
      }
    }
  }
  printf("APPROVED\n");
  return 0;
}


Measured memory_bytes: 128
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(k,n);
    vl A(n); in1(A); 
    ll mm=A[0]+k-A[n-1];
    FOR(i,1,n){
        chmax(mm,A[i]-A[i-1]);
    }

    out(k-mm);
}

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

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF 2e9
#define MOD 1e9+7
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL<<(n))

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template<class InputIterator>
InputIterator adv(InputIterator x, typename std::iterator_traits<InputIterator>::difference_type n) {
    advance(x, n);
    return x;
}

int ni() {
    int i;
    cin >> i;
    return i;
}

int main() {
    int N = ni();
    vector<ll> a;
    REP(i, N) a.push_back(ni());
    deque<ll> q;
    bool r = (N % 2 == 0);
    REP(i, N) {
        if (r) q.push_back(a[i]);
        else q.push_front(a[i]);
        r = !r;
    }

    REP(i, N) {
        if (i < N-1) cout << q.front() << " ";
        else cout << q.front() << endl;
        q.pop_front();
    }
    return 0;
}

Measured memory_bytes: 5360
s = input()
if s in ("KIHBR", "KIHBRA", "KIHBAR", "KIHBARA", "KIHABR", "KIHABRA", "KIHABAR", "KIHABARA", "AKIHBR", "AKIHBRA", "AKIHBAR", "AKIHBARA", "AKIHABR", "AKIHABRA", "AKIHABAR", "AKIHABARA"): print("YES")
else: print("NO")

Measured memory_bytes: 2940
//author: clorf
//Think twice,Code once.
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=200010;
const double Pi=acos(-1.0);
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}
int n,num1,num2;
char s[maxn];
int main()
{
	scanf("%d\n",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		if(s[i]=='W')
			num1++;
	for(int i=n-num1+1;i<=n;i++)
		if(s[i]=='W')
			num2++;
	printf("%d",num1-num2);
	return 0;
}

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

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

int n, z, w, ans;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> z >> w;
	vi a(n);
	for (auto& i : a) cin >> i;
	ans = abs(w - a[n - 1]);
	if (n > 1) ans = max(ans, abs(a[n - 2] - a[n - 1]));
	cout << ans;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int main(){
int c,q,i,j,z=0,k=1,o=0,m[1001][1001]={0},e[6][2]={0};
for(i=0;i<6;i++){
cin>>q>>c;
if(q>c)m[q][c]++;
else m[c][q]++;
}
for(i=0;i<1001;i++){
for(j=0;j<1001;j++){
if(m[i][j]){
if(m[i][j]==4){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
else if(m[i][j]==6){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
else{ e[z][0]=i;e[z++][1]=j;}
}
}
}
if(e[0][0]!=e[2][1]||e[1][0]!=e[2][0]||e[0][1]!=e[1][1])k=0;
if(k)cout<<"yes"<<endl;
else cout<<"no"<<endl;
}

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

Int N;
vector<P> A;

Int used[50][4][2], mem[50][4][2];
Int last;
Int dfs(Int idx, Int num, Int px, Int pt){
  if(idx == N) return px;
  Int x, t; tie(x, t) = A[idx];
  Int a = INF, b = INF;
  Int f = num <= 2 && pt + (num + 1) * abs(px - x) <= t;
  if(used[idx][num][f]++) return mem[idx][num][f];

  if(num){//戻る
    Int nidx = idx;
    Int nnum = 0;
    Int npx = 0;
    Int npt = pt + (num + 1) * px;
    a = px + dfs(nidx, nnum, npx, npt);
  }

  if(f){//もつ
    Int nidx = idx + 1;
    Int nnum = num + 1;
    Int npx = x;
    Int npt = t;
    Max(last, nidx);
    b = abs(px - x) + dfs(nidx, nnum, npx, npt);
  }
  Int res = min({a, b, INF});
  return mem[idx][num][f] = res;
}

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

  while(1){
    cin>>N;
    if(N == 0) break;
    A.clear();
    A.resize(N);
    cin>>A;

    last = 0;
    memset(used, 0, sizeof(used));
    Int ans = dfs(0, 0, 0, 0);

    if(ans < INF) cout<<"OK "<<ans<<endl;
    else cout<<"NG "<<last+1<<endl;
  }

  return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define GET(a) cin >> (a)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;

int main() {
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	int white = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == '.') {
			white++;
		}
	}
	
	int leftWhite = 0;
	int leftBlack = 0;
	int ans = white;
	for(int i = 0; i < n; i++) {
		if(s[i] == '.') {
			leftWhite++;
		}
		else {
			leftBlack++;
		}
		
		if(ans > leftBlack + white - leftWhite) {
			ans = leftBlack + white - leftWhite;
		}
	}
	
	cout << ans << endl;
	
    return 0;
}

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

namespace ABC080_D___Recording
{
    class Program
    {
        static void Main(string[] args)
        {
            var NC = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var events = new List<Event>();
            for (int i = 0; i < NC[0]; i++)
            {
                var stc = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                events.Add(new Event(stc[0], stc[2], false));
                events.Add(new Event(stc[1], stc[2], true));
            }

            events = events.OrderBy(e => e.time).ThenBy(e => e.isEnd).ToList();
            var isRecording = new bool[NC[1] + 1];
            var requireRecorder = 0;
            var lastProgramStart = new int[NC[1] + 1];
            foreach (Event e in events)
            {
                if (e.isEnd)
                {
                    if (lastProgramStart[e.channel] != e.time) isRecording[e.channel] = false;
                }
                else
                {
                    isRecording[e.channel] = true;
                    requireRecorder = Math.Max(requireRecorder, isRecording.Count(r => r));
                    lastProgramStart[e.channel] = e.time;
                }
            }
            Console.WriteLine(requireRecorder);
        }
    }
    struct Event
    {
        public int time;
        public bool isEnd;
        public int channel;
        public Event(int _time, int _channel, bool _isEnd)
        {
            time = _time;
            channel = _channel;
            isEnd = _isEnd;
        }
    }
}


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

int main(){
	ll n, m;
	scanf("%lld%lld", &n, &m);
	ll l = 0, r = m >> 1;
	while (r > l){
		ll m0 = l + r >> 1;
		ll a = min(n + m0, m - (m0 << 1) >> 1), b = min(n + (m0 + 1), m - (m0 + 1 << 1) >> 1);
		if (a > b)r = m0;
		else l = m0 + 1;
	}
	printf("%lld\n", min(n + l, m - (l << 1) >> 1));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v,path,tr;
ll pr[200005];

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

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

	ll n,i,m,j,k,x,y,a,b,c,t,sm=0,xw;
	string s,w;
	
	cin >> n >> k;
	v.pb(0);
	for(i=0;i<n;i++)
	{
		cin >> x;
		v.pb(x);
	}
	i=1;
	while(k--)
	{
		if(k==0)
		{
			cout << v[i];
			return 0;
		}
		if(pr[i])
		{
			for(j=0;j<path.size();j++)
				if(path[j]==i)
					break;
			for(;j<path.size();j++)
				tr.pb(path[j]);
			break;
		}
		path.pb(i);
		pr[i]=1;
		i=v[i];
	}
	cout << tr[(1+k)%tr.size()];
	return 0;
}


Measured memory_bytes: 9380
#include<stdio.h>
#include<stdlib.h>

void run(void){
  int n,s;
  scanf("%d%d",&n,&s);
  int *a=(int *)calloc(n,sizeof(int));
  int i,j;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int min=n+1;
  j=0;
  for(i=0;i<n;i++){
    while(j<n && s>0) s-=a[j++];
    if(s<=0 && j-i<min) min=j-i;
    s+=a[i];
  }
  printf("%d\n",min==n+1?0:min);
}

int main(void){
  run();
  return 0;
}



Measured memory_bytes: 2224
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [usize],
    }
    let mut broken = vec![false; n + 1];
    for &a in &a {
        broken[a] = true;
    }
    let mut dp = vec![0i64; n + 1];
    dp[0] = 1;
    for i in 1..n + 1 {
        if broken[i] { continue; }
        dp[i] += dp[i - 1];
        if i >= 2 { dp[i] += dp[i - 2]; }
        dp[i] %= 1_000_000_007;
    }
    puts!("{}\n", dp[n]);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < n; i++)
const uint64_t MOD = 1E+9 + 7;
using namespace std;


int main() {
	uint64_t N, K;
	cin >> N >> K;
	vector<int> A(N);
	rep(i, N) cin >> A[i];

	uint64_t p = 0, q = 0;

	rep(i, N) {
		rep(j, N) {
			if (A[i] > A[j]) {
				q++;
				if (i < j) p++;
			}
		}
	}
	uint64_t ans = 0;
	ans = K * (K - 1) / 2;
	ans %= MOD;
	ans *= q;
	ans %= MOD;
	ans += p * K;
	ans %= MOD;
	cout << ans % MOD << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;
int a,b,c,d,ans;
string s,s1,s2;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    cout << a*b;
    return 0;
}
 

Measured memory_bytes: 3652