akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  
vector<int> vec(M);
for (int i = 0; i < M; i++) {
  cin >> vec[i];
}
  
  int sum = 0;
    
  for (int i = 0; i < M; i++) {
    sum += vec[i];
  }
  
  int B = N - sum;
  
  if (N < sum) {
  cout << -1 << endl;
  } else {
  cout << B << endl;
  }
  
}

Measured memory_bytes: 3660
#pragma GCC optimiz(O2)

#include <bits/stdc++.h>

#define rg register
using namespace std;
typedef long long ll;

template<typename T>
inline bool read(T &n) {
    T ans = 0, flag = 1;
    char ch;
    while ((ch = getchar()) < '0' || ch > '9') if (ch == '-') flag = -1; else if (ch == EOF) return false;
    ans = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') ans = ans * 10 + ch - '0';
    n = ans * flag;
    return true;
}

inline ll read() {
    ll ans = 0, flag = 1;
    char ch;
    while ((ch = getchar()) < '0' || ch > '9') if (ch == '-') flag = -1;
    ans = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') ans = ans * 10 + ch - '0';
    return ans * flag;
};
const int maxn = 100005;
struct NODE {
    ll val, ord;
    bool operator<(NODE b) const {
        return val < b.val;
    }
} node[maxn];
struct EDGE{
    int nex,t;
}edge[maxn<<1];

int ecnt,head[maxn],siz[maxn],fa[maxn];
unordered_map<ll,int> unM;
inline void addedge(int u,int v){
    edge[++ecnt].nex=head[u];head[u]=ecnt;edge[ecnt].t=v;
    edge[++ecnt].nex=head[v];head[v]=ecnt;edge[ecnt].t=u;
}
ll dfs(int rt,int fa,int dis){
    ll ans=dis;
    for(rg int i=head[rt];i;i=edge[i].nex){
        int y=edge[i].t;
        if(y==fa) continue;
        ans+=dfs(y,rt,dis+1);
    }
    return ans;
}
int main() {
    int n;
    read(n);priority_queue<NODE> pq;
    for (rg int i = 1; i <= n; ++i) {
        siz[i] = 1;read(node[i].val);
        node[i].ord = i;
        pq.push(node[i]);
        unM[node[i].val]=i;
    }
    for(rg int i=n;i>=2;i--){
        NODE now=pq.top();pq.pop();
        if(unM.find(now.val+2*siz[now.ord]-n)==unM.end()){
            puts("-1");return 0;
        }
        fa[now.ord]=unM[now.val+2*siz[now.ord]-n];
        siz[fa[now.ord]]+=siz[now.ord];
        addedge(now.ord,fa[now.ord]);
    }
    if(siz[pq.top().ord]!=n||dfs(pq.top().ord,0,0)!=pq.top().val) puts("-1");
    else for(rg int i=1;i<=n;i++){
        if(fa[i]) cout<<i<<' '<<fa[i]<<endl;
    }
    return 0;
}

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

#define reg register
typedef long long ll;
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)

char IO;
int rd(){
	int s=0,f=0;
	while(!isdigit(IO=getchar())) if(IO=='-') f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=1e5+10,P=1e9+7;

char s[4],p[4];




int main(){
	cin>>s>>p;
	int ans=0;
	rep(i,0,2) if(s[i]==p[i]) ans++;
	cout<<ans<<endl;
}








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

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

	sort(p.begin(), p.end());
	int sum = p[n - 1]/2;
	for (int i = 0;i < n - 1;i++) {
		sum += p[i];
	}

	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
vector <long long> A;
vector <long long> B;
int N;
int M = 30;
int main(void) {
	long long ans = 0;
	long long T = 1;
	cin >> N;
	rep(i, N) { 
		long long p;
		cin >> p;
		A.push_back(p);
	}
	rep(i, N) { 
		long long p;
		cin >> p;
		B.push_back(p);
	}
	rep(k, M) {
		vector <long long> C;
		vector <long long> D;
		rep(i, N) { 
			C.push_back(B[i] % (2 * T));
			D.push_back(A[i] % (2 * T));
		}
		sort(C.begin(),C.end());
		long long tmp = 0;
		rep(i, N) {
			tmp += lower_bound(C.begin(), C.end(), 2 * T - D[i]) - C.begin();
			tmp -= lower_bound(C.begin(), C.end(), 1 * T - D[i]) - C.begin();
			tmp += lower_bound(C.begin(), C.end(), 4 * T - D[i]) - C.begin();
			tmp -= lower_bound(C.begin(), C.end(), 3 * T - D[i]) - C.begin();
		}
		ans += T * (tmp % 2);
		T = T * 2;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

const int MAX_N = 40;

int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n >> m;

    std::vector<vector<int> > v;
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        std::vector<int> vi(k);
        for (int j = 0; j < k; ++j) scanf("%d", &vi[j]);
        sort(vi.begin(), vi.end());
        v.emplace_back(vi);
    }

    std::vector<int> vec = v[0];

    for (int i = 0; i < n; ++i) {
        std::vector<int> vec_inter;
        std::set_intersection(vec.begin(), vec.end(), v[i].begin(), v[i].end(), std::back_inserter(vec_inter));
        vec = vec_inter;
    }

    cout << vec.size() << endl;

    


    return 0;
}

Measured memory_bytes: 256
#![allow(dead_code)]
use std::io;

fn main() {
    solve_d();
}

fn solve_d() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let line: Vec<_> = line.trim()
        .split(' ')
        .map(|s| s.parse::<u32>().unwrap())
        .collect();
    let n = line[0];
    let m = line[1];

    let mut a: Vec<u32> = vec![0; (n * m) as usize];
    for i in 0..n {
        let mut aline = String::new();
        io::stdin().read_line(&mut aline).unwrap();
        let aline: Vec<_> = aline
            .trim()
            .split(' ')
            .map(|s| s.parse::<u32>().unwrap())
            .collect();
        for j in 0..m {
            a[(i * m + j) as usize] = aline[j as usize];
        }
    }

    let mut b: Vec<u32> = vec![0; m as usize];
    for i in 0..m {
        let mut bline = String::new();
        io::stdin().read_line(&mut bline).unwrap();
        b[i as usize] = bline.trim().parse::<u32>().unwrap();
    }

    for i in 0..n {
        let mut sum = 0;
        for j in 0..m {
            let index = i * m + j;
            sum += a[index as usize] * b[j as usize];
        }
        println!("{}", sum);
    }
}



