akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

const int N=505,M=1e4+5;

int n,p[M],t;
bool vis[M];
ll a[N][N];

void pre(int N) {
	fo(i,2,N) {
		if (!vis[i]) p[++p[0]]=i;
		fo(j,1,p[0]) {
			int k=i*p[j];if (k>N) break;
			vis[k]=1;if (!(i%p[j])) break;
		}
	}
}

ll lcm(ll a,ll b) {return a/__gcd(a,b)*b;}

int main() {
	scanf("%d",&n);pre(8e3);
	if (n==2) {
		puts("4 7");
		puts("23 10");
		return 0;
	}
	fo(i,0,n-1) fo(j,0,n-1) a[i][j]=1;
	fo(i,0,n-1) fo(j,0,n-1) if (!((i+j)&1)) a[i][j]=a[i][j]*p[(i+j)/2+1];
	fo(i,0,n-1) fo(j,0,n-1) if (!((i+j)&1)) a[i][j]=a[i][j]*p[(i-j)/2+n/2+n];
	fo(i,0,n-1) fo(j,0,n-1)
		if ((i+j)&1) {
			if (i) a[i][j]=lcm(a[i][j],a[i-1][j]);
			if (j) a[i][j]=lcm(a[i][j],a[i][j-1]);
			if (i+1<n) a[i][j]=lcm(a[i][j],a[i+1][j]);
			if (j+1<n) a[i][j]=lcm(a[i][j],a[i][j+1]);
			a[i][j]++;
		}
	fo(i,0,n-1) {fo(j,0,n-1) printf("%lld ",a[i][j]);puts("");}
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(){
    int n, m, cards[201], i;
    scanf("%d\n%d", &n, &m);
    for (i=0; i<=2*n; i++)
        cards[i] = i;
    while(m--){
        int k, tmp[201];
        scanf("%d", &k);
        if (k == 0){
            for(i=1; i<=n; i++)
                tmp[2*i-1] = cards[i];
            for(; i<=2*n; i++)
                tmp[2*(i-n)] = cards[i];
        } else {
            for (i=1; i<=k; i++)
                tmp[i+2*n-k] = cards[i];
            for ( ; i<=2*n; i++)
                tmp[i-k] = cards[i];
        }
        for (i=1; i<=2*n; i++)
            cards[i] = tmp[i];
    }
    for (i=1; i<=2*n; i++)
        printf("%d\n", cards[i]);
    return 0;
}

Measured memory_bytes: 600
using System;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
            //using (var sr = new InputReader(new StreamReader("input.txt")))
            {
                var task = new Task();
                using (var sw = Console.Out) {
                    //using (var sw = new StreamWriter("output.txt")) {
                    task.Solve(sr, sw);
                    //Console.ReadKey();
                }
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var array = sr.ReadArrayOfInt64();
            var y = array.Skip(1).Sum();
            var x = array[0];
            var min = Math.Abs(x - y);
            for (var i = 1; i < array.Length - 1; i++) {
                var curr = Math.Abs(x - y);
                if (curr < min) {
                    min = curr;
                }
                y -= array[i];
                x += array[i];
            }

            sw.WriteLine(min);
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose) {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

Measured memory_bytes: 33876
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,Q; cin >> N >> Q;
	VV<int> G(N);
	rep(i,N-1){
		int x,y; cin >> x >> y; x--,y--;
		G[x].pb(y);G[y].pb(x);
	}
	V<ll> w(N);
	rep(i,Q){
		int v,x; cin >> v >> x; v--;
		w[v] += x;
	}
	function<void(int,int)> dfs = [&](int v,int p){
		if(p != -1) w[v] += w[p];
		for(int u: G[v]) if(u != p) dfs(u,v);
	};
	dfs(0,-1);
	rep(i,N) cout << w[i] << " ";
	cout << endl;
}


Measured memory_bytes: 27392
n=int(input())
h=list(map(int,input().split()))
def dfs(l,r):
  if l==r:
    return h[l]
  if r<l:
    return 0
  res=10**18
  for i in range(l,r+1):
    res=min(res,h[i])
  for i in range(l,r+1):
    h[i]-=res
  for i in range(l,r+1):
    if h[i]==0:
      return dfs(l,i-1)+dfs(i+1,r)+res
  return 0
print(dfs(0,n-1))

Measured memory_bytes: 3064
//ALDS1_1B
#include <iostream>
#include <algorithm>
using namespace std;

int gcd(int x,int y){
 if(y==0) return x;
 if(x<y) swap(x,y);
 int temp=x%y;
 x=y;
 y=temp;

 return gcd(x,y);
}

int main(){
 int x,y;
 cin>>x>>y;
 int n=gcd(x,y);
 cout<<n<<endl;
 
 return 0;
}

Measured memory_bytes: 1164
u[9];D(s,v){int i,r;if(!s)return!v;if(v<0||v>s*-~s*5)return 0;for(r=i=0;i<=9;++i)!u[i]?u[i]=1,r+=D(s-1,v-i*s),u[i]=0:0;return r;}main(n,v){while(~scanf("%d%d",&n,&v))printf("%d\n",D(n,v));exit(0);}

Measured memory_bytes: 600
import * as fs from 'fs'
const reader = (s: string) => s.split('\n').map(t => parseInt(t, 10))

function Main(input: string) {
  const [a, b, h] = reader(input)
  console.log(((a + b) * h) / 2)
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
        ll N,K,i,j,rDiv,nDiv,numDiv,rIns,nIns,numIns;
        cin >> N >> K;
        vector<vector<ll>> comb(N+1, vector<ll>(N+1));
        comb.at(0).at(0) = 1;
        for(i=1;i<N+1;++i){
                comb.at(i).at(0) = 1;
                for(j=1;j<i;++j){
                        comb.at(i).at(j) = comb.at(i-1).at(j-1)+comb.at(i-1).at(j);
                        comb.at(i).at(j) %= MOD;
                }
                comb.at(i).at(i) = 1;
        }
        for(i=1;i<K+1;++i){
                rDiv = i-1;
                nDiv = K-1;
                numDiv = comb.at(nDiv).at(rDiv);
                rIns = i;
                nIns = N-K+1;
                if(rIns>nIns) numIns = 0;
                else numIns = comb.at(nIns).at(rIns);
                cout << (numDiv*numIns)%MOD << endl;
        }
        return 0;
}

Measured memory_bytes: 34644
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
ll dx[4]={0,-1,0,1};
ll dy[4]={1,0,-1,0};
/****************************/
string s;
ll n,m,k;
ll a[100010];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	rep3(i,-300,301)
	{
		a[i+300]=i*i*i*i*i;
	}
	rep(i,601)
	{
		rep(j,601)
		{
			if(a[i]-a[j]==n)
			{
				cout<<i-300<<" "<<j-300;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3616
# coding: utf-8
# Your code here!
N=int(input())
a=list(map(int,input().split()))
A=0
B=0


a=sorted(a,reverse=True)

for i in range(len(a)):
    if i%2==0:
        A+=a[i]
    else:
        B+=a[i]
    
print(A-B)
    
    




Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int n, m;
    cin >> n >> m;
    vector<modint> x(n), y(m);
    for(int i = 0; i < n; ++i)  cin >> x[i];
    for(int i = 0; i < m; ++i)  cin >> y[i];
    modint X, Y;
    for(int k = 0; k < n; ++k){
        X += x[k] * k - x[k] * (n - k - 1);
    }
    for(int k = 0; k < m; ++k){
        Y += y[k] * k - y[k] * (m - k - 1);
    }
    modint ans = X * Y;
    cout << ans << endl;
}

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

int main() {
  int N;
  long K;
  cin >> N >> K;
  vector<ll> A(N), F(N);
  rep(i, N)  cin >> A.at(i);
  rep(i, N)  cin >> F.at(i);
  sort(A.begin(), A.end());
  sort(F.begin(), F.end());
  reverse(F.begin(), F.end());
  ll ng = -1 , ok = A.at(N - 1) * F.at(0);
  while ( abs(ok-ng) > 1 ) {
    ll mid = ng + (ok - ng) / 2;
    ll count = 0;
    rep(i, N) {
      count += max((ll)0, (A.at(i) * F.at(i) - mid + F.at(i) - 1) / F.at(i));
    }
    if (count <= K)  ok = mid;
    else  ng = mid;
  }
  cout << ok << endl;
}

Measured memory_bytes: 3456
#include <stdio.h>
#define MAX 103
int main(){
  int ho,cin,i,j,ku,ver,ru,chi,ko,ri;
  int abc[MAX][MAX]={};
  scanf("%d",&ko);
  for(i=1;i<=ko;i++){
    scanf("%d%d",&chi,&ru);
    for(j=1;j<=ru;j++){
      scanf("%d",&ri);
      abc[chi][ri]=1;
    }
  }
  for(ho=1;ho<=ko;ho++){
    for(ver=1;ver<=ko;ver++){
      printf("%d",abc[ho][ver]);
      if(ver!=ko){
	printf(" ");
      }	
    }
    printf("\n");
  }
  return 0;
}

  
      



Measured memory_bytes: 2148
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstdlib>
#include <clocale>
#include<cmath>
#include<sstream>
#include<set>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
const int MX=3e5+10;
typedef unsigned long long ull;
typedef pair<int ,int> p; 
int main(){
	int n,num[MX];
	cin>>n;
	for(int i=0;i<3*n;i++)
		cin>>num[i];
	sort(num,num+3*n);
	ull ans=0;
	//for(int i=0;i<n/3;i++)
		for(int j=3*n-1;j>n;j-=2){
			ans+=num[j-1];	
		}
	cout<<ans<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 1656
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

signed main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int E = lcm(C, D);

    int ret1 = B / C + B / D - B / E;
    int ret2 = (A - 1) / C + (A - 1) / D - (A - 1) / E;

    int ret3 = ret1 - ret2;
    cout << (B - A + 1) - ret3 << endl;
    return 0;
}

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


int main(){
    int n,k; cin >> n >> k;
    int h[n]; rep(i,n) cin >> h[i];
    int ans= 0;
    rep(i,n) if(h[i] >= k) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 640
from math import cos, sqrt, radians
a, b, h, m = list(map(int, input().split()))
# 角度を求める
a_angle = 30*h + m/2
b_angle = 6*m
angle=a_angle-b_angle

As = a**2
Bs = b**2
D = 2*a*b

result = sqrt(As + Bs - D*cos(radians(angle)))
print(result)

Measured memory_bytes: 9528
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int h, w; cin >> h >> w;
  vector<vector<char> > s(h, vector<char>(w));
  REP(i, h) {
    REP(j, w) {
      cin >> s[i][j];
    }
  }

  vector<vector<char> > rot(h+w-1, vector<char>(h+w-1, '.'));
  vector<vector<int> > row(h+w-1, vector<int>(h+w-1, 0));
  vector<vector<int> > column(h+w-1, vector<int>(h+w-1, 0));
  REP(i, h) {
    REP(j, w) {
      rot[i+j][j-i+h-1] = s[i][j];
    }
  }

  REP(i, h+w-1) {
    if (rot[i][0] == '#') row[i][0] = 1;
  }
  REP(i, h+w-1) {
    FOR(j, 1, h+w-1) {
      if (rot[i][j] == '#') ++row[i][j];
      row[i][j] += row[i][j-1];
    }
  }
  REP(i, h+w-1) {
    if (rot[0][i] == '#') column[0][i] = 1;
  }
  FOR(i, 1, h+w-1) {
    REP(j, h+w-1) {
      if (rot[i][j] == '#') ++column[i][j];
      column[i][j] += column[i-1][j];
    }
  }

  int ans = 0, firstj = -1;
  bool go_second = false;
  REP(i, h+w-1) {
    while (true) {
      for (int j = firstj+1; j < h+w-1; ++j) {
        if (rot[i][j] == '#') {
          if (go_second) {
            if (i-(j-firstj) >= 0) {
              if (firstj == 0) {
                ans += row[i-(j-firstj)][j];
              } else {
                ans += row[i-(j-firstj)][j] - row[i-(j-firstj)][firstj-1];
              }
            }
            if (i+(j-firstj) < h+w-1) {
              if (firstj == 0) {
                ans += row[i+(j-firstj)][j];
              } else {
                ans += row[i+(j-firstj)][j] - row[i+(j-firstj)][firstj-1];
              }
            }
          } else {
            firstj = j;
            go_second = true;
          }
        }
      }
      if (!go_second) break;
      go_second = false;
    }
    firstj = -1;
  }
  int firsti = -1;
  REP(j, h+w-1) {
    while (true) {
      for (int i = firsti+1; i < h+w-1; ++i) {
        if (rot[i][j] == '#') {
          if (go_second) {
            if (j-(i-firsti) >= 0) ans += column[i-1][j-(i-firsti)] - column[firsti][j-(i-firsti)];
            if (j+(i-firsti) < h+w-1) ans += column[i-1][j+(i-firsti)] - column[firsti][j+(i-firsti)];
          } else {
            firsti = i;
            go_second = true;
          }
        }
      }
      if (!go_second) break;
      go_second = false;
    }
    firsti = -1;
  }

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


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

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

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll MOD = 2;

ll choose(ll n, ll k) {
	return ((k & n) == k) ? 1 : 0;
}

int N;
int getPar(vi a) {
	int ans = 0;
	F0R(i, N) {
		ans += choose(N - 1, i) * (a[i] % MOD) % MOD;
		ans %= MOD;
	}
	return ans;
}

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

	cin >> N;
	
	vi arr (N);
	F0R(i, N) {
		char c; cin >> c;
		arr[i] = c - '0';
	}
	F0R(i, N) arr[i]--;
	if (getPar(arr) == 1) {
		print(1);
	} else {
		bool containsOne = false;
		F0R(i, N) if (arr[i] == 1) containsOne = true;
		if (containsOne) {
			print(0);
		} else {
			F0R(i, N) arr[i] /= 2;
			print(getPar(arr) * 2);
		}
	}
}

Measured memory_bytes: 8124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int H, W, K;
    cin >> H >> W >> K;
    string field[820];
    int sh, sw;
    for(int i = 1; i <= H; i++){
        cin >> field[i];
        field[i] = "." + field[i];
        for(int j = 1; j <= W; j++){
            if(field[i][j] == 'S'){
                sh = i;
                sw = j;
            }
        }
    }
    int map1[820][820];
    int map2[820][820];
    for(int i = 0; i <= 800; i++){
        for(int j = 0; j <= 800; j++){
            map1[i][j] = INF;
            map2[i][j] = INF;
        }
    }
    map1[sh][sw] = 0;
    int dh[4] = {1, -1, 0, 0};
    int dw[4] = {0, 0, 1, -1};
    queue<i_i> que;
    que.push({sh, sw});
    while(!que.empty()){
        i_i out = que.front();
        que.pop();
        int h = out.first;
        int w = out.second;
        if((h == 1) || (h == H) || (w == 1) || (w == W)){
            cout << 1 << endl;
            return 0;
        }
        if(map1[h][w] >= K) continue;
        for(int k = 0; k < 4; k++){
            int newh = h + dh[k];
            int neww = w + dw[k];
            if((neww <= 0) || (neww > W)) continue;
            if((newh <= 0) || (newh > H)) continue;
            if(field[newh][neww] == '#') continue;
            if(map1[newh][neww] <= map1[h][w] + 1) continue;
            map1[newh][neww] = map1[h][w] + 1;
            que.push({newh, neww});
        }
    }
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            //cout << map1[i][j] << " ";
            if(map1[i][j] <= K){
                que.push({i, j});
                map2[i][j] = K;
            }
        }
        //cout << endl;
    }
    while(!que.empty()){
        i_i out = que.front();
        que.pop();
        int h = out.first;
        int w = out.second;
        if((h == 1) || (h == H) || (w == 1) || (w == W)){
            cout << (map2[h][w] + K - 1) / K << endl;
            return 0;
        }
        for(int k = 0; k < 4; k++){
            int newh = h + dh[k];
            int neww = w + dw[k];
            if((neww <= 0) || (neww > W)) continue;
            if((newh <= 0) || (newh > H)) continue;
            if(map2[newh][neww] <= map2[h][w] + 1) continue;
            map2[newh][neww] = map2[h][w] + 1;
            que.push({newh, neww});
        }
    }
    return 0;
}


