akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 1000000;


int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
	// primeツδ環スツトツづーツ渉可甘コツ可サ
	fill(isPrime,isPrime+MAX_PRIME,true);
	p = 0;
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i <= MAX_PRIME; i++){
		if(isPrime[i]){
			prime[p++] = i;
		}
		else
			continue;
		// ツづ督づゥツつ「ツづ可つゥツつッツづゥ
		for(int j = 2*i; j <= MAX_PRIME; j+=i){
			isPrime[j] = false;
		}
	}
}

int main(){

	int N,P;
	erats();
	while(cin>>N>>P&&!(N==-1&&P==-1)){
		int *it = upper_bound(prime,prime+p,N);
		int prv=it-prime;
		int init=prv;
		vector<int> v;
		for(int i = init; i <= init+100; i++){
			for(int j = i; j <= init+100; j++){
				v.push_back(prime[i]+prime[j]);
			}
		}
		sort(v.begin(),v.end());
		cout<<v[P-1]<<endl;
	}

	return 0;
}

Measured memory_bytes: 2244
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n;
    int k = 0;
    while ((n = sc.nextInt()) != 0){
      k++;
      System.out.println("Case " + k + ": " + n);
    }
  }
}



Measured memory_bytes: 45036
e = 0
loop do
    n, x =gets.chomp.split.map(&:to_i)
    if n == 0 && x == 0
        break
    end
    (1..(n - 2)).each do |i|
        ((i + 1)..(n - 1)).each do |j|
            ((j + 1)..n).each do |k|
                d = i + j + k
                if d == x
                    e += 1
                end
            end
        end
    end
puts e
e = 0
end

Measured memory_bytes: 8776
#include <cstdio>
using namespace std;

int main(){
	int dp[31] = {1, 1, 2};
	for(int i = 3; i <= 30; ++i){
		dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
	}
	int n;
	while(scanf("%d", &n), n){
		printf("%d\n", (dp[n] + 3649) / 3650);
	}
}

Measured memory_bytes: 1028
import string


def solution(s):
    if len(s) == 0:
        for c in string.ascii_lowercase:
            if S[0] < c:
                print(c)
                return
        print(-1)
        return

    for c in string.ascii_lowercase:
        if len(s + c) == len(set(s + c)) and (s + c) > S:
            print(s + c)
            return
    solution(s[:-1])


if __name__ == "__main__":

    S = input()
    solution(S)


Measured memory_bytes: 74564
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
ll t,a,b,v,w;