Measured memory_bytes: 5040
//
// Created by yoshihito.hotta on 2018/06/17.
//
#include <iostream>
#include <stdio.h>
#include <stdlib.h>     /* atoi */
//
// Created by yoshihito.hotta on 2018/06/17.
//
#include <iostream>

using namespace std;

char a[100];
int stack[100];
int top = 0;

int pop() {
    top--;
    return stack[top+1];
}

void push(int d) {
    top++;
    stack[top] = d;
}

int main() {

    while (scanf("%s", a) != EOF) {
        if (a[0] == '+') {
            int p1 = pop();
            int p2 = pop();
            push(p1 + p2);
        } else if (a[0] == '-') {
            int p1 = pop();
            int p2 = pop();
            push(p2 - p1);
        } else if (a[0] == '*') {
            int p1 = pop();
            int p2 = pop();
            push(p1 * p2);
        } else {
            push(atoi(a));
        }
    }

    cout << pop() << endl;

    return 0;
}




Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;

#define INF 0

int main(void)
{
    int A, B;
    cin >> A >> B;
    for (int i = 0; i <= 1000; ++i)
    {
        if (int(i * 0.08) == A && int(i * 0.1) == B)
        {
            cout << i << "\n";
            return 0;
        }
    }
    cout << -1 << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%lld", &n)
#define sff(a,b) scanf("%lld %lld", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define f find
#define ub upper_bound
#define lb lower_bound
#define ld long double
#define in insert
#define bs binary_search  
#define le length()
const ll max_i=1e15;
#define np(s) next_permutation(s.begin(),s.end())
//it gives the lexicographically next string
 ll GCD(ll a,ll b)
    {
        if(b==0)
            return a;
        else return GCD(b,a%b);
    }
int main()
{
  int t=1;
  //cin>>t;
  while(t--)
  {
   ll n;
   cin>>n;
   cout<<(n*(n-1))/2;
  }
  return 0;
}


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

struct Edge {
  int from, to, capacity, reverse;
  Edge(int f, int t, int c, int r) : from(f), to(t), capacity(c), reverse(r) {}
};
using Graph = vector<vector<Edge>>;

int N;
Graph G;
int source, sink;

int FordFulkerson() {
  int result = 0;
  vector<Edge*> aug;
  vector<bool> visited(2 * N);

  auto initialize = [&]() {aug.clear(); visited.assign(2 * N, false);};

  function<bool(int, int)> augmenting_path = [&](int cur, int goal) {
    if(cur == goal) return true;
    if(visited[cur]) return false;
    visited[cur] = true;
    for(auto& e: G[cur]) if(0 < e.capacity) {
      aug.emplace_back(&e);
      if(augmenting_path(e.to, goal)) return true;
      aug.pop_back();
    }
    return false;
  };

  while(augmenting_path(source, sink)) {
    for(auto e: aug) {
      e->capacity -= 1;
      G[e->to][e->reverse].capacity += 1;
    }
    ++result;
    initialize();
  }

  if(result != N - 1) {
    cout << "no" << endl;
    return result;
  }

  cout << "yes" << endl;
  vector<int> answer(N);
  for(int i = 1; i < N; ++i) {
    for(int j = G[i].size() - 1; 0 < j; --j) {
      auto& e = G[i][j];
      if(e.capacity) {
        e.capacity = 0;
      } else {
        answer[i] = e.to - N;
        initialize();
        if(!augmenting_path(e.from, e.to)) continue;
        for(auto e: aug) {
          e->capacity -= 1;
          G[e->to][e->reverse].capacity += 1;
        }
        G[e.to][e.reverse].capacity = 0;
      }
    }
  }
  for(int i = 1; i < N; ++i) cout << answer[i] << endl;

  return result;
}

int main() {
  cin >> N;
  G.resize(2 * N);
  source = 0;
  sink = N;
  for(auto i = 1; i < N; ++i) {
    G[source].emplace_back(source, i, 1, G[i].size());
    G[i].emplace_back(i, source, 0, G[source].size() - 1);
  }
  for(auto j = 1 + N; j < N + N; ++j) {
    G[j].emplace_back(j, sink, 1, G[sink].size());
    G[sink].emplace_back(sink, j, 0, G[j].size() - 1);
  }
  for(auto i = 1; i < N; ++i) {
    for(auto j = 1; j < N; ++j) {
      int b;
      cin >> b;
      if(!b) continue;
      G[j].emplace_back(j, i + N, 1, G[i + N].size());
      G[i + N].emplace_back(i + N, j, 0, G[j].size() - 1);
    }
  }
  FordFulkerson();
}

Measured memory_bytes: 3436
import heapq

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
q=[]
for i in range(n):
  if arr2[i]!=arr1[i]:
    heapq.heappush(q,(-arr2[i],i))
cnt=0
while q:
  val,pos=heapq.heappop(q)
  val*=-1
  diff=arr2[pos-1]+arr2[(pos+1)%n]
  move=(val-arr1[pos])//diff
  if move==0:
    break
  cnt+=move
  tmp=arr2[pos]-diff*move
  arr2[pos]=tmp
  if tmp!=arr1[pos]:
    heapq.heappush(q,(-tmp,pos))
for i in range(n):
  if arr1[i]!=arr2[i]:
    print(-1)
    break
else:
  print(cnt)

Measured memory_bytes: 122012
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

const int MAX = 128;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

//dp[i][j] := iターン後にjにいる確率
double dp[MAX][MAX];
bool l[MAX], b[MAX];

void solve(void){
    int N, T, L, B;
    while (1) {
        cin >> N >> T >> L >> B;
        if (N == 0 && T == 0 && L == 0 && B == 0) return;
        memset(dp, 0, sizeof(dp));
        memset(l, false, sizeof(l));
        memset(b, false, sizeof(b));
        rep(L, i) {
            int d; scanf("%d\n", &d);
            l[d] = true;
        }
        rep(B, i) {
            int d; scanf("%d\n", &d);
            b[d] = true;
        }
        dp[0][0] = 1.;
        rep(T, t) rep(N, n) {
            Rep(1, 6, d) {
                int x = n+d;
                if (x > N) x = 2*N-n-d;
                if (b[x]) dp[t+1+l[n]][0] += dp[t][n]/6.;
                else dp[t+1+l[n]][x] += dp[t][n]/6.;
            }
        }
        /*
        rep(T+1, t) {
            rep(N+1, n) printf("%lf ", dp[t][n]);
            printf("\n");
        }*/
        double ans = 0.;
        rep(T+1, t) ans += dp[t][N];
        printf("%.6lf\n", ans);
    }
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}



Measured memory_bytes: 3324
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef unsigned long long ll;
vector<ll> vc[200];
string ss[200];
bool con[200][200];
typedef pair<string,string> P;
vector<P> ans;
ll b=1e9+7;
ll hash(string s){
	ll ret=0;
	rep(i,s.size()){
		ret*=b;
		ret+=s[i];
	}
	return ret;
}
int main(){
	while(true){
		int n,d;
		cin>>n;
		if(n==0) break;
		cin>>d;
		rep(i,n){
			vc[i].clear();
			string s,sc;
			cin>>s;
			ss[i]=s;
			int m=s.size();
			rep(j,m){
				sc=s;
				sc.erase(j,1);
				vc[i].pb(hash(sc));
			}
			rep(k,m+1){
				rep(j,26){
					sc=s;
					sc.insert(sc.begin()+k,'a'+j);
					vc[i].pb(hash(sc));
				}
			}
			rep(k,m){
				rep(j,26){
					sc=s;
					sc[k]='a'+j;
					vc[i].pb(hash(sc));
				}
			}
			rep(j,m-1){
				sc=s;
				swap(sc[j],sc[j+1]);
				vc[i].pb(hash(sc));
			}
			sort(all(vc[i]));
			vc[i].erase(unique(all(vc[i])),vc[i].end());
		}
		rep(i,n) rep(j,n) con[i][j]=0;
		if(d==1){
			rep(i,n){
				ll s=hash(ss[i]);
				rep(j,i){
					if(binary_search(all(vc[j]),s)) con[i][j]=true;
				}
			}
		}else{
			rep(i,n){
				rep(k,vc[i].size()){
					ll s=vc[i][k];
					rep(j,i){
						if(binary_search(all(vc[j]),s)) con[i][j]=true;
					}
				}
			}
		}
		ans.clear();
		rep(i,n) rep(j,n){
			if(con[i][j]){
				if(ss[i]<ss[j]) ans.pb(P(ss[i],ss[j]));
				else ans.pb(P(ss[j],ss[i]));
			}
		}
		sort(all(ans));
		rep(i,ans.size()) cout<<ans[i].fs<<","<<ans[i].sc<<endl;
		cout<<ans.size()<<endl;
	}
}

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

using namespace std;

int main()
{
	int sx, sy, tx, ty;
  	cin >> sx >> sy >> tx >> ty;
  
  	for(int x=sx; x<tx; x++){
      cout << "R";
    }
    for(int y=sy; y<ty; y++){
      cout << "U";
    }
  
    for(int x=sx; x<tx; x++){
      cout << "L";
    }
    for(int y=sy; y<ty; y++){
      cout << "D";
    }
  
  	cout << "D";
    for(int x=sx; x<tx+1; x++){
      cout << "R";
    }
    for(int y=sy; y<ty+1; y++){
      cout << "U";
    }
  	cout << "L";
  
    cout << "U";
    for(int x=sx; x<tx+1; x++){
      cout << "L";
    }
    for(int y=sy; y<ty+1; y++){
      cout << "D";
    }
  	cout << "R" << endl;
          
	return 0;
}  


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

int main(){
  int n, d; cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> x.at(i).at(j);
    }
  }
  long out = 0;
  for(int i = 0; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      long dis = 0;
      for(int k = 0; k < d; k++){
        dis += (x.at(i).at(k) - x.at(j).at(k)) * (x.at(i).at(k) - x.at(j).at(k));
      }
      for(int i = 1; i < 1000; i++){
        if(dis == i*i){
          out++;
          break;
        }
      }
    }
  }
  cout << out;
}


