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

long long int N, A, B, h[114514], s, i, lef, rig, mid;

bool chck(long long int kai){
    long long int a = 0;
    //cout << kai;
    for(int j = 0; j < N; ++j){
        a += (h[j] - B * kai > 0) ? (h[j] - B * kai + A - 1) / A : 0;
    }
    //cout << " : " << a << endl;
    return a <= kai;
}

int main(){
    scanf("%lld%lld%lld", &N, &A, &B);
    A -= B;
    for(; i < N; ++i){
        scanf("%lld", h + i);
        s += h[i];
    }
    //cout << s << " " << A << " " << B << endl;
    lef = s / (A + B * N) - 1;
    rig = s / B + 2;
    while(lef < rig){
        //cout << lef << " " << rig << endl;
        mid = (lef + rig) / 2;
        if(chck(mid))rig = mid;
        else lef = mid + 1;
    }
    cout << (chck(rig) ? rig : rig + 1) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(int argc,char* argv[]){
  int i,j,temp;
  int nums[5];
  scanf("%d %d %d %d %d",&nums[0],&nums[1],&nums[2],&nums[3],&nums[4]);
  
  for(i = 0;i < 5;++i){
    for(j = 5;j > i;--j){
      if(nums[j] > nums[j - 1]){
	temp = nums[j];
	nums[j] = nums[j-1];
	nums[j-1] = temp;
      }
    }
  }
  
  printf("%d %d %d %d %d\n",nums[0],nums[1],nums[2],nums[3],nums[4]);
  
  return 0;
  
}

Measured memory_bytes: 0
import java.util.Scanner;
//import java.util.ArrayList;
public class Main{

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

for(;;){
int h = sc.nextInt();
int w = sc.nextInt();


if((h == 0) && (w == 0)) break;

  for(int i = 0; i<h ; i++){
    for(int p = 0; p<w ; p++){
    System.out.print("#");
  }
  System.out.println("");
  }
System.out.println("");
}//for

}//main

}//class



