akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while(t--)
    {
        int n,m,i,x,y,z;
        cin>>n>>m;
        int arr[n+1];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        sort(arr,arr+n);
        int sum=0;
        for(i=0;i<m;i++)
            sum+=arr[i];
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int a, p;

    cin >> a >> p;

    cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = 1
    if 0 in As:
        print(0)
        return

    for a in As:
        ans *= a
        if ans > 10**18:
            print(-1)
            return

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84628
h,w=map(int,input().split())
a=[input() for i in range(h)]
b=[]

for i in range(h):
    if a[i].count(".")==w:
        b.append(i)

for i in reversed(b):
    a.pop(i)

h-=len(b)
for i in range(w-1,-1,-1):
    flag=True
    for j in range(h-1,-1,-1):
        if a[j][i]=="#":
            flag=False
    if flag:
        for k in range(h-1,-1,-1):
            a[k]=a[k][:i]+a[k][i+1:]

for i in range(h):
    print(a[i])

Measured memory_bytes: 39024
import java.text.Format;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	//2343 cording
	char [] map = {' ', '.', ',', '-', '\'', '?'};
	HashMap<String, Character> map2;
	
	private void doit() {
		init();
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String input = sc.nextLine();
			
			StringBuilder s = new StringBuilder(input);
			StringBuilder ss = new StringBuilder();
			for(int i = 0; i < s.length(); i++){
				char c = s.charAt(i);
				if(Character.isLetter(c) ){
					int temp = c - 'A';
					String temp2 = Integer.toBinaryString(temp);
					ss.append(String.format("%05d", Integer.parseInt(temp2)));
				}
				else{
					int ind = -1;
					for(int j = 0; j < map.length; j++){
						if(map[j] == c){
							ind = j + 'Z' - 'A' + 1;
							break;
						}
					}
					ss.append(String.format("%05d", Integer.parseInt(Integer.toBinaryString(ind))));
				}
			}
			
			StringBuilder sss = new StringBuilder();
			int start = 0;
			for(int i = 0; i < ss.length(); i++){
				String sub = ss.substring(start,i + 1 );
				if(map2.containsKey(sub)){
					sss.append(map2.get(sub));
					start = i + 1;
				}
			}
			
			System.out.println(sss.toString());
		}
	}
	
	private void init() {
		map2 = new HashMap<String, Character>();
		map2.put("101", ' ');
		map2.put("000000", '\'');
		map2.put("000011", ',');
		map2.put("10010001", '-');
		map2.put("010001", '.');
		map2.put("000001", '?');
		map2.put("100101", 'A');
		map2.put("10011010", 'B');
		map2.put("0101", 'C');
		map2.put("0001", 'D');
		map2.put("110", 'E');
		map2.put("01001", 'F');
		map2.put("10011011", 'G');
		map2.put("010000", 'H');
		map2.put("0111", 'I');
		map2.put("10011000", 'J');
		map2.put("0110", 'K');
		map2.put("00100", 'L');
		map2.put("10011001", 'M');
		map2.put("10011110", 'N');
		map2.put("00101", 'O');
		map2.put("111", 'P');
		map2.put("10011111", 'Q');
		map2.put("1000", 'R');
		map2.put("00110", 'S');
		map2.put("00111", 'T');
		map2.put("10011100", 'U');
		map2.put("10011101", 'V');
		map2.put("000010", 'W');
		map2.put("10010010", 'X');
		map2.put("10010011", 'Y');
		map2.put("10010000", 'Z');
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b, c;
  cin >> a >> b >>c;

  int x = max({a, b, c});
  int y = min({a, b, c});

  cout << abs(y - x) << endl;
}


Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, d, i, j, k, ans = 0, tmp = 0;
  scanf("%d%d", &n, &d);
  int a[n + 1][d + 1];
  for (i = 0; i < n; i++)
  {
    for (j = 0; j < d; j++)
    {
      int x;
      scanf("%d", &x);
      a[i][j] = x;
    }
  }
  for (i = 0; i < n; i++)
  {
    for (j = i + 1; j < n; j++)
    {
      for (k = 0; k < d; k++)
      {
        tmp += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
      }
      if ((sqrt(tmp) * sqrt(tmp) == tmp) && (sqrt(tmp) == floor(sqrt(tmp))))
        ans++;
      tmp = 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
//============================================================================
// Name        : aoj0068.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

class pri_x_y{
public:
	bool operator()(const pair<double,double>& l,const pair<double,double>& r){
		if(l.first != r.first){
			return l.first > r.first;
		}
		return l.second > r.second;
	}
};

double outer(pair<double,double> a,pair<double,double> b,pair<double,double> c){
	return (a.first - b.first) * (c.second - b.second) - (a.second - b.second) * (c.first - b.first);
}

int main() {
	int n, k;
	double x, y;
	vector<pair<double,double> > v, s;
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}

		for(int i = 0;i < n;i++){
			cin >> x;
			cin.get();
			cin >> y;
			v.push_back(make_pair(x,y));
		}
		sort(v.begin(),v.end(),pri_x_y());
		k = 0;
		for(int i = 0;i < n;i++){
			while(1 < k && outer(s[k - 2],s[k - 1],v[i]) <= 0){
				s.pop_back();
				k--;
			}
			s.push_back(v[i]);
			k++;
		}
		int t = k;
		for(int i = n - 2;i >= 0;i--){
			while(t < k && outer(s[k - 2],s[k - 1],v[i]) <= 0){
				s.pop_back();
				k--;
			}
			s.push_back(v[i]);
			k++;
		}
		s.pop_back();
		cout << n - s.size() << endl;
		s.clear();
		v.clear();
	}
	return 0;
}

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