Measured memory_bytes: 256
n,l=map(int,input().split())

if l-1<(-1*n):
    print(int((n-1)*(l-1)+n*(n-1)/2))
elif (-1*n)<=l-1 and l-1<=-1:
    print(int(n*(l-1)+n*(n+1)/2))
else:
    print(int((n-1)*(l-1)+n*(n+1)/2-1))
    

    

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<bool> a(n+1,false);
    REP(i,m){
        int idx;
        cin>>idx;
        //idx--;
        a[idx] = true;
    }
    vi dp(n+5,0);
    dp[0] = 1;
    REP(i,n+1){
        if(!a[i+1]) dp[i+1] = (dp[i+1]+dp[i]) % MOD;
        if(!a[i+2]) dp[i+2] = (dp[i+2]+dp[i]) % MOD;
        //DEBUG_VEC(dp);
    }

    //DEBUG_VEC(dp);
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 640
from collections import Counter
h, w, m = map(int, input().split())
A = []
B = []
points = set()
for _ in range(m):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)
    points.add((a - 1, b - 1))
ac = Counter(A).most_common()
bc = Counter(B).most_common()
#print(ac, bc, points)

x = ac[0][1]
y = bc[0][1]

acm = []
bcm = []

for i, j in ac:
    if j == x:
        acm.append(i)
    else:
        break

