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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> v(m);
    for(int i = 0; i < m; i++){
        cin >> v[i];
    }
    int hozona = 0;
    int hozonb = 0;
    for(int i = x; i > 0; i--){
        for(int j = 0; j < m; j++){
            if(v[j] == i){
                hozona++;
            }
        }
    }
    for(int i = x; i < n; i++){
        for(int j = 0; j < m; j++){
            if(v[j] == i){
                hozonb++;
            }
        }
    }
    cout << min(hozona,hozonb) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<bitset>
using namespace std;

//Switches
int main(){
	int n,m;
	cin >> n >> m;
	int* switches = new int[m];
	for(int i = 0;i<m;i++){
		int k; 
		cin >> k;
		int tmp = 0;
		for(int j = 0; j<k;j++){
			int s;
			cin >> s;
			tmp += (int)pow(2,(s-1));
		}
		switches[i] = tmp;
	}
	int* p = new int[m];
	for(int i=0;i<m;i++){
		cin >> p[i];
	}
	int case_num = 0;
	bool all_on = true;
	for(int i = 0;i<pow(2,n);i++){
		all_on = true;
//		cout <<"swich_on_place" << bitset<16>(i) << endl;
		for(int j=0;j<m;j++){
			int switch_on_place = i & switches[j];
//			cout << "light_on_place: "<< bitset<16>(switch_on_place) << endl;
			int switch_on_num=0;
			for(int k=0;k<n;k++){
				if(switch_on_place/(int)pow(2,k) % 2== 1){
					switch_on_num++;
				}
			}
//			cout << switch_on_num << endl;
			if(switch_on_num % 2 != p[j]){
				all_on=false;
				continue;
			}
		}
		if(all_on == true){
			case_num++;
		}
	}
	cout << case_num << endl;

	return 0;
}
	



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

typedef struct {
    int index;
    int num;
} Pair;

int comp(const void* a, const void* b) {
    return ((Pair*)a)->num - ((Pair*)b)->num;
}

int main(void) {
    int N;
    scanf("%d", &N);

    Pair Ai[N];
    for (int i=0; i<N; i++) {
        Ai[i].index = i;
        scanf("%d", &(Ai[i].num));
    }

    int count = 0;
    qsort(Ai, N, sizeof(Ai[0]), comp);

    for (int i=0; i<N; i++) {
        if (i%2 != Ai[i].index%2) {
            count++;
        }
    }

    printf("%d\n", count/2);

}

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define N 100010
#define ll long long
#define mod 1000000007
using namespace std;
struct matrix{
	ll num[3][3];
	matrix(int x=0){memset(num,0,sizeof(num));num[0][0]=num[1][1]=num[2][2]=x;}
	ll * operator [](int i){return (*this).num[i];}
};
matrix operator +(matrix a,matrix b)
{
	matrix c;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
		c[i][j]=(a[i][j]+b[i][j])%mod;
	return c;
}
matrix operator *(matrix a,matrix b)
{
	matrix c(0);
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
			c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod;
	return c;
}
matrix ksm(matrix x,ll y)
{
	matrix res(1),o=x;
	while(y)
	{
		if(y&1) res=res*o;
		o=o*o;
		y>>=1;
	}
	return res;
}
ll len;
int n;
ll val[N],d[N];
matrix p,o,u(1);
int main()
{
	scanf("%lld%d",&len,&n);
	p.num[0][0]=1;p.num[0][1]=0;p.num[0][2]=0;
    p.num[1][0]=1;p.num[1][1]=1;p.num[1][2]=0;
    p.num[2][0]=1;p.num[2][1]=2;p.num[2][2]=1;
    o.num[0][0]=1;o.num[0][1]=0;o.num[0][2]=1;
    o.num[1][0]=1;o.num[1][1]=1;o.num[1][2]=1;
    o.num[2][0]=1;o.num[2][1]=2;o.num[2][2]=2;
    for(int i=1;i<=n;i++) scanf("%lld",&val[i]);
	for(int i=1;i<=n;i++) d[i]=val[i]-val[i-1]-1;
	d[n+1]=len-val[n];
	n++;
	for(int i=1;i<=n;i++)
	{
		u=u*ksm(o,d[i]);
		if(i<n) u=u*p;
	}
    printf("%lld\n",u.num[2][0]);
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

/*
  素因数分解
    nを素因数分解した結果をllpに格納する。結果はllp[i].first = (素因数)、llp[i].second = （個数）
    n <= 1 の時は何もしないので注意。
    n が素数ならばllpには (n, 1) のpairのみが入っている
*/
void factorization(vector<LLP>& llp, long long n) {
    if (n <= 1) return;
    long long n2 = n;
    for (long long i = 2; i * i <= n ; i++) {
        int count = 0;
        while (n2 % i == 0) {
            n2 = n2 / i;
            count ++;
        }
        if (count > 0) {
            LLP temp;
            temp.first = i;
            temp.second = count;
            llp.push_back(temp);
        }
    }
    if (n2 > 1) {
        LLP temp;
        temp.first = n2;
        temp.second = 1;
        llp.push_back(temp);
    }
}

int main() {

    int X;
    cin >> X;
    while (true) {
        vector<LLP> list;
        factorization(list, X);
        if (list.size() <= 1 && list[0].second == 1) {
            cout << X << endl;
            return 0;
        }
        X++;
    }
    
    return 0;
}

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

using namespace std;
multimap<long long ,int>s;
multimap<long long ,int>s0;
multimap<long long ,int>t;
multimap<long long ,int>t0;
long long INF=1'0000'0000'0000'0000'00;
int main(){
int A,B,Q;
cin >> A>> B>>Q;
long long  s1,t1,x;
    s.insert(make_pair(INF,0));
    s.insert(make_pair(-INF,0));
    s0.insert(make_pair(-INF,0));
    s0.insert(make_pair(INF,0));
    t.insert(make_pair(INF,0));
    t.insert(make_pair(-INF,0));
    t0.insert(make_pair(-INF,0));
    t0.insert(make_pair(INF,0));

for(int i=0;i<A;i++){
    cin >> s1;
    s.insert(make_pair(s1,i));
    s0.insert(make_pair(-s1,i));
}

for(int i=0;i<B;i++){
    cin >> t1;
   t.insert(make_pair(t1,i));
   t0.insert(make_pair(-t1,i));
}
long long sa,sb;
long long da,db;
for(int i=0;i<Q;i++){
    cin >> x;
    sa=s.upper_bound(x)->first;//xよりも右で最も近いshrine
    sb=-s0.upper_bound(-x)->first;//xよりも左で最も近いshrine
    da=t.upper_bound(x)->first;//xよりも右で最も近いtemple
    db=-t0.upper_bound(-x)->first;//xよりも左で最も近いtemple
long long ans=INF;
ans=min(ans,abs(sa-x)+abs(sa-da));
ans=min(ans,abs(sa-x)+abs(sa-db));

ans=min(ans,abs(sb-x)+abs(sb-da));
ans=min(ans,abs(sb-x)+abs(sb-db));

ans=min(ans,abs(da-x)+abs(da-sa));
ans=min(ans,abs(da-x)+abs(da-sb));

ans=min(ans,abs(db-x)+abs(db-sa));
ans=min(ans,abs(db-x)+abs(db-sb));

cout<<ans<<endl;
}
    

 return 0;
}

Measured memory_bytes: 27776
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		Integer[] l = new Integer[n];
		for(int i = 0; i < n; i++){
		    l[i] = sc.nextInt();
		}

		// 計算
	    int result = 0;
	    Arrays.sort(l);
	    for(int i = 0; i < n; i++){
		    for(int j = i + 1; j < n; j++){
		        int index = lowerBound(l, l[i] + l[j]) - 1;
		        result += index - j;
		    }
		}

		// 出力
		System.out.println(result);
        
	}
	
	static int lowerBound(Integer[] array, int n){
	    int index = ~Arrays.binarySearch(array, n, (x,y) -> x.compareTo(y) >= 0 ? 1 : -1);
	    return index;
	}
}