int main(){
  int a,b,c,array[101],i;
  string s;
  cin>>a;
  for(i=0;i<a;i++){
    cin>>array[i];
  }
  sort(array,array+a);
  cout<<array[a-1]-array[0]<<endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string> 
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <cmath>



typedef long long ll;


using namespace std;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

ll maxn=2*100000;
string l;
//vector<ll> b;
vector<ll> w;


int main(){
    cin>>l;
    ll ans=0;
    for (int i=0;i<l.size();i++){
        if (l[i]=='W') {
            w.push_back(i);
        }
    }
    for (int i=0;i<w.size();i++){
            ans+=w.at(i)-i;
    }
    cout<<ans<<endl;
}

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

long long n,m,q,aa,bb,A[100005],B[100005],ans,x;

int main(){
	scanf("%lld%lld%lld",&n,&m,&q);
	for(int i =0;i<n;i++) scanf("%lld",&A[i]);
	for(int i =0;i<m;i++) scanf("%lld",&B[i]);
	while(q--){
		scanf("%lld",&x);
		
		aa = lower_bound(A,A+n,x)-A;
		bb = lower_bound(B,B+m,x)-B;
		
//		printf("it %lld %lld\n",aa,bb);
		
		
		ans = 100000000000000;
		//maju maju
		if(aa!=n && bb!=m) ans = min(ans,max(A[aa],B[bb])-x);
		
		//maju mundur
		if(aa!=n && bb-1>=0)ans = min(ans,2*(A[aa]-x)+x-B[bb-1]);
		if(aa!=n && bb-1>=0)ans = min(ans,(A[aa]-x)+2*(x-B[bb-1]));
		
		//mundur maju
		if(aa-1>=0 && bb!=m)ans = min(ans,2*(x-A[aa-1])+B[bb]-x);
		if(aa-1>=0 && bb!=m)ans = min(ans,(x-A[aa-1])+2*(B[bb]-x));
		
		//mundur mundur
		
		if(aa-1>=0 && bb-1>=0)ans = min(ans,x-min(A[aa-1],B[bb-1]));
		printf("%lld\n",ans);
		
	}
	
	return 0;
}

Measured memory_bytes: 2816
class UnionFind:
    def __init__(self,n):
        self.parent=[i for i in range(n)]
        self.rank=[0 for _ in range(n)]

    def find(self,x):
        if self.parent[x]==x:
            return x
        else:
            rootx=self.find(self.parent[x])
            self.parent[x]=rootx
            return rootx

    def union(self,x,y):
        rootx=self.find(x)
        rooty=self.find(y)
        if self.rank[rootx]<self.rank[rooty]:
            self.parent[rootx]=rooty
        else:
            self.parent[rooty]=rootx
            if self.rank[rootx]==self.rank[rooty]:
                self.rank[rootx]+=1

n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for _ in range(m)]
uf=UnionFind(n)
for x,y,z in xyz:
    x,y=x-1,y-1
    uf.union(x,y)

# print(uf.parent)
for i in range(n):
    uf.find(i)
print(len(set(uf.parent)))

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

using namespace std;

#define int64 long long
#define printarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";

const int mxn = 2e5 + 10;
long long a[mxn];
long long suma[mxn];
map<long long,long long> mymap;


int main()
{

    int n;
    cin>>n;

    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);


    long long cnt = 0;
    mymap[0]++;
    for(int i=1;i<=n;i++)
    {
        suma[i] = suma[i-1] + a[i];
        mymap[suma[i]]++;

        cnt  = cnt + mymap[suma[i]] - 1;
    }

    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

/////////////         qsortのラッピング