for i, j in bc:
    if j == y:
        bcm.append(i)
    else:
        break

ans = x + y - 1
for i in acm:
    for j in bcm:
        if (i, j) not in points:
            print(ans + 1)
            exit()
print(ans)


Measured memory_bytes: 202800
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;





int main(void){

    

    int n,m,x;
    cin >>n>>m>>x;
    long ans;


    int *c = new int[n];
    int (*a)[12] = new int[n][12];

    for(int i = 0; i < n; i++) {
        cin>>c[i];
        for(int j = 0; j < m; j++) {
            cin >>a[i][j];
        }
    }
    int k,t;
    int (*arr)[4096] = new int[m+1][4096];

    int p = 1;
    for(int i = 0; i < n; i++) p*=2; 

    for(int i = 0; i < p; i++) {
        k = i;
        t = 0;
        for(int j = 0; j<=m; j++) {
            arr[j][i]=0;
        }
        while(k>0) {
            if(k%2==0) {
                k/=2;
                t++;
                continue;
            }
            for(int j = 0; j < m; j++) {
                arr[j][i]+=a[t][j];
            }
            arr[m][i]+=c[t];
            k/=2;
            t++;
        }
    }

    bool b;
    int min = 100000000;

    

    for(int i = 0; i < p; i++) {
        b= true;
        for(int j = 0; j < m; j++) {
            if(arr[j][i]<x) b = false;
        }
        if(!b) continue;
        if(arr[m][i]<min) min = arr[m][i];
    }
    if(min==100000000) min = -1;


    cout<< min;


    return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vec a = ivec(n);
    bool ok = true;
    rep (i, n) {
        if (a[i] % 2 == 0 and a[i] % 3 != 0 and a[i] % 5 != 0) {
            ok = false;
            break;
        }
    }
    if (ok)
        print("APPROVED");
    else
        print("DENIED");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,m;
	cin>>n>>m;
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	sort(ar+1,ar+n+1);

	ll b,c;
	vector< pair<ll,ll> > vc;
	for(i=1;i<=m;i++){
		cin>>b>>c;
		vc.ps({c,b});
	}

	sort(all(vc));
	reverse(all(vc));

	ll s=0; j=0;
	for(i=1;i<=n&&j<m;i++){
		if(ar[i]<vc[j].fs&&vc[j].sc>0){
			ar[i]=vc[j].fs;
			vc[j].sc-=1;
		}
		else {
			j+=1; i-=1;
		}
	}

	for(i=1;i<=n;i++){
		//cout<<ar[i]<<" ";
		s+=ar[i];
	}
	//cout<<endl;
	cout<<s;
	return 0;
}