int main() {
	//freopen("1.txt","r",stdin);
	read(a); read(v); read(b); read(w); read(t);
	if (v<=w) printf("NO\n");
	else {
		if (t*(v-w)>=abs(a-b)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 3608
n = int(input())
s = [int(input()) for _ in range(n)]
sl = sorted([i for i in s if i % 10 != 0])

S = sum(s)
if len(sl) == 0:
    print(0)
elif S % 10 != 0:
    print(S)
else:
    print(S - sl[0])


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int k, s;cin >> k >> s;
    LL ans = 0;
    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            if(0 <= s-x-y && s-x-y <= k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 2123
char s[N][N];
char tmp[N];
int a[N][N], b[N][N], c[N][N], d[N][N];

int main(){
	REP(i, N) REP(j, N) s[i][j]='#';
	int h, w; scanf("%d%d", &h, &w);
	REP(i, h){
		scanf("%s", tmp);
		REP(j, w) s[i+1][j+1]=tmp[j];
	}
	REP(ia, 2){
		REP(i, h+1){
			a[i][0]=0;
			FOR(j, 1, w+2) a[i][j]=s[i][j]=='#'?0:a[i][j-1]+1;
			b[i][w+1]=0;
			for(int j=w; j>=0; j--) b[i][j]=s[i][j]=='#'?0:b[i][j+1]+1;
		}
		swap(a, c);
		swap(b, d);
		swap(h, w);
		REP(i, N) FOR(j, i+1, N) swap(s[i][j], s[j][i]);
	}
	REP(i, N) FOR(j, i+1, N) swap(c[i][j], c[j][i]);
	REP(i, N) FOR(j, i+1, N) swap(d[i][j], d[j][i]);
	int ans = 0;
	FOR(i, 1, h+1){
		FOR(j, 1, w+1){
			// if(s[i][j]=='#') continue;
			LAR(ans, a[i][j] + b[i][j] + c[i][j] + d[i][j] - 3);
			DEBUG("[%d %d %d %d] ", a[i][j], b[i][j], c[i][j], d[i][j]);
		}
		DEBUG("\n");
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 75008
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100005
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    int n,G;
    cin>>n>>G;
    vector<int>p(n);
    vector<int>c(n);
    REP(i,n)cin>>p[i]>>c[i];
    int ans=INF;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> S,T;
        REP(i,n){
            if(bit & (1<<i)){
                S.push_back(i);
            }else{
                T.push_back(i);
            }
        }
        int cnt=0;
        int sum=0;
        for(auto a:S){
            cnt+=p[a];
            sum+=p[a]*100*(a+1)+c[a];
        }
        int i=SZ(T)-1;
        while(G>sum){
            int w=min(p[T[i]]-1,(G-sum+100*(T[i]+1)-1)/(100*(T[i]+1)));
            cnt+=w;
            sum+=w*100*(T[i]+1);
            i--;
            if(i<0&&G>sum){
                cnt=INF;
                break;
            }
        }
        ans=min(ans,cnt);
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid] + [INF]
    R = A[mid:right] + [INF]
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
            cnt += mid - left - i

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

INF = 10000000000
n = int(input())
A = list(map(int,input().split()))
cnt = 0
mergeSort(A,0,n)
print(cnt)


Measured memory_bytes: 27468
n = int(input())
a = [0] * n; b = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split()) 

a.sort(); b.sort()
if n%2 != 0 :
    print(b[n//2] - a[n//2] + 1)
    exit(0)

def m_r(c):
    return (c[n//2] + c[n//2 - 1])

z = m_r(b) - m_r(a) + 1
print(z)



Measured memory_bytes: 75628
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a,b,c;
	cin>>n;
	for(int i=0;i<n;i++){
		bool t=false;
		cin>>a>>b>>c;
		if(a*a+b*b==c*c)
			t=true;
		if(a*a+c*c==b*b)
			t=true;
		if(b*b+c*c==a*a)
			t=true;
		if(t==true)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <algorithm>
#include <utility>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> pll;

const int mx = 1e6, len = 1e6+5;
const ll inf = 1e13;
pll tree[4*len];
ll dp[len];
int arr[len];

struct node{
    pll line;
    node *left, *right;

    node(pll li = mp(0, inf), node *l = NULL, node *r = NULL){
        line = li;
        left = l;
        right = r;
    }
};

typedef node* pnode;
pnode null = new node();
pnode root;

ll fun(pll line, ll x){
    return line.fi*x+line.se;
}

pnode update(pnode t, int l, int r, pll cur){
    int mid = (l+r)/2;
    pll best = cur, bad = t->line;
    if (fun(bad, mid) < fun(best, mid))
        swap(best, bad);

    if (l == r)
        return new node(best, null, null);

    if (fun(bad, l) < fun(best, l))
        return new node(best, update(t->left, l, mid, bad), t->right);
    return new node(best, t->left, update(t->right, mid+1, r, bad));
}

ll query(pnode t, int l, int r, int x){
    if (l == r)
        return fun(t->line, x);

    int mid = (l+r)/2;
    if (x <= mid)
        return min(fun(t->line, x), query(t->left, l, mid, x));
    return min(fun(t->line, x), query(t->right, mid+1, r, x));
}

int main(){
    int n;
    ll c;
    scanf("%d %lld", &n, &c);
    for (int i = 1; i <= n; i++)
        scanf("%d", &arr[i]);

    root = null->left = null->right = null;
    root = update(root, 1, mx, mp(-2*arr[n], dp[n]+arr[n]*1LL*arr[n]));
    for (int i = n-1; i >= 1; i--){
        dp[i] = query(root, 1, mx, arr[i]);
        dp[i] += arr[i]*1LL*arr[i]+c;

        root = update(root, 1, mx, mp(-2*arr[i], dp[i]+arr[i]*1LL*arr[i]));
    }

    printf("%lld\n", dp[1]);
    return 0;
}


Measured memory_bytes: 198784
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n,k,s;
ll a[MAX];
int main(){FAST;
cin>>n>>k>>s;
ll comp = s+1;
if(comp>1000000000)comp = 1;
for(int i=1;i<=k;++i){
  cout<<s<<' ';
}
for(int i=k+1;i<=n;++i){
  cout<<comp<<' ';
}
return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

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

  int mini = a[0];
  int ans = -pow(10, 9) - 1;
  for (int i = 1; i < n; i++)
  {
    ans = max(ans, a[i] - mini);
    mini = min(mini, a[i]);
  }

  cout << ans << endl;
}


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

using namespace std;

int main() {
    int N,W,H,x,y,w;
    cin >> N >> W >> H;
    vector<int> xvect(W+2,0), yvect(H+2,0);
    bool ans=true;
    for(int i=0; i < N ;i++){
        cin >> x >> y >> w;
        xvect[max(x-w,0)]++;
        xvect[min(x+w,W+1)]--;
        yvect[max(y-w,0)]++;
        yvect[min(y+w,H+1)]--;
    }
    int sum=0;
    for(int i=0;i<W;i++){
        sum+=xvect[i];
        if(sum == 0) ans=false;
    }
    sum=0;
    if(ans==false){
        ans = true;
        for(int i=0;i<H;i++){
            sum+=yvect[i];
            if(sum == 0) ans=false;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define pp pair<int,int>
#define MZ 1000000007
#define Pi acos(-1)
#define pq priority_queue

using namespace std;

queue <int> q;
vector <int> vec[100005];
int color[100005];
bool life[100005];
int lens;

bool dfs1(int x,int len)
{
    life[x]=1;
    if(x==1)
    {
        lens=len;
        color[x]=-1;
        return 1;
    }
    for(int i=0;i<vec[x].size();i++)
    {
        if(!life[vec[x][i]])
        {
            if(dfs1(vec[x][i],len+1))
            {
                if(len*2<=lens)
                    color[x]=1;
                else
                    color[x]=-1;
                return 1;
            }
        }
    }
    return 0;
}
void dfs2(int x,int col)
{
    color[x]=col;
    for(int i=0;i<vec[x].size();i++)
    {
        if(!color[vec[x][i]])
            dfs2(vec[x][i],col);
    }
}

int main()
{
    int n,a,b,x,ans=0;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    dfs1(n,1);
    for(int i=1;i<=n;i++)
    {
        if(color[i])
            dfs2(i,color[i]);
    }
    for(int i=1;i<=n;i++)
    {
        if(color[i]==-1)
            ans++;
        else
            ans--;
    }
    if(ans>0)
        printf("Fennec\n");
    else
        printf("Snuke\n");
    return 0;
}


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

typedef struct Bomb{
	int map[8][8];
} BOMB;

Input(BOMB *);
void explode(BOMB *);

int x_cnt, y_cnt;

int main()
{
	int input_times, input_cnt;
	BOMB Bomb[50];
	int x, y;
	
	scanf("%d", &input_times);
	for(input_cnt = 0; input_cnt < input_times; input_cnt++){
		Input(&Bomb[input_cnt]);
		scanf("%d\n%d", &x, &y);
		Bomb[input_cnt].map[x - 1][y - 1] = 2;
		explode(&Bomb[input_cnt]);
	}
	
	for(input_cnt = 0; input_cnt < input_times; input_cnt++){
		printf("Data %d:\n", input_cnt + 1);
		for(y_cnt = 0; y_cnt < 8; y_cnt++){
			for(x_cnt = 0; x_cnt < 8; x_cnt++)
				printf("%d", Bomb[input_cnt].map[x_cnt][y_cnt]);
			printf("\n");
		}
	}
	
	return 0;
}

Input(BOMB *bomb)
{
	char dump;
	dump = getchar();
	for(y_cnt = 0; y_cnt < 8; y_cnt++){
		dump = getchar();
		for(x_cnt = 0; x_cnt < 8; x_cnt++)
			bomb->map[x_cnt][y_cnt] = getchar() - 48;
	}
}

void explode(BOMB* bomb_map)
{
	int explode_cnt;
	for(y_cnt = 0; y_cnt < 8; y_cnt++)
		for(x_cnt = 0; x_cnt < 8; x_cnt++)
			/*Find exploded bomb and process*/
			if(bomb_map->map[x_cnt][y_cnt] == 2){
				bomb_map->map[x_cnt][y_cnt] = 0;
				/*Left*/
				explode_cnt = 1;
				while((x_cnt - explode_cnt) >= 0 && explode_cnt <= 3){
				    if((bomb_map->map[x_cnt - explode_cnt][y_cnt]) == 1)
				        (bomb_map->map[x_cnt - explode_cnt][y_cnt]) = 2;
				    explode_cnt++;
				}
				/*Right*/
				explode_cnt = 1;
				while((x_cnt + explode_cnt) <= 7 && explode_cnt <= 3){
				    if((bomb_map->map[x_cnt + explode_cnt][y_cnt]) == 1)
				        (bomb_map->map[x_cnt + explode_cnt][y_cnt]) = 2;
				    explode_cnt++;
				}
				/*Down*/
				explode_cnt = 1;
				while((y_cnt - explode_cnt) >= 0 && explode_cnt <= 3){
				    if((bomb_map->map[x_cnt][y_cnt - explode_cnt]) == 1)
				        (bomb_map->map[x_cnt][y_cnt - explode_cnt]) = 2;
				    explode_cnt++;
				}
				/*Up*/
				explode_cnt = 1;
				while((y_cnt + explode_cnt) <= 7 && explode_cnt <= 3){
				    if((bomb_map->map[x_cnt][y_cnt + explode_cnt]) == 1)
				        (bomb_map->map[x_cnt][y_cnt + explode_cnt]) = 2;
				    explode_cnt++;
				}
				explode(bomb_map);
			}
}

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

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

  int num[] = {1, 2, 4, 8, 16, 32, 64, 128};
  for (int i = 0; i < 8; i++) {
    if (num[i] > N) {
      cout << num[i-1] << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
  vector<int> length(3);
  for (int i = 0; i < 3; ++i)
  {
    cin >> length[i];
  }
  sort(length.begin(), length.end());
  cout << length[0] + length[1] << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
a.remove(ma)
num = 0
ind = 0
a.sort()
for i in range(N-1):
    if a[i] < ma//2:
        ind += 1

if ind == 0:
    print(ma,a[0])
    exit()
elif ind == N-1:
    print(ma,a[-1])
    exit()

if abs(ma//2 - a[ind-1]) < abs(ma//2 - a[ind]):
    print(ma,a[ind-1])
else:
    print(ma,a[ind])

Measured memory_bytes: 19936
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, M = getNM()
A = getList()
A.sort()

ans = 0
way = 1

fact =[1] #階乗
# 5 * 4 * 3 * 2 * 1
for i in range(1, N + 1):
    fact.append(fact[i - 1] * i % mod)

facv = [0] * (N + 1) #階乗の逆元
facv[-1] = pow(fact[-1], mod - 2 , mod)

# 1 / 5 * 4 * 3 * 2 * 1のmod
for i in range(N - 1, -1, -1):
    facv[i] = facv[i + 1] * (i + 1) % mod

def cmb(n, r):
    if n < r:
        return 0
    # 計算
    return fact[n] * facv[r] * facv[n - r] % mod

for i in range(N - 2 + 1):
    min_sum = A[i] * cmb(N - i - 1, M - 1)
    max_sum = A[-i - 1] * cmb(N - i - 1, M - 1)
    ans += (max_sum - min_sum) % mod
print(ans % mod)

Measured memory_bytes: 88176
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
	Node *x = root;
	Node *y = NIL;
	Node *z;

	z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) return;
	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}

Node* find(Node *u,int k) {
	while (u != NIL && k != u->key) {
		if (k < u->key) {
			u = u->left;
		}
		else {
			u = u->right;
		}
	}

	return u;
}

int main() {
	int n, x;
	string com;

	scanf("%d", &n);

	for (int i = 0; i < n; ++i) {
		cin >> com;
		if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com == "find") {
			scanf("%d", &x);
			Node *t = find(root, x);
			if (t != NIL) {
				printf("yes\n");
			}
			else {
				printf("no\n");
			}
		}
	}


	return 0;
}




Measured memory_bytes: 22016
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int h, w, s, u[50][50];

int rect(int x1, int y1, int x2, int y2)
{
    return u[x2][y2] - u[x1][y2] - u[x2][y1] + u[x1][y1];
}

pair<int,int> memo[36][36][36][36];

pair<int,int> recur(int x1, int y1, int x2, int y2)
{
    if (memo[x1][y1][x2][y2].first >= 0)
	return memo[x1][y1][x2][y2];

    pair<int,int> ret = mp(1, rect(x1, y1, x2, y2));
    for (int x = x1 + 1; x < x2; ++x) {
	pair<int,int> l = recur(x1, y1, x, y2);
	pair<int,int> r = recur(x, y1, x2, y2);
	pair<int,int> m = mp(l.first + r.first, min(l.second, r.second));
	if (m.second >= rect(0, 0, w, h) - s)
	    ret = max(ret, m);
    }
    for (int y = y1 + 1; y < y2; ++y) {
	pair<int,int> l = recur(x1, y1, x2, y);
	pair<int,int> r = recur(x1, y, x2, y2);
	pair<int,int> m = mp(l.first + r.first, min(l.second, r.second));
	if (m.second >= rect(0, 0, w, h) - s)
	    ret = max(ret, m);
    }
    return memo[x1][y1][x2][y2] = ret;
}

void solve()
{
    rep(i, 36) rep(j, 36) rep(k, 36) rep(l, 36)
	memo[i][j][k][l] = mp(-1, -1);

    pair<int,int> ans = recur(0, 0, w, h);
    cout << ans.first << ' ' << s + ans.second - rect(0, 0, w, h) << endl;
}

int main()
{
    while (cin >> h >> w >> s && h) {
	memset(u, 0, sizeof(u));
	rep(y, h) rep(x, w) cin >> u[x + 1][y + 1];
	for (int y = 1; y <= h; ++y)
	    for (int x = 1; x <= w; ++x)
		u[x][y] += u[x - 1][y] + u[x][y - 1] - u[x - 1][y - 1];

	solve();
    }
    return 0;
}

Measured memory_bytes: 14308
#include <cstdio>

//input
int a, b, c, d, e, f;

void solve(){
	double x = 1.0 * (c * e - b * f) / (a * e - b * d);
	double y = (c - a * x) / b;
	if(x == -0)x = 0;
	if(y == -0)y = 0;
	printf("%.3lf %.3lf\n", x, y);
}

int main(int argc, char const *argv[]){
//	freopen("in.txt", "r", stdin);

	while(scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if(a>=b && a>=c){
			int sum = b + c;
			System.out.println(sum);
		}else if(b>=a && b >=c){
			int sum = a + c;
			System.out.println(sum);
		}else{
			int sum = a + b;
			System.out.println(sum);
		}

	}

}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm> 
using namespace std;


long long N,M,K,ans,x[100],ma,mi,summin,num;

string s;
int main(){
	cin >> N;
	ma = -101;
	mi = 101;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		ma = max(ma, x[i]);
		mi = min(mi, x[i]);
	}
	long long sum;
	for (int i = mi; i <= ma; i++) {
		sum = 0;
		for (int j = 0; j < N; j++) {
			sum += abs(x[j] - i)*abs(x[j] - i);
		}
		if (i == mi)ans = sum;
		ans = min(ans, sum);
	}




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

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

int main(){
    int N;
  cin >> N;
    vector<tuple<string, int, int>> table(N);

    for(int i=0;i<N;i++){
        string a;
        int b,c;
        c = i+1;

        cin >> a >> b ;
        b = -b;
        table[i] = make_tuple(a,b,c);
    }

    sort(table.begin(),table.end());
    for(tuple<string,int,int> t : table){
      int y,z;
      string x;
      tie(x,y,z) = t;
      
      cout << z << endl;
    }
}

Measured memory_bytes: 256
N,x,y = map(int,input().split())
k = [0]*(N-1)
kn = 0
for i in range(1,N):
  for j in range (i+1,N+1):
    k1 = abs(i-j)
    k2 = abs(i-x)+1+abs(y-j)
    kn = min(k1,k2)
    k[kn-1] += 1
for i in range(N-1):
  print(k[i])

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

typedef long long ll;
#define pb push_back

#define rep(i, n) for (int i=0;i<(n);++i)
#define rep2(i, s, n) for (int i=s;i<(n);++i)
#define INF (1e9+1e9)

class Edge{
public:
    int u, v, cost;
    Edge(int u, int v, int cost=1):
        u(u), v(v), cost(cost) {}
    bool operator < (const Edge& e) const {
        return cost != e.cost ? cost > e.cost : // for min-priority queue
            u != e.u ? u < e.u : v < e.v;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

/* Bipartie Matching using Ford-Fulkerson with DFS */
// DFS
// vertex u is always in L
bool dfs(Graph& G, int u, vector<bool>& visited, vector<int>& to)
{
    if (u == -1) return true; // augmenting path
    for(auto& e:G[u]) if(!visited[e.v]) {
        visited[e.v] = true; // vertex e.v is always in R
        if (dfs(G,to[e.v],visited,to)) { // we always traverse the matched edge (e.v, to[e.v])
            to[e.v] = u, to[u] = e.v;    // new matching
            return true; 
        }
    }
    return false; // no augmenting path 
}

int matching(Graph& G, int X, Edges& M)
{
    int V = G.size(), m = 0;
    vector<int> to(V,-1); // to[src] = dst
    
    rep(i,X) {
        vector<bool> visited(V,false);
        if (dfs(G,i,visited,to)) m++; // augmenting path found
    }

    //rep(i,X) if (to[i] != -1) M.pb(Edge(i, to[i]));
    return m;
}

int main()
{
    int X,Y,E; cin>>X>>Y>>E;
    Graph G(X+Y);
    rep(i,E) {
        int u,v; cin>>u>>v;
        G[u].pb(Edge(u,v+X));
        G[v+X].pb(Edge(v+X,u));
    }
    
    Edges M;
    int m = matching(G,X,M);
    cout << m << endl;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int h, w;
    char tmp;
    cin >> h >> w;
    map<char, int> cnt;
    rep(i, w){
        rep(j, h){
            cin >> tmp;
            cnt[tmp]++;
        }
    }

    int odd = 0;
    int d_four = 0;
    int d_two = 0;
    for(auto const& e : cnt){
        if(e.second%4 == 0) d_four++;
        else if(e.second%2 == 0) d_two++;
        else odd++;
    }

    bool res;
    if(h%2 == 0 && w%2 == 0){
        if(d_two == 0 && odd == 0) res = true;
        else res = false;
    }else if(h%2 == 1 && w%2 == 1){
        int num = (h-1)/2 + (w-1)/2;
        if(d_two <= num && odd == 1) res = true;
        else res = false;
    }else{
        int h_or_w = h%2==0 ? h/2 : w/2;
        if(d_two <= h_or_w && odd == 0) res = true;
        else res = false;
    }

    ans(res);
    //mdebug(cnt);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <climits>
#include <iomanip>
#include <queue>

using namespace std;

const int N = 2e5 + 9;
const int INF = 2e9 + 2;
const int mod = 1e9 + 7;
const int K = 25;
const int P = 51;
const long long LONG_INF = LONG_MAX;
const int SZ = (1 << 18) - 1;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define mkp make_pair
#define all(s) s.begin(), s.end()

#define ll long long

#define int ll

void solve() {
	int x;
	cin >> x;
	int sum = 0;
	while(true) {
		if (x < 5)
			break;
		if (x >= 500) {
			sum += 1000;
			x -= 500;
		}
		else{
			sum += 5;
			x -= 5;
		}
	}
	cout << sum;
}


signed main() {
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();

		int KA =0;
		int KB =0;
		int KC = 0;
		int sum = 0;
		
		if(K>=A) {
			KA = A;
			KB = K - KA;
		}else {
			KA = K;
			KB = 0;
			KC = 0;
		}
		
		if(KB >= B) {
			KB = B;
			KC = K - A- B; 
		}else{
			KC = 0;
		}
		
		sum = (KA * 1) + (KB * 0) + (KC * -1);
			
		
		System.out.println(sum);
		
		sc.close();
	}
}

Measured memory_bytes: 35764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        int[] hw = Console.ReadLine().ToIntArray();
        int H = hw[0];
        int W = hw[1];

        char[,] s = new char[H, W];

        for(int i = 0; i < H; i++)
        {
            var line = Console.ReadLine().ToCharArray();
            for(int j = 0; j < W; j++)
            {
                s[i, j] = line[j];
            }
        }

        //全部の黒マスについて、「４方向のいずれかが黒」であれば良い。
        //指定したマスについて、「そのマスが白か、または４方向のいずれかが黒」か判定する関数をJudgeとする
        Func<int, int, bool> judge = (i, j) => {
            if (s[i, j] == '.') return true;
            if (i + 1 < H && s[i + 1, j] == '#') return true;
            if (i - 1 >= 0 && s[i - 1, j] == '#') return true;
            if (j + 1 < W && s[i, j + 1] == '#') return true;
            if (j - 1 >= 0 && s[i, j - 1] == '#') return true;
            return false;

        };

        if (Enumerable.Range(0, H).SelectMany(h => Enumerable.Range(0, W).Select(w => new { h, w })).All(itm => judge(itm.h, itm.w)))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

    }
}

Measured memory_bytes: 13396
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
int bit_count(ll x) {
    int cnt = 0;
    ll mask = 0x01;
    REP(i,64) {
        if (x & mask) cnt++;
        mask <<= 1;
    }
    return cnt;
}
#endif


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


    int N, M; cin >> N >> M;
    vi K(M);
    vvi S(M);
    REP(i,M) {
        cin >> K[i];
        REP(j, K[i]) {
            int sw; cin >> sw;
            S[i].push_back(sw);
        }
    }
    vi P(M); REP(i, M) cin >> P[i];


    vi mask(M, 0);
    REP(i,M) {
        for (int j : S[i]) {
            mask[i] |= (0x01 << (j - 1));
        }
    }

    int PAT = 0x01 << N;

    int ans = 0;
    REP(i, PAT) {
        int pt = i;
        bool ok = true;
        REP(j,M) {
            int t = pt & mask[j];
            int cnt = bit_count(t);
            if (cnt%2 != P[j]) {
                ok = false;
                break;
            }
        }
        if (ok) ans++;
    }

    cout <<  ans << endl;

    return 0;
}

Measured memory_bytes: 256
from itertools import product


def main():
    N = int(input())
    A = map(int, input().split())

    f(N, A)


def f2(N, A):
    """
    Bの項どれか1つは偶数
    B = A, A+1, A-1
    Aの項が奇数: Bは奇数1,偶数2
    Aの項が偶数: Bは奇数2,偶数1
    B1が偶数なら、B2以降は似ていればなんでも良い
    B1が奇数なら、B2以降のどれかは似ていいるかつ偶数

    全列挙しなくてもAの項の偶奇性を使ってO(N)で計算できそう
    """
    pass


def f(N, A):
    """全組み合わせ

    3^10=59,049
    """
    B = [
        (a, a+1, a-1)
        for a in A
    ]
    ans = 0
    for b in product(*B):
        p = 1
        for _b in b:
            p *= _b
        if p % 2 == 0:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;


int main(){
    int N;
    cin >> N;
    vector <int> A(N);

    int min = std::pow(10, 9);
    int count = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if (A[i] <= 0) {
            A[i] = -1 * A[i];
            count += 1;
        }
        if (min >= A[i]) {
            min = A[i];
        }
    }
    long long sum = 0;
    for(int i = 0; i < N; i++){
        sum += A[i];
    }

    if (count % 2 == 1) {
        sum -= 2 * min;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end() //使うときはsort(all())という感じで
using ll = long long;
#define PI 3.14159265359

int main(void){
  int n;
  cin>>n;
  bool ju=true;
  rep(i,n){
    int s;
    cin>>s;
    if(s%2==0){
      if((s%3!=0)&&(s%5!=0)){
        ju=false;
      }
    }
  }
  if(ju) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
  return 0;
}

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

string s;
int index;
 
int cur;
bool endf;
 
string rec()
{
    string res;
 
    while(cur < s.size() && !endf) {
        while('A' <= s[cur] && s[cur] <= 'Z') {
            res += s[cur];
            cur++;
        }
 
        if('0' <= s[cur] && s[cur] <= '9') {
            int n = s[cur++] - '0';
            while('0' <= s[cur] && s[cur] <= '9') {
                n = 10 * n + s[cur++] - '0';
            }
 
            string pattern;
            if(s[cur] == '(') {
                cur++;
                pattern = rec();
            } else {
                pattern = s[cur++];
            }
 
            for(int i = 0; i < n; ++i) {
                res += pattern;
                if(res.size() > index) {
                	endf = true;
                	break;
                }
            }
        }
 
        if(s[cur] == ')') {
            cur++;
            return res;
        }
    }
 
    return res;
}
 
 
int main()
{
    while(true){
        cin >> s >> index;
        if(s == "0" && index == 0) break;
 
        cur = 0;
        endf = false;
        string res = rec();
        //cout << res << endl;
        if(res.size() <= index) {
            cout << 0 << endl;
        } else {
            cout << res[index] << endl;
        }
    }
}

Measured memory_bytes: 8704
#include <stdio.h>
#define swap(a, b) {int tmp = a; a = b; b = tmp;}

int triangle(int a, int b, int c)
{
    if (a + b <= c) return -1;
    if (a * a + b * b == c * c) return 1;
    if (a * a + b * b > c * c) return 2;
    if (a * a + b * b < c * c) return 3;
}

int main(void)
{
    int a, b, c;
    int tri[4] = {0};

    while (scanf("%d %d %d", &a, &b, &c) != EOF){
        int t;

        if (a > b) swap(a, b);
        if (b > c) swap(b, c);
        if (a > b) swap(a, b);
        t = triangle(a, b, c);
        if (t == -1) break;
        tri[0]++;
        tri[t]++;
    }
    printf("%d %d %d %d\n", tri[0], tri[1], tri[2], tri[3]);

    return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] arr = new long[n];
		long[] sums = new long[n - 1];
		long total = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
			total += arr[i];
			if (i != n - 1) {
				sums[i] = total;
			}
		}
		for (int i = 0; i < n - 1; i++) {
			sums[i] = Math.abs(total - sums[i] * 2);
		}
		Arrays.sort(sums);
		System.out.println(sums[0]);
	}
}


Measured memory_bytes: 88284
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S;
  cin >> S;

  vector<int> ascii(26);

  for (int i = 0; i < S.size(); i++) {
    ascii[S[i] - 'A']++;
  }

  string answer = "Yes";

  for (int i = 0; i < 26; i++) {
    if (ascii[i] != 0 && ascii[i] != 2) {
      answer = "No";
      break;
    }
  }
  
  cout << answer << endl;
  
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] n = sc.next().toCharArray();

		for (char c : n) {
			if (c == '1') {
				pr.print('9');
			} else if (c == '9') {
				pr.print('1');
			}
		}
		pr.println();
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n, k;
    cin >> n >> k;
    int d;
    vector<int> sweet(n, 0);
    for(int i = 0; i < k; i++){
        cin >> d;
        for(int j = 0; j < d; j++){
            int t;
            cin >> t;
            sweet[t-1] = 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(sweet[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
check = 10000000
taste_all = 0
list1 = []
N, L = map(int, input().split()) 
for i in range(1,N+1):
    taste = L + i -1
    if (check > abs(taste)):
        check = min (check,abs(taste))
        remove_apple = taste
    list1.append(taste)
    taste_all =taste_all + taste
list1.remove(remove_apple)

print(sum(list1))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;

static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int stage_w,stage_h,total_buyers;
int ans[50][50];

void disp(int stage[50][50]){
  for(int y = 0; y < stage_h; y++){
    for(int x = 0; x < stage_w; x++){
      printf("%d%s",stage[y][x], x == stage_w - 1 ? "" : " ");
    }
    printf("\n");
  }
}

bool check(int stage[50][50]){
  for(int y = 0; y < stage_h; y++){
    for(int x = 0; x < stage_w; x++){
      if(stage[y][x] == 0) return false;
    }
  }
  memcpy(ans,stage,sizeof(int)*50*50);
  return true;
}

int dfs(int id,int areas[50],P occupied[50],int stage[50][50]){
  if(id > total_buyers){
    return check(stage) ? 1 : 0;
  }

  int res = 0;
  for(int w = 1; w <= areas[id]; w++){
    int h = areas[id] / w;
    if(h * w != areas[id]) continue;
    int cx = occupied[id].first;
    int cy = occupied[id].second;

    for(int lx = cx - w + 1; lx <= cx; lx++){
      if(lx < 0) continue;

      int rx = lx + w - 1;

      if(rx >= stage_w) continue;
      for(int ly = cy - h + 1; ly <= cy; ly++){
        if(ly < 0) continue;

        int ry = ly + h - 1;
        if(ry >= stage_h) continue;

        int prev[50][50];
        memcpy(prev,stage,sizeof(int)*50*50);
        for(int x = lx; x <= rx; x++){
          for(int y = ly; y <= ry; y++){
            if(stage[y][x] == 0){
              stage[y][x] = id;
            }
            else if(stage[y][x] != id){
              goto fail;
            }
          }
        }
        res += dfs(id + 1,areas,occupied,stage);
      fail:;
        memcpy(stage,prev,sizeof(int)*50*50);
      }
    }
  }

  return res;
}

int main(){

  while(~scanf("%d %d %d",&stage_w,&stage_h,&total_buyers)){
    if(stage_w == 0 && stage_h == 0) break;

    int stage[50][50];
    int areas[50];
    for(int buyer_i = 0; buyer_i < total_buyers; buyer_i++){
      int id;
      int area;
      scanf("%d %d",&id,&area);
      areas[id] = area;
    }

    P occupied[50];
    for(int y = 0; y < stage_h; y++){
      for(int x = 0; x < stage_w; x++){
        scanf("%d",&stage[y][x]);
        if(stage[y][x] != 0){
          occupied[stage[y][x]] = P(x,y);
        }
      }
    }

    if(dfs(1,areas,occupied,stage) == 1){
      disp(ans);
    }
    else{
      printf("NA\n");
    }
  }
}

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

string S,T;
int main(){
	while(cin >> S >> T){
		string ans = S;
		bool prejudge = true, judge = false;
		if(S.size()>=T.size()){
			for(int i=0;i<=S.size()-T.size();i++){
				string now = S;
				for(int j=0;j<T.size();j++){
					if(S[i+j] == T[j] || S[i+j] == '?') now[i+j] = T[j];
					else prejudge = false;
				}
				if(prejudge){
					judge = true;
					for(int k=0;k<S.size();k++){
						if(now[k] == '?'){
							now[k] = 'a';
						}
					}
					if(S == ans) ans = now;
					if(now<ans) ans = now;
				}
				prejudge = true;
			}
		}
		if(judge) cout << ans << endl;
		else cout << "UNRESTORABLE" << endl;
	}
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int l=0,r=n-1;
    cout<<0<<endl;
    fflush(stdout);
    string s1;
    cin>>s1;
    if (s1=="Vacant") {cout<<endl; return 0;}
    while (l<=r)
    {
        int f=(l+r)/2;
        cout<<f<<endl;
        fflush(stdout);
        string s;
        cin>>s;
        if (s=="Vacant") {cout<<endl; return 0;}
        else if (l==r) break;
        else if ((f%2==0&&s!=s1)||(f%2==1&&s==s1))
        {
            r=(l+r)/2-1;
        }
        else
        {
            l=(l+r)/2+1;
        }
        //s1=s;
        //fflush(stdout);
    }
    for (int f=(l+r)/2-1;f<=(l+r)/2+1;f++)
    {
        cout<<f<<endl;
        fflush(stdout);
        string s;
        cin>>s;
        if (s=="Vacant") {cout<<endl; return 0;}
    }
    cout<<"no";
    return 0;
}


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

int main(void){
  char s[11];
  int i,j=0,k=0,l=0,m;
  
  cin>>s;
  for(i=0;i<11;i++){
    if(s[i]=='\0')
      break;
    j++;
  }
  if(s[0]!='A'){
    cout<<"WA"<<endl;
    return 0;
  }
  else{
    for(i=2;i<j-1;i++){
      if(s[i]=='C'){
        k++;
        m=i;
        break;
      }
    }
    
   if(k!=1){
      cout<<"WA"<<endl;
     return 0;
   }
    else{
      for(i=1;i<j;i++){
        if(i==m)
          continue;
        else if(s[i]+0>=97)
          l++;
      }
      
    }
  }
    cout<<(l==j-2?"AC":"WA")<<endl;
  
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int a,b,c,k;
	cin >> a >> b >> c >> k;

	int sum = 0;
	sum += min(a,k);
	k-= min(a,k);
	if(k)
	{
		k -= min(k,b);
	}

	if(k)
	{
		sum-= min(k,c);
	}

	cout << sum;

    return 0;
}

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

using namespace std;

#define INF 210000000
#define int long long

signed main() {
		int n;
		cin >> n;
		vector<int> a;
		for(int i=0;i<n;i++){
				int tmp;
				cin >> tmp;
				a.push_back(tmp);
		}
		vector<int> ans;
		while(true){
				int f = 0;
				for(int i=a.size()-1;i>=0;i--){
						if(a[i] == i+1){
								f = 1;
								ans.insert(ans.begin(),a[i]);
								a.erase(a.begin() + i);
								break;
						}
				}
				if(a.size() == 0 or f == 0) break;
		}
		if(a.size() == 0){
				for(auto& A : ans) cout << A << endl;
		}else{
				cout << -1 << endl;
		}
}


Measured memory_bytes: 256