int qsort_long_compare_ascend(const void* a, const void* b) {//long型
	long c = *(long*)a - *(long*)b;
	if (c > 0) { return 1; }
	else if (c < 0) { return -1; }
	return 0;
}
int qsort_long_compare_descend(const void* a, const void* b) {//long型
	long c = *(long*)b - *(long*)a;
	if (c > 0) { return 1; }
	else if (c < 0) { return -1; }
	return 0;
}
void ascendOrder(int size, long* array) {//昇順
	qsort(array, size, sizeof(long), qsort_long_compare_ascend);
}
void descendOrder(int size, long* array) {//降順
	qsort(array, size, sizeof(long), qsort_long_compare_descend);
}

int main() {
	int N; cin >> N;
	bool* sign = new bool[N];
	long* a = new long[N];

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	descendOrder(N, a);

	for (int i = 0; i < N; i++) {
		sign[i] = (a[i] >= 0);
	}
	if (a[0] < 0) {
		sign[0] = true;
	}
	else if (a[N - 1] >= 0) {
		sign[N - 1] = false;
	}

	long sum = 0;
	for (int i = 0; i < N; i++) {
		if (sign[i]) {
			sum += a[i];
		}
		else {
			sum -= a[i];
		}
	}
	cout << sum << endl;

	int k = 0;
	for (int i = 0; i < N; i++) {
		if (sign[i]) { k++; }
		else { break; }
	}

	long sum1 = a[0];
	long sum2 = a[N - 1];

	for (int i = k; i < N - 1; i++) {
		cout << sum1 << " " << a[i] << endl;
		sum1 -= a[i];
	}
	for (int i = 1; i < k; i++) {
		cout << sum2 << " " << a[i] << endl;
		sum2 -= a[i];
	}
	cout << sum1 << " " << sum2 << endl;

	return 0;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;

int main() {
	int a, b, c; CI a >> b >> c;

	if (a<c and b<c or a>c and b>c) CO "No" EN;
	else CO "Yes" EN;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

type drink struct {
	taste int
}

type drinkList []drink

func (d drinkList) Len() int {
	return len(d)
}

func (d drinkList) Swap(i, j int) {
	d[i], d[j] = d[j], d[i]
}

func (d drinkList) Less(i, j int) bool {
	return d[i].taste > d[j].taste
}

func dif(dList drinkList, index int) int {
	return dList[index].taste - dList[index+1].taste
}

func min(a, b int) int {
	if a > b {
		return b
	}

	return a
}

func main() {
	io := NewIo()
	defer io.Flush()

	X := io.NextInt()
	Y := io.NextInt()
	Z := io.NextInt()
	K := io.NextInt()

	listA := make(drinkList, X)
	for i := range listA {
		listA[i].taste = io.NextInt()
	}
	listB := make(drinkList, Y)
	for i := range listB {
		listB[i].taste = io.NextInt()
	}
	listC := make(drinkList, Z)
	for i := range listC {
		listC[i].taste = io.NextInt()
	}

	sort.Sort(listA)
	sort.Sort(listB)
	sort.Sort(listC)

	result := make(drinkList, 0, min(K, X*Y*Z))

	for i := 0; i < X; i++ {
		for j := 0; j < Y; j++ {
			if (i+1)*(j+1) > 3000 {
				break
			}
			for k := 0; k < Z; k++ {
				if (i+1)*(j+1)*(k+1) <= 3000 {
					result = append(result, drink{listA[i].taste + listB[j].taste + listC[k].taste})
				} else {
					break
				}
			}
		}
	}

	sort.Sort(result)

	for i := 0; i < min(K, X*Y*Z); i++ {
		io.PrintLn(result[i].taste)
	}
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll k;
    cin >> k;
    vi a(k);
    rep(i, k) cin >> a[i];

    // nとしてあり得る範囲を[l, r)として逆順に処理していく
    ll l = 2, r = 3;
    for(ll i=k-1; i>=0; i--){
        ll nmin = ceil(1.0*l/a[i]);
        ll nmax = (r-1)/a[i];

        // 下限の係数が0ならmaxだけ頼る
        if(nmin <= 0){
            // どちらも0なら達成不可
            if(nmax <= 0){
                cout << -1 << endl;
                return 0;
            }
            // 範囲の更新
            else{
                l = a[i] * nmax;
                r = a[i] * (nmax+1);
            }
        }
        // 下限が得られている場合
        else{
            if(nmax <= 0 || nmax < nmin){
                cout << -1 << endl;
                return 0;
            }
            else if(nmin == nmax){
                l = a[i] * nmax;
                r = a[i] * (nmax+1);
            }
            else{
                l = a[i] * nmin;
                r = a[i] * (nmax+1);
            }
        }
    }
    cout << l << " " << r-1 << endl;
}

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

int S,T,U,N,O,D;
int e[100],c[100];
int h[100],a[100];
int dp1[101][101];
int dp2[10100];
int dp3[101][101];

int main(){
  cin >> S >> T >> U >> N >> O >> D;
  for(int i=0;i<T;i++)cin >> e[i] >> c[i];
  for(int i=0;i<N;i++)cin >> h[i] >> a[i];

  memset(dp1,-1,sizeof(dp1));
  dp1[0][0] = 0;
  for(int i=0;i<T;i++){
    for(int j=U-1;j>=0;j--){
      for(int k=0;k<=S;k++){
	if(dp1[j][k]<0)continue;
	if(k+e[i]<=S)dp1[j+1][k+e[i]] = max(dp1[j+1][k+e[i]], dp1[j][k]+c[i]);
      }
    }
  }

  memset(dp2,0,sizeof(dp2));
  for(int i=0;i<N;i++){
    for(int j=0;j<=100*T;j++){
      if(j+a[i]<=100*U)dp2[j+a[i]] = max(dp2[j+a[i]], dp2[j] + h[i]);
    }
  }

  memset(dp3,-1,sizeof(dp3));
  dp3[0][S] = 0;
  for(int i=0;i<D;i++){
    for(int j=0;j<=S;j++){
      if(dp3[i][j]<0)continue;
      for(int k=0;k<=j;k++){
	int nxtS = min(j-k+O, S);
	if(dp1[U][k]<0)continue;
	dp3[i+1][nxtS] = max(dp3[i+1][nxtS], dp3[i][j] + dp2[dp1[U][k]]);
      }
    }
  }

  int ans = -1;
  for(int i=0;i<=S;i++)ans = max(ans, dp3[D][i]);
  cout << ans << endl;
}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX_N 100

int n,time,head,tail;
int *queue;
int *dist;
int *color;
int* matrix[MAX_N];

void enqueue(int);
int dequeue(void);
void bfs(void);

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  int nn=n*n; 
  queue = malloc(nn * sizeof(int));
  color = malloc(n * sizeof(int));
  dist = malloc(n * sizeof(int));

  for(i = 0 ; i < n ; i++){
    matrix[i] = malloc(n * sizeof(int));
  }
 for(i = 0 ; i < n ; i++){
   dist[i] = -1;
 }
 for(i = 0 ; i < n ; i++){
   for(j = 0 ; j < n ; j++){
     matrix[i][j] = 0;
   }
 }

 for(i = 0 ; i < n ; i++){
    scanf("%d",&u); u--;
    scanf("%d",&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v); v--;
      matrix[u][v] = 1;
    }
  }

  bfs();
  for(i = 0 ; i < n ; i++){
    printf("%d %d\n",i+1,dist[i]);
  }

  for(i = 0 ; i < n ; i++){
    free(matrix[i]);
  }
  free(queue);
  free(dist);
  free(color);
  return 0;
}