Measured memory_bytes: 33120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

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

    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    int num = 0;
    rep(i,n){
        if(a[i+1]-a[i] != 0){
            ans += (i+1-num)/2;
            num = i + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

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

    int N;
    cin >> N;
    for(int i=111; i<=999; i+=111){
        if(i >= N){
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}


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


int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> x(N);
  for (int i=0; i<N; i++) {
    cin >> x.at(i);
  }
  
  int dist = 0;
  for (auto y : x) {
    if (abs(y-K) >= abs(y)) dist += abs(y)*2;
    else dist += abs(y-K)*2;
  }
  
  cout << dist << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdbool.h>

bool map[100][100];
int n,m,ans;
int d[4]={0,1,0,-1};

void solve(int x,int y,int n);

int main(void){
  int i,j;
  while(1){
    scanf("%d %d",&m,&n);
    if(m+n==0)break;
    ans = 0;
    for(i=0;i<=n+1;i++)for(j=0;j<=m+1;j++)map[i][j]=0;
    for(i=1;i<=n;i++)for(j=1;j<=m;j++)scanf("%d",&map[i][j]);
    for(i=1;i<=n;i++)for(j=1;j<=m;j++)if(map[i][j])solve(i,j,1);
    printf("%d\n",ans);
  }
  return 0;
}

void solve(int x, int y,int n){
  bool ch = 0;
  int i,nextx,nexty;
  map[x][y]=0;
  for(i=0;i<4;i++){
    nextx = x+d[i];
    nexty = y+d[i^1];
    if(map[nextx][nexty])solve(nextx,nexty,n+1);
  }
  if(n>ans)ans = n;
  map[x][y]=1;
}



Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

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

    int a,b;
    cin >> a >> b;
    if(a <= 0 && b >= 0) cout << "Zero";
    else if(a >0) cout <<"Positive";
    else if(b < 0){
        if((a-b)%2 == 0) cout << "Negative";
        else cout << "Positive";
    }
    return 0;
}









Measured memory_bytes: 3560
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Program{
  public static void Main(){
	string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int X = int.Parse(input[1]);
    int Y = int.Parse(input[2]);
    
    List<int> len = new List<int>();
    for (int k = 1; k < N; k++){
      len.Add(0);
    }
    
    for (int i = 1; i < N; i++){
      for (int j = i+1; j <= N; j++){
        int a = j - i;
        int b = System.Math.Abs(X-i) + System.Math.Abs(Y-j) + 1;
        if (a < b){
          len[a-1]++;
        }
        else
        {
          len[b-1]++;
        }
      }
    }
    
    for (int k = 1; k < N; k++){
      Console.WriteLine(len[k-1]);
    }
  }
}

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

ll modpow(ll a, ll b){
    ll x=1, y=a; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) ; // multiplying with base
        }
        y = (y*y) ; // squaring the base
        b /= 2;
    }
    return x;
}
 
 
int main(){
 
	
	
	int n ; cin>>n;
	vector<int>q(n);
	vector<int>t(n);
	for(int i = 0 ; i< n ; i++){
		cin>>q[i];
		t[i]=q[i];
	}

	sort(q.begin(),q.end(),greater<int>());

	int x = q[0] ; int  y = q[1];

	for(int i = 0 ; i< n ; i++){
		if(t[i]==x){
			cout<<y<<endl;
		}
		else{
			cout<<x<<endl;
		}
	}
	int l  ; cin>>l;

	
	
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 1e9;
  for (int i = 0; i < n; i++) {
    int x = a[i];
    vector<int> subs;
    vector<int> full;
    for (int j = 0; j < n; j++) {
      if (a[j] >= x) {
	subs.emplace_back(a[j]);
      }
      else {
	if (subs.size() >= k) {
	  sort(subs.begin(), subs.end());
	  for (int l = 0; l < subs.size() - k + 1; l++) {
	    full.emplace_back(subs[l]);
	  }
	}
	subs.clear();
      }
    }
    if (subs.size() >= k) {
      sort(subs.begin(), subs.end());
      for (int l = 0; l < subs.size() - k + 1; l++) {
	full.emplace_back(subs[l]);
      }
    }
    sort(full.begin(), full.end());
    if (full.size() >= q) {
      ans = min(ans, full[q - 1] - x);
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    println(6 - a - b);
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string r;
  cin >> r;
  if (r.at(0) == '7' || r.at(1) == '7'|| r.at(2) == '7') {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

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

    cout << (n - 1) * (m - 1) << endl;

    return 0;
}

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

using namespace std;

long long N, M, sol;

int main() {
    cin >> N >> M;

    if (M - 2LL * N <= 0) {
        cout << M / 2LL << '\n';
        return 0;
    }

    sol += N;
    M -= 2LL * N;

    sol += M / 4LL;
    cout << sol << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int h,w,i,j;
    while(1){
        scanf("%d %d",&h,&w);
        if(h==0 && w==0)
        break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++)
            printf("#");
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <vector>

using namespace std;
using LL = long long;
using ULL = unsigned long long;
using pii = pair<LL, LL>;

#define div divdiv

#define X first
#define Y second

// DBG =======================================================================
template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
  out << "{";
  bool f = false;
  for (const auto& x : v) {
    if (f)
      out << ", ";
    f = true;
    out << x;
  }

  return out << "}";
}

template<typename T>
void dbg_p(int line, const char* name, T x) {
  cerr << "line " << line << ": " << name << " = " << x << endl;
}

#define DBG(x) { dbg_p(__LINE__, #x, x); }
// DBG =======================================================================

//const int N = 220000;
//const ULL p = 123789
//ULL hash[N];
string s;

LL solve() {
  const int n = s.size();
  map<char, LL> cnt;
  for (char c : s)
    cnt[c]++;
  LL res = 0;
  for (auto p : cnt)
    res += p.Y * (n - p.Y);
  res /= 2;
  return res + 1;
}

int main() {
  cin >> s;
  cout << solve() << endl;
}

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

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

 
int main(){

	lli n;
	map<lli,lli> a;

	cin>>n;
	REP(i,n){
		lli tmp;
		cin>>tmp;
		if(a[tmp]==0){
			a[tmp]=1;
		}
		else{
			a[tmp]=0;
		}
	}

	lli cnt=0;
	for(auto itr = a.begin();itr != a.end();itr++){
		if((*itr).second){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

int main()
{
    int n, r;

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

    if(n>=10){
        printf("%d",r);
    }else{
        r = r +(100*(10-n));
        printf("%d", r);
    }
    return 0;
}

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

typedef long long ll;
const int N = 1e5+3;
int n,m;
int vis[N];
int penl[N];
int main(){
	while(~scanf("%d %d", &n, &m)){
		int ans=0,pen=0;
		memset(vis,0,sizeof(vis));
		memset(penl,0,sizeof(penl));
		while(m--){
			int id;
			string s;
			scanf("%d", &id);
			cin>>s;
			if(s=="AC"){
				if(!vis[id]){
					ans++;
					pen+=penl[id];
					vis[id]=1;
				}
			}else{
				if(!vis[id]){
					penl[id]++;
				}
			}
		}
		printf("%d %d\n", ans, pen);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	int d, n;
	cin >> d >> n;
	if (n == 100) {
		n++;
	}

	int ans = 0;
	if (d == 0) {
		ans = n;
	} else {
		ans = (int) pow(100, d) * n;
	}

	cout << ans << 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 RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<LL, LL> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 90;

vector<PII> A[MAX];

LL F[MAX];

LL solve(LL x, LL y, int level)
{
	if (x > y) swap(x, y);
	if (level <= 1) return (x * 2 + y - 2) % MOD;
	int ind = level - 1;

	LL res = 0;

	FOR (i, 0, SZ(A[ind]))
	{
		LL f = A[ind][i].first;
		LL s = A[ind][i].second;

		if (s <= y && s + f <= x)
		{
			LL diff = x - f;
			LL cnt = diff / s;
			res += cnt;
			res %= MOD;
		}

		if (s <= x && s + f <= y)
		{
			LL diff = y - f;
			LL cnt = diff / s;
			res += cnt;

			res %= MOD;
		}
	}
	return res;
}

int getLevel(LL x, LL y)
{
	FOR (i, 2, MAX)
	{
		if (F[i] <= x && F[i+1] <= y) continue;
		if (F[i] <= y && F[i+1] <= x) continue;
		return i - 1;
	}
	throw -1;
}

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

	F[0] = 1;
	F[1] = 1;
	FOR (i, 2, MAX)
	{
		F[i] = F[i-1] + F[i-2];
	}

	A[1].PB(MP(1, 2));
	A[1].PB(MP(1, 3));

	FOR (i, 2, MAX)
	{
		FOR (j, 0, SZ(A[i-1]))
		{
			FOR (k, 1, MAX)
			{
				PII c = A[i-1][j];
				swap(c.first, c.second);
				c.second += c.first * k;
				if (c.first <= F[i + 1] && c.second <= F[i+2]) A[i].PB(c);
				if (c.second > F[i+2]) break;
			}
		}
	}

	int tt;
	scanf("%d", &tt);
	for (;tt;tt--)
	{
		LL x, y;
		scanf("%lld%lld", &x, &y);

		int level = getLevel(x, y);

		LL res = solve(x, y, level);
		printf("%d %lld\n", level, res);
	}


}


Measured memory_bytes: 4096
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
// #include <iostream>
// #include <iomanip>
// #include <sstream>
using namespace std;
// const int dx[] = {0, 1, 0, -1};
// const int dy[] = {1, 0, -1, 0};
// const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
// const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dx[] = {2, 2, -2, -2, 1, 1, -1, -1};
// const int dy[] = {-1, 1, 1, -1, 2, -2, 2, -2};
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define test_ fr(_iii_, 0, 66)pf(">");puts("in")
#define deb(x) fr(_iii_, 0, 66)cerr<<'>';cerr<<#x"="<<x<<"\n"
#define fr(i, a, b) for(int i = a ; i < (int)b ; i++)
#define frr(i, a, b) for(int i = a ; i >= (int)b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false)
#define boost2 cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
int on_bit(int x, int pos) {x |= (1 << pos); return x;}
int off_bit(int x, int pos) {x &= ~(1 << pos); return x;}
bool is_on_bit(int x, int pos) {return ((x & (1 << pos)) != 0);}
int flip_bit(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int on_bit_all(int x, int pos) {x = (1 << pos)-1; return x;}
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}


int main() {
	int n;
	sf("%d",&n);
	if(n==1){
		puts("Hello World");
	}
	else{
		int qwe,asd;
		sf("%d%d",&qwe,&asd);
		pf("%d\n",qwe+asd);
	}
	return 0;
}

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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N; cin >> N;
  int cnt = 0;
  int i = 1;
  for (; i <= N; i++) {
    int p; cin >> p;
    if (p == i) {
      cnt++;
      if (i < N) {
	cin >> p;
	i++;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define H 500000
  
int A[H],n;
 
void maxHeapify(int *A,int i){
 
  int largest,l,r,temp;
 
  l = 2*i;
  r = (2*i)+1;
 
  if(l<=n && A[l]>A[i])
    largest = l;
  else
    largest = i;
 
  if(r<=n && A[r]>A[largest])
    largest = r;
   
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(A,largest);
  }
}
 
void buildMaxHeap(int *A){
 
  int i;
 
  for(i=n/2;i>0;i--){
    maxHeapify(A,i);
  }
}
 
 
int main(void){
  
  int k,p,l,r,i;
 
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
    buildMaxHeap(A);
 
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}
 

Measured memory_bytes: 2552
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		double T = sc.nextDouble();
		double A = sc.nextDouble();
		long ans = 1;
		double H = sc.nextDouble();
		double tmp = T - H * 0.006;
		double tem = Math.abs(A - tmp);
		for(long i = 2; i < N + 1; i++) {
			H = sc.nextDouble();
			tmp = T - H * 0.006;
			if(tem > Math.abs(A - tmp)) {
				tem = Math.abs(A - tmp);
				ans = i;
			}
		}
		System.out.println(ans);

	}

}


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

using namespace std;

int test[16][16];
int pers[16];//0:none 1:hon 2:un
int n, t, p, ans;
bool flag;

bool istrue()
{
	for(int i = 1; i <= n; i ++)
	{
		if(pers[i] == 2) continue;
		for(int j = 0; j < 16; j ++)
		{
			if(test[i][j] != pers[j] && test[i][j] != 0)
				return 0;
		}
	}
	return 1;
}

void dfs(int dep)
{
	if(dep == n + 1)
	{
		int lsans = 0;
		if(istrue())
		{
			for(int i = 1; i <= n; i ++)
				if(pers[i] == 1) lsans ++;
			if(lsans > ans) ans = lsans;
		}
		return;
	}
	pers[dep] = 1;
	dfs(dep + 1);
	pers[dep] = 2;
	dfs(dep + 1);
}

int main()
{
	cin>>n;
	for(int i = 1; i <= n; i ++)
	{
		cin>>t;
		for(int j = 0; j < t; j ++)
		{
			cin>>p;
			cin>>flag;
			if(flag == 1) test[i][p] = 1;
			else test[i][p] = 2;
		}
	}
	dfs(1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e20;

int myd(int x,int y){
    if(x%y==0)return x/y;
    else return x/y+1;
}

signed main(){
    int N;cin>>N;
    vector<int>A(N);
    REP(i,N)cin>>A[i];
    sort(A.begin(),A.end());
    int count=0;
    REP(i,N-1){
        if(A[i]==A[i+1])count++;
    }
    cout<<N-2*myd(count,2)<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll x,y,z,k;
	cin >> x >> y >> z >> k;
	ll a[1010],b[1010],c[1010];
	FOR(i,x)cin >> a[i];
	FOR(i,y)cin >> b[i];
	FOR(i,z)cin >> c[i];
	vector<ll> v,vv;
	FOR(i,x){
		FOR(j,y){
			v.push_back(a[i]+b[j]);
		}
	}
	sort(all(v));
	reverse(all(v));
	FOR(i,min((ll)v.size(),k)){
		FOR(j,z){
			vv.push_back(v[i]+c[j]);
		}
	}
	sort(all(vv));
	reverse(all(vv));
	FOR(i,k){
		cout << vv[i] << endl;
	}
}

Measured memory_bytes: 43108
#include<bits/stdc++.h>
using namespace std;
char s[100];
int l;
int main(){
	cin>>s;l=strlen(s);for (int i=1;i<l;i++)
		if (s[i-1]=='A'&&s[i]=='C'){puts("Yes");return 0;}
	puts("No");
}

Measured memory_bytes: 256
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln "\n"
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
int t,n,m,x,y,d;
string k;
vv64 dp;
int lim;
int main(){
	fastio;
	cin>>k>>d;
	lim=k.size()+2;
	dp.assign(lim,v64(d,0));
	dp[0][0]=1;
	forsn(i,1,lim){
		forn(j,10){
			forn(k,d){
				dp[i][(j+k)%d]+=dp[i-1][k];
				dp[i][(j+k)%d]%=MOD;
			}
		}
	}
	ll ans=0;
	ll req=0;
	reverse(k.begin(),k.end());
	rforn(i,k.size()-1){
		auto in=k[i]-'0';
		forn(j,in){
			ans+= dp[i][(d+req-j)%d];
			ans%=MOD;
		}
		req= (req+d-in)%d;
	}
	if(req!=0) ans=(ans+MOD-1)%MOD;
	cout<< ans<<ln;
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    ll H, A;
    cin >> H >> A;
    cout << (H+A-1) / A << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n;
    short x[101];
    scanf("%d",&n);
    for(int i=0; i<n; i++)scanf("%hd",&x[i]);
    if (n >= 1) printf("%d", x[n - 1]);
    for(int j=n-2; j>=0; j--)printf(" %d",x[j]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 2056
n = int(input())
s = input()

a = [0]*n

for i in range(n):
    if s[i] == 'R':
        a[i] = 0
    if s[i] == 'G':
        a[i] = 1
    if s[i] == 'B':
        a[i] = 2

cnt = [0]*3

for i in range(n):
    cnt[a[i]] += 1

ans = 1

for i in range(3):
    ans *= cnt[i]

for j in range(n):
    for i in range(j):
        k = j + (j-i)
        if k < n:
            
            if a[i] == a[j]:
                continue
            if a[j] == a[k]:
                continue
            if a[k] == a[i]:
                continue
            ans -= 1
print(ans)

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

int main()
{
	string s;
	int q;
	cin >> s >> q;
	int h = 0;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			//reverse(s.begin(), s.end());
			h++;
		}
		else
		{
			int f;
			string c;
			cin >> f >> c;
			if (f == 1) {
				if (h % 2 == 0) {
					s.insert(0, c);
				}
				else
				{
					s += c;
				}
			}
			else
			{
				if (h % 2 == 0) {
					s += c;
				}
				else
				{
					s.insert(0, c);
				}
			}
		}
	}
	if (h % 2 == 1) {
		reverse(s.begin(), s.end());
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 900
/*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<int>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;

int main()
{
    int n;
    scn(n);

    int sum=0;

    int arr[n];

    rep(i,0,n)
    {
        scn(arr[i]);

        sum=sum+arr[i];
    }

    int k1=sum/n,k2=sum/n+1;

    int ans1=0,ans2=0;

    for(int i=0;i<n;i++)
    {
        ans1+=(k1-arr[i])*(k1-arr[i]);
    }

    for(int i=0;i<n;i++)
    {
        ans2+=(k2-arr[i])*(k2-arr[i]);
    }

    cout<<min(ans1,ans2)<<endl;
}



Measured memory_bytes: 3680
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	ll x;
	cin >> x;
	ll a = x / 500;
	ll b = (x % 500) / 5;
	cout << a * 1000 + b * 5 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
#define MAXLEN 20000
 
int garea,gareas[(MAXLEN/2)+1],gcnt;
 
 
int getArea( char *inputs, int start )
{
    int i,j;
    int ravine,water;
    int down;
    
    gareas[gcnt]=water=ravine=down=0;
    for( i=start, j=0; '\0'!=*(inputs+i) &&  j<MAXLEN; i++, j++ ) {
        if( '\\'== *(inputs+i) ) {
            water+=(ravine*2);
            ravine++;
            water++;
        } else if( 0 < ravine && '/' == *(inputs+i) ) {   
            ravine--;
            if( 0 == ravine ) {
                gareas[gcnt]+=water;
                garea+=gareas[gcnt];
                gcnt++;
                return j;
            }           
        } else {
	     	gareas[gcnt]+=ravine;
        }       
    }
 
    return 0;
}
 
void getAreas( char *inputs )
{
    int i,next;
     
    next=0;
    for( i=0; '\0'!=inputs[i]; i++ ) {
        next=getArea( inputs, i );
        i+=next;
    }
 
    return;
}
 
int main( void ) 
{
    char inputs[MAXLEN+1];
    int i;
 
    scanf( "%s", inputs );
    garea=gcnt=0;
    getAreas( inputs );
     
    printf( "%d\n", garea );
    
    if( gcnt ) {
        printf( "%d ", gcnt );
        gcnt--;
        for( i=0; i<=gcnt; i++ ) {
            printf( "%d", gareas[i] );
            if( i < gcnt ) {
                printf( " " );  
            }
        }
        printf( "\n" ); 
    } else {
        printf( "0\n" );
    }
     
    return 0;
}

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

using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  if(s < t)cout<< "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
def dfs(node,paths,dp,vis):
    vis[node]=True
    for i in range(0, len(paths[node])):
        if not vis[paths[node][i]]:
            dfs(paths[node][i],paths,dp,vis)
        dp[node]=max(dp[node],1+dp[paths[node][i]])
n,m=map(int,input().split())
paths=[[] for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    paths[a].append(b)
dp,vis=[0]*(n+1),[False]*(n+1)
for i in range(1,n+1):
    if not vis[i]:
        dfs(i,paths,dp,vis)
print(max(dp))


Measured memory_bytes: 59568
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char const *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, tmp;
	int t, a;
	int ans = 0;
	cin >> n;
	cin >> t;
	cin >> a;

	float diff = 900;

	for (int i = 0; i < n; ++i) {
		cin >> tmp;
		float pt = abs(a - (t - tmp * 0.006));
		if (pt < diff) {
			ans = i + 1;
			diff = pt;
		}
	}


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


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

const int N=100005;

int fst[N],v[N],k[N],a[N],ans=0,tot=0,A,B;
bool u[N],typ[N];

struct Edge{
	int to,nxt;
}e[N*2];

void addedge(int x,int y){
	e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;
}

void dfs(int x,int father){
	u[x]=1;
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;
		if (y!=father){
			if (u[y]){
				A=x;B=y;continue;
			}
			typ[y]=typ[x]^1;
			dfs(y,x);
		}
	}
}

void solve(int x){
	u[x]=0;
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;
		if (u[y]){
			solve(y);
			v[x]+=v[y];
			k[x]+=k[y];
		}
	}
	if (!k[x]) ans+=abs(v[x]);
}
int main(){
	int n,m;
	scanf("%d%d\n",&n,&m);
	for (int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d\n",&x,&y);
		addedge(x,y);
		addedge(y,x);
	}
	dfs(1,0);
	int cnt=0;
	for (int i=1;i<=n;i++) cnt+=(v[i]=typ[i]?1:-1);
	if (n-1==m){
		if (cnt) ans=-1;
			else solve(1);
	}
	else if (typ[A]==typ[B]){
		if (cnt&1) ans=-1;
		else{
			v[A]-=cnt/2;v[B]-=cnt/2;
			ans=abs(cnt/2);
			solve(1);
		}
	}
	else if (cnt) ans=-1;
	else{
		k[A]=1;k[B]=-1;
		solve(1);
		int len=1;a[1]=0;
		for (int i=1;i<=n;i++)
			if (k[i]==1) a[++len]=-v[i];
				else if (k[i]==-1) a[++len]=v[i];
		std::sort(a+1,a+len+1);
		for (int i=1;i<=len;i++)
			ans+=abs(a[i]-a[len/2+1]);
	}
	printf("%d\n",ans);
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    ll a,b,k;

    cin >>a>>b>>k;
    ll ansa=a,ansb=b;


    ansa = max(0LL,a-k);

    if(ansa==0){
        k -= a;
        ansb = max(0LL,b-k);
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ansa << " "<< ansb << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		int min = 10000;
		
		for(int i = 0; i < n; i++)
		{
			
			int a = scan.nextInt();
			int count = 0;
			while(a%2 == 0)
			{
				a = a/2;
				count++;
			}
			if(count < min)min = count;
		}
		System.out.println(min);
		scan.close();
	}
}

Measured memory_bytes: 22740
n,k = map(int,input().split())
s = input()
ls = []

tmp = s[0]
count = 1
for i in range(1,n):
  if s[i] == tmp:
    count += 1
  else:
    tmp = s[i]
    ls.append(count)
    count = 1
ls.append(count)

length = len(ls)
for i in range(k):
  if length==1: break
  tmp = 0
  if length == 2:
    ls = [ls[0]+ls[1]]
    break
  else:
    tmp += ls.pop(0)
    tmp += ls.pop(0)
    ls[0] += tmp
    length -= 2
  
print(n-len(ls))


Measured memory_bytes: 3964
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}

struct edge{int to,cap,rev;};
vector<edge> G[202];
bool used[202];
int dfs(int v,int t,int f){
	if(v==t){return f;}
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		edge &e=G[v][i];
		if(!used[e.to]&&e.cap>0){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
		
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	while(-1){
		for(int i=0;i<202;i++){
			used[i]=0;
		}
		int f=dfs(s,t,mod);
		if(f==0){return flow;}
		flow+=f;
	}
}
void add_edge(int from,int to,int cap){
	edge E;
	E.to=to,E.cap=cap;E.rev=(int)G[to].size();
	G[from].pub(E);
	E.to=from,E.cap=0;E.rev=(int)G[from].size()-1;
	G[to].pub(E);
}
vector<int>primelist;
bool isprime(int it){
	if(it<2){return false;}
	for(int i=0;i<primelist.size();i++){
		int p=primelist[i];
		if(p*p>it){break;}
		if(it%p==0){return false;}
	}
	return true;
}
void primeinit(void){
	for(int i=2;i<3200;i++){//root(1e7)
		if(isprime(i)){primelist.pub(i);}
	}
}

int main(void){
	llint n,i,j,q,ans=0;cin>>n;
	//頂点名
	//0 start
	//1~100 奇数
	//101~200 偶数
	//201 goal
	vector<int>flip;
	primeinit();
	for(i=0;i<n;i++){
		cin>>q;
		if(i==0||flip.back()!=q){flip.pub(q);}
		else{flip.pob();}
		flip.pub(q+1);
	}
	int kif[100]={0};
	int guf[100]={0};
	int kisu=0,gusu=0;
	for(i=0;i<flip.size();i++){
		if(flip[i]%2==1){
			kif[kisu]=flip[i];kisu++;
		}else{
			guf[gusu]=flip[i];gusu++;
		}
	}
	for(i=0;i<kisu;i++){
		for(j=0;j<gusu;j++){
			if(isprime(abs(kif[i]-guf[j]))){
				add_edge(i+1,j+101,1);
			}
		}
	}
	for(i=0;i<kisu;i++){add_edge(0,i+1,1);}
	for(i=0;i<gusu;i++){add_edge(i+101,201,1);}
	int match=max_flow(0,201);
	ans+=match;
	ans+=((kisu-match)/2)*2;
	ans+=((gusu-match)/2)*2;
	if((kisu-match)%2==1){ans+=3;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	int ans = 0;
	for (int a = 1; a <= n; ++a) {
		for (int b = 1; b <= n; ++b) {
			int c = n - a * b;
			if (c < 1) break;
			ans++;
		}
	}
	printf("%d\n", ans);
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	if(a < b){
		cout << "a < b" << endl;
	}
	else if(a > b){
		cout << "a > b" << endl;
	}
	else{
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  x = InputLine.to_i

  p = x / 500

  x = x % 500

  q = x / 5

  puts (p * 1000 + q * 5).to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main(){
    int n, max=0;
    string str;
    map<string, int> map;
    vector<string> v;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> str;
        decltype(map)::iterator it = map.find(str);        
        if(it!=map.end()) it->second+=1;
        else map.insert(make_pair(str, 1));
    }
    decltype(map)::iterator it = map.begin();
    while (it!=map.end())
    {

        if(it->second>max){
            v.clear();
            v.push_back(it->first);
            max=it->second;
        }else if(it->second==max){
            v.push_back(it->first);
        }
        it++;
    }
    sort(v.begin(), v.end());
    for(int i=0;i<v.size();i++){
        cout << v[i] << endl;
    }
    
    return 0;
} 

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int64_t const inf = 1LL<<55;

int64_t a[100001];
int main() {
  int N; cin >> N;
  rep(i, N) cin >> a[i];
  int64_t ans = inf;
  rep(flag, 2) {
    int64_t cand = 0;
    int64_t curr_sum = 0;
    rep (i, N) {
      curr_sum += a[i];
      if ((flag ^ (i % 2)) == 1 && curr_sum <= 0) {
        cand += -curr_sum + 1;
        curr_sum = 1;
      }
      else if ((flag ^ (i % 2)) == 0 && curr_sum >= 0) {
        cand += curr_sum + 1;
        curr_sum = -1;
      }
    }
    ans = min(ans, cand);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = a; i < min(a + k, b + 1); ++i)
        cout << i << '\n';
    for (int i = max(b - k + 1, a + k); i <= b; ++i)
        cout << i << '\n';

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;
template<class T> void add(T &a, T b) { a = (a + b) % MOD; }

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    rep(i, 0, N) cin >> S[i];
    rep(i, 0, M) cin >> T[i];
    vector<vector<long long>> dp(N + 1, vector<long long>(M + 1));
    vector<vector<long long>> sum(N + 1, vector<long long>(M + 1));
    sum[N][M] = 1;
    rep(i, 0, N) rep(j, 0, M) {
        if(S[i] == T[j]) add(dp[i + 1][j + 1], sum[i][j] + 1);
        add(sum[i + 1][j + 1], sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1] + MOD);
    }
    cout << sum[N][M] << endl;
    return 0;
}


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

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            cin >> s.at(i).at(j);
        }
    }

    vector<int> dx = {-1,0,1,0};
    vector<int> dy = {0,-1,0,1};

    bool flg = true;

    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            if(s.at(i).at(j) == '#'){
                int cnt = 0;
                for(int k=0; k<4; ++k){
                    int nx=i+dx.at(k), ny=j+dy.at(k);
                    if(0<=nx && nx<H && 0<=ny && ny<W){
                        if(s.at(nx).at(ny) == '#') cnt++;
                    }
                }
                if(cnt == 0){
                    flg = false;
                    break;
                }
            }
        }
        if(flg == false) break;
    }    
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
vector<pa> v;
int n,a[500010],l[500010],N,s[500010],ans,A,B,r[500010],fa[500010];
void dfs(int x){
	if (l[x]){
		dfs(l[x]);
		dfs(r[x]);
		s[x]=-s[l[x]]+s[r[x]];
		v.pb(mp(s[r[x]],s[l[x]]));
	}
	else{
		s[x]=a[x];
	}
}
int main(){
	cin>>n;
	FOR(i,1,n) getint(a[i]);
	sort(a+1,a+n+1);
	ans=a[n]-a[1];
	N=n+1;
	l[N]=1;
	r[N]=n;
	fa[1]=N;
	fa[n]=N;
	A=1;
	B=n;
	FOR(i,2,n-1){
		if (a[i]<0){
			if (B==l[fa[B]]) l[fa[B]]=++N;
			else r[fa[B]]=++N;
			r[N]=B;
			l[N]=i;
			fa[N]=fa[B];
			fa[B]=fa[i]=N;
			ans-=a[i];
		
		}
		else{
			if (A==r[fa[A]]) r[fa[A]]=++N;
			else l[fa[A]]=++N;
			l[N]=i;
			r[N]=A;
			fa[N]=fa[A];
			fa[i]=fa[A]=N;
			ans+=a[i];
			
		}
	}
	dfs(n+1);
	cout<<ans<<endl;
	FOR(i,0,SZ(v)-1) printf("%d %d\n",v[i].fi,v[i].se);
	return 0;
}

Measured memory_bytes: 12916
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)



int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size(), ans = 0;
	rep(i, n) {
		if (s[i] != t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}//かいとうみた

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int int64_t
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  vi A(N);
  int sum=0;
  rep(i,0,N){
    int X; cin>>X;
    sum+=X;
    A[i]=sum;
  }
  int ans=abs(A[N-1]-A[0]*2);
  rep(i,1,N-1){
    ans=min(ans,abs(A[N-1]-A[i]*2));
  }
  cout<<ans<<endl;
  }




Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;
      
      
int main(){
  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++){
  int q;
  cin >> q;
  n-=q;}
  if(n<0){cout << -1 << endl;}else{cout << n << endl;}
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    long long N, T;
    cin >> N >> T;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    map<long long, long long> m;
    long long minA = A[0];
    for(int i = 1; i < N; i++){
        if(A[i] > minA) m[A[i] - minA]++;
        else if(minA > A[i]) minA = A[i];
    }
    long long res = 0;
    long long cnt = 0;
    for(auto v: m){
        if(res < v.first) {
            cnt = v.second;
            res = v.first;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
 
/*
    方針：1時関数の式を作成
    式に代入した際に右辺と左辺が等しければおk
    残り＊１を必要なコストとする
    p <
 */
int main(){
    int x,a;
    scanf("%d %d",&x,&a);
    if (x < a){
        cout << 0 << endl;
    }
    else{
        cout << 10 << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
void solve(){
    long long n;
    cin >> n;
    long long memo = 1;
    for (long long i = 1; i * i <= n; i++){
        if(n % i == 0){//割り切れる
            memo = i;
        }
    }
    long long x, y;
    x = memo - 1;
    y = n / memo - 1;
    cout << x + y << endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    string str;
    cin >> N;
    if(N == 0) str.push_back('0');

    while(N != 0){
        if(N%(-2) != 0){
            str.push_back('1');
            N = -(N - 1)/2;
        }else{
            str.push_back('0');
            N /= -2;
        }
    }
    N= (int)str.size();
    for(int i=0;i<N;i++){
        cout << str[N - i - 1];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    
    rep(i,n) cin >> a[i];
    sort(a.rbegin(),a.rend());
    ll sum = 0;
    ll ans = 0;
    n--;
    rep(i,n/2+1) ans += 2*a[i];
    if(n%2==0) ans-= a[n/2];
    ans -= a[0];
    cout << ans << endl;
}

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

    int N;

    cin >> N;

    int ans = 10000;
    for(int i=1; i <= (N+1)/2; i++ ){
        int a = i;
        int b = N-i;
        int sum = 0;

        while( a> 0){
            sum+= a%10;
            a /= 10;
        }
        
        while( b> 0){
            sum+= b%10;
            b /= 10;
        }

        ans = min(ans,sum);

    }
     cout << ans << endl;


}


Measured memory_bytes: 256
#include<stdio.h>

int main() {

      int n= 0,num=0;

      double result=0;
      scanf("%d", &n) ;

      for  (int  i =1;  i <=n;  i++) {

      if  (i%2!=0)  num++ ;
      }

      result=  num  *1.0/n;
printf("%.10lf", result) ;return  0;}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int lli;
    int main(){
      ios_base::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
      lli n,m;
      cin >> n>> m;
      lli a[m];
      for(lli i=0;i<m;i++)	cin>>a[i];
      lli sum=0, f=1;
      for(lli i=0;i<m;i++){
        sum+=a[i];
        if(sum>n)
        {	f=0; cout << -1 << endl; break;}
      }
     	if(f)	cout << n - sum << endl;
      return 0;
    }

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;
int a[N];
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1, x; i < n; i++) {
        scanf("%d", &x);
        a[x]++;
    }
    for(int i = 1; i <= n; i++) {
        printf("%d\n", a[i]);
    }
    return 0;
}

Measured memory_bytes: 4536
s=input()

n=len(s)

a=s[::-1]

mae=(a[0:int((n-1)/2)])

maer=(mae[::-1])

ato=(a[int((n+2)/2):])

ator=(ato[::-1])

if a==s :
    if mae==maer and ato==ator:
        print("Yes")
    else :
        print("No")
        

else :
    print('No')
    


Measured memory_bytes: 3188