Measured memory_bytes: 47892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		try {

			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			
			char[] alfabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
			int[] count = new int[26];
			String str;
			while ((str = reader.readLine()) != null) {
				if (str.length() == 0) break;
				str = str.toLowerCase();
				char ch;
				for (int i = 0; i < str.length(); i++) {
					ch = str.charAt(i);
					if (ch == 'a') {
						count[0]++;
					} else if (ch == 'b') {
						count[1]++;
					} else if (ch == 'c') {
						count[2]++;
					} else if (ch == 'd') {
						count[3]++;
					} else if (ch == 'e') {
						count[4]++;
					} else if (ch == 'f') {
						count[5]++;
					} else if (ch == 'g') {
						count[6]++;
					} else if (ch == 'h') {
						count[7]++;
					} else if (ch == 'i') {
						count[8]++;
					} else if (ch == 'j') {
						count[9]++;
					} else if (ch == 'k') {
						count[10]++;
					} else if (ch == 'l') {
						count[11]++;
					} else if (ch == 'm') {
						count[12]++;
					} else if (ch == 'n') {
						count[13]++;
					} else if (ch == 'o') {
						count[14]++;
					} else if (ch == 'p') {
						count[15]++;
					} else if (ch == 'q') {
						count[16]++;
					} else if (ch == 'r') {
						count[17]++;
					} else if (ch == 's') {
						count[18]++;
					} else if (ch == 't') {
						count[19]++;
					} else if (ch == 'u') {
						count[20]++;
					} else if (ch == 'v') {
						count[21]++;
					} else if (ch == 'w') {
						count[22]++;
					} else if (ch == 'x') {
						count[23]++;
					} else if (ch == 'y') {
						count[24]++;
					} else if (ch == 'z') {
						count[25]++;
					} 
				}
			}
			
			for (int i = 0; i < count.length; i++) {
				System.out.print(alfabet[i] + " : ");
				System.out.println(count[i]);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24140
#include <bits/stdc++.h>
using namespace std;
typedef float fl;
typedef long long ll;
int A;
ll B,N;

ll f(ll x){
    ll ans = (A*x)/B - A*(x/B);
    return ans;
}

int main(){
    cin >> A >> B >> N;
    // if(B > N){
    //     cout << f(N) << endl;
    // }else{
    //     cout << f(B-1) << endl;
    // }
    cout << f(min(N,B-1)) << endl;
    return 0;
}

Measured memory_bytes: 3564
import java.math.BigInteger;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] as = new long[n];
		for(int i=0; i<n; i++){
			as[i] = sc.nextLong();
			if(as[i] == 0) {
				System.out.println(0);
				return;
			}
		}
		BigInteger ans = new BigInteger("1");
		BigInteger hikaku = new BigInteger("1000000000000000000");
		for(int i=0; i<n; i++){
			String str = String.valueOf(as[i]);
			BigInteger a = new BigInteger(str);
			ans = ans.multiply(a);
			if(ans.compareTo(hikaku) == 1){
				System.out.println(-1);
				return;
			}
		}	
		System.out.println(ans);
	}
}