void bfs(){
  int u,i;

  head = tail = 0;
  color[0] = GRAY;
  dist[0] = 0;
  enqueue(0);

  while(head != tail){
    u = dequeue();
    for(i = 0 ; i < n ; i++){
      if(matrix[u][i] == 1 && color[i] == WHITE){
        color[i] = GRAY;
        dist[i] = dist[u] + 1;
        enqueue(i);
      }
    }
    color[u] = BLACK;
  }
}

void enqueue(int q){
  queue[tail] = q;
  if(++tail == n+1) tail = 0;
}

int dequeue(){
  int v = queue[head];
  if(++head == n+1) head = 0;
  return v;
}

Measured memory_bytes: 644
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int ans;
		int fod[] = new int[m + 1];
		Arrays.fill(fod, 0);
		int you = 0;

		for (int i = 1; i <= n; i++) {
			you = sc.nextInt();
			for (int s = 1; s <= you; s++) {
				ans = sc.nextInt();
				fod[ans]++;

			}

		}
		
		
		
		int kotae = 0;
		for (int i = 0; i <= m; i++) {
			if (fod[i] == n) {
				kotae++;
			}
		}
		System.out.println(kotae);
	}
}

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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int h,w,n;cin>>h>>w>>n;
  int ans=0;int now=0;
  if(h>w)swap(h,w);
  for(int i=0;;i++){
    now+=w;
    if(now>=n)fin(i+1);
  }
}


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


namespace Test1 {

    


    class ClassMain {


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = ints[0];

                int n = int.Parse(line);
                if (n == 0) { break; }
                int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

