akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
    int u, minv;
    int d[MAX], p[MAX], color[MAX];

    for (int i=0; i<n; i++) {
        color[i] = WHITE;
        d[i] = INFTY;
        p[i] = -1;
    }
    d[0] = 0;

    while (1) {
        minv = INFTY;
        for (int i=0; i<n; i++) {
            if (color[i]!=BLACK && d[i]<minv) {
                minv = d[i];
                u = i;
            }
        }

        if (minv == INFTY) {
            break; // All nodes visited
        }

        color[u] = BLACK;
        for (int v=0; v<n; v++) {
            if (color[v]!=BLACK && M[u][v]<INFTY) {
                if (M[u][v]<d[v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }

    int sum = 0;
    for (int i=0; i<n; i++) {
        // if (p[i]!=-1) {
        //     sum += M[i][p[i]];
        // }
        sum += d[i];
    }

    return sum;
}

int main() {
    cin >> n;
    int e;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cin >> e;
            if (e!=-1) {
                M[i][j] = e;
            } else {
                M[i][j] = INFTY;
            }
        }
    }
 
    cout << prim() << endl;
    return 0;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
long long a,b,qw,wq,qq=1,ww=1,f[500001],o=0,h[500001],c[500001],v[500001];
long long q[500001],w[500001],ans=0;
long long get(long long y)
{
    if(f[y]==y) return y;
    return f[y]=get(f[y]);
}
void dfs(long long n,long long m)
{
    c[n]=m;
    for(int i=h[n];i;i=w[i])
    {
        if(q[i]!=f[n])
        {
            f[q[i]]=n;
            dfs(q[i],-m);
            c[n]+=c[q[i]];
        }
    }
}
int main()
{
    for(int i=1;i<=500000;i++)
    {
        f[i]=i;
    }
    cin>>a>>b;
    for(int i=1;i<=b;i++)
    {
        cin>>qw>>wq;
        if(get(qw)!=get(wq))
        {
            f[f[qw]]=f[wq];
        }
        else
        {
            qq=qw;
            ww=wq;
            continue;
        }
        o++;
        q[o]=wq;
        w[o]=h[qw];
        h[qw]=o;
        o++;
        q[o]=qw;
        w[o]=h[wq];
        h[wq]=o;
    }
    f[qq]=0;
    dfs(qq,1);
    if(a==b)
    {
        long long u=0;
        for(int i=ww;i;i=f[i])
        {
            u++;
            v[u]=c[i];
        }
        if(u%2)
        {
            if(c[qq]%2)
            {
                cout<<"-1";
                return 0;
            }
            for(int i=ww;i;i=f[i])
            {
                c[i]-=c[qq]/2;
            }
        }
        else
        {
            if(c[qq]!=0)
            {
                cout<<"-1";
                return 0;
            }
            sort(v+1,v+u+1);
            for(int i=ww;i;i=f[i])
            {
                c[i]-=v[u/2];
            }
        }
    }
    else
    {
        if(c[qq]!=0)
        {
            cout<<"-1";
            return 0;
        }
    }
    for(int i=1;i<=a;i++)
    {
        ans+=abs(c[i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 19164
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> x;
vector<int> y;
int X,Y;
int n,m;
int main()
{
    ios::sync_with_stdio(false);
    int number;
    while(cin>>n>>m>>X>>Y)
    {
        x.clear();y.clear();
        for(int i=0;i<n;i++)
        {
            cin>>number;x.push_back(number);
        }
        for(int i=0;i<m;i++)
        {
            cin>>number;y.push_back(number);
        }
        sort(x.begin(),x.end(),greater<int>());
        sort(y.begin(),y.end());
        bool flag=0;
        //cout<<x[0]<<endl;
        //cout<<y[0]<<endl;
        for(int i=X+1;i<=Y;i++)
        {
            if(i>x[0]&&i<=y[0])
            {
                flag=1;
                break;
            }
        }
        if(flag) cout<<"No War"<<endl;
        else cout<<"War"<<endl;
    }
}

Measured memory_bytes: 256
<?php
	$numOfSkewers = (int)trim(fgets(STDIN));
	$lengthsOfSkewers = explode(' ', trim(fgets(STDIN)));
	$numOfMaterial = 0;

	sort($lengthsOfSkewers);

	for ($i = 0; $i < $numOfSkewers * 2; $i += 2) {
    	$numOfMaterial += min($lengthsOfSkewers[$i], $lengthsOfSkewers[$i + 1]);
    }

	echo $numOfMaterial, PHP_EOL;

Measured memory_bytes: 4604
# frozen_string_literal: true

N = gets.chomp.to_i
array = gets.chomp.split.map(&:to_i)

number_count = Array.new(100000, 0)

array.each do |num|
  number_count[num - 1] += 1
end

Q = gets.chomp.to_i

total = array.sum
Q.times do
  b, c = gets.chomp.split.map(&:to_i)

  b_count = number_count[b - 1]
  total = (total - (b - c) * b_count)
  puts total

  number_count[b - 1] = 0
  number_count[c - 1] += b_count
end


Measured memory_bytes: 22680
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections
import itertools


def prime_factorization(n):

    assert n > 0
    if n == 1:
        return collections.deque([1])
    else:
        result = collections.deque()
        for i in itertools.count(2):
            if i * i > n:
                break
            else:
                while n % i == 0:
                    n //= i
                    result.append(i)
        if n > 1:
            result.append(n)
        return result

if __name__ == "__main__":
    n = int(input())
    factors = prime_factorization(n)
    print("{n}: {factors}".format(n=n, factors=" ".join(map(str, factors))))

Measured memory_bytes: 8056
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF 1e18
#define MOD 1e9 + 7

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    ll n, cnt, a[112345];
    M mp;
    cin >> n;

    cnt = 0;
    REP(i, n)
    {
        cin >> a[i];
        if (mp[a[i]] > 0)
            cnt++;

        mp[a[i]]++;
    }

    ll eat = cnt + (cnt % 2 == 1);
    cout << n - eat << endl;

    return 0;
}

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

int main() {
	string S;
	cin >> S;
	int count = 0;
	int a = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			if (S[i] == S[j]) {
				count++;
			}
	     }
		if (count == 2) {
			a++;
		}
		count = 0;
	}
	if (a == 4) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  long long sum=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    sum+=s[i]-'0';
  }
  if(sum%9==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3780
public class Main {
  private static void solve() {
    int n = ni();
    int c = ni();
    int[] a = na(n);
    int[] b = na(n);
    int mod = 1000000000 + 7;

    long[][] table = new long[n][c + 1];
    for (int i = 0; i < n; i++) {
      for (int k = a[i]; k <= b[i]; k++) {
        long now = 1;
        for (int j = 0; j <= c; j++) {
          table[i][j] += now;
          table[i][j] %= mod;

          now *= k;
          now %= mod;
        }
      }
    }

    long[][] dp = new long[n + 1][c + 1];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= c; j++) {
        for (int k = 0; j + k <= c; k++) {
          dp[i + 1][j + k] += dp[i][j] * table[i][k];
          dp[i + 1][j + k] %= mod;
        }
      }
    }

    System.out.println(dp[n][c]);
  }


  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 24396
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    vvc grid(h, vc(w));
    rep(i, h) rep(j, w) cin >> grid[i][j];

    set<int> hst, wst;
    rep(i, h) {
        bool flag = true;
        rep(j, w) if (grid[i][j] == '#') {
            flag = false;
            break;
        }
        if (flag) hst.insert(i);
    }
    rep(j, w) {
        bool flag = true;
        rep(i, h) if (grid[i][j] == '#') {
            flag = false;
            break;
        }
        if (flag) wst.insert(j);
    }

    rep(i, h) {
        if (hst.count(i)) continue;
        rep(j, w) {
            if (wst.count(j)) continue;
            cout << grid[i][j];
        }
        cout << endl;
    }
}

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

int main(int argc, const char * argv[]) {
    int N, A;
    
    cin >> N >> A;
    
    int mod = N % 500;
    if (A >= mod) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import sys

if __name__ == '__main__':
    while 1:
        line = raw_input()
        if line == '0 0':
            break
        a, b = map(int, line.split())
        for i in range(a):
            print '#' * b
        print



Measured memory_bytes: 4636
local mod=1000000007
local n=io.read("n")
local r,g,b=0,0,0
local combination=1
for i=1,n do
    local counter=0
    local a=io.read("n")
    if r==a then
        counter=counter+1
    end
    if g==a then
        counter=counter+1
    end
    if b==a then
        counter=counter+1
    end
    combination=combination*counter%mod
    if r==a then
        r=r+1
    elseif g==a then
        g=g+1
    elseif b==a then
        b=b+1
    end
end
print(combination)

Measured memory_bytes: 2708
import java.util.*;

	public class Main {

		public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int D = sc.nextInt();
        if(N%(D*2+1)==0) System.out.println(N/(D*2+1));
        else System.out.println(N/(D*2+1)+1);
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
typedef long long ll;
typedef pair<int,int> Pii;
const int INF=(1<<30)-1;
const int MAX=310;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int n;
int a[100000];
int main(){
	cin>>n;
	cin>>a[0];
	int max=a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
		max=max(a[i],max);
	}
	double t=max/2;
	int ans;
	int dif=INF;
	for(int i=0;i<n;i++){
		int dia=abs(t-a[i]);
		if(max!=a[i]&&dif>dia){
			dif=dia;
			ans=a[i];
		}
	}
	cout<<max<<" "<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
//#define DBG
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
int now[256], nxt[N][256];
ll ans=-1, jump = 0;
string s, t;
int main() {
  cin >> s >> t;
  memset(now, -1, sizeof(now));
  memset(nxt, -1, sizeof(nxt));
  for (int i = (int)s.size() - 1; i >= 0; i--) {
    for (int j = 'a'; j <= 'z'; j++) {
      nxt[i][j] = now[j];
    }
    now[s[i]] = i;
  }
  /*
  for (int i = 1; i < s.size(); i++) {
    for (int j = 'a'; j <= 'z'; j++) if (nxt[i][j] == -1) {
      nxt[i][j] = nxt[0][j];
    }
  }
  */
  #ifdef DBG
  for (int i = 1; i < s.size(); i++) {
    for (int j = 'a'; j <= 'z'; j++) if (nxt[i][j] != -1) {
      printf("nxt[%d][%c]:%d\n", i, j, nxt[i][j]);
    }
  }
  #endif
  if (t[0] == s[0]) {
    ans = 0;
  }
  else {
    ans = nxt[0][t[0]];
  }
  if (ans == -1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i < t.size(); i++) {
    if (nxt[ans][t[i]] != -1) {
      ans = nxt[ans][t[i]];
    }
    else {
      if (t[i] == s[0]) {
        ans = 0;
      }
      else {
        ans = nxt[0][t[i]];
      }
      jump++;
    }
    if (ans == -1) {
      break;
    }
  }
  if (ans == -1) cout << -1;
  else cout << ans + jump*s.size() + 1;
}

Measured memory_bytes: 100608
#include<cassert>
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const double eps = 1e-10;

class Point{
public:
  double x,y,z;
  double dist(){
    return sqrt(x*x+y*y+z*z);
  }
  Point operator+(Point a)const{
    return (Point){x+a.x,y+a.y,z+a.z};
  }
  Point operator-(Point a)const{
    return (Point){x-a.x,y-a.y,z-a.z};
  }
  Point operator*(double a)const{
    return (Point){a*x,a*y,a*z};
  }
  Point operator/(double a)const{
    return (Point){x/a,y/a,z/a};
  };
};


int get_most_distant(vector<Point> & a,Point c){
  int index=-1;
  double val=0;
  rep(i,a.size()){
    if ((a[i]-c).dist() > val)val=(a[i]-c).dist(),index=i;
  }
  return index;
}



double solve(vector<Point> &in){
  int n=in.size();
  Point ret=(Point){0,0,0};
  double movedist=100;
  while(movedist >1e-7){
    rep(i,100){
      int index=get_most_distant(in,ret);
      Point tmp = in[index]-ret;
      tmp=tmp/tmp.dist();
      ret=ret+tmp*movedist;
    }
    movedist/=2;
  }
  
  int index=get_most_distant(in,ret);
  return (in[index]-ret).dist();
}


main(){
  int n;
  while(cin>>n && n){
    vector<Point> in;
    rep(i,n){
      double x,y,z;
      cin>>x>>y>>z;
      in.push_back((Point){x,y,z});
    }

    printf("%.8lf\n",solve(in));
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll dp[51][51][2501];    // 1 to j , k cards , sum=s

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,a;
    cin>>n>>a;
    vector<int> v;
    v.pb(0);
    for(int i=0;i<n;i++){
        int c;
        cin>>c;
        v.pb(c);
    }
    dp[0][0][0]=1;

    for(int s=0;s<=2500;s++){
        for(int k=0;k<=n;k++){
            for(int j=1;j<=n;j++){
                if(s<v[j]){
                    dp[j][k][s]=dp[j-1][k][s];
                }
                else if(s>=v[j] && k>=1){
                    dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-v[j]];
                }
            }
        }
    }

    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=dp[n][i][a*i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 50048
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <cstring>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <ctime> 
using namespace std;

#define pb push_back
#define All(a) a.begin(), a.end()
#define met(a, b) memset(a, b, sizeof(a))
#define rep1(i, l, r) for(int i = l; i <= r; ++i)
#define rep2(i, l, r) for(int i = l; i < r; ++i) 
#define per(i, r, l) for(int i = r; i >= l; --i)
typedef long long ll;
typedef double db;
typedef long double ldb;
const int NIL = -1;
const int oo = 0x3f3f3f3f;
const ll INF = 2e18;
const db eps = 1e-8;
const db PI = acos(-1.0);
const int maxn = 2e5 + 7;

ll T[maxn], S[maxn];

inline int read(void)
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{ if(ch == '-') f = -1; ch = getchar(); } 
	while(ch >= '0' && ch <= '9') {	x = (x << 1) + (x << 3) + ch - '0';	ch = getchar();	}
	return x * f;
}

inline void write(int x)
{
	if(x < 0) { putchar('-'); x = -x; }
    if(x >= 10) write(x/10); 
	putchar(x%10+'0'); 
}

int main(void)
{
	int n = read();
//	int n = 1e5;
	rep1(i, 1, n)
	{
		T[i] = read();
//		T[i] = i;
		S[i] = S[i-1] + T[i];
	}
	ll ans = INF;
	rep1(i, 2, n-2)
	{
		ll A, B, C, D;
		A = C = 0;
		B = S[i];
		D = S[n] - S[i];
		int l, r;
		l = 1;
		r = i;
		while(l <= r)
		{
			int mid = (l + r) >> 1;
			if(S[mid] * 2 < B) l = mid + 1;
			else r = mid - 1;
		}
		if(abs(S[l-1]*2-B) < abs(S[r+1]*2-B))
		{
			A = S[l-1];
			B = B - A;
		}
		else
		{
			A = S[r+1];
			B = B - A;
		}
		l = i+1; 
		r = n;
		while(l <= r)
		{
			int mid = (l + r) >> 1;
			if((S[mid]-S[i]) * 2 < D) l = mid + 1;
			else r = mid - 1;
		}
		if(abs((S[l-1]-S[i])*2-D) < abs((S[r+1]-S[i])*2-D))
		{
			C = S[l-1] - S[i];
			D = D - C;
		}
		else
		{
			C = S[r+1] - S[i];
			D = D - C;
		}
		ans = min(ans, max(max(A, B), max(C, D)) - min(min(A, B), min(C, D)));
	}
	cout<<ans;
	
	return 0;
} 

Measured memory_bytes: 3328
import java.util.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();

        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != t.charAt(i)) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 41268
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    string S;
    string T;

    cin >> S >> T;

    int ans = 0;

    for (int i = 0; i < S.size(); ++i) {
        if (S[i] != T[i]) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3916
//Let's join Kaede Takagaki Fan Club !!
//明日は高垣楓さんの誕生日！おめでとうございます！！！
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int n, nn, k, s, t, aa[55], a[55];
int must[20];
ll way[55], C[60][60];

int main(){
	C[0][0]=1LL;
	for(int i=1;i<=55;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(!j){ C[i][j]=1LL;}
			else if(j==i){ C[i][j]=1LL;}
			else{C[i][j]=(C[i-1][j]+C[i-1][j-1]);}
		}
	}

	ios::sync_with_stdio(false);
	cin >> nn >> k >> s >> t;
	repn(i, nn){
		cin >> aa[i];
	}
	rep(i, 18){
		int x = ((s >> i)&1);
		int y = ((t >> i)&1);
		if(x == 0 && y == 0) must[i] = 0;
		else if(x == 1 && y == 1) must[i] = 1;
		else if(x == 1 && y == 0){
			cout << 0 << endl;
			return 0;
		}
		else must[i] = -1;
	}
	repn(i, nn){
		rep(j, 18){
			if(must[j] == -1) continue;
			int k = ((aa[i]>>j)&1);
			if(k != must[j]) goto nxt;
		}
		a[++n] = aa[i];
		nxt:;
	}
	k = min(k, n);
	if(n == 0){
		cout << 0 << endl;
		return 0;
	}
	for(int i=1;i<55;i++){
		for(int j=1;j<=k;j++){
			way[i] += C[i][j];
		}
	}
	ll ans = 0;
	rep(mask, (1<<18)){
		bool ok = 1;
		vector<int>look;
		rep(i, 18){
			if(((mask>>i)&1) == 0) continue;
			look.pb(i);
			if(must[i] != -1) {ok = 0; goto nxt2;}
		}
		nxt2:;
		if(!ok) continue;
		//cout << mask << endl;
		map<int, int>M;
		repn(i, n){
			int x = 0;
			for(auto j:look) x = (x<<1) + ((a[i]>>j)&1);
			M[x]++;
		}
		bool f = __builtin_popcount(mask)%2;
		for(auto x:M){
			if(f) ans += way[x.sc];
			else ans -= way[x.sc];
		}
	}
	cout << -ans << endl;
}

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

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2000+5;
int a[N],mn[N];

int main()
{
	//freopen("1.in","r",stdin);
	int n,x;
	cin>>n>>x;
	s64 ans=0;
	rep(i,1,n)
	{
		scanf("%d",a+i);
		mn[i]=a[i];
		ans+=a[i];
	}
	rep(c,0,n-1)
	{
		rep(i,1,c)chmin(mn[i],a[i-c+n]);
		rep(i,c+1,n)chmin(mn[i],a[i-c]);
		s64 sum=0;	
		rep(i,1,n)sum+=mn[i];
		chmin(ans,sum+(s64)c*x);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int h,w;
	cin>>h>>w;
	int n;
	cin>>n;
	vint a(n);
	rep(i,n) cin>>a[i];
	vvint ans;
	initvv(ans, h, w);
	int p = 0;
	rep(i,h){
		if(i&1){
			for(int j=w-1; j>=0; j--){
				if(a[p]==0) p++;
				a[p]--;
				ans[i][j]=p+1;
			}
		}
		else{
			rep(j,w){
				if(a[p]==0) p++;
				a[p]--;
				ans[i][j]=p+1;
			}
		}
	}
	rep(i,h){
		rep(j,w){
			if(j) cout<<" ";
			cout<<ans[i][j];
		}
		cout<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

	ll n,k;
  	cin >> n >> k;
  	ll x = n%k;
  	ll y = abs(n-(n/k+1)*k);
  	if(x>y){ cout<< y << endl;}
  	else{cout << x << endl;}
  	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
    int n; cin >> n;
    vector<ll> a(n);
    for(auto &e : a)cin >> e;
    ll ans = 0LL;
    for(auto e : a)ans += e-1;
    cout << ans <<endl;

    return 0;
}



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

using namespace std;

typedef long long ll;

void solve() {
	int n, x, t;
	cin >> n >> x >> t;
	cout << ((n + x - 1) / x) * t;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(){
char ch[10001];
int i=0,joi,ioi;
while(scanf("%s",&ch)==1){
ioi=0;
joi=0;
i=0;
while(ch[i]!='\0'){
if(ch[i]=='J' &&  ch[i+1]=='O' && ch[i+2]=='I'){
joi++;
}
if(ch[i]=='I' &&  ch[i+1]=='O' && ch[i+2]=='I'){
ioi++;
}
i++;
}

printf("%d\n%d\n",joi,ioi);
}

return 0;
}

Measured memory_bytes: 552
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	string s;
	cin>>s;
	int l=(int)s.length();
	cout<<s[0]<<l-2<<s[l-1];
}

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

const int N = 1e5 + 100;

int q, l, r, cnt[N];
bool mark[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	for (int i = 2; i < N; i++)
		if(mark[i] == false) {
			for (int j = i << 1; j < N; j += i)
				mark[j] = true;
		}
	for (int i = 3; i < N; i++)
		cnt[i] = cnt[i - 1] + (mark[i] == false && mark[(i + 1) >> 1] == false);
	cin >> q;
	while(q--) {
		cin >> l >> r;
		cout << cnt[r] - cnt[l - 1] << '\n';
	}
	return 0;
}


Measured memory_bytes: 1152
import sys
from collections import deque
s = input()
q = int(input())
is_reverse = False
res = deque(list(s))
for i in range(q):
    query = [i for i in sys.stdin.readline().split()]
    if query[0] == "1":
        is_reverse = False if is_reverse else True
    else:
        if query[1] == "1":
            if is_reverse:
                res.append(query[2])
            else:
                res.appendleft(query[2])
        else:
            if is_reverse:
                res.appendleft(query[2])
            else:
                res.append(query[2])
if is_reverse:
    res.reverse()
    print("".join(res))
else:
    print("".join(res))

Measured memory_bytes: 71416
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int n,m;

vector<pair<int, int> > g[444];

int kt[444];

int fail=0;

void killl(int x, int t){
	if (fail) return;
	if (kt[x]){
		fail=1;
		return;
	}
	kt[x]=t;
	for (auto nx:g[x]){
		if (nx.S>=t) break;
		killl(nx.F, nx.S);
	}
}

int test(int a, int b){
	for (int i=1;i<=n;i++){
		kt[i]=0;
	}
	fail=0;
	killl(a, m+1);
	killl(b, m+1);
	return fail==0;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	for (int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back({y, i});
		g[y].push_back({x, i});
	}
	int v=0;
	for (int i=1;i<=n;i++){
		for (int ii=i+1;ii<=n;ii++){
			v+=test(i, ii);
		}
	}
	cout<<v<<endl;
}

Measured memory_bytes: 2816
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int miti[] = new int[N];
      
      for(int i=0;i<M;i++){
       miti[sc.nextInt()-1] +=1;
       miti[sc.nextInt()-1] +=1;
      }
      
      for(int i=0;i<N;i++){
        System.out.println(miti[i]);
      }

      
    }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    for(int i = 0; i < n-1; i++) cin >> b[i];
    vector<int> a(n);
    a[0] = b[0];
    for(int i = 1; i < n-1; i++) a[i] = min(b[i-1], b[i]);
    a[n-1] = b[n-2];
    int ans = 0;
    for(int i = 0; i < n; i++) ans += a[i];
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N; cin >> N;
  vector<pair<int,int>> l;
  for(int i=0; i<N; i++){
    int tmp; cin >> tmp;
    l.emplace_back(tmp,i+1);
  }
  sort(l.begin(),l.end());
  for(int i=0; i<N; i++){
    cout << l[i].second;
    if(i<N-1) cout << " ";
    else cout << endl;
  }
}

Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,n,k=0;
  cin>>x>>n;
  vector<int> a(102,0);
  for(int i=0;i<n;i++){
    int j;
    cin>>j;
    a[j]++;
  }while(1){
    if(a[x-k]==0){
      cout<<x-k<<endl;
      break;
    }else if(a[x+k]==0){
      cout<<x+k<<endl;
      break;
    }
    k++;
  }
}

Measured memory_bytes: 3600
import sys
S = input()
if len(S) == 1:
    print(0)
    sys.exit()
ans_1 = 0
ans_2 = 0
for i in range(len(S)):
    if i % 2 == 0 and S[i] == "0":
        ans_1 += 1
    if i % 2 != 0 and S[i] == "1":
        ans_1 += 1

for i in range(len(S)):
    if i % 2 == 0 and S[i] == "1":
        ans_2 += 1
    if i % 2 != 0 and S[i] == "0":
        ans_2 += 1

print(min(ans_1,ans_2))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  int64_t tot = 0LL;
  if (N % 2LL == 1LL) {
    cout << 0 << endl;
  }
  else {
    for (int64_t i = 10LL; N / i != 0LL; i *= 5LL) {
      tot += N / i;
    }
    cout << tot << endl;
  }
}

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")


signed main() {
    vector<int> ds(5);
    rep(i, 5) cin >> ds[i];
    int k;
    cin >> k;
    bool ans = true;
    for(auto d : ds) {
        for(auto e: ds) {
            if (abs(d - e) > k) ans = false;
        }
    }
    cout << (ans ? "Yay!" : ":(" )<< nl;
}


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

const int inf = 1e9;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    
    for(int i=0;i<1000;i++){
        string t = "000";
        if(0 < i &&i < 10){
            t[2] = '0' + i;
        }
        else if(i < 100){
            t[1] = '0' + i/10;
            t[2] = '0' + i%10;           
        }else{
            t[0] = '0' + i/100;
            t[1] = '0' + (i/10)%10;
            t[2] = '0' + i%10;
        }

        bool exist = false;

        for(int a=0;a<n-2;a++){
            if(s[a] == t[0]){
                for(int b=a+1;b<n-1;b++){
                    if(s[b] == t[1]){
                        for(int c=b+1;c<n;c++) if(s[c] == t[2]) exist = true;
                        break;
                    }
                }
                break;
            }
        }

        if(exist) ans++;
    }
 
    cout << ans << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main()
{
    fastio;

    int N;
    vector<int> d;
    cin >> N;
    copy_n(istream_iterator<int>(cin), N, back_inserter(d));

    sort(d.begin(), d.end());

    cout << d[N / 2] - d[N / 2 - 1] << endl;

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long int
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
#define BLK 555
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp);
void ipgraph(int m);
const int mod = 1000000007;
const int MOD = 998244353;
const int N = 2e5+5, M = N;
//=========================================
 
 
int32_t main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
 
    int t;
    t = 1;
    while(t--){
        int n;
        cin >> n;
        int a[n][n];
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j)
                cin >> a[i][j];
        }
 
        int dp[1ll << n];
        memset(dp, 0, sizeof(dp));
        dp[0] = 1;
 
        for(int mask = 0; mask < (1ll << n); ++mask){
            int topics_taken = __builtin_popcount(mask);
            for(int j = 0; j < n; ++j){
                if(a[topics_taken][j] == 0 || (mask & (1ll << j)))
                    continue;
                dp[mask|(1ll << j)] = (dp[mask|(1ll << j)] + dp[mask]) % mod;
            }
        }
 
        cout << dp[(1ll << n) - 1] << endl;
    }
 
    return 0;
}


