akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	int n, m; std::cin >> n >> m;
	std::vector<std::vector<int>> node(n);
	std::vector<int> in_edge_count(n, 0);
	for (auto i = 0; i < m; ++i) {
		int x, y; std::cin >> x >> y;
		node[x - 1].push_back(y - 1);
		in_edge_count[y - 1]++;
	}
	std::queue<int> queue;
	for (auto i = 0; i < n; ++i) if (in_edge_count[i] == 0) queue.push(i);
	std::vector<int> max_length(n, 0);
	while (!queue.empty()) {
		auto front = queue.front(); queue.pop();
		for (const auto next : node[front]) {
			max_length[next] = std::max(max_length[next], max_length[front] + 1);
			if (--in_edge_count[next] == 0) queue.push(next);
		}
	}
	std::cout << *std::max_element(max_length.begin(), max_length.end()) << std::endl;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main {

    public static void main(String[] args) {

        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        LinkedList<String> first = new LinkedList<>(Arrays.asList(sc.next().split("")));
        for (int i = 1; i < n; i++) {
            List<String> copy = (LinkedList<String>)first.clone();
            List<String> other = new LinkedList<>(Arrays.asList(sc.next().split("")));
            for (String s: copy
                 ) {
                if (other.contains(s)) {
                    other.remove(s);
                } else {
                    first.remove(s);
                }
            }
        }
        Collections.sort(first);
        StringBuilder builder = new StringBuilder();
        for (String s: first
             ) {
            builder.append(s);
        }
        System.out.println(builder);
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
    int x,y,z;
    double a;
    scanf("%d %d %d",&x,&y,&z);
    a=(double)x/z;
    if(a<=y)
    {
      printf("Yes\n");
    }
    else 
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1612
# coding:utf-8

import sys
from collections import defaultdict, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    a, b = LI()

    if a <= 0 and b >= 0:
        return 'Zero'

    if a > 0:
        return 'Positive'

    if (b - a) % 2:
        return 'Positive'
    else:
        return 'Negative'


print(main())


Measured memory_bytes: 3316
import sys
from math import sqrt, gcd, ceil, log
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

def main():
	n = int(input()); arr = read()
	stocks = 0; money = 1000
	j = n-1
	while j > 0 and arr[j] <= arr[j-1]:
		j -= 1
	for i in range(j):
		if arr[i] < arr[i+1] and stocks == 0:
			stocks += money//arr[i]
			money = money%arr[i]
		elif arr[i] > arr[i+1] and stocks:
			money += stocks*arr[i]
			stocks = 0

	# print(j)
	if stocks:
		money += arr[j]*stocks

	print(money)







if __name__ == "__main__":
	main()

Measured memory_bytes: 65072
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

ll n;
ll ans;
ll c=1;

bool f(ll num, ll digit){
	if(digit==(ll)log10(num)+1){
		if(n==c){
			ans = num;
			return true;
		}else{
			c++;
			return false;
		}
	}
	
	int rnum = num%10;
	for(int i = max(rnum-1,0); i<=min(rnum+1,9); i++){
		if(f(num*10 + i,digit)) return true;
	}
	return false;
}

int main(){
	cin >> n;
	
	ll digit=1;
	while(true){
		bool res = false;
		for(int i=1; i<=9; i++){
			res = f(i,digit);
			if(res) break;
		}
		if(res)break;
		digit++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
#define l1 long long
int main(){
	l1 n,m,c=0,p; cin>>n;m=1;
	while(m<=n){ p=0;c=0;
	for(int i=1;i<=100;i++){p=(i*i);
                if(p>m)break;
        for(int j=1;j<=100;j++){p=(i*i)+(j*j)+(i*j);
                if(p>m)break;
            for(int k=1;k<=100;k++){
                p=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(i*k);
                if(p>m)break;
                else if(p==m){c++;}
            }
        }
	} m++;  cout<<c<<endl;
	}
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s,t;
  cin >> s >> t;
  if(s==t.substr(0,s.size())) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;



int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);


	Int a, b;
	cin >> a >> b;

	cout << max(0LL, a - 2 * b) << "\n";

	
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define RREP(i,a,b) for(ll i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> p;
typedef vector<pair<ll, ll>> vpl;


int main(){
    string n; cin >> n;
    rep(i,3){
        if(n[i] == '1') n[i] = '9';
        else n[i] = '1';
    }
    int ans=0;
    int toNum = 1;
    for(int i=2; i>=0; i--){
        ans += (int)(n[i]-'0') * toNum;
        toNum *= 10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main{
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String, Integer> m = new HashMap<String, Integer>();
        int mc = 0;
        String fre = "";
        String max = "";
        while(sc.hasNext()){
            String s = sc.next();
            if(max.length() < s.length())max = s;
            if(m.containsKey(s)){
                int c = m.get(s);
                if(mc < c+1){
                    mc = c+1;
                    fre = s;
                }
                m.put(s, c+1);
            }
            else{
                if(mc < 1){
                    mc = 1;
                    fre = s;
                }
                m.put(s, 1);
            }
        }
        System.out.println(fre + " " + max);
    }
}

Measured memory_bytes: 17180
class Interval
	def initialize(*args)
		@min, @max = args
	end
	attr_reader :min, :max
end

def merged_length(intervals)
	a = intervals.map{|i| [i.min, i.max]}.sort_by(&:first)
	merged = []
	a.each{|l, r|
		if merged.empty? or merged[-1][1] < l
			merged << [l, r]
		else
			merged[-1][1] = r if r > merged[-1][1]
		end
	}
	merged.map{|l, r| r - l}.inject(0, :+)
end

loop.with_index {|_, k|
	n = gets.to_i
	break if n == 0

	event_queue = []
	n.times {
		x, y, r = gets.split.map(&:to_f)
		i = Interval.new(y - r, y + r)
		event_queue << [x - r, :add, i]
		event_queue << [x + r, :del, i]
	}
	event_queue.sort_by!(&:first)

	area = 0
	len = 0
	intervals = []
	x = 0
	until event_queue.empty?
		area += len * (event_queue[0][0] - x)
		x = event_queue[0][0]
		while !event_queue.empty? && event_queue[0][0] == x
			_, command, interval = event_queue.shift
			if command == :add
				intervals << interval
			else
				intervals.delete interval
			end
		end
		
		len = merged_length(intervals)
	end

	printf("%d %.2f\n", k+1, area)
}

Measured memory_bytes: 6176
//By Bibi
///                 .-~~~~~~~~~-._       _.-~~~~~~~~~-.
///             __.'              ~.   .~              `.__
///           .'//                  \./                  \`.
///        .'//                     |                     \`.
///       .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \`.
///     .'//.-"                 `-.  |  .-'                 "-.\`.
///   .'//______.============-..   \ | /   ..-============.______\`.
/// .'______________________________\|/______________________________`.
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
int read(){
	int sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
	return sum*flag;
}
int a,b,c;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	a=read();b=read();c=read();
	if(b<c) swap(b,c);
	if(a<b) swap(a,b);
	if(b<c) swap(b,c);
	printf("%d\n",a*10+b+c );
	return 0;
}

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

int main() {
    int K;
    cin >> K;
    int ans = 1;
    int ones[K];
    for (int i = 0; i < K; i++)
    {
        ones[i] = 0;
    }
    
    bool exist = true;
    int n = 7 % K;
    while (true) {
        if (n == 0) break;
        if (n > 0 && ones[n] > 0) {
            exist = false;
            break;
        }
        ones[n]++;
        n = (n * 10 + 7) % K;
        ans++;
    }
    if (!exist) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7524
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define pb(x) push_back(x)
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)

/*struct comp
{
    bool operator()()
    {
        
    }
};*/
struct node
{
    int idx,a,b,c;
    node(int i,int A,int B,int C)
    {
        idx=i;a=A;b=B;c=C;
    }
};
int N,A,B,C;
vector<string> S;
vector<int>ANS;
bool flag=false;
//et<pair<int,pair<int,pair<int,int> > > >MAP;
void call(int idx,int a,int b,int c)
{
    //cout<<idx<<" "<<a<<" "<<b<<" "<<c<<endl; MAP;
    if(idx==N) {flag=true;return;}
   // pair<int,pair<int,pair<int,int> > > temp=mp(idx,mp(a,mp(b,c)));
    
    /*if(MAP.find(temp)!=MAP.end())
    {
        return;
    }*/
    if(S[idx]=="AB")
    {
        if(b>0)
        {
            ANS.pb(1);
            call(idx+1,a+1,b-1,c);
            if(flag) return;
            ANS.pop_back();
        }
        if(a>0)
        {
            ANS.pb(2);
            call(idx+1,a-1,b+1,c);
            if(flag) return;
            ANS.pop_back();
        }
    }
    
    else if(S[idx]=="BC")
    {
        if(c>0)
        {
            ANS.pb(1);
            call(idx+1,a,b+1,c-1);
            if(flag) return;
            ANS.pop_back();
        }
        if(b>0)
        {
            ANS.pb(2);
            call(idx+1,a,b-1,c+1);
            if(flag) return;
            ANS.pop_back();
        }
    }
    
    else if(S[idx]=="AC")
    {
        if(c>0)
        {
            ANS.pb(1);
            call(idx+1,a+1,b,c-1);
            if(flag) return;
            ANS.pop_back();
        }
        if(a>0)
        {
            ANS.pb(2);
            call(idx+1,a-1,b,c+1);
            if(flag) return;
            ANS.pop_back();
        }
    }
    //.insert(temp);
    return;
}
int32_t main() {
    int t=1;
    //cin>>t;
    while(t--)
    {
    
     cin>>N>>A>>B>>C;
     for(int i=0;i<N;i++)
     {
         string s;
         cin>>s;
         S.pb(s);
     }
     flag=false;
     call(0,A,B,C);
     if(flag==false) 
        {
            cout<<"No";return 0;
        }
    cout<<"Yes\n";
    for(int i=0;i<ANS.size();i++)
    {
        if(ANS[i]==1)
        {
            cout<<S[i][0]<<endl;
        }
        else
        {
            cout<<S[i][1]<<endl;
        }
    }
    

    }
    return 0;
}


Measured memory_bytes: 14496
import java.util.Scanner;
class Main{
	Scanner sc = new Scanner(System.in);
	int n;
	int[] S;
	int q;
	int[] T;
	int C;
	void t(){
		n=sc.nextInt();
		S=new int[n];
		for(int i=0; i<n; i++){
			S[i]=sc.nextInt();
		}
		q=sc.nextInt();
		T=new int[q];
		for(int j=0; j<q; j++){
			T[j]=sc.nextInt();
		}
		for(int j=0; j<q; j++){
			for(int i=0; i<n; i++){
				if(S[i]==T[j]){
					C++;
					break;
				}
			}
		}
		System.out.println(C);
	}
	public static void main(String[]agrs){
		new Main().t();
	}
}

Measured memory_bytes: 31096
#include<stdio.h>
int h[100001],ans[100001];
//int ab[100001][100001];
int main(void){
  int n,m,i,a,b,j,saf,sum=0;
  for(i=0;i<100001;i++){
    /*for(j=0;j<100001;j++){
      ab[i][j]=0;
    }*/
    ans[i]=1;
  }
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  for(i=0;i<m;i++){
    scanf("%d%d",&a,&b);
    a--;
    b--;
    if(h[a]<h[b]){
      ans[a]=0;
    }else if(h[a]>h[b]){
      ans[b]=0;
    }else{
      ans[a]=0;
      ans[b]=0;
    }
    //ab[a][b]=1;
    //ab[b][a]=1;

  }
/*  for(i=0;i<n;i++){
    saf=0;
    for(j=0;j<n;j++){
      if(ab[i][j]==1&&h[i]<=h[j]){
        saf=1;
        break;
      }
    }
    if(saf==0){
      sum++;
    }
  }*/
  for(i=0;i<n;i++){
    if(ans[i]==1){
      sum++;
    }
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2508
#include <stdio.h>
#define N 2000
#define inf 2000000
#define WHITE 1
#define BLACK 2 
void prim();
int n,A[N][N],a=0,d[N],pi[N],color[N],d[N],u;
int main(){
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&A[i][j]);
      
    }
   
  }
  prim();
  
  
  printf("%d\n",a);
  return 0;
}

void prim(){
  int mincost,i,v,u,y;
  for(u=0;u<n;u++){
    d[u]=inf;
    pi[u]=-1;
    color[u]=WHITE;
  }
  d[0]=0;

  while(1){
    mincost=inf;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==inf){
      break;
    }
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && A[u][v]<d[v]&&A[u][v]!=-1){
	pi[v]=u;
	d[v]=A[u][v];

      }
      
    }
  
  }
  for(y=0;y<n;y++){
      a+=A[y][pi[y]];
    }
}
  
       

Measured memory_bytes: 1036
from queue import deque

n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
li = [[] for _ in range(n)]

for i,j in l:
    i,j = i-1,j-1
    li[i].append(j)
    li[j].append(i)

stack = 0
color = [0]*n

work_queue = deque([])
visited = [False]*n
visited[0] = True
color_list = [0]*n
work_queue.append(stack)
path = {}
ma = 0
while work_queue:
    here = work_queue.popleft()
    color = 1
    for i in li[here]:
        if visited[i]:
            continue
        work_queue.append(i)
        visited[i] = True
        if color_list[here] == color:
            color += 1
        path[(here,i)] = color
        color_list[i] = color
        ma = max(ma,color)
        color += 1

print(ma)
for i,j in l:
    i,j = i-1,j-1
    print(path[(i,j)])

Measured memory_bytes: 58640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        //入力
        string s = Console.ReadLine();
        int R = int.Parse(s.Split(' ')[0]);
        int G = int.Parse(s.Split(' ')[1]);
        int B = int.Parse(s.Split(' ')[2]);
        int N = int.Parse(s.Split(' ')[3]);

        //解答となる数値
        int ans = 0;

        //検証
        int rMax = N / R;
        int gMax = N / G;
        int bMax = N / B;

        for (int r = rMax; r >= 0; r--) {
            for (int g = gMax; g >= 0; g--) {
                if ((N - (R * r + G * g)) % B == 0 && (N - (R * r + G * g)) >= 0) {
                    ans++;
                }
            }
        }

        //出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
# coding: utf-8
# Eratosthenes
def eratosthenes(n):
    prime_table = [False,False,True]+[False if i%2!=0 else True for i in range(n-2)]
    i=3
    while i*i<=n:
        if prime_table[i]:
            j=i*i
            while j<=n:
                prime_table[j]=False
                j+=i
        i+=2
    return prime_table

pt=eratosthenes(10**6+1)
while 1:
    a,d,n=map(int,input().split())
    if a==d==n==0:
        break
    while 1:
        if pt[a]:
            n-=1
            if n==0:
                print(a)
                break
        a+=d
    



Measured memory_bytes: 21232
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let x: i32 = read();
    let n: usize = read();
    let vec: Vec<i32> = (0..n).map(|_| read()).collect();
    for i in 0..102 {
        if !vec.contains(&(x - i)) {
            println!("{}", x - i);
            return;
        }
        if !vec.contains(&(x + i)) {
            println!("{}", x + i);
            return;
        }
    }
}


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