Measured memory_bytes: 3188
/* Includes */
#include <stdio.h>

/* Prototypes */
void OutputMatrix(int list_matrix[100][100]);
void OutputVector(int list_val[100][1], int val);

/* Values */
int a[100][100];
int b[100][1];
int c[100][1];

int n,m;

/* Main */
int main ()
{
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    for (int i = 0; i < m; i++) {
        scanf("%d", &b[i][0]);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            c[i][0] += a[i][j] * b[j][0];
        }
    }

    OutputVector(c, n);
}

/* Sub */
void OutputVector(int list_val[100][1], int val)
{
    for (int i = 0; i < val; i++){
        printf("%d\n", list_val[i][0]);
    }
}


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

using namespace std;

const int INF = 1e9 + 10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, A, B;
  cin >> N >> A >> B;
  string S;
  cin >> S;

  int a = 0, b = 0, c = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'a') {
      if (a + b < A + B) {
        a++;
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else if (S[i] == 'b') {
      if (a + b < A + B && b < B) {
        b++;
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 848
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;

const int INF = 1<<30;
const int maxn = 1000+10;

int w,h,n;
char mp[maxn][maxn];
int d[maxn][maxn];

int dir[4][2] = {
	{-1,0},
	{1,0},
	{0,1},
	{0,-1},
};

int fac[10][2];

int bfs(int sx,int sy,int gx,int gy){
	memset(d,-1,sizeof(d));

	queue<pair<int,int> > Q;
	Q.push(make_pair(sx,sy));
	d[sx][sy] = 0;
	while(!Q.empty()){
		pair<int,int> p = Q.front(); Q.pop();
		if(p.first==gx && p.second==gy) break;

		for(int i=0; i<4; i++){
			int tx = p.first + dir[i][0];
			int ty = p.second + dir[i][1];
			if(tx>=0 && tx<h && ty>=0 && ty<w && mp[tx][ty]!='X' && d[tx][ty]==-1){
				Q.push(make_pair(tx,ty));
				d[tx][ty] = d[p.first][p.second] + 1;
			}
		}
	}

	return d[gx][gy];
}

int main(){
	scanf("%d%d%d",&h,&w,&n);	
	for(int i=0; i<h; i++)
		for(int j=0; j<w; j++)
			cin >> mp[i][j];

	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(mp[i][j] == 'S'){
				fac[0][0] = i;
				fac[0][1] = j;
				mp[i][j] = '.';
			}else if(isdigit(mp[i][j])){
				int index = mp[i][j] - '0';
				fac[index][0] = i;
				fac[index][1] = j;
			}
		}
	}

	int step = 0;
	for(int i=0; i<n; i++){
		step += bfs(fac[i][0],fac[i][1],fac[i+1][0],fac[i+1][1]);
	}

	printf("%d\n",step);
}

Measured memory_bytes: 8248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int,int>;

const int mx = 205;

int n, a[mx], dp[mx];
int fun(int idx){
    if(idx >= n) return 0;

    int &ans = dp[idx];
    if(~ans) return ans;

    ans = 0;
    ans = min(a[idx], a[idx+1]) + fun(idx+2);
    ans = max(ans, fun(idx+1));
    return ans;
}

void solve(){
    cin >> n; n+=n;
    for(int i=1; i<=n; i++)
        cin >> a[i];
    sort(a+1, a+n+1);

//    for(int i=1; i<=n; i++)
//        cout << a[i] << " ";
//    cout << "\n";

    memset(dp, -1, sizeof dp);
    cout << fun(1) << "\n";
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(0);

    int tc=1; ///cin >> tc;
    while(tc--) solve();
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
using namespace std;

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






int main() {



	int n,x,l[101],a[102];
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
		a[0] = l[0];
		if (i > 0)
			a[i] = l[i] + a[i - 1];
	}
	int cnt = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] <= x)cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var T = (double)vals[0];
            var A = vals[1];

            var hs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var result = Enumerable.Range(0, N)
                .Select(x => new Tuple<int, double>(x, T - 0.006 * (double)hs[x]))
                .OrderBy(x => Math.Abs(A - x.Item2))
                .First().Item1 + 1;

            Console.WriteLine(result);
        }
    }

}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli h, w;

int main(void){
    cin >> h >> w;
    vector<string> m(h);
    vector<lli> c(26);
    rep(i, h){
        cin >> m[i];
        rep(j, w) c[m[i][j]-'a']++;
    }
    bool ok = true;
    lli s, t, u;
    s = (h%2)*(w%2);
    t = (h%2)*(w/2)+(w%2)*(h/2);
    u = (h*w-s-2*t)/4;
    rep(i, 26){
        while(u > 0 && c[i] >= 4){
            c[i]-=4;
            u--;
        }
    }
    rep(i, 26){
        while(t > 0 && c[i] >= 2){
            c[i]-=2;
            t--;
        }
    }
    if(u > 0 || t > 0) ok = false;

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


Measured memory_bytes: 3596
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
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;}

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v(n,0);
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int a;
            cin>>a;
            v[a-1]++;
        }
    }
    int ans =0;
    rep(i,n){
        if(v[i]==0)ans++;
    }
    cout<<ans<<endl;