                int prev = ints[0];
                Console.Write(prev);
                int state = 0;
                for (int i = 1; i < n; i++) {
                    if (state == 0) {//put only 1
                        if (prev + 1 == ints[i]) {
                            state = 1;
                        }
                        else {//separated
                            Console.Write(" "+ints[i]);
                            state = 0;
                        }
                    }
                    else if (state == 1) {//continuous 2 digits
                        if (prev + 1 == ints[i]) {
                            state = 1;
                        }
                        else {//separated
                            Console.Write("-" +prev+" "+ ints[i]);
                            state = 0;
                        }
                    }
                    prev = ints[i];
                }
                if (state == 1) { Console.Write("-" + prev); }
                Console.WriteLine();
            }
            
        }

        
    }

    

    
}

Measured memory_bytes: 6140
#include<bits/stdc++.h>
using namespace std;
 
int e[500000] = {};
int w[500000] = {};
 
int main(){
  int n;
  string s;
 
  cin>> n >> s;
  for(int i = 1; i <= n; i++) {
    e[i] = e[i - 1];
    w[i] = w[i - 1];
    if(s[i - 1] == 'E') e[i]++;
    if(s[i - 1] == 'W') w[i]++;
  }
 
  int ans = 1145141919; //┌（┌ ＾o＾）┐ﾎﾓｫ
 
  for(int i = 1; i <= n; i++) {
    int tmp = w[i - 1] + e[n] - e[i];
    ans = min(ans, tmp);
  }
 
  cout<< ans <<endl;
  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
ll INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll N,A,B;
vector<ll> V;
bool judge(ll x){
    ll cnt = 0;
    rep(i,0,N){
        if(V[i] <= B * x)continue;
        cnt += (V[i] - B * x + A - B - 1) / (A-B);
    }
    return cnt <= x;
}
main(){
    cin >> N >> A >> B;
    V.resize(N);
    rep(i,0,N)cin >> V[i];
    ll ok = INF, ng = -1;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        if(judge(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second



using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i; 
int multiply(int a, int b, int in_mod){return (a*b)%in_mod;} 
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}




const int MAXN=2e1+100;
vector<int> adj[MAXN];
map<pair<pair<int, int>, int>  , int> cnt; 
int ans =0;
int k;
int n, m;
vector<vector<int> > a(MAXN, vector<int> (MAXN));
void dfs(int x, int y,int left, int xo=0)
{
    xo = xo^(a[x][y]);
    if(left==0)
    {
        cnt[{{x,y}, xo }]++;
        return;
    }
    if(x!=n-1)
        dfs(x+1, y, left-1, xo);
    if(y!=m-1)
        dfs(x, y+1, left-1, xo);
}


void dfs2(int x, int y,int left, int xo=0)
{
    xo = xo^(a[x][y]);

    if(left==0)
    {
        ans += cnt[{{x,y}, xo^k^a[x][y]}];
        return;
    }
    if(x!=0)
        dfs2(x-1, y, left-1, xo);
    if(y!=0)
        dfs2(x, y-1, left-1, xo);
}



void solve()
{ 
    int a, b, c, k;
    cin>>a>>b>>c>>k;
    int sm = min(a, k);
    k-=min(a,k);
    k-=min(b, k);
    sm -=min(c,k);
    cout<<sm<<endl;
}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock(); 
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------     

    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 3896
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i,t,m,k;
		for(i=0; i<4; i++) {
			t = sc.nextInt();
			m = sc.nextInt();
			switch(t) {
			case 1:
				k = 6000 * m;
				break;
			case 2:
				k = 4000 * m;
				break;
			case 3:
				k = 3000 * m;
				break;
			default:
				k = 2000 * m;
			}
			System.out.println(k);
		}
	}
}

Measured memory_bytes: 17168
a = gets.chomp.split.map{|aa|aa.to_i}
ans,b = 0,[]
a[0].times do
  b.push(gets.chomp.split.map{|aa|aa.to_i})
end
for bb in b
  if bb[0] >= a[1] && bb[1] >= a[2]
    ans += 1
  end
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int perm[5]={};
	for(int i=0;i<5;i++)
		cin >> perm[i];

	
	int ans=1e9;
	do
	{
		int tans=0;
		for(int i=0;i<5;i++)
		{
			tans+=perm[i];
			if(i!=5-1)
			{
				while(1)
				{
					if(tans%10==0)
						break;
					tans++;
				}
			}
		}
		ans=min(ans,tans);

	}while(next_permutation(perm,perm+5));

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



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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

inline int sign(ll n){
  if(n==0) return 0;
  if(n>0) return 1;
  else return -1;
}

ll adjust(vector<ll> a){
  int n= a.size(), sign0 = sign(a[0]), cur_sign;
  ll acum = a[0], ans = 0, x;
  for(int i= 1; i<n; ++i){
    sign0 *=-1;
    acum+= a[i];
    cur_sign = sign(acum);
    if(cur_sign == sign0){
      continue;
    }else{
      x = sign0 - acum;
      ans+= abs(x);
      a[i] += x;
      acum = sign0;
    }
  }
  return ans;
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cout<< setprecision(20)<< fixed;
  int n ; cin>> n;
  vector<ll> a(n);
  forn(i,n) cin>> a[i];
  ll ans = 0;
  ll initial_cost = 0;
  if(a[0]>0){
    ans = adjust(a);
    initial_cost = a[0]+1;
    a[0] = -1;
    ans = min(ans, initial_cost + adjust(a));
  }else if(a[0]<0){
    ans = adjust(a);
    initial_cost = -a[0]+1;
    a[0] = 1;
    ans = min(ans,initial_cost+ adjust(a));
  }else{
    a[0]=1;
    ans = 1 + adjust(a);
    a[0]= -1;
    ans = min(ans, 1 + adjust(a));
  }
  cout<< ans<<el;
}




Measured memory_bytes: 1804
#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,q,b,c,w,ans=0;
	cin >> n;
	vector<int> a(500010);
	rep(i,n){
		cin >> w;
		a[w]++;
		ans+=w;
	}
	cin >> q;
	rep(i,q){
		cin >> b>>c;
		ans -= a[b] * (b-c);
		a[c] += a[b];
		a[b] = 0;
		cout << ans <<endl;
	}
}