Measured memory_bytes: 20016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,a,ans=0;cin>>n;
  rep(i,n) {
    cin>>a;
    ans+=a-1;
  }
  print(ans);
  return 0;
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter prnt = new PrintWriter(System.out);
        Map<Character, Integer> ocur = new HashMap<>();

        String word = read.readLine();

        for (int i = 0; i < word.length(); i++) {
            int freq = ocur.getOrDefault(word.charAt(i), 0);
            freq++;
            ocur.put(word.charAt(i), freq);
        }
        boolean yes = true;
        for (int i = 0; i < word.length(); i++) {
            if (ocur.get(word.charAt(i)) % 2 != 0) {
                prnt.println("No");
                yes = false;
                break;
            }
        }
        if (yes) prnt.println("Yes");
        prnt.close();
    }
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    cin >> n >> m >> k;
    vl a(n);
    vl b(m);

    IPT(a, n)
    IPT(b, m)

    vl sum_a(n + 1);
    vl sum_b(m + 1);

    sum_a[0] = 0;
    sum_b[0] = 0;

    REP(i, 1, n + 1) {
        sum_a[i] = sum_a.at(i - 1) + a.at(i - 1);
    }

    REP(i, 1, m + 1) {
        sum_b[i] = sum_b.at(i - 1) + b.at(i - 1);
    }

    REP(i, 0, n + 1) {
        if (sum_a.at(i) > k) {
            break;
        }

        auto b_itr = upper_bound(ALL(sum_b), k - sum_a.at(i));

        ll a_count = i;
        ll b_count = distance(sum_b.begin(), b_itr);
        b_count--;

        if (b_count < 0) b_count = 0;
        ans = max(ans, a_count + b_count);
    }
    MSG(ans)
}


Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
int main(){
  int c,q,i,j,z=0,k=1,m[1001][1001]={0},e[6][2]={0};
  for(i=0;i<6;i++){
    cin>>q>>c;
    if(q>c)m[q][c]++;
    else m[c][q]++;
  }
  for(i=0;i<1001;i++)for(j=0;j<1001;j++){
    if(m[i][j]){
      if(m[i][j]==4){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
      else if(m[i][j]==6){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
      else{e[z][0]=i;e[z++][1]=j;}
    }
  }
  if(e[0][0]!=e[2][1]||e[1][0]!=e[2][0]||e[0][1]!=e[1][1])k=0;
  if(k)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

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

typedef long long LL;
const int MAXN = 1e5+5;
int ans[MAXN], sum1[MAXN];
int main() {
    int n, k; cin>>n>>k;
    string s; cin>>s;
    int cnt = 0, sum = 1, id = 0;
    for(int i=1; i<n; i++) {
        if(s[i] != s[i-1]) {
            if(s[id] == '0') ans[cnt++]=sum;
            else ans[cnt++]=sum;
            id = i-1;
            sum = 1;
        }
        else sum++;
    }
    if(s[id] == '0') ans[cnt++]=sum;
    else ans[cnt++]=sum;
    sum1[0] = 0;
    for(int i=1; i<=cnt; i++) sum1[i] = sum1[i-1]+ans[i-1];
    int ok = s[0]-'0';
    if(ok) {
        sum = 0;
        int res = 0;
        for(int i=1; i<=cnt; i+=2) {
            int t=min(i+2*k, cnt);
            res = max(res,sum1[t]-sum1[i-1]);
        }
        cout<<res<<endl;
    }
    else {
        sum = 0;
        int res = 0;
        for(int i=2; i<=cnt; i+=2) {
            int t=min(i+2*k, cnt);
            res = max(res,sum1[t]-sum1[i-1]);
        }
        int t=min(2*k, cnt);
        res = max(res, sum1[t]);
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(void)
{
    int N, tmp;
    set<int> st;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> tmp;
        st.insert(tmp);
    }
    cout << st.size() << "\n";
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;

using ll = long long;

int main(void)
{
    const int N_MAX = 200000;
    int N;
    int A[N_MAX];
    cin >> N;
    REP(i, N) cin >> A[i];
    ll result = 0;
    int SUM = 0;
    int XOR = 0;
    int first = 0, last = 0;
    while (first <= last) {
        while (last < N && (XOR ^ A[last]) == SUM + A[last]) {
            XOR ^= A[last];
            SUM += A[last];
            ++last;
        }
        result += last - first;
        XOR ^= A[first];
        SUM -= A[first];
        ++first;
    }
    cout << result << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	string s;
	lint k; cin>>s>>k;

	int n=s.length();
	if(count(s.begin(),s.end(),'1')==n){ cout<<1<<endl; return 0; }

	int pos;
	rep(i,n) if(s[i]!='1') { pos=i; break; }
	cout<<(k<=pos?'1':s[pos])<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main() {
    // ifstream in("data.txt");
    // cin.rdbuf(in.rdbuf());
    int A, B, C;
    cin >> A >> B >> C;

    int ans = 0;
    ans = C - (A - B);
    if(ans < 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
r,c=map(int, input().split())
A=[list(map(int, input().split())) for i in range(r)]
add=0
add_l=[]
for i in range(r):
    A[i].append(sum(A[i]))
for i in range(c+1):
    for j in range(r):
        add+=A[j][i]
    add_l.append(add)
    add = 0

A.append(add_l)

for i in range(r+1):
    print(*A[i])



Measured memory_bytes: 6228
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MOD = 1000000007;

int f[1 << 20], g[1 << 20], N, M, K;
int mat[25][25];

inline void update(int &x, int y) {
  x = (x + y) % MOD;
}

int main() {
  scanf("%d%d%d", &N, &M, &K);
  memset(mat, -1, sizeof mat);
  for (int i = 1; i <= K; ++i) {
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);
    mat[A][B] = C;
  }

  f[0] = 1;
  for (int i = 1; i <= M; ++i)
    for (int j = 1; j < N; ++j) {
      memset(g, 0, sizeof g);
      for (int mask = 0; mask < 1 << N; ++mask) {
	if (!f[mask]) continue;
	if (mat[i][j] != 1 && !(mask & (1 << j - 1))) {
	  update(g[mask], f[mask]);
	}
	if (mat[i][j] != 0) {
	  int temp = mask & ((1 << j - 1) - 1);
	  int nxt_mask = mask ^ temp;

	  if (mask & (1 << j - 1)) nxt_mask = mask;
	  else nxt_mask ^= (nxt_mask & -nxt_mask) ^ temp ^ (1 << j - 1);

	  update(g[nxt_mask], f[mask]);
	}
      }
      memcpy(f, g, sizeof f);
    }

  int res = 0;
  for (int mask = 0; mask < 1 << N; ++mask)
    update(res, f[mask]);

  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <cstring>
#include <iomanip>

using namespace std;

double dp[310][310][310];
int N;

double rec(int i, int j, int k){
    if(dp[i][j][k] >= 0) return dp[i][j][k];
    if(i ==0 && j ==0 && k ==0) return 0.0;

    double res = 0.0;
    if(i > 0) res += rec(i-1, j, k) * i;
    if(j > 0) res += rec(i+1, j-1, k) * j;
    if(k > 0) res += rec(i, j+1, k-1) * k; 

    res += N;
    res /= (i+j+k);
    return dp[i][j][k] = res;
}

int main(){
    cin >> N;

    int one =0, two = 0, three = 0;
    for(int i=0; i<N; ++i){
        int a;
        cin >> a;
        if(a == 1){
            one++;
        }else if(a ==2){
            two++;
        }else{
            three++;
        }
    }

    memset(dp, -1, sizeof(dp));
    cout << fixed << setprecision (10) << rec(one, two, three) << endl;

}

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

int a[110];

int main(){
	int n, x;
	scanf("%d%d", &n, &x);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	sort(a, a + n);
	int ans = 0, i = 0;
	while(x > 0 && i < n) {
		x -= a[i++];
		if(x >= 0) ans++;
	}
	printf("%d\n", (x > 0) ? ans - 1 : ans);
}


Measured memory_bytes: 256