Measured memory_bytes: 6400
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, a[4];
  char s[10];
  scanf("%s", s);
  for(i = 0; i < 4; ++i) a[i] = s[i] - '0';
  for(i = 0; i < 8; ++i) {
    ll tmp = a[0];
    if(i & 1) tmp += a[1];
    else tmp -= a[1];
    if(i & 2) tmp += a[2];
    else tmp -= a[2];
    if(i & 4) tmp += a[3];
    else tmp -= a[3];
    if(tmp == 7) break;
  }
  ll t = i;
  printf("%lld", a[0]);
  for(i = 1; i < 4; ++i) {
    printf("%c%lld", ((t >> (i - 1) & 1) ? '+' : '-'), a[i]);
  }
  printf("=7");
  return 0;
}

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

int main(){
	int n,m; cin >> n >> m;
	vector<vector<int>> s(m);
	rep(i,m){
		int k; cin >> k;
		rep(j,k){
			int t; cin >> t;
			t--;
			s[i].push_back(t);
		}
	}
	vector<int> p(m);
	rep(i,m){
		cin >> p[i];
	}
	
	int ans = 0;
	
	rep(bit, 1<<n){
		bool ok = true;
		rep(i,m){
			int count = 0;
			rep(j,s[i].size()){
				if(bit & (1 << s[i][j])) count++;
			}
			if(count % 2 != p[i]) ok = false;
		}
		if(ok) ans++;
	}
	
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
class Solve:
    def __init__(self):
        self.N, self.K = [int(i) for i in input().split()]
        self.W = [int(input()) for i in range(self.N)]

        self.a = max(self.W)-1  # >= 0; False
        self.b = sum(self.W)  # <= 10**9; True

    def check(self, P):
        k, p, W = 1, P, [w for w in self.W]
        for w in W:
            if p >= w:
                p -= w
            elif P >= w and k < self.K:
                k, p = k+1, P-w
            else:
                return False
        return True

    def solve(self):
        while self.b - self.a > 1:
            m = (self.a + self.b) // 2
            if self.check(m):
                self.b = m
            else:
                self.a = m
        return self.b

print(Solve().solve())

Measured memory_bytes: 12376
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main (){
    int n;
    cin >> n;
    int b;
    int a[n+1] = {0};
    rep(i,n-1){
        cin >> b;
        a[b]++;
    }
    for(int i =1;i<=n;i++){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4348
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,x;
    cin >> a >> b >> x;
    if(x>=a&&x<=a+b){
        puts("YES");
    }else{
        puts("NO");
    }

    return 0;
}

Measured memory_bytes: 256
#include "iostream"
using namespace std;

int main() {
  int n;
  cin >> n;
  int ones = n % 10;
  string ans;
  switch (ones) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      ans = "hon";
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      ans = "pon";
      break;
    case 3:
      ans = "bon";
      break;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define all(c) (c).begin(), (c).end()
const int M = 100000;

template<typename T> inline T sqr(T x){return x * x;}

vector<int> ps;

void sieve(vector<int>& v, int n){
    v.assign(n, 0); iota(all(v), 2);
    for(auto div=v.begin(); sqr(*div)<=v.back(); ++div){
        v.erase(remove_if(div+1, v.end(), [&](int x){return x % *div == 0;}), v.end());
    }
}

ostream& operator<<(ostream& os, const pair<int, int>& p){
    return os << p.first << " " << p.second;
}

pair<int, int> solve(int m, int a, int b){
    int p = 2, q = 2;
    for(int i=0; i<(int)ps.size() && ps[i]<m; ++i){
        for(int j=i; j<(int)ps.size() && ps[i]*ps[j]<=m; ++j){
            if(p*q < ps[i]*ps[j] && a*ps[j] <= b*ps[i])p = ps[i], q = ps[j];
        }
    }
    return {p, q};
}

int main(){
    sieve(ps, M/2);
    int m, a, b;
    while(cin >> m >> a >> b, m|a|b)cout << solve(m, a, b) << '\n';
    return 0;
}

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

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a>12)
        printf("%d\n",b);
    else if(a<6)
        printf("0\n");
    else
        printf("%d\n",b/2);
    return 0;
}


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

int main() {
  int k;
  cin >> k;
  int a = 0;
  for(int i = 0; i < 1000000; i++) {
    a = (a*10 + 7) % k;
    if(a == 0) {
      cout << i+1 << endl;
      return 0;

    }
  }
  
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3608
S = input()

a = [0,0]
ans = 0
for i in range(len(S)):
  if a[1] == 0 and S[i] == '0':
    a[0] += 1
  elif a[0] == 0 and S[i] == '1':
    a[1] += 1
  elif a[1] > 0 and S[i] == '0':
    ans += 2
    a[1] -= 1
  else:
    ans += 2
    a[0] -= 1
    
print(ans)
  

Measured memory_bytes: 3188
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    ans = 0
    for i in range(1,N+1):
        if len(str(i))%2 == 1:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 39792
n, m = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]
x.sort()
x_diff = []
for i in range(m - 1):
  x_diff.append(x[i + 1] - x[i])
x_diff.sort()
move = 0
for i in range(m - n):
  move += x_diff[i]
print(move)


Measured memory_bytes: 13832
n = gets.to_i
h = gets.split.map(&:to_i)

ans = 0
h.each_with_index do |v,i|
  if i == 0 then
    ans += 1
    next
  end

  flag = false
  (0..i).each do |n|
    if h[n] > v then
      flag = true
    end
  end
  if flag then
    next
  else
    ans += 1
  end
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define repp(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define popcnt __builtin_popcount
#define all(v) v.begin(),v.end()
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
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;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int main(){
    int n,m; cin >> n >> m;
    vector<pint> a(n);
    rep(i,n) cin >> a[i].first >> a[i].second;
    sort(all(a));
    
    unsigned long long ans = 0;
    int cnt = 0;
    int index;
    
    for(int i = 0; i < n; ++i){
        ans += (ll)a[i].second * (ll)a[i].first;
        cnt += a[i].second;
        if(cnt > m){
            index = i;
            break;
        }
    }
    
    if(cnt == m){
        cout << ans << endl;
        return 0;
    }
    else{
        for(int i = 1; cnt > m; ++i){
            ans -= a[index].first;
            --cnt;
        }
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int INF = 1100100100;

int main(){
    int n, x, y;
    cin >> n >> x >> y;

    vector<int> res(n-1, 0);
    for(int i = 0; i < n-1; i++){
        vector<bool> visited(n, false);
        vector<int> memo(n, INF);
        memo[i] = 0;
        visited[i] = true;
        queue<int> Q;
        Q.push(i);
        while(Q.size()){
            int cur = Q.front();
            Q.pop();
            if(cur+1 == x && !visited[y-1]){
                Q.push(y-1);
                visited[y-1] = true;
                //memo[y-1] = min(memo[y-1], memo[cur]+1);
                if(memo[cur]+1 < memo[y-1]) memo[y-1] = memo[cur]+1;
            }

            if(cur+1 < n && !visited[cur+1]){
                Q.push(cur+1);
                visited[cur+1] = true;
                //memo[cur+1] = min(memo[cur+1], memo[cur]+1);
                if(memo[cur]+1 < memo[cur+1]) memo[cur+1] = memo[cur]+1;
            }

            if(cur-1 >= 0 && !visited[cur-1]){
                Q.push(cur-1);
                visited[cur-1] = true;
                //memo[cur-1] = min(memo[cur-1], memo[cur]+1);
                if(memo[cur]+1 < memo[cur-1]) memo[cur-1] = memo[cur]+1;
            }
            
        }
        
        for(int j = i+1; j < n; j++){
            if(memo[j]-1 >= 0) res[memo[j]-1]++;
        }
        
    }
    for(int i = 0; i < n-1; i++) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#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 ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	ll ans = 0;
	FOR(i, 1, N + 1) {
		for (int j = i; j <= N; j += i) {
			ans += (ll)j;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n;
  ll ans = 1;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, a, b, c, d, r;
  cin >> n;
  
  a = n / 1000;
  r = n % 1000;
  b = r / 100;
  r = r % 100;
  c = r / 10;
  r = r % 10;
  d = r;
  
  if(a == b && b == c){
    cout << "Yes" << endl;
  }
  else if(b == c && c == d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main() {
  int N, M;
  
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }
  
  int MAX = -M;
  for (int i = 0; i < N; i++) {
    int temp = 0;
    for (int j = i; j < N; j++) {
      if (s.at(i) == s.at(j)) temp++;
    }
    for (int j = 0; j < M; j++) {
      if (s.at(i) == t.at(j)) temp--;
    }
    if (temp > MAX) MAX = temp;
  }
  if (MAX < 0) MAX = 0;
  cout << MAX;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll mod(ll a, ll b) { return (a%b+b)%b; }
ll gcd(ll x, ll y) { return __gcd(x, y); }
ll lcm(ll x, ll y) { return x * 1ll * y / gcd(x, y); }
 
 
const ll MAXN = 1e18;
const ll SIZE = 2e5 + 5;
const ll MOD  = 1e9 + 7;


int n, m, dp[SIZE], res[SIZE];
vector<int> adj[SIZE];
bool used[SIZE];

void bfs () {
	queue<int> q;
	used[1] = true;
	q.push(1);

	while (!q.empty()) {
		int from = q.front();
		q.pop();
		
		for (int to : adj[from]) {
			if (used[to])
				continue;
			used[to] = true;
			q.push(to);
			dp[to] = dp[from] + 1;
		}
	}
}


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

	forn (i, m) {
		int u, v;
		cin >> u >> v;

		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	bfs ();

	forn (i, n) {
		if (!used[i]) {
			cout << "No";
			return 0;
		}
		if (dp[i]) {
			for (int v : adj[i]) {
				if (dp[v] + 1 == dp[i]) {
					res[i] = v;
					break;
				}
			}
		}
	}

	cout << "Yes" << endl;
	for (int i = 2; i <= n; i++)
		cout << res[i] << endl;
	


	return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define all(s)  s.begin(),s.end()
#define vi vector<int>
int main(){
    int n;
    cin>>n;
    vi A={111,222,333,444,555,666,777,888,999};
    cout<<*lower_bound(all(A),n);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 201

void calc(int n,int q){
  int cc[SIZE] = {};
  int m,d;
  
  for(int i=0;i<n;i++){
    scanf("%d",&m);
    for(int j=0;j<m;j++){
      scanf("%d",&d);

      cc[d]++;
    }
  }

  int ans = 0,mem = q-1;
  
  for(int i=1;i<=100;i++){
    if(cc[i] > mem){
      ans = i;
      mem = cc[i];
    }
  }
  
  printf("%d\n",ans);
}

int main(){
  int n,q;
  
  while(1){
    scanf("%d%d",&n,&q);
    if(n==0) break;
    calc(n,q);
  }
  
  return 0;
}

Measured memory_bytes: 1188
A, B, C = map(int, input().split())
if A == B == C:
    print(0 if A%2 else -1)
else:
    cnt = 0
    while A%2==0 and B%2==0 and C%2==0:
        A, B, C = (B+C)//2, (C+A)//2, (A+B)//2
        cnt += 1
    print(cnt)


Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    ll x,y,z,k;
    cin>>x>>y>>z>>k;
    vll a(x),b(y),c(z);
    rep(i,x)cin>>a[i];
    rep(i,y)cin>>b[i];
    rep(i,z)cin>>c[i];
    vll ab;
    rep(i,x)rep(j,y)ab.pb(a[i]+b[j]);
    Rort(ab);
    Rort(c);
    vll ans;
    rep(i,min(k,(ll)ab.size())){
        rep(j,min(k,(ll)c.size())){
            ans.pb(ab[i]+c[j]);
        }
    }
    Rort(ans);
    rep(i,k)fin(ans[i]);
}



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

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

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

  int res = ~(1 << 31);
  for (int x = -100; x <= 100; ++x) {
    int cost = 0;
    for (int y: arr) cost += static_cast<int>(pow(abs(x - y), 2));
    res = min(res, cost);
  }

  cout << res << '\n';
}


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

int main() {
    int N;
    cin >> N;
    
    int i = 0;
    int dekai = 0;
    int sonota = 0;
    
    while(i < N){
        i++;
        int L;
        cin >> L;
        sonota = sonota + L;
        
        if(dekai < L){
            dekai = L;
        }
    }
    
    sonota = sonota - dekai;
    
    if(sonota > dekai){
        cout << "Yes" << endl;
    }
    
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int X = 0;
        for (int i=0; i<2; i++) {
            if (A > B) {
                X += A;
                A--;
            } else {
                X += B;
                B--;
            }
        }
        System.out.println(X);
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;int max_p=-1, ans=0;
  for(int i=0;i<n;i++){
    int p;cin>>p;
    max_p=max(max_p, p);
    ans+=p;
  }
  cout << ans - max_p/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
    ll n,m;
    cin >> n>> m;
    ll ans;
    if(n>=m/2){
        ans=m/2;
    }
    else{
        ans=n;
        ans+=(m-2*n)/4;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int main(void) {
    int num, k;
    get_int2(&num, &k);
    int64_t ans = 0;
    int num_k = num/k;
    ans += (int64_t)num_k*num_k*num_k;
    if(!(k%2)) {
        int num_k = (num+k/2)/k;
        ans += (int64_t)num_k*num_k*num_k;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string S;
    cin >> S;
    
    vi A(2020,0),B(2020,0);
    
    
    int ans = 0;
    int N = int(S.length());
    rep(i,N){
        int a = int(S[i]-'0');
        
        A[a]++;
        rep(j,2019){
            
            if(B[j] == 0) continue;
            A[(j*10+a)%2019] += B[j];
            if((j*10+a)%2019 == 0) ans += B[j];
            
        }
        
        
        B = A;
        A = vi(2020,0);
    }

    cout << ans << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 3680
num = gets.to_s.chomp
sum = 0
j = 0
num.chars do |i|
  if i == 9
    sum += 9
    j += 1
  else
    sum += i.to_i - 1
    j += 1
    break
  end
end
sum += ( num.length - j ) * 9
if num.length == 1
  p num.to_i
elsif num[j..-1].length < (num[j..-1].to_i + 1).to_s.length
  p sum + 1
else
  p sum
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int n;
ll dp[405][405],a[405];
ll func(int i,int j){
    if(i==j)
        return 0;

    //cout<<i<<" "<<j<<endl;
    if(dp[i][j]!=-1)
        return dp[i][j];

    ll sum=0;
    for(int k=i;k<=j;k++)
        sum+=a[k];

    ll ans=1e18;
    for(int k=i;k<j;k++){
        ans=min(ans,func(i,k)+func(k+1,j)+sum);
    }
    //cout<<i<<" "<<j<<" "<<ans<<endl;
    return dp[i][j]=ans;
}
int main(){
    cin>>n;

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

    memset(dp,-1,sizeof dp);

    cout<<func(0,n-1);

}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(cin>>s){
    for(int i=0;i<s.size();i++){
      if(s[i]=='@'){
        for(int j=0;j<s[i+1]-'0';j++)
          cout<<s[i+2];
        i+=2;
      }
      else cout<<s[i];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3048