Measured memory_bytes: 5116
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>

using namespace std;
typedef pair<int,int> P;
set<P> T;

void output(P t){
  cout << t.first << ":";
  if(t.second<10) cout << "0";
  cout << t.second;
}
int main(){
  int n;
  cin>>n;
  while(n--){
    int a,b;cin>>a>>b;
    T.insert(P(a,b));
  }
  cin>>n;
  while(n--){
    int a,b;cin>>a>>b;
    T.insert(P(a,b));
  }
  
  int i = 0;
  for(set<P>::iterator it=T.begin();it!=T.end();++it){
    output(*it);
    if(i<T.size()-1) cout << " ";
    ++i;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1200
#include<cstring>
#include <cstdio> 
#include <iostream>
#include <cmath>
#include<algorithm>
using namespace std;
#define pi 3.1415926 
#define N 510
int main()
{
	int a;
	cin>>a;
	printf("%d",a+a*a+a*a*a); 
	return 0;
}



Measured memory_bytes: 3764
#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;
    vector<int> p(n), q(n), a(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    rep(i,n) {
        a[i] = i + 1;
    }
    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    } while (next_permutation(a.begin(),a.end()));

    cout << abs(mp[p] - mp[q]) << endl;

    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a[50];
int main(){
	ll n;
	cin>>n;
	ll ma=-1e9,mi=1e9,nma,nmi;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(ma<a[i]){
			ma=a[i];
			nma=i;
		}
		if(mi>a[i]){
			mi=a[i];
			nmi=i;
		}
	}
	if(mi>=0){
		cout<<n-1<<endl;
		for(int i=1;i<n;i++)cout<<i<<' '<<i+1<<endl;
	}else if(ma<=0){
		cout<<n-1<<endl;
		for(int i=n;i>1;i--)cout<<i<<' '<<i-1<<endl;
	}else{
		cout<<2*n-1<<endl;
		if(abs(ma)>abs(mi)){
			for(int i=1;i<=n;i++)cout<<nma<<' '<<i<<endl;
			for(int i=1;i<n;i++)cout<<i<<' '<<i+1<<endl;
		}else{
			for(int i=1;i<=n;i++)cout<<nmi<<' '<<i<<endl;
			for(int i=n;i>1;i--)cout<<i<<' '<<i-1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3644
### subroutines

def t_cmp(a, b)
  c0 = b[2] - a[2]
  c1 = a[3] - b[3]
  (c0 != 0) ? c0 : ((c1 != 0) ? c1 : a[0] - b[0])
end

### main

loop do
  n = gets.to_i
  break if n == 0

  ts = []
  n.times do
    t = gets.split.map(&:to_i)
    ts << t
  end

  ts.sort!{|a, b| t_cmp(a, b)}
  #p ts

  sels = {}
  scount = 0

  for t in ts
    id, af = t

    sels[af] = [] if sels[af].nil?
    slen = sels[af].length
    sok = false

    case scount
    when 0...10
      sok = true if slen < 3
    when 10...20
      sok = true if slen < 2
    when 20...26
      sok = true if slen < 1
    end

    if sok
      scount += 1
      sels[af] << id
      puts id
    end
  end
end

Measured memory_bytes: 6120
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    string x, y;
    cin >> x >> y;
    if(x < y) {
        cout << '<' << endl;
    } else if(x == y) {
        cout << '=' << endl;
    } else {
        cout << '>' << endl;
    }
    return 0;
}

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

#define fi first
#define se second

typedef pair<int,int> ii;
typedef vector<int> vi;

const int MAXN = 100005;
const int LOGN = 20;

int idx_in_path[MAXN];
ii path[MAXN<<1];
vi adjList[MAXN];

int path_size = 0;

// compute and store the dfs order in path
// initial call with dfs(root)
void dfs(int u, int depth = 0) {
    idx_in_path[u] = path_size;

    path[path_size++] = ii(depth,u);
    for (int v : adjList[u]) {
        dfs(v, depth + 1);

        path[path_size++] = ii(depth, u);
    }
}

// must call dfs before build
ii ST[LOGN][MAXN<<1];
void build(int n) {
    int h = ceil(log2(n + 1));

    for (int i = 0; i < n; i++) ST[0][i] = path[i];
    for (int i = 1; i < h; i++)
        for (int j = 0; j + (1<<i) <= n; j++)
            ST[i][j] = min(ST[i-1][j], ST[i-1][j+(1<<(i-1))]);
}

// return the lowest common ancestor between node u and v
int lca(int u, int v) {
    int l = idx_in_path[u], r = idx_in_path[v]; 
    if (l > r) swap(l, r); r++; // range [l, r)
    
    int p = 31 - __builtin_clz(r-l);
    return min(ST[p][l],ST[p][r-(1<<p)]).se;
}

int main() {

    int num_nodes;
    scanf("%d", &num_nodes);
    for (int u = 0; u < num_nodes; u++) {
        int num_neighbors;
        scanf("%d", &num_neighbors);
        for (int i = 0; i < num_neighbors; i++) {
            int v;
            scanf("%d", &v);
            
            adjList[u].push_back(v); // directed edge
        }
    }

    dfs(0);
    build(path_size);

    int num_queries;
    scanf("%d",&num_queries);
    for (int i = 0; i < num_queries; i++) {
        int u, v;
        scanf("%d%d",&u,&v);

        printf("%d\n", lca(u, v));
    }

    return 0;
}

Measured memory_bytes: 41500
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
static constexpr Int Inf = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char ch;

template< typename T >
struct edge {
  int fr, to;
  T w;

  edge(int fr, T w) : fr(-1), to(to), w(w) {}

  edge(int fr, int to, T w) : fr(fr), to(to), w(w) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > bellman_ford(Edges< T > &edges, int N, int fr) {
  static constexpr T INF = numeric_limits<T>::max();
  vector< T > dist(N, INF);
  dist[fr] = 0;
  for(int i = 0; i < N; i++) {
    bool upd = 0;
    for(auto e : edges) {
      if(dist[e.fr] == INF) continue;
      if(dist[e.fr] + e.w < dist[e.to]){
        dist[e.to] = dist[e.fr] + e.w;
        upd=1;
      }
    }
    if(!upd)break;
    if(i==N-1)return vector<T>();
  }
  return dist;
}

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

  cin>>n>>m>>_; Edges<int>g;
  rep(i,m){
    cin>>x>>y>>q;
    g.eb(x,y,q);
  }
  V(int)d=bellman_ford(g,n,_);
  if(d.empty()){pri1("NEGATIVE CYCLE"); return 0;}
  rep(i,n)pri1(d[i]==numeric_limits<int>::max()?"INF":to_string(d[i]));
}


Measured memory_bytes: 3292
s = list(input())
t = list(input())

ans = 0
for i in range(len(s) - len(t) + 1):
    temp = 0
    for j in range(len(t)):
        if t[j] == s[i+j]:
            temp += 1
            if ans < temp:
                ans = temp

print(len(t)-ans)
            

Measured memory_bytes: 8876
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int e = min(a, b);
	int f = min(c, d);

	cout << e + f << endl;
	

 
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;
const int dg5 = 1e5;

// dp[j][i] : i 日目に j を選ぶとしたときの最大幸福度
LL dp[3][dg5 + 1];
LL abc[3][dg5 + 1];

void solve()
{
    int N;
    cin >> N;
    REP0(i, N)
    {
        cin >> abc[0][i] >> abc[1][i] >> abc[2][i];
    }

    REP0(i, 3)
    {
        dp[i][0] = abc[i][0];
    }

    REP1(i, N - 1)
    {
        REP0(j, 3)
        {
            dp[j][i] = max(dp[(j + 1) % 3][i - 1] + abc[j][i],
                           dp[(j + 2) % 3][i - 1] + abc[j][i]);
        }
    }

    LL ans = 0;
    REP0(i, 3)
    {
        ans = max(ans, dp[i][N - 1]);
    }

    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 4992
k, s = map(int, input().split())

ans = 0

for x in range(k+1):
  if x > s:
    break
  for y in range(k+1):
    if x + y > s:
      break
    z = s - x - y
    if 0 <= z <= k:
      ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};
typedef pair<int, int> pi;

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<llong> sum_A_plus_B(n);
    llong sum_B = 0;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        sum_A_plus_B.push_back(a + b);
        sum_B += b;
    }
    sort(sum_A_plus_B.begin(), sum_A_plus_B.end(), greater<llong>());

    llong ans = 0; 
    rep(i, n) {
        if (i % 2 == 0) ans += sum_A_plus_B[i];
    }

    cout << ans - sum_B << endl;

    return 0;
}

Measured memory_bytes: 1792
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

ll dp[200005],n,k;
vector<ll> g[200005];

void dfs(ll node,ll p,ll c)
{
    ll t=(node==1)?1:2;
    dp[node]=(k-c)%mod;
    for(auto y:g[node])
    {
        if(y==p)continue;
        dfs(y,node,t);
        t++;
    }   
}

int main()
{   ios;
    ll i,j,l;
    cin>>n>>k;
    dp[1]=k;
    rep(i,0,n-2)
    {
        cin>>j>>l;
        g[j].pb(l);g[l].pb(j);
    }dfs(1,-1,0);
    ll ans=1;
    rep(i,1,n)
    {   //cout<<dp[i]<<" ";
        ans*=(dp[i]);
        ans%=mod;
    }cout<<ans%mod<<en;
    //cout<<1522054186920312832%mod;
    return 0;
}


Measured memory_bytes: 13056
class Tree
  AND, OR, XOR = (0..2).to_a
  ALL = "1111".to_i(2)

  def initialize(exp, sweet)
    @size = 0
    @root = parse(exp, sweet)
  end

  class Node
    attr_accessor :left, :right, :value
  end

  def parse(exp, sweet)
    node = Node.new
    case exp.chr
      when "("
        @size += 1
        exp.slice!(0) # "("
        node.left = parse(exp, sweet)
        exp.slice!(0) # " "
        node.right = parse(exp, sweet)
        exp.slice!(0) # ")"
      else
        node.value = sweet[exp.slice!(0).to_i - 1]
    end
    node
  end

  def solve(depth = 0, operator = Array.new)
    return (calculate(operator.dup) == ALL ? 1 : 0) if (depth == @size)
    [AND, OR, XOR].inject(0){|sum, op|
      operator[depth] = op
      sum + solve(depth + 1, operator)
    }
  end

  def calculate(operator, node = @root)
    return node.value if node.value
    case operator.shift
      when AND
        calculate(operator, node.left) & calculate(operator, node.right)
      when OR
        calculate(operator, node.left) | calculate(operator, node.right)
      when XOR
        calculate(operator, node.left) ^ calculate(operator, node.right)
    end
  end
end

until (exp = gets.chomp) == "END"
  p Tree.new(exp, gets.to_i.times.map{gets.delete(" ").to_i(2)}).solve
end

Measured memory_bytes: 6164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << a / __gcd(a, b) * b << endl;
}

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