return 0;
}


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

#pragma warning(disable : 4996)

using namespace std;

vector<int> dat;
vector<int> tmp;

int doubles, lengths;

bool compare_suffix(int i, int j)
{
	if (dat[i] == dat[j])
	{
		int ri = (i + doubles <= lengths ? dat[i + doubles] : -1);
		int rj = (j + doubles <= lengths ? dat[j + doubles] : -1);

		return ri < rj;
	}

	return dat[i] < dat[j];
}

vector<int> suffix_array(string S)
{
	lengths = S.size();

	vector<int> arrays(lengths + 1);

	dat.resize(lengths + 1);
	tmp.resize(lengths + 1);

	for (int i = 0; i <= lengths; i++)
	{
		arrays[i] = i;

		dat[i] = i < lengths ? S[i] : -1;
	}

	for (doubles = 1; doubles <= lengths; doubles <<= 1)
	{
		sort(arrays.begin(), arrays.begin() + lengths + 1, compare_suffix);

		tmp[arrays[0]] = 0;

		for (int i = 1; i <= lengths; i++)
		{
			tmp[arrays[i]] = tmp[arrays[i - 1]] + (compare_suffix(arrays[i - 1], arrays[i]) ? 1 : 0);
		}

		for (int i = 0; i <= lengths; i++)
		{
			dat[i] = tmp[i];
		}
	}

	return arrays;
}

int main()
{
	string S, T; int Q;
	
	cin >> S >> Q;

	vector<int> sa = suffix_array(S);

	for (int i = 0; i < Q; i++)
	{
		cin >> T;

		int l = 0;
		int r = sa.size();

		bool flag = false;

		while (r - l > 1)
		{
			int m = (l + r) / 2;

			string S1 = S.substr(sa[m], T.size());

			if (S1 == T)
			{
				flag = true; break;
			}
			
			if (S1 < T)
			{
				l = m;
			}
			else
			{
				r = m;
			}
		}

		if (flag)
		{
			printf("1\n");
		}
		else
		{
			printf("0\n");
		}
	}

	return 0;
}

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

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int a,b;
int main() {
	cin>>a>>b;
	if((a+b)%2==1)cout<<(a+b)/2+1<<endl;
	else cout<<(a+b)/2<<endl;

	return 0;
}


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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()
using ll = int64_t;
using p = pair<int, int>;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int INF = 100000000;
const bool DEBUG = true;

int h, w, black=0;
vector<vector<int>> s(60, vector<int>(60, INF));
p start, goal;

void input() {
    char c;
    cin >> h >> w;
    rep(i, h) { rep(j, w) {
        cin >> c;
        if(c == '#') {
            s[i][j] = -1;
            black++;
        }
    }}
    start = p(0, 0);
    goal = p(h-1, w-1);
}

int bfs() {
    queue<p> Q;
    Q.push(start);
    s[start.first][start.second] = 0;
    while(!Q.empty()) {
        p target = Q.front(); Q.pop();
        if(target == goal) break;
        rep(i, 4) {
            int tx = target.first  + dx[i];
            int ty = target.second + dy[i];
            if(0>tx || tx>=h) continue;
            if(0>ty || ty>=w) continue;
            if(s[tx][ty] == -1) continue;
            if(s[tx][ty] != INF) continue;
            s[tx][ty] = s[target.first][target.second] + 1;
            Q.push(p(tx, ty));
        }
    }
    int result = s[goal.first][goal.second];
    if(result == INF) {
        return -1;
    }
    return result;
}

void Main() {
    input();
    int r = bfs();
    if(r == -1) {
        cout << -1 << endl;
    } else {
        cout << h*w-black-r-1 << endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dp = new int[N];
            dp[0] = 0;

            for (var i = 1; i < N; i++)
            {
                if (i > 1)
                    dp[i] = Math.Min(
                        dp[i - 1] + Math.Abs(h[i] - h[i - 1]),
                        dp[i - 2] + Math.Abs(h[i] - h[i - 2]));
                else
                    dp[i] = Math.Abs(h[i] - h[i - 1]);
            }

            Console.WriteLine(dp[N - 1]);
        }
    }
}


Measured memory_bytes: 20064
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	flag := make([]int, 26)
	for _, a := range s {
		flag[int(a-'a')] = 1
	}
	for i, f := range flag {
		if f == 0 {
			fmt.Println(string('a' + rune(i)))
			return
		}
	}

	fmt.Println("None")
}


Measured memory_bytes: 1280
import collections

N=int(input())
A=[]
PRECISION_DIGITS=9
cnt=collections.defaultdict(int)


for n in range(N):
	tmpA = float(input())
	tmpA = round(tmpA*10**PRECISION_DIGITS)
	#print(tmpA)

	five = 0
	two = 0
	while (tmpA % 2) == 0:
		two += 1
		tmpA //= 2
	while (tmpA % 5) == 0:
		five += 1
		tmpA //= 5

	# (10**9) -> (two,five)=(9,9)
	two -= PRECISION_DIGITS
	five -= PRECISION_DIGITS

	cnt[(two,five)]+=1