using namespace std;
int a[100001];
vector <int> b[100001];
int dp[100001];
int longest_path(int i){
    if(b[i].empty())return 0;
    if(dp[i]!=-1)return dp[i];
    int max=0;
    for(auto j : b[i]){
        int t=longest_path(j);
        if(max<t)max=t;
    }
    return dp[i]=max+1;
}

int main()
{
    int n,m,i,j,x,y;
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin >>x>>y;
        a[x-1]=1;
        b[y-1].push_back(x-1);
    }
    for(j=0;j<n;j++)
        dp[j]=-1;
    int max=0;
    for(i=0;i<n;i++){
        if(a[i]==0){
            int t=longest_path(i);
            if(t>max)max=t;
        }
    }
    cout<<max;
   return 0;
}

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

int main() {
  string S;
  cin >> S;
  bool b=true;
  int n=S.size();
  for (int i=0;i<=n/2;i++){
      if (S.at(i)!=S.at(n-1-i)){
          b=false;break;
      }
  }
  for (int i=0;i<(n-1)/2;i++){
      if (S.at(i)!=S.at((n-2)/2-i)){
          b=false;break;
      }
  }
  for (int i=n-1;i<n-((n+3)/2);i--){
      if (S.at(i)!=S.at(i-(n+3)/2)){
          b=false;break;
      }
  }
  if (b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <boost/math/common_factor_rt.hpp>

#define ll long long
using namespace std;
ll l = 1000000007;
vector<char> s;

int main()
{
	ll z = 0, o = 0;
	string S;
	cin >> S;
	for (ll i = 0; i < S.size(); i++)
	{
		s.push_back(S.at(i));
	}
	for (ll i = 0; i < s.size(); i++)
	{
		if (s.at(i) == '0') {
			z++;
		}
		else {
			o++;
		}
	}
	
	if (z >= o) {
		cout << o * 2 << endl;
	}
	else {
		cout << z * 2 << endl;

	}

}



Measured memory_bytes: 640
#include <stdio.h>
int main(void) {
	int data[100], n, i, j, tmp, times = 0;
	const char *fmt = "%d";

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", data+i);
	}
	for (i = 0; i < n; i++) {
		for (j = n-1; j > i; j--) {
			if (data[j] < data[j-1]) {
				tmp = data[j];
				data[j] = data[j-1];
				data[j-1] = tmp;
				times++;
			}
		}
	}
	for (i = 0; i < n; i++) {
		printf(fmt, data[i]);
		fmt = " %d";
	}
	printf("\n%d\n", times);
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int ans = 100;
  for(int i=0; i<26; ++i){
    int nans = 0, num = 0;
    for(int j=0; j<n; ++j){
      if(s[j] == 'a'+i){
        nans = max(nans, j-num);
        num = j+1;
      }
    }
    nans = max(nans, n-num);
    ans = min(ans, nans);
  }
  cout << ans << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int x = int.Parse(Console.ReadLine());
            int count = 0;

            for (int i = 0; i <= a; i++)
            {
                for (int j = 0; j <= b; j++)
                {
                    for (int k = 0; k <= c; k++)
                    {
                        if (x == 500 * i + 100 * j + 50 * k)
                        {
                            count++;
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}



Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    string s ;
    cin >> s;
    vector<char> v;
    for(auto &x : s){
         if(x == '0' or x == '1'){
            v.pb(x);
            con ;
         }
         if(v.sz == 0) con ;
         else v.pop_back();
    }
    for(auto &x :  v) cout << x;
    cout << el ;
}































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

int main(){
    ll n;
    cin >> n;
    ll i=1, j=n;
    ll ans = i+j-2;
    while (i <= pow(n, 0.5)){
        if(n%i==0) {
            j = n/i;
            ans = min(ans, i+j-2);
        }
        i++;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 384
#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) (v).begin(),(v).end()
#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; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int N, K;
int A[2000], B[2000];
vector<int> g[2000];
int d[2000];

void dfs(int v, int prev, int c) {
	d[v] = c;
	
	REP(i, g[v].size()) {
		int u = g[v][i];
		if (u != prev) dfs(u, v, c + 1);
	}
	
}

int main() {
	cin >> N >> K;
	REP(i, N - 1) {
		scanf("%d %d", A + i, B + i);
		A[i]--; B[i]--;
		g[A[i]].push_back(B[i]);
		g[B[i]].push_back(A[i]);
	}
	
	int ans = INF;
	
	if (K & 1) {
		REP(i, N - 1) {
			dfs(A[i], B[i], 0);
			dfs(B[i], A[i], 0);
			int cnt = 0;
			REP(j, N) if (d[j] > K / 2) cnt++;
			chmin(ans, cnt);
		}
	}
	else {
		REP(i, N) {
			dfs(i, -1, 0);
			int cnt = 0;
			REP(j, N) if (d[j] > K / 2) cnt++;
			chmin(ans, cnt);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct union_find {
  int32_t *parent;
  int32_t size;
} union_find;

void init_union_find (union_find * const u) {
  for (int32_t i = 0; i < u->size; ++i){
    u->parent[i] = -1;
  }
}

union_find* new_union_find (const int32_t size) {
  union_find * const u = (union_find *) calloc (1, sizeof (union_find));
  u->parent = (int32_t *) calloc (size, sizeof (int32_t));
  u->size = size;
  init_union_find (u);
  return u;
}

void free_union_find (union_find * const u) {
  free (u->parent);
  free (u);
}

int32_t root (union_find * const u, int32_t x) {
  int32_t index[32];
  int32_t top = 0;
  while (u->parent[x] >= 0) {
    index[top++] = x;
    x = u->parent[x];
  }
  while (top > 0) {
    u->parent[index[--top]] = x;
  }
  return x;
}

int same (union_find * const u, const int32_t x, const int32_t y) {
  return root (u, x) == root (u, y);
}

int32_t get_size (union_find * const u, const int32_t x) {
  return - (u->parent[root (u, x)]);
}

void unite (union_find * const u, int32_t x, int32_t y) {
  x = root (u, x);
  y = root (u, y);
  if (x == y) return;
  if (u->parent[x] > u->parent[y]) {
    const int32_t swap = x;
    x = y;
    y = swap;
  }
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
}

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  union_find *u = new_union_find (n);
  for (i32 i = 0; i < m; ++i) {
    i32 a, b, c;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &a, &b, &c);
    a--;
    b--;
    unite (u, a, b);
  }
  i32 *ok = (i32 *) calloc (n, sizeof (i32));
  i32 ans = 0;
  for (i32 i = 0; i < n; ++i) {
    i32 r = root (u, i);
    if (ok[r]) continue;
    ans++;
    ok[r] = 1;
  }
  printf ("%" PRIi32 "\n", ans);
}

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


Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] a = new int[h][w];
        for (int i = 0 ; i < h ; i++) {
            for (int j = 0 ; j < w ; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        List<Integer> y1 = new ArrayList<>();
        List<Integer> x1 = new ArrayList<>();
        List<Integer> y2 = new ArrayList<>();
        List<Integer> x2 = new ArrayList<>();
        int n = 0;
        for (int i = 0 ; i < h ; i ++) {
            for (int j = 0 ; j < w - 1; j++) {
                if (a[i][j] % 2 != 0) {
                    a[i][j]--;
                    a[i][j + 1]++;
                    y1.add(i + 1);
                    x1.add(j + 1);
                    y2.add(i + 1);
                    x2.add(j + 2);
                    n++;
                }
            }
        }

        for (int i = 0 ; i < h - 1; i++) {
            if (a[i][w - 1] % 2 != 0) {
                a[i][w - 1]--;
                a[i + 1][w- 1]++;
                y1.add(i + 1);
                x1.add(w);
                y2.add(i + 2);
                x2.add(w);
                n++;
            }
        }
        System.out.println(n);
        for (int i = 0 ; i < n ; i++) {
            System.out.println(y1.get(i) + " " + x1.get(i) + " "  + y2.get(i) + " "  + x2.get(i));
        }
    }
}

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

int main() {
  string o, e;
  cin >> o >> e;
  auto s = max(o.size(), e.size());
  for(int i = 0; i < s; ++i) {
    if(i < o.size()) {
      cout << o[i];
    }
    if(i < e.size()) {
      cout << e[i];
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
input()
h = [int(_) for _ in input().split()]

opr_count = 0
h_highest = max(h)

while any(h):
    flag = 0
    for i, v in enumerate(h):
        if v == h_highest:
            h[i] -= 1
            if not flag:
                opr_count += 1
                flag = 1
                continue
        else:
            flag = 0
    h_highest -= 1

print(opr_count)

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

int gcd(int x,int y){
	if(y==0)return x;
	return gcd(y,x%y);
}

int main(){
	int k;
	long long sum=0;
	scanf("%d",&k);
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int r=1;r<=k;r++){
				sum+=gcd(r,gcd(i,j));
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}

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

int main(){

  string S;
	
  cin>>S;
	
  int count=0;
	
  int N=S.length()-1;
  rep(i,N){

    if(S[i]!=S[i+1])count++;
    
  }
  
  cout<<count<<endl;
  

}



Measured memory_bytes: 512
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
      n: usize,
      mut aa: [usize; n],
    }

    let mut aa: Vec<_> = aa.into_iter().enumerate().map(|(i, v)| (v, i)).collect();
    aa.sort();
    for (v, i) in aa {
        puts!("{} ", i+1);
    }
    puts!("\n");
}


Measured memory_bytes: 8956
numbers = gets.chomp.split(' ').map(&:to_i)
@s = gets.chomp.split('').map(&:to_s)
@n = numbers.first
@a = numbers[1]
@b = numbers[2]
@c = numbers[3]
@d = numbers[4]
@abcd = [@a, @b, @c, @d]
@output = 'Yes'

def ng
  @output = 'No'
end

# @return Bool
def double_rock_between_min_and_max
  @s.each_with_index do |v, i|
    next if (@abcd.min > i + 1 || @abcd.max < i + 1)
    return true if (v == '#' && @s[i + 1] == '#')
  end
  return false
end

# Exists triple empty between C and D
# @return Bool
def exists_triple
  @s.each_with_index do |_, i|
    next if ((i + 1 < @b - 1) || (i + 1 > @d - 1))
    return true if ([@s[i], @s[i + 1], @s[i + 2]] == ['.', '.', '.'])
  end
  return false
end

if @c == @d || double_rock_between_min_and_max
  ng
elsif @c < @d
elsif @c > @d
  ng unless exists_triple
end


print @output

Measured memory_bytes: 18172
#include <stdio.h>
int main() {
    int a, b;
    char op;
    while (scanf("%d %c %d", &a, &op, &b) && op != '?'){
        switch (op){
            case '+': 
                printf("%d\n", a+b);
                break;
            case '-':
                printf("%d\n", a-b);
                break;
            case '*':
                printf("%d\n", a*b);
                break;
            case '/':
                printf("%d\n", a/b);
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 2700
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <list>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int n,k,m;
	while(cin>>n>>k>>m,n){
		list<int> l;
		REP(i,n)l.push_back(i+1);
		list<int>::iterator it = l.begin();
		REP(i,n-1){
			int len = n - i;
			int now = distance(l.begin(),it);
			if(i==0){
				advance(it, m-1);
			}else{
				//printf("%d %d %d\n",now,(now+k-1)%len - now,(now+k-1)%len);
				advance(it, (now + k-1)%len - now);
			}
			//cout<<*it<<endl;
			it = l.erase(it);
		}
		cout<<*l.begin()<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    ll m;
    cin >> m;
    vi a(n);
    vector<ll> suu(n+1);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));
    suu[n] = 0;
    rep(i, n) {
        suu[n-i-1] = suu[n-i] + a[n-1-i]; 
    }

    int aa = 0, c = INF;
    int b;
    while(1 != c-aa) {
        b = aa+c;
        b >>= 1;
        ll sum = 0;
        rep(i, n){
            vi::iterator itr = lower_bound(all(a), b-a[i]);
            sum += a.end() - itr;
        }
        if(sum >= m) {
            aa = b;
        } else {
            c = b;
        }
    } 


    ll ss = 0;
    ll cou = 0;
    rep(i, n) {
        vi::iterator itr = upper_bound(all(a), aa-a[i]);
        ll num = a.end() - itr;
        ss += (ll)a[i]*num+suu[n-num];
        cou += num;
    }
    ss += (m-cou) * aa;

    cout << ss << endl;
}

Measured memory_bytes: 1408
#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 long long
#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>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
  COMinit();
  int N,K; cin>>N>>K;
  int ans=0;
  REP(i,0,min(N-1,K)){
    ans+=COM(N,i)*COM(N-1,N-i-1)%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int A, B, C, K, sum = 0;

	cin >> A >> B >> C >> K;

	if ( ( A > K ) || ( A == K ) ) {
		sum += K;

		cout << sum  << endl;
		return 0;
	}
	else {
		K =  K - A;
		sum += A;
	}

	if ( B > K || B == K ) {
		K = B - K;
	}
	else {
		K = K - B;
	}

	if ( C > K || C == K ) {
		sum -= K;
	}
	else {
		sum -= C;
	}

	cout << sum << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


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

    int a = 1, b = m;
    if(m%2 == 0) b++;
    for (int i = 0; i < m/2; i++)
    {
        cout << a++ << " " << b-- << endl;
    }

    a = m+1, b = a+m;
    if(m%2 == 0) a++;
    for (int i = 0; i < (m+1)/2; i++)
    {
        cout << a++ << " " << b-- << endl;
    }
    


    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll A[3];
	ll sum = 0;
	REP(i, 3) {
		cin >> A[i];
	}
	sort(A, A + 3);
	sum = A[2] * 2 - A[1] - A[0];
	if (sum % 2 == 0) {
		cout << sum / 2;
	}
	else {
		cout << sum / 2 + 2;
	}


	return 0;


}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    while(true) {
        int L;
        cin >> L;
        if(!L) break;

        int amt = 0;
        int ans = 0;
        for(int i = 0; i < 12; ++i) {
            int M, N;
            cin >> M >> N;
            amt += M-N;
            if(ans == 0 && amt >= L) ans = i+1;
        }
        if(ans > 0) cout << ans << endl;
        else cout << "NA" << endl;
    }
    return 0;
}

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


int main(){
    int n; cin >> n;
    int h[n];
    for(int i = 0; i < n; i++) cin >> h[i];

    int maximum = 0;
    for(int i = 0; i < n; i++){
        if(h[i] < maximum - 1){
            cout << "No\n";
            return 0;
        }
        maximum = max(maximum, h[i]);
    }
    cout << "Yes\n";
}


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

void main_()
{
    string S;
    cin >> S;

    set<string> divides;

    char prev = '\0';
    int count = 0;
    bool cont = false;
    bool prev_cont = false;
    for (auto it = begin(S); it != end(S); ++it) {
        if (prev != *it || cont || prev_cont) {
            count++;
            prev_cont = cont;
            cont = false;
        } else {
            if (it == end(S) - 1 && prev_cont) {
                count++;
            }
            prev_cont = cont;
            cont = true;
        }
        prev = *it;
    }

    cout << count << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int m1,d1,m2,d2;
    in>>m1>>d1>>m2>>d2;
    if(m1!=m2) cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

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

    int ans = 0;
    int R = min(n, k);
    for (int a = 0; a <= R; a++) {
        for (int b = 0; b <= R; b++) {
            int c = k - a - b;
            if (R < a + b) {
                continue;
            }

            int val = 0;
            priority_queue<int, vector<int>, greater<int>> pq;
            for (int i = 0; i < a; i++) {
                if (v[i] < 0) {
                    pq.push(v[i]);
                } else {
                    val += v[i];
                }
            }
            for (int i = 0; i < b; i++) {
                if (v[n - i - 1] < 0) {
                    pq.push(v[n - i - 1]);
                } else {
                    val += v[n - i - 1];
                }
            }

            for (int i = 0; i < c; i++) {
                if (!pq.empty()) {
                    pq.pop();
                } else {
                    break;
                }
            }
            while (!pq.empty()) {
                val += pq.top();
                pq.pop();
            }

            ans = max(ans, val);
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n%1000==0) cout << 0 << endl;
  else cout << 1000 - n%1000 << endl;
  return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i=0; i<n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    int bottom = 0;
    int top = a[n-1];
    while ((top - bottom) > 1) {
        auto divide = [](int a, int b) -> int {
            return (a + b - 1) / b;
        };
        auto isOK = [k, &a, &divide](int l) -> bool {
            int sum = 0;
            for (int i: a) {
                sum += divide(i, l) - 1;
            }
            return sum <= k;
        };
        int mid = (top + bottom) / 2;
        if (isOK(mid)) {
            top = mid;
        } else {
            bottom = mid;
        }
    }
    cout << top << endl;
}

Measured memory_bytes: 3952
N = int(input())
Data = list(map(int,input().split()))
sum1 = sum(Data)

ans = 10**15
su = 0
for i in range(0,N-1):
    su += Data[i]
    ku = sum1-su
    diff = abs(su-ku)
    ans = min(ans,diff)
print(ans)


Measured memory_bytes: 24812
import math
import sys

# print(math.pow(10**9,1/5))

x = int(input())

maxn = 128
for a in range(maxn):
    for b in range(a+1,maxn):
        if b**5 - a**5 == x:
            print(b,a)
            sys.exit()
        elif a**5 + b**5 == x:
            print(a,-1*b)
            sys.exit()


Measured memory_bytes: 64576
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N,A,B,ans=0;

int wa(int x){
    int temp=0;
    for(int i=10;x>0;){
        temp+=x%i;
        x/=10;
    }
    // out(temp);
    return temp;
}

int main(){
    cin>>N>>A>>B;
    repi(i,1,N+1){
        if(A<=wa(i)&&wa(i)<=B){
            ans+=i;
        }
    }
    out(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long int ll;
int a[100005];

int main()
{
    int n;
    int i;

    while(scanf("%d",&n) != EOF)
    {
        for(i = 0;i < n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        int sum = 0;
        for(i = 0;i < n;)
        {
            int cnt = 1;
            while(i < n && i+1 < n && a[i+1] == a[i])
            {
                i++;
                cnt++;
            }
            i++;
            if(cnt%2) sum++;
        }
        printf("%d\n",sum);
    }

    return 0;
}


Measured memory_bytes: 640