Measured memory_bytes: 3612
// author: Saman Mahdanian
#include <bits/stdc++.h>

using namespace std;
const int N = 55555 + 1;

bool mark[N];
vector <int> p[10];

int main() {
	for (int i = 2; p[3].size() < 60 && i < N; i++)
		if (!mark[i]) {
			p[i % 5].push_back(i);
			if (i < INT_MAX / i)
				for (int j = i * i; j < N; j += i)
					mark[j] = true;
			}

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cout << p[3][i] << ' ';
	cout << endl;
}

// SamMHD :: Jun26-2019 :: Another Day with Shayan...

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    string s;
    cin >> s;
    map<char,int> mp;
    for(int i=0; i<s.size(); i++){
        mp[s[i]]++;
    }
    for(auto it : mp){
        if(it.second >= 2){
            cout << "no" <<endl;
            return 0;
        }
    }
    cout << "yes" <<endl;
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;

mint calc(long long N, long long K) {
    mint res = 1;
    for (long long n = 0; n < K; ++n) {
        res *= (N - n);
        res /= (n + 1);
    }
    return res;
}
int main() {
//cout << fixed << setprecision(12);
ll n,k;
cin>>n>>k;
if((n+k)%3!=0){
cout << 0 << endl;}
else{
ll m = (n+k)/3;
ll r = n-m;
ll l = k-m;
if(r<0||l<0){
cout << 0 << endl;}
else{
mint ans = calc(r+l,l);
cout << ans << endl;}}}

Measured memory_bytes: 3632