# print(cnt)
ans = 0
for t1, cnt1 in cnt.items():
	for t2, cnt2 in cnt.items():
		# 2**a(a>=0) and 5**b(b>=0) => integer
		if 0 <= t1[0]+t2[0] and 0 <= t1[1]+t2[1]:
			if t1 < t2:
				ans += int(cnt1*cnt2)
			elif t1 == t2:
				# same entry
				# Total number of combinations choose 2 items
				# nC2 = n*(n-1)/2
				ans += int((cnt1*(cnt2-1))/2)


print(ans)



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

struct data{
	int n,s,rank;
	data(){}
	data(int _n,int _s){
		n=_n; s=_s;
	}
	bool operator<(const data &a)const{
		return s>a.s;
	}
	bool operator==(const data &a)const{
		return s==a.s;
	}
};

int main(){
	vector<data> team;
	int N,S;
	while(scanf("%d,%d",&N,&S),N||S) team.push_back(data(N,S));
	sort(team.begin(),team.end());
	for(int i=0,rank=1;i<team.size();i++){
		if(i!=0 && !(team[i]==team[i-1])) rank++;
		team[i].rank = rank;
	}
	while(cin>>N){
		for(int i=0;i<team.size();i++){
			if(team[i].n==N){
				printf("%d\n",team[i].rank);
				continue;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1236
N = int(input())
T = list(map(int,input().split()))
M = int(input())

P,X = [],[]

for _ in range(M):
  Pi,Xi = map(int,input().split())
  P.append(Pi-1)
  X.append(Xi)

for p , x in zip(P,X):
  print(sum(T) - T[p] + x)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
vector<ll> six(1,1);
vector<ll> nine(1,1);

ll f(ll x){
    if(x<6) return x;
    ll a,b;
    auto itsix = upper_bound(six.begin(),six.end(),x);
    itsix--;
    a = x-*itsix;
    auto itnine = upper_bound(nine.begin(),nine.end(),x);
    itnine--;
    b = x-*itnine;

    return min(f(a),f(b)) + 1;
}


int main(){
    ll n ; cin >> n;
    ll s = 1;
    while(s<=100000){
        six.push_back(s);
        s*=6;
    }
    s = 1;
    while(s<=100000){
        nine.push_back(s);
        s*=9;
    }
    //rep(i,100) cout << f(i) << endl;
    cout << f(n) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
struct Point
{
	int x,y;
	Point () {}
	Point (int x,int y):x(x),y(y) {}
	bool operator<(const Point &p)const
	{
		if(x!=p.x)
			return x<p.x;
		return y<p.y;
	}
	bool operator!=(const Point &p)const
	{
		return x!=p.x||y!=p.y;
	}
}p[1010101];
map <Point,bool> mp;
long long ans[10];
int main()
{
	int h,w,n,xx,yy,pn,cnt;
	scanf("%d%d%d",&h,&w,&n);
	pn=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&xx,&yy);
		mp[Point(xx,yy)]=true;
		for(int j=max(xx-2,1);j<=min(xx,h-2);j++)
			for(int k=max(yy-2,1);k<=min(yy,w-2);k++)
				p[++pn]=Point(j,k);
	}
	sort(p+1,p+pn+1);
	memset(ans,0,sizeof(ans));
	ans[0]=(long long)(h-2)*(w-2);
	for(int i=1;i<=pn;i++)
		if(i==1||p[i]!=p[i-1])
		{
			ans[0]--;
			cnt=0;
			for(int j=p[i].x;j<p[i].x+3;j++)
				for(int k=p[i].y;k<p[i].y+3;k++)
					if(mp.count(Point(j,k)))
						cnt++;
			ans[cnt]++;
		}
	for(int i=0;i<=9;i++)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = pow(10, 18) + 5;
ll search(vector<ll> &A,ll x) {
    ll cnt = 0;
    for(int i=0; i<A.size();i++) {
        int l=-1;
        int r=A.size();
        int mid;
        if(A.at(i)<0) {
            while(l+1!=r) {
                mid =(l+r)/2;
                if(A.at(i)*A.at(mid)<x) {
                    r=mid;
                } else {
                    l=mid;
                }
            }
            cnt+=A.size()-r;
        } else {
            while(l+1!=r) {
                mid=(l+r)/2;
                if(A.at(i)*A.at(mid)<x) {
                    l=mid;
                } else {
                    r=mid;
                }
            }
            cnt+=r;
        }
        if(A.at(i)*A.at(i)<x) {
            cnt--;
        }
    }
    return cnt/2;
}

int main() {
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) {
        cin>>A.at(i);
    }
    sort(A.begin(),A.end());
    ll l=-MAX;
    ll r=MAX;
    ll mid;
    ll n;
    while(l+1<r) {
        mid=(l+r)/2;
        n=search(A, mid);
        if(n < K) {
            l=mid;
        } 
		else {
            r=mid;
        }
    }
    cout<<l<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

int main() {
    int K, X, Y;
    std::cin >> K >> X >> Y;

    auto f = [&](int p, int q) {
        if (std::abs(X) < std::abs(Y)) std::swap(p, q);

        if (X < 0) p = -p;
        if (Y < 0) q = -q;

        std::cout << p << " " << q << "\n";
    };

    int x = std::abs(X);
    int y = std::abs(Y);

    if (x < y) std::swap(x, y);

    if (K % 2 == 0 && (x + y) % 2 == 1) {
        std::cout << "-1\n";
        return 0;
    }

    int p = 0, q = 0;

    if (x + y < K && (x + y) % 2 == 1) {
        std::cout << "3\n";

        p += x;
        q -= K - x;
        f(p, q);

        p += (K + x - y) / 2;
        q += K - (K + x - y) / 2;
        f(p, q);

        f(x, y);

        return 0;
    }

    int s = 2;
    if (x + y >= K) {
        s = (x + y + K - 1) / K;
        if ((K - (x + y) % K) % K % 2 == 1) s++;
    }
    std::cout << s << "\n";

    if (s == 1) {
        f(x, y);
        return 0;
    }

    while (q - K >= -(K * s - x - y) / 2) {
        q -= K;
        f(p, q);
    }

    p = K - ((K * s - x - y) / 2 + q);
    q = -(K * s - x - y) / 2;
    f(p, q);

    while (p + K <= x) {
        p += K;
        f(p, q);
    }

    q = K - (x - p) - (K * s - x - y) / 2;
    p = x;
    f(p, q);

    while (q + K <= y) {
        q += K;
        f(p, q);
    }
}

Measured memory_bytes: 2304
N = int(input())
ansList = []

def Eratosthenes(N):
    li = [i for i in range(2, N+1)]
    serial = []
    amari1 = []
    while li:
        li.sort()
        num = li[0]
        if num % 5 == 1:
            amari1.append(num)
        serial = [k * num for k in range(1, N//num + 1)]
        li = list(set(li) - set(serial))
    return(amari1)
        
ansList = list(map(str, Eratosthenes(1500)))
print(" ".join(ansList[0:N]))

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

long long x, k, d, one = 1;

int main() {
  cin >> x >> k >> d;
  if (x < 0) one *= -1, x *= -1;
  long long now = min(x / d, k);
  x -= d * now;
  k -= now;
  k %= 2;
  if (k & 1) x -= d;
  cout << abs(x) << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
int main() {
	ll n;
	cin >> n;
	vector<ll> a;
	ll j = 1;
	rep(i,n){
		ll A;
		cin >> A;
		if(j==A){
			a.push_back(A);
			j++;
		}
	}
	if(a.size() == 0) cout << -1 << endl;
	else cout << n-a.size() << endl;
 	return 0;
}

Measured memory_bytes: 5356
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    int N,M; cin >> N >> M;
    vector<int> A(N); // button_listing
    rep(i,M){
        int k; cin >> k;
        rep(j,k){
            int x; cin >> x;
            x--;
            A[x] |= 1 << i;
        }
    }
    
    int check = 0;
    rep(i,M){
        int x; cin >> x;
        check |= x<<i;
    }
    
    int ans = 0;
    for(int i = 0; i<(1<<N); i++){
        int state = 0;
        rep(j, N) if(i>>j & 1) state ^= A[j];
        if(check == state) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

class Program
{
    static void Main()
    {
        int[] nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = nk[0];
        int K = nk[1];
        int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        //大事なのは1のある場所
        int idxOf1 = Array.FindIndex(A, itm => itm == 1);

        int min = int.MaxValue;

        for(int i = idxOf1 - K + 1; i <= idxOf1; i++)
        {
            //左側の残り
            int left = i;

            //右側の残り
            int right = A.Length - 1 - (i + K - 1);

            //左側の残りを埋めるのに何手必要か
            int needLeft = left <= 0 ? 0 : (int)Math.Ceiling(left / (double)(K - 1));
            int needRight = right <= 0 ? 0 : (int)Math.Ceiling(right / (double)(K - 1));

            int need = needLeft + needRight;

            min = Math.Min(min, need + 1);
        }

        Console.WriteLine(min);
    }
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}



Measured memory_bytes: 20064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    long N, x;
    cin>>N>>x;
    vl a(N);
    REP(i, 0, N){
        cin >> a[i];
    }
    long ans = 0;
    REP(i, 0, N-1){
        if(a[i] + a[i+1] > x){
            ans += a[i] + a[i+1] -x;
            if(a[i+1] < a[i] + a[i+1] -x){
                a[i+1]= 0;
                a[i] -= ans - a[i+1]; 
            }else{
                a[i+1] -= a[i] + a[i+1] -x;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<algorithm> 
using namespace std;
int n,a[100010][4],f[100010][4];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=3;j++) f[i][j]=-2e9;
		for(int j=1;j<=3;j++){
			for(int k=1;k<=3;k++){
				if(j!=k) f[i][j]=max(f[i][j],f[i-1][k]);
			}
			f[i][j]+=a[i][j];
		}
	}
	printf("%d",max(f[n][1],max(f[n][2],f[n][3])));
}

Measured memory_bytes: 3328