Measured memory_bytes: 50560
import fractions
from functools import reduce
 
N = int(input())
lst = list(map(int,input().split()))

L = [0] * (N+1)
R = [0] * (N+1)
for i in range(N):
    L[i+1] = fractions.gcd(L[i], lst[i])
    R[N-i-1] = fractions.gcd(R[N-i], lst[N-i-1])
ans = 0
for i in range(N):
    ans = max(ans, fractions.gcd(L[i], R[i+1]))
print(ans)

Measured memory_bytes: 16120
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
typedef long long LL;
const int MAXN = 100005;
const LL inf = 0x3f3f3f3f3f3f3f3f;
int a[MAXN], b[MAXN], c[MAXN];
int n;
int search(int x)
{
    int ans=-1;
    int l=0,r=n-1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(a[mid]<x)
        {
            ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    return ans;
}
int main()
{
    scanf("%d", &n);
    for(int i=0;i<n;++i)
        scanf("%d", &a[i]);
    sort(a, a+n);
    for(int i=0;i<n;++i)
        scanf("%d", &b[i]);
    sort(b, b+n);
    for(int i=0;i<n;++i)
        scanf("%d", &c[i]);
    sort(c,c+n);
    LL sum=0;
    for(int i=0;i<n;++i)
    {
        int u=search(b[i]);
        //printf("u=%d v=%d\n", u, lower_bound(c,c+n,b[u])-c);
        sum+=(n-(upper_bound(c,c+n,b[i])-c))*(u+1);
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>

using namespace std;

int main(){
	int H, W;
	for (int i = 0; i < 100000; i++){
		cin >> H >> W;
		if (H == 0 && W == 0){
			break;
		}
		for (int i = 0; i < W; i++){
			cout << "#";
		}
		cout << endl;
		for (int i = 0; i < H - 2; i++){
			cout << "#";
			for (int i = 0; i < W - 2; i++){
				cout << ".";
			}
			cout << "#";
			cout << endl;
		}

		for (int i = 0; i < W; i++){
			cout << "#";
		}
		cout << endl << endl;
	}
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 55, M = 1010, INF = 0x3f3f3f3f;

int n;
int a[N];
vector<PII> res;

int main()
{
	cin >> n;
	
	int maxa = -INF, mina = INF, axi, ini;
	for (int i = 1; i <= n; i ++ )
	{
		cin >> a[i];
		if (a[i] > maxa) maxa = a[i], axi = i;
		if (a[i] < mina) mina = a[i], ini = i;
	}
	
	if (maxa > -mina)
	{
		for (int i = 1; i <= n; i ++ ) res.PB({axi, i});
		for (int i = 1; i < n; i ++ ) res.PB({i, i + 1});
	}
	else
	{
		for (int i = 1; i <= n; i ++ ) res.PB({ini, i});
		for (int i = n; i > 1; i -- ) res.PB({i, i - 1});
	}
	
	cout << res.size() << endl;
	for (auto u : res) cout << u.F << ' ' << u.S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    fast_io
    
    int n;
    cin>>n;
    int a[n];
    rep(i,n) cin>>a[i];
    int ans=0;
    rep(i,n){
        ans+=a[i]-1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

struct lr{
	int l;
	int r;
};

int main(){
	int n; cin >> n;
	VI a(n), b(n);
	REP(i,n) cin >> a[i];
	REP(i,n) cin >> b[i];
	vector<lr> ap(n+10,{-1,-1}), bp(n+10,{-1,-1});
	ap[a[0]].l=0; ap[a[n-1]].r=n-1;
	REP(i,n-1){
		if(a[i]!=a[i+1]){
			ap[a[i]].r=i;
			ap[a[i+1]].l=i+1;
		}
	}
	bp[b[0]].l=0; bp[b[n-1]].r=n-1;
	REP(i,n-1){
		if(b[i]!=b[i+1]){
			bp[b[i]].r=i;
			bp[b[i+1]].l=i+1;
		}
	}
	VI s(n*2,0);
	for(int i=1;i<=n;i++){
		if(ap[i].l!=-1&&bp[i].l!=-1){
			int bl=bp[i].r-bp[i].l+1;
			int sl=ap[i].l-bl+1-bp[i].l;
			int sr=ap[i].r+bl-1-bp[i].r+1;
			if(sr-sl>=n){
				s[0]++;
			}
			else{
				if((sl+3*n)%n<(sr+3*n)%n){
					s[(sl+3*n)%n]++;
					s[(sr+3*n)%n]--;
				}
				else{
					s[(sl+3*n)%n]++;
					s[0]++;
					s[(sr+3*n)%n]--;
				}
			}
		}
	}
	int p=0;
	REP(i,n){
		p+=s[i];
		if(p==0){
			cout << "Yes" << endl;
			REP(j,n)
				cout << b[(j-i+n)%n] << " ";
			cout << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 12752
import java.util.*;

public class Main {
	public static void main(String[] a){
		Scanner input=new Scanner(System.in);
		int loop=input.nextInt();
		int[] keepNum=new int[loop];
		
		for(int i=0;i<loop;i++)
			keepNum[i]=input.nextInt();
		
		for(int i=0;i<loop;i++){
			if(i!=loop-1)
			System.out.print(keepNum[i]+" ");
			else
				System.out.print(keepNum[i]);
		}
		System.out.println();
		
		for(int i=1;i<keepNum.length;i++){
			int insert=keepNum[i];
			int j=i-1;
			
			while(j>=0 && keepNum[j]>insert){
				keepNum[j+1]=keepNum[j];
				j--;
			}
			keepNum[j+1]=insert;
			
		for(int k=0;k<keepNum.length;k++){
			if(k!=keepNum.length-1)
			System.out.print(keepNum[k]+" ");
			else
				System.out.print(keepNum[k]);
		}
		System.out.println();
			
		}
	
	}

}

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

int main() {
    vector<string> N = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;
    for (long long i = 0; i < N.size(); ++i) {
        if (N[i] == s) {
            if (i == 2) {
                cout << N[0] << endl;
            } else {
                cout << N[i+1] << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a, b, c, d;

	scanf("%d %d %d", &a, &b, &c);

	while ((a>b) || (b>c))
	{
		if (a>b)
		{
			d = a;
			a = b;
			b = d;
		}
		if (b>c)
		{
			d = b;
			b = c;
			c = d;
		}
	}

	printf("%d %d %d\n", a, b, c);
	

	return 0;
}


Measured memory_bytes: 2044
// Code by Denverjin.
#include <bits/stdc++.h>
using namespace std;

using ld = double;
using ll = long long;
using ull = unsigned long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;

const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
#define getchar() (++ pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos)

inline ll read() {
	ll x = 0; int f = 1, c = getchar();
	for (;!isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x<<3) + (x<<1) + (c^48);
	return x * f;
}

ll k, a, b;

ll solve() {
	ll kk = k;
	if (b <= a + 2) return 0;
	if (a > kk) return 0;
	kk -= a - 1;
	ll ans = a;
	ans += (b - a) * (kk / 2);
	if (kk & 1) ++ ans;
	return ans;
}

int main() {
	k = read(), a = read(), b = read();
	printf("%lld\n", max(1LL * k + 1, solve()));
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

bool chk(ll N, ll A, ll B, const vector<ll> &h, ll T) {
  ll check = 0;
  REP(i, N) {
    if (h[i] - B * T <= 0)
      continue;
    check += (h[i] - B * T + A - B - 1) / (A - B);
  }
  // cout << T << " " << check << endl;
  return check <= T;
}

void solve(long long N, long long A, long long B, vector<long long> h) {
  ll b = 1L << 30;
  ll ans = (b << 1) - 1;

  for (; b; b >>= 1) {
    ll t = ans - b;
    if (chk(N, A, B, h, t))
      ans = t;
    // cout << ans << endl;
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long A;
  long long N;
  long long B;
  cin >> N;
  vector<long long> h(N - 1 + 1);
  cin >> A;
  cin >> B;
  for (int i = 0; i <= N - 1; i++) {
    cin >> h[i];
  }
  solve(N, A, B, h);
  return 0;
}


Measured memory_bytes: 1792
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
using namespace std;
int main()
{
    ll n,t,i,r,p=0,j,k;
    cin>>n>>k;
    ll a[n];
    f(i,n)
    cin>>a[i];
    sort(a,a+n);
    f(i,k)
    p+=a[i];
    cout<<p;

}









Measured memory_bytes: 3648
n = gets.to_i
hs = gets.split.map(&:to_i)

def split(hs)
  result = []
  tmp = []
  hs.each do |h|
    if h == 0
      result << tmp if !tmp.empty?
      tmp = []
    else
      tmp << h
    end
  end

  result << tmp if !tmp.empty?
  result
end

$ans = 0

def water(hs)
  return if hs.empty?
  hsg = split(hs)
  hsg.each do |hs|
    hs.size.times do |i|
      hs[i] -= 1
    end
    $ans += 1
    water(hs)
  end
end

water(hs)

puts $ans


Measured memory_bytes: 3964
#include <cstdio>
using namespace std;
char s[] = "RGYB";
int n, m, k;
int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; putchar(10), i++)
		for (int j = 0; j < m; j++)
			putchar(s[(i + j) / k % 2 * 2 + (i + m - j) / k % 2]);
}

Measured memory_bytes: 512
#include <stdio.h>
void ABC42(void);
void ABC43(void);
void ABC44(void);
void ABC45(void);

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

void ABC42(void){
    int a,b,c,n=0;
    scanf("%d %d %d",&a,&b,&c);
    if(a==7||b==7||c==7){
        if((a==5&&b==5)||(b==5&&c==5)||(c==5&&a==5)){
            printf("YES");
            n++;
    }}
    if(n==0)printf("NO");
}

void ABC43(void){
    int i,n,sum=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        sum+=i;
    }
    printf("%d",sum);
}

void ABC44(void){
    int n,k,x,y,i,sum=0;
    scanf("%d",&n);
    scanf("%d",&k);
    scanf("%d",&x);
    scanf("%d",&y);
    if(n>k){
        for(i=1;i<=k;i++)sum+=x;
        for(i=k+1;i<=n;i++)sum+=y;
    }else{
        for(i=1;i<=n;i++)sum+=x;
    }
    printf("%d",sum);
}

void ABC45(void){
    int a,b,h;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&h);
    printf("%d",(a+b)*h/2);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1LL << 60
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

int k;
vector<int> w;

// 最大積載量が決定された時にk台以下のトラックで運べる荷物の数
ll f(ll p) {
    ll used = 0;
    ll x = 0;
    ll carry = 0;
    for(const auto &item: w) {
        if(item > p) return carry;
        x += item;
        carry++;
        if(x > p) {
            used++;
            x = item;
            if(used == k) {
                carry--;
                return carry;
            }
        }
    }
    return carry;
}

void solve() {
    int n;
    cin >> n >> k;
    w.resize(n);
    REP(i,n) cin >> w[i];
    ll l = -1;
    ll r = INFLL;
    while ((r - l) > 1) {
        ll mid = l + (r-l) / 2;
        if (f(mid) == n) r = mid;
        else l = mid;
    }
    cout << r << endl;

}

void test() {
    int n;
    cin >> n >> k;
    w.resize(n);
    cout << f(10) << endl;
}
int main() {
    // test();
    solve();
    return 0;
}


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

int main ()
{
    int k;
    int a,b;
    bool flag=0;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            flag=1;
            break;
        }
    if(!flag) cout<<"NG"<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n;
  cin >> n;
  string s;
  ll co = 0;
  map<string,ll> m;
  rep(i,n){
    cin >> s;
    m[s]++;
    chmax(co,m[s]);
  }
  vector<string> un;
  for (auto i : m){
    if(i.second == co){
      un.pb(i.first);
    }
  }
  sort(all(un));
  rep(i,un.size()){
    pri(un[i]);
  }
  return 0;
}


Measured memory_bytes: 25584
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  long N = input(); 
  long M = input(); 

  vector<long> p;
  vector<string> S;

  for(long i=0;i<M;i++){
    long temp_p = input();
    string temp_S = input<string>();
    p.push_back(temp_p);
    S.push_back(temp_S);
  }

  map<long,long> temp_huseikai;
  map<long,long> huseikai;
  map<long,long> seikai;

  for(long i=0;i<M;i++){
    if(seikai[p[i]] == 0){
      if(S[i] == "AC"){
        seikai[p[i]]++;
        huseikai[p[i]] = temp_huseikai[p[i]];
      }
      else{
        temp_huseikai[p[i]]++;
      }
    }
  }

  long seikaiCount = 0;
  long huseikaiCount = 0;
  for(auto iter:seikai){
    if(iter.second > 0)seikaiCount++;
  }
  for(auto iter:huseikai){
    huseikaiCount+=iter.second;
  }

  cout << seikaiCount << " " << huseikaiCount << endl;

  return 0;
}


Measured memory_bytes: 25192
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int N;
    int K;
    string S;
    cin >> N >> K;
    cin >> S;
    S[K-1] = (int)S[K-1] + 32;
    
    cout << S;
    return 0;
}

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

using namespace std;

long long a, b, c, d;

long long find(long long n, long long k) {
	return n / k;
}

long long interval(long long l, long long r, long long k) {
	return find(r, k) - find(l - 1, k);
}

long long gcd(long long a, long long b) {
	return __gcd(a, b);
}

int main () {

	cin >> a >> b >> c >> d;

	cout << (b - a + 1) - interval(a, b, c) - interval(a, b, d) + interval(a, b, (c * d) / gcd(c, d)) << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;

int main(){
	ll N, K;
	cin >> N >> K;
	ll left = 0, right = 0;
	ll ans = 0;
	for(ll i=0;i<=N;i++) {
		left += i;
		right += (N-i);
		if(i >= K - 1) {
			ans += (right - left + 1);
			ans %= MOD;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;		
class Main{		
	public static void main(String[ ] args)throws java.lang.Exception {	
		
		//????????¬?????°?????????????????????????????????
		Scanner reader = new Scanner(System.in);
		
		//???????????????????????\?????????????¬??????°???????????°???????´?
		int s = reader.nextInt();
		
		reader.close();
		
		//??\??????????????°???????§???°????????????????????????????????°???????´?
		int h = s/3600;
		
		//???????????????????????????????§???°
		s = s%3600;
		
		//??????????????????????????????????§???°??????????????????????????°???????´?
		int m = s/60;
		
		//??\??????????????°???????§???°????????????????§???°????????°???????´?
		s = s%60;
		
		//???????????????
		System.out.println(h + ":" + m + ":" + s);
		
	}	
}		

Measured memory_bytes: 26240
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int mp[500010];
int cant,snum,si,cou;
bool par = true;

int main()
{
	int n;cin >> n;
	
	REP(a,n)
	{
		int tmp;
		cin >> tmp;
		
		if(!par)
		{
			cout << "No" << endl;
			continue;
		}
		
		if(tmp > 500000)
		{
			cout << "Yes" << endl;
			cou++;
			continue;
		}
		
		if(tmp <= cant || tmp <= si)
		{
			cout << "No" << endl;
			continue;
		}
		
		mp[tmp]++;
		
		bool ok = true;
		bool tmpp = true;
		int ssi = 0,ssnum = 0;
		for(ll i=si+1,k=2,num=snum;i<500001;i++)
		{
			k -= mp[i];num+=mp[i];
			if(k < 0)
			{
				ok = false;
				break;
			}
			if(k == 0)
			{
				tmpp = false;
			}
			if(k == 1 && num < cou)
			{
				ssi = max(si,(int)i);
				ssnum = num;
			}
			if(k > 500000)
			{
				break;
			}
			k *= 2;
		}
		if(ok)
		{
			cout << "Yes" << endl;
			cou++;
			par &= tmpp;
			si = max(si,ssi);
			snum = max(snum,ssnum);
		}
		else
		{
			cout << "No" << endl;
			mp[tmp]--;
			cant = max(cant,tmp);
		}
		//cout << si << ' ' << snum << endl;
	}
			
			
	
	
	return 0;
}

Measured memory_bytes: 5060
#include<iostream> 
using namespace std;
int main(){
	int maxx=0;
	string t,s;
	cin>>t>>s;
	for(int i=0;i<t.length()-s.length()+1;i++){
		int sum=0;
		for(int j=i;j<i+s.length();j++){
			if(s[j-i]==t[j])sum++;
		}
		maxx=max(maxx,sum);
	}
	cout<<s.length()-maxx<<'\n';
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <bits/stdc++.h> 
using namespace std;
int main ()
{
	
	long long int n, k, napad=0;
	cin>>n>>k;
	vector <int> h(n);
	for (int i=0; i<n; i++) cin>>h[i];
	sort(h.begin(), h.end(), greater<int>());
	
	for (int i=k; i<n; i++)
	napad+=h[i];
	cout<<napad<<endl;
	return 0;
}

Measured memory_bytes: 1024
fun c106(args: Array<String>) {
    val s = args[0]
    val k = args[1].toLong()

    val firstNonOne = s.toCharArray().firstOrNull { it != '1' }
    if (firstNonOne == null) {
        println(1)
        return
    }

    val firstNonOneIndex = s.toCharArray().indexOf(firstNonOne!!)
    if (firstNonOneIndex + 1 > k) {
        println(1)
    } else {
        println(firstNonOne)
    }
}

fun main(args: Array<String>) {
    c106(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 38176
#include <iostream>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long

using namespace std;

int main() {
  fast_io;

  string s;
  cin >> s;
  
  if (s == "AAA" || s == "BBB")
  	cout << "No" << endl;
  else 
  	cout << "Yes" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int count = 0;
    int sum = 0;
    for(int i = 1; i <= N; i++){
        sum = 0;
            for(int j = 1; j <= N; j++){
                if(i%j == 0){
                    sum++;
                }
                else continue;
            }
        if(sum == 8){
            count++;
        }
      i++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3560
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
vector<vector<int>>go;
vector<int>ki;
void dfs(int ter,int per,int a){
	ki[ter]=a;
	for(auto it:go[ter]){
		if(it==per){continue;}
		dfs(it,ter,a^1);
	}
}
int main(void){
	int n,i;cin>>n;
	go.res(n);ki.res(n);
	for(i=1;i<n;i++){
		int a,b;cin>>a>>b;a--;b--;
		go[a].pub(b);
		go[b].pub(a);
	}
	dfs(0,-1,0);
	int aki=0;
	for(i=0;i<n;i++){aki+=ki[i];}
	vector<int>ans(n);
	if(aki<=n/3||n-aki<=n/3){
		
		deque<int>uuu;
		for(i=1;i<=n;i++){
			if(i%3==0){uuu.puf(i);}
			else{uuu.pub(i);}
		}
		if(n-aki<=n/3){REV(uuu);}
		for(i=0;i<n;i++){
			if(ki[i]){ans[i]=uuu.front();uuu.pof();}
			else{ans[i]=uuu.back();uuu.pob();}
		}
	}else{
		deque<int>uuu;
		for(i=1;i<=n;i+=3){uuu.puf(i);}
		for(i=3;i<=n;i+=3){uuu.puf(i);}
		for(i=2;i<=n;i+=3){uuu.puf(i);}
		if(n-aki<=n/3){REV(uuu);}
		for(i=0;i<n;i++){
			if(ki[i]){ans[i]=uuu.front();uuu.pof();}
			else{ans[i]=uuu.back();uuu.pob();}
		}
	}
	for(i=0;i<n;i++){cout<<ans[i]<<endl;}
}

Measured memory_bytes: 18052
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin >> s;

	int sz = s.size();

	long long sum = 0;
	int i = 0;
	while (i < sz) {
		int val = 0;
		while (i < sz && s[i] == '<') {
			sum += val;
			++val;
			++i;
		}

		int peak = 0;
		while (i < sz && s[i] == '>') {
			++peak;
			++i;
		}

		if (val >= peak) {
			sum += val;
		} else {
			sum += peak;
		}

		for (int j = peak - 1; j >= 1; --j) {
			sum += j;
		}
	}

	cout << sum << "\n";

	return 0;

}

Measured memory_bytes: 1172
H, W, K = gets.split.map(&:to_i)
arr = []
ans = 0
blk = 0
H.times do |i|
	tmp = gets.chomp.to_s
	tmp = tmp.split("")
	arr << tmp
end

tmp = Marshal.load(Marshal.dump(arr))
blk = 0


h = []
w = []
[0, 1].repeated_permutation(H) do |bit|
	h << bit
end
[0, 1].repeated_permutation(W) do |bit|
	w << bit
end
(h.length).times do |m|
	(w.length).times do |n|
		(h[m].length).times do |s|
			if h[m][s] == 1
				tmp[s].fill("*")
			end
		end
		(w[n].length).times do |o|
			if w[n][o] == 1
				H.times do |p|
					tmp[p][o] = "*"
				end
			end
		end
		H.times do |n|
			blk += tmp[n].count("#")
		end
		if blk == K
			ans += 1
		end
		tmp = Marshal.load(Marshal.dump(arr))
		blk = 0
	end
end

p ans

Measured memory_bytes: 14244
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#define read(X) scanf("%d",&X);
#define readLL(X) cin>>X;
#define readN(N,a) for(int i=0;i<N;i++)scanf("%lld",&a[i]);
#define LL long long
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define pii pair<int,int>
using namespace std;

const int MAXN = 200002; /* max number of vertices - adjust */
const int MAXM = 200002; /* max number of edges - adjust */
const int INF = 1<<30;

int flow;
int bottleneck;
int n, m, e;
int s, t;
int x, y, w;
int p[MAXN], edge[MAXN];
int last[MAXN];
int prevwow[MAXM];
int to[MAXM];
int c[MAXM], f[MAXM];

/* add directed edge x->y with capacity w */
void add(int x, int y, int w)
{   prevwow[e] = last[x];
    last[x] = e;
    to[e] = y;
    c[e] = w;
    f[e] = 0;
    e++;
    prevwow[e] = last[y];
    last[y] = e;
    to[e] = x;
    c[e] = 0;
    f[e] = 0;
    e++;
}

/* find augmenting path in residual graph */
bool path(int u, int v)
{   queue<int> Q;
    int C, F;
    
    for(int i = 0; i < n; i++) p[i] = -1;
    Q.push(u);
    p[u] = u;
    while(!Q.empty())
    {   
        x = Q.front(), Q.pop();
        //cout<<x<<endl;
        
        if(x == v) return true;
        for(int i=last[x]; i!=-1; i=prevwow[i])
        {   
            //cout<<i<<endl;
            y = to[i];
            F = f[i];
            C = c[i];
            if(p[y] == -1 && C > F)
            {   p[y] = x;
                edge[y] = i;
                Q.push(y);
            }
        }
    }
    return false;
}

/* send flow through augmenting path */
int send(int u, int v)
{   bottleneck = INF;
    int x, y, index, sym;
    y = v;

    while(p[y] != y)
    {   x = p[y];
        index = edge[y];
        bottleneck = (bottleneck > c[index]-f[index] ? c[index]-f[index] : bottleneck);
        y = x;
    }

    y = v;
    while(p[y] != y)
    {   x = p[y];
        index = edge[y];
        f[index] += bottleneck;
        f[index^1] -= bottleneck;
        y = x;
    }

    return bottleneck;
}

int N,M;
char lho[111][111];
int nid[111][111];
int main(){
    read(N);
    read(M);
    n,m=0;

    /* build graph */
    memset(last, -1, sizeof(last));

    FOR(i,0,N){
        scanf("%s",lho[i]);
    }
    //cout<<"dah"<<endl;
    n = N+M+2;
    s = N+M;
    t = N+M+1;
    FOR(i,0,N)
        FOR(j,0,M){
            if (lho[i][j]=='.') continue;
            if (lho[i][j]=='S'){
                 add(s,i,INF); m++;   
                 add(s,N+j,INF); m++;   

            }
            
            if (lho[i][j]=='T'){
                add(i,t,INF); m++;   
                add(N+j,t,INF); m++;   
            }
            if (lho[i][j]!='.'){
                add(i,N+j,1); m++;
                add(N+j,i,1); m++;
            }
        }

    //cout<<"wut "<<s<<" "<<t<<endl;
    flow = 0;
    while(path(s, t)){
        //if (flow > 200) break;
        //cout<<"hah "<<flow<<endl;
        flow += send(s, t);
    }
    if (flow >= INF) flow = -1;
    printf("%d\n", flow);
    
    return 0;
}


Measured memory_bytes: 2816
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n;
    double p[3000];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
    }
    double dp[3001][3001];
    // 
    // 
    
    Fill(dp,0);
    
    dp[0][0] = 1-p[0];
    dp[0][1] = p[0];
    
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= i+1; j++) {

            dp[i][j] = 0;
            if(j>0){
                dp[i][j] += dp[i-1][j-1] * p[i];
            }
             dp[i][j] += dp[i-1][j] * (1-p[i]);
        }
    }
    double result = 0;
    for (int i = 0; i <= n/2; i++) {
        result += dp[n-1][i+(n+1)/2];
    }
    std::cout<< std::setprecision(10)<< result << std::endl;
}

Measured memory_bytes: 70656
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#include <bitset>
#include<math.h>
#include<queue>
using namespace std;
#define MAX 300000
#define INF 3000
typedef long long ll;
typedef pair<int,int> P;




int main(){
  int N,M,a,b,temp=0,ans=0;
  P A[110000];
  cin>>N>>M;
  for(int i=0;i<M;i++){
    cin>>a>>b;
    A[i]=make_pair(b,a);
  }
  sort(A,A+M);
  for(int i=0;i<M;i++){
    if(temp<=A[i].second){
      ans++;
      temp=A[i].first;
    }
  }
  cout<<ans<<endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int matrix[n][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> matrix[i][j];
        }
    }
    int vector[m];
    for (int i = 0; i < m; i++) {
        cin >> vector[i];
    }

    int result[n];
    for (int i = 0; i < n; i++) {
        result[i] = 0;
        for (int j = 0; j < m; j++) {
            result[i] += matrix[i][j] * vector[j];
        }
    }
    for (int i = 0; i < n; i++) {
        cout << result[i] << endl;
    }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 100005, MAXM = 1003, Mod = 1000000007 , MAXLog = 20;



int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    int n, k;
    cin >> n >> k;
    if (k > (n - 1) * (n - 2) / 2)
    {
        cout << -1 << '\n';
        return 0;
    }

    vector<pair<int, int>> edges;
    int v = 2;
    int cnt = 0;
    while (cnt < k) {
        cnt += edges.size();
        edges.emplace_back(1, v++);
    }
    v--;
    for (int i = 2; cnt > k; ++i) {
        edges.emplace_back(i, v);
        --cnt;
    }

    ++v;
    while (v <= n) {
        for (int i = 1; i < v; ++i) {
            edges.emplace_back(i, v);
        }
        ++v;
    }

    cout << edges.size() << '\n';
    for (pair<int, int> edge : edges) {
        cout << edge.first << ' ' << edge.second << '\n';
    }

    return 0;
}

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

using namespace std;

int cnt = 0;

void query(long long x) {
  cout << "? " << x << endl;
  cnt++;
}

long long getRes(int len) {
  long long low = 1, high = 0;
  for (int i = 1; i < len; i++) {
    low *= 10;
  }
  for (int i = 1; i <= len; i++) {
    high = high * 10 + 9;
  }
  while (high - low > 1) {
    long long mid = (1ll * high + low) >> 1ll;
    query(10ll * mid);
    char ver;
    cin >> ver;
    if (ver == 'N') {
      low = mid;
    } else {
      high = mid;
    }
  }
  return high;
}

int main() {
  int mn = -1000, mx = 10000;
  long long curMin = 1, curMax = 9;
  for (int i = 1; i <= 10; i++) {
    char verMin, verMax;
    query(curMin);
    cin >> verMin;
    query(curMax);
    cin >> verMax;
    if (verMin == 'N') {
      mx = min(mx, i - 1);
    }
    if (verMax == 'N') {
      mn = max(mn, i + 1);
    }
    curMin *= 10;
    curMax *= 10;
    curMax += 9;
  }
  if (mx == 10000) {
    int res = 1;
    for (int i = 1; i < mn; i++) {
      res = res * 10;
    }
    cout << "! " << res << endl;
  } else {
    long long res = getRes(mx);
    cout << "! " << res << endl;
  }
//  else {
//    int res = 0;
//    for (int i = 1; i <= mx; i++) {
//      res = res * 10 + 9;
//    }
//    cout << "! " << res << endl;
//  }
  return 0;
}


Measured memory_bytes: 596
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

template<class T>
inline bool chmax(T& a, const T b) { return a < b && (a = b, true); }

int main() {

	int R, C, K;
	cin >> R >> C >> K;
	const int s_max = 3;

	auto dp = make_vec(R + 1, C + 1, s_max + 1, 0LL);
	auto grid = make_vec(R, C, 0LL);

	for (int i = 0; i < K; i++) {
		int r, c, v;
		cin >> r >> c >> v;
		r--, c--;
		grid[r][c] = v;
	}

	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			for (int suc = 0; suc <= s_max; suc++) {
				if (suc != 3) chmax(dp[i][j + 1][suc + 1], dp[i][j][suc] + grid[i][j]);
				chmax(dp[i + 1][j][0], dp[i][j][suc] + (suc != 3 ? grid[i][j] : 0));
				chmax(dp[i][j + 1][suc], dp[i][j][suc]);
			}
		}
	}

	lint ans = 0;
	for (int suc = 0; suc <= s_max; suc++) {
		chmax(ans, dp[R][C - 1][suc]);
		chmax(ans, dp[R - 1][C][suc]);
	}

	cout << ans << "\n";

	return 0;
}



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

int main(void)
{
	bool b[100]={};
	for(int i=0;i<28;++i)
	{
		int n;
		cin >> n;
		b[n]=true;
	}
	for(int i=1;i<31;++i)
	{
		if(!b[i])
			cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 0