akhauriyash/Code-Regression huggingface dataset:
var
	n:Longint;
function f(x:int64;a,b,c:Longint):Longint;
begin
	f:=0;
	if x<=n then f:=a*b*c+f(x*10+3,1,b,c)+f(x*10+5,a,1,c)+f(x*10+7,a,b,1);
end;
begin
	read(n);
	if n>700000000 then writeln(17656+f(7,0,0,1))
	else if n>500000000 then writeln(8828+f(5,0,1,0))
	else if n>300000000 then writeln(5556+f(3,1,0,0))
	else writeln(f(0,0,0,0));
end.

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

class mint {
private:
	long long x;

public:
	mint(long long x = 0)
		: x((x% mod + mod) % mod) {}

	mint operator-() const {
		return mint(-x);
	}

	mint& operator+=(const mint& a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}

	mint& operator-=(const mint& a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}

	mint& operator*=(const mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}

	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}

	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}

	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(long long t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint inv() const {
		return pow(mod - 2);
	}

	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}

	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend std::ostream& operator<<(std::ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

struct combination {
	vector<mint> fact, ifact;

	combination(int n)
		:fact(n + 1), ifact(n + 1)
	{
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i)
		{
			fact[i] = fact[i - 1] * i;
		}
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i)
		{
			ifact[i - 1] = ifact[i] * i;
		}
	}

	mint nCk(int n, int k)
	{
		if (k < 0 || k > n)
		{
			return 0;
		}
		return fact[n] * ifact[k] * ifact[n - k];
	}

	mint nHk(int n, int k)
	{
		return nCk(n + k - 1, k);
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll N, K;
	cin >> N >> K;

	if (K >= N) {
		K = N - 1;
	}

	mint ans = mint(1);
	combination comb(1000000);

	REP(k, 1, K + 1) {
		ans += comb.nCk(N, k) * comb.nHk(N - k, k);
	}

	out(ans);

	return 0;
}

Measured memory_bytes: 15872
N,K=(int(x) for x in input().split())
answer = 0
for i in range(N):
  p = 1
  point = i + 1
  while point < K:
#    if point >= K:
#      answer = answer + p / N
#      break
    point = point * 2
    p = p / 2 
    answer = answer + p / N

print(1 - answer)

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

const int def = 3500;
const ll limit = 1LL << 50;

int n, i, j, c0, c1;
bool pr[maxN];
vector< pair<ll, ll> > divs, work;
ll x;
int ans;

map<ll, bool> M;

void pre() {
    ll i, j;

    for (i = 2; i <= def; i++) {
        if (pr[i]) continue;

        divs.pb(mp(i, 1LL * i * i * i));
        for (j = i * i; j <= def; j += i)
            pr[j] = true;
    }

    for (i = def + 1; i * i <= 10000000000LL; i++)
        M[i * i] = true;
}

void mult(ll& a, ll b) {
    if (limit / a < b)
        a = limit;
    else
        a *= b;
}

void add_number(ll x) {
    int i;
    ll op, aux;

    aux = x;

    for (auto e : divs) {
        while (x % e.second == 0) {
            x /= e.second;
            aux /= e.second;
        }

        while (aux % e.first == 0)
            aux /= e.first;

        if (aux < e.first) break;
    }


    op = 1LL;
    if (M[aux]) {
        mult(op, sqrt(aux));
    } else {
        mult(op, aux);
        mult(op, aux);
    }

    for (auto e : divs) {
        if (x % e.first == 0) {
            if (x % (e.first * e.first) == 0) {
                mult(op, e.first);
            } else {
                mult(op, e.first * e.first);
            }
        }

        if (x < e.first) break;
    }

    if (x < op)
        work.pb(mp(x, 0));
    else
        work.pb(mp(op, 1));
}

int main()
{
    //freopen("test.in","r",stdin);

    pre();
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        scanf("%lld", &x);
        add_number(x);
    }

    sort(work.begin(), work.end());
    for (i = 0; i < work.size(); i = j) {
        c0 = c1 = 0;
        for (j = i; j < work.size(); j++) {
            if (work[i].first != work[j].first) break;
            if (work[j].second) c1++; else c0++;
        }

        if (work[i].first != 1)
            ans += max(c0, c1);
        else
            ans++;
    }

    printf("%d", ans);


    return 0;
}


Measured memory_bytes: 12656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		String s = scan.next();
		String a = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
		StringBuilder ans = new StringBuilder();

		for (int i = 0; i < s.length(); i++) {
			char si = s.charAt(i);
			for (int j = 0; j < a.length(); j++) {
				char aj = a.charAt(j);
				if (si == aj) {
					String sa = String.valueOf(a.charAt(j + n));
					ans.append(sa);
					break;
				}

			}
		}

		System.out.println(ans);


	}
}


Measured memory_bytes: 22996
N,A[999][1000],id[1000],used[1000];
i,j;day;flag=2;
main(){
	for(scanf("%d",&N);i<N;++i)for(j=0;j<N-1;)scanf("%d",A[j++]+i);
	for(;flag&2;)
		for(flag=1,i=!++day;i<N;++i)
			used[i]<day&id[i]<N-1&&used[flag&=2,j=A[id[i]][i]-1]<day&&id[j]<N-1&&A[id[j]][j]==i+1&&++id[used[i]=used[j]=day,++id[i],flag=2,j];
	printf("%d",flag*day-1);
}

Measured memory_bytes: 4096
//  main.cpp
//  CppTest

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

int main(int argc, const char * argv[]) {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    int A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;
    
    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int MOD = 1e9 + 7;


#define INPUT(x)                freopen(x,"r",stdin)
#define OUTPUT(x)               freopen (x,"w",stdout)


#define pb                      push_back
#define endl                    '\n'
#define LCM(a,b)                (a/__gcd(a,b))*b
#define GCD(a,b)                __gcd(a,b)
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define PI                      acos(-1.0)
#define distance(x1,y1,x2,y2)   sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define MAX                     1e9 + 9

#define taratari                ios_base::sync_with_stdio(0);cin.tie(NULL);



int main()
{
    taratari

    map <int, int> a;

    map <int,int>::iterator it;

    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;

        a[x]++;
    }

    int sum=0;

    for(it=a.begin();it!=a.end();it++)
    {
            if(it->second & 1) // % operator
            sum++;

    }

    cout<<sum;

    return 0;

}



Measured memory_bytes: 8200
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  ll n,k; cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  sort(all(a));

  vector<ll> same(0);
  int flag = a.at(0);
  int cont = 1;
  for(int i=1;i<n;i++){
    if(flag!=a.at(i)){
      same.push_back(cont);
      cont=1;
      flag = a.at(i);
    }else{
      cont++;
    }
  }
  same.push_back(cont);

  sort(all(same));

  int ans =0;

  n = same.size()-k;

  for(int i=0;i<n;i++){
    ans+=same.at(i);
  }

  cout << ans <<endl;
}

Measured memory_bytes: 3956
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int> P;
string field[1000];
int w, h;
int n;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
struct unionfind {
    int par[1000005], rank[1000005];
    unionfind(int w, int h) {
        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                par[i*w+j]=i*w+j;
                rank[i*w+j]=i*w+j;
            }
        }
    }
    int find(int x) {
        if (x==par[x]) {
            return x;
        } else {
            return par[x]=find(par[x]);
        }
    }
    void unite(int x, int y) {
        x=find(x);
        y=find(y);
        if (x==y) return;
        if (rank[x]<rank[y]) {
            par[x]=y;
        } else {
            par[y]=x;
            if (rank[x]==rank[y]) rank[x]++;
        }
    }
    bool same(int x, int y) {
        return find(x)==find(y);
    }
};
bool isin(int x, int y) {
    return x>=0&&x<h&&y>=0&&y<w;
}
int main() {
    scanf("%d%d",&w,&h);
    for (int i=0; i<h; i++) cin>>field[i];
    int res=-1;
    unionfind uf(w,h);
    int rx=-1, ry=-1;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (field[i][j]=='t') {
                rx=i; ry=j;
                field[i][j]='.';
            }
            if (field[i][j]=='.') {
                field[i][j]='-';
                queue<P> que;
                que.push(P(i,j));
                while (!que.empty()) {
                    P p=que.front(); que.pop();
                    for (int k=0; k<4; k++) {
                        int nx=p.first+dx[k], ny=p.second+dy[k];
                        if (isin(nx,ny)&&field[nx][ny]=='.') {
                            que.push(P(nx,ny));
                            uf.unite(i*w+j,nx*w+ny);
                            field[nx][ny]='-';
                        } else if (isin(nx,ny)&&field[nx][ny]=='t') {
                            que.push(P(nx,ny));
                            uf.unite(i*w+j,nx*w+ny);
                            rx=nx; ry=ny;
                            field[nx][ny]='-';
                        }
                    }
                }
            }
        }
    }
//    for (int i=0; i<h; i++) cout<<field[i]<<endl;
    int r=rx*w+ry;
    if (uf.same(0,r)) res=0;
    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        int x, y; scanf("%d%d",&y,&x);
        field[x][y]='-';
        if (res==-1) {
            for (int j=0; j<4; j++) {
                int nx=x+dx[j], ny=y+dy[j];
                if (isin(nx,ny)&&field[nx][ny]=='-') {
                    uf.unite(x*w+y,nx*w+ny);
                }
            }
            if (uf.same(0,r)) res=i;
        }
    }
    printf("%d\n",res);
}

Measured memory_bytes: 9764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, 1000) {
    char si[4];
    sprintf(si, "%03d", i);
    int k = 0;
    rep(j, n) {
      if (si[k] == s[j]) k++;
    }
    if (k == 3) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# Problem https://atcoder.jp/contests/abc095/tasks/abc095_b
# Python 1st Try


def solver(kinddonus, eachsource, havesource):
    result = 0
    allsource = 0
    minsource = 1000
    for j in range(0, kinddonus, +1):
        allsource = eachsource[j] + allsource
        if eachsource[j] <= minsource:
            minsource = eachsource[j]
    result = kinddonus + (havesource - allsource) // minsource
    return result


if __name__ == "__main__":
    N, X = list(map(int, input().split(' ')))
    M = []
    for j in range(0, N, +1):
        M.append(int(input()))
    print(solver(N, M, X))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    for(ll i = 1; i <= 3500; i++){
        for(ll j = 1; j <= 3500; j++){
            if(4 * i * j - n * i - n * j == 0)
            continue;
            ll w = (n *i * j) / (4 * i * j - n * i - n * j);
            if(w > 0 && (n *i * j) % (4 * i * j - n * i - n * j) == 0){
                cout << j << " " << i << " " << w << endl;
                return 0;
            }
            
           }
        }
    }


Measured memory_bytes: 256
#include <iostream>

using namespace std;
const int DMAX = 1'000 * 1'000 + 1;
int main()
{
    int N, M;
    int a[1'000], b[1'000], c[1'000];
    int d[100][100];

    cin >> N >> M;

    for (int i = 0; i < M; i++)
    {
        int aa, bb, cc;
        cin >> aa >> bb >> cc;
        aa--;
        bb--;
        a[i] = aa;
        b[i] = bb;
        c[i] = cc;
    }

    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if (i == j)
            {
                d[i][j] = 0;
            }
            else
            {
                d[i][j] = DMAX;
            }
        }
    }

    for (int i = 0; i < M; i++)
    {
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }

    for (int k = 0; k < N; k++)
    {
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                int nd = d[i][k] + d[k][j];
                if (nd < d[i][j])
                {
                    d[i][j] = nd;
                }
            }
        }
    }

    int sum = 0;
    for (int k = 0; k < M; k++)
    {
        bool contained = false;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (d[i][j] == d[i][a[k]] + d[b[k]][j] + c[k])
                {
                    contained = true;
                }
            }
        }
        if (!contained)
        {
            sum++;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    X, A = map(int, input().split())
    if X < A:
        print(0)
    else:
        print(10)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
/*
        AOJ - ALDS1_1_C
        Date: 20190309
        Author: Mikoron * ♡mikoiwate_351♡
*/

#define N 10001

#include<stdio.h>
#include<math.h>

int dec_prime(int a) {
        int i;

        if(a == 2) return 1;
        else if(a % 2 == 0) return 0;
        for(i = 3; i <= sqrt(a); i += 2) {
                if(a%i == 0) return 0;
        }
        return 1;
}

int main(void) {
        short i, n;
        short count = 0;
        int nums[N];

        scanf("%hd", &n);
        for(i = 0; i < n; i++) {
                scanf("%d", &nums[i]);
                if(dec_prime(nums[i]) == 1) count++;
        }
        printf("%d\n", count);

        return 0;
}



Measured memory_bytes: 2088
def calc(x):
    global mount
    global list
    count=0
    for y in range(1,x+1):
        if mount[x] >= mount[x-y]:
            count+=1
    if x == count:
        list.append(x)

N=int(input())

mount=list(map(int, input().split()))

list=[]

for z in range(1,len(mount)):
    calc(z)

print(1+len(list))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <numeric>
#include <limits>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n);
    for (auto& x : a) cin >> x;
    partial_sum(a.begin(), a.end(), a.begin());

    auto get_sum = [&](int l, int r) {
        return a[r] - (l > 0 ? a[l - 1] : 0);
    };

    vector<vector<long long> > dp(n, vector<long long>(n));
    for (int j = 0; j < n; ++j)
        for (int i = j - 1; i >= 0; --i) {
            dp[i][j] = numeric_limits<long long>::max();
            auto s = get_sum(i, j);
            for (int k = i; k < j; ++k)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
            dp[i][j] += s;
        }

    cout << dp[0][n - 1];
    return 0;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

bool is_prime(int N) {
  if (N == 2) return true;
  if (N % 2 == 0) return false;
  for (int i = 3; i*i <= N; ++i) {
    if (N % i == 0) return false;
  }
  return true;
}

int main() {
  int N; std::cin >> N;
  if (N == 2) {
    std::cout << 2 << std::endl;
    return 0;
  } else if (N % 2 == 0) {
    ++N;
  }

  for (int i = N;; i += 2) {
    if (is_prime(i)) {
      std::cout << i << std::endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
      	int c = sc.nextInt();
		int flag = 0;
      if((100*a+10*b+c)%4==0){
        flag = 1;
      }
		// 出力
      if(flag==0){
		System.out.println("NO");
	}else{
        System.out.println("YES");
      }
      }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define int ll

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define pb emplace_back
#define mp make_pair

#define DEBUG

using namespace std;

const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

typedef pair<ll, ll> P;

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

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

ll X, Y, N, M, K;

ll k[10], p[10], s[10][10];


signed main() {

    cin >> N >> M;

    rep(i,M){
        cin >> k[i];
        rep(j,k[i]){
            cin >> s[i][j];
            s[i][j] --;
        }
    }
    rep(i,M){
        cin >> p[i];
    }
    int res = 0;
    bool ok;
    rep(i, 1ll << (N)){
        ok = true;
        rep(j,M){
            int temp = 0; 
            rep(l,k[j]){
                if((i>>s[j][l]) & 1) temp +=1;
            }
            if(temp%2 != p[j]){
                ok = false;
                break;
            }
        }
        if(ok){
            res ++;
        }
    }

    cout << res << endl;
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> table(H, vector<char>(W));
    vector<int> rows(H, 0);
    vector<int> cols(W, 0);

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> table.at(i).at(j);
        }
    }

    for (int i = 0; i < H; i++)
    {
        bool s = true;
        if (table.at(i).at(0) == '.')
        {
            for (int j = 0; j < W - 1; j++)
            {
                if (table.at(i).at(j) != table.at(i).at(j + 1))
                {
                    s = false;
                    break;
                }
            }
        }
        else
        {
            s = false;
        }

        if (s == true)
        {
            rows.at(i) = 1;
        }
    }

    for (int i = 0; i < W; i++)
    {
        bool s = true;
        if (table.at(0).at(i) == '.')
        {
            for (int j = 0; j < H - 1; j++)
            {
                if (table.at(j).at(i) != table.at(j + 1).at(i))
                {
                    s = false;
                    break;
                }
            }
        }
        else
        {
            s = false;
        }

        if (s == true)
        {
            cols.at(i) = 1;
        }
    }

    for (int i = 0; i < H; i++)
    {
        if (rows.at(i) == 0)
        {
            for (int j = 0; j < W; j++)
            {
                if (cols.at(j) == 0)
                {
                    cout << table.at(i).at(j);
                }
            }
            cout << endl;
        }
    }

    return 0;
}

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

typedef long long ll;

using namespace std;

const ll inf=1000000007;


ll n, m, x[500005], y[500005], kx[500005], ky[500005], jx=0, jy=0, q;
map<ll,ll> ma;

int main()
{
    memset(x,0,sizeof(x));
    memset(y,0,sizeof(y));
    memset(kx,0,sizeof(kx));
    memset(ky,0,sizeof(ky));
    cin >> n >> m >> q;
    while(q--)
    {
        ll u, v;
        cin >> u >> v;
        x[u]++;
        y[v]++;
        ma[u*1000000+v]=1;
    }
    ll x2=0;
    for(int i=1;i<=300005;i++)
    {
        x2=max(x[i],x2);
    }
    for(int i=1;i<=300005;i++)
    {
        if(x[i]==x2)
        {
            kx[jx]=i;
            jx++;
        }
    }
    ll y2=0;
    for(int i=1;i<=300005;i++)
    {
        y2=max(y[i],y2);
    }
    for(int i=1;i<=300005;i++)
    {
        if(y[i]==y2)
        {
            ky[jy]=i;
            jy++;
        }
    }
    ll ans=0;
    for(int i=0;i<jx;i++)
    {
        for(int j=0;j<jy;j++)
        {
            if(ma[kx[i]*1000000+ky[j]]!=1)
            {
                ans=y2+x2;
                break;
            }
        }
        if(ans!=0)
        {
            break;
        }
    }
    ans=max(ans,x2+y2-1);
    cout<< ans << endl;
    return 0;
}


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


int main() {
    
    int n, m;
    cin >> n >> m;
    int d[55] = {};
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        d[--x]++;
        d[--y]++;
    }
    for (int i = 0; i < n; i++) {
        cout << d[i] << endl;
    }
    return 0;
    
}




Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;
map<int, int> S;
void print(){
    map<int, int>::iterator it;
    long long ans=0;
    for(it=S.begin();it!=S.end();it++){
        pair<int, int> pa = *it;
        if(pa.second==0) ans++;
    }
    cout << ans << endl;
}

int main(){
    long long N, K;

    cin >> N >> K;
    for(int i=0;i<N;i++){
        S[i]=0;
    }
    for(int i=0;i<K;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int a;
            cin >> a;
            S[a-1]++;
        }
    }
    print();
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#define D 100

int bubble(int A[],int N){
  int a = 0,flag =1,es;
  for(int i=0;flag>0;i++){
    flag = 0;
    for(int j = N-1;j>i;j--){
      if(A[j]<A[j-1]){
	es=A[j];
	A[j]= A[j-1];
	A[j-1] = es;
	flag = 1;
	a++;
      }
    }
  }
  return a;
}

int main(){
  int A[D],N,a,i;
  scanf("%d",&N);
  for(i = 0;i<N;i++)
    scanf("%d",&A[i]);

  a = bubble(A,N);

  for(i = 0;i<N;i++){
    if(i>0)
      printf(" ");
    printf("%d",A[i]);
  }

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

  return 0;
}

  




Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+11;
int n,a[N];
int main(){
	cin>>n;
	int i,an=0;
	for(i=1;i<=n;++i)scanf("%d",a+i),an|=a[i]%2;
	puts(an?"first":"second");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 305  //check the limits, man
int main()
{
    int i,n;
    in(n);
    vector<ll> v(n);
    rep(i,n)
        cin >> v[i];
    lp(i,1,n)
        v[i]+=v[i-1];
    ll ans=(1e18);
    ll temp;
    rep(i,n-1)
    {
        temp=abs(v[i]-(v[n-1]-v[i]));
        ans=min(ans,temp);
    }
    llout(ans);

}





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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<P> ab(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }
  sort(ab.begin(), ab.end());
  int res = 0;
  ll cnt = 0;
  int i = 0;
  while (cnt < k) {
    cnt += (ll) ab[i].second;
    res = ab[i].first;
    i++;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1024
S = gets.chomp.split("")
digit = S.size

(digit-1).times do |i|
	S.insert(2*i+1, nil)
end

ans = 0
#=begin
for bit in 0..(2**(digit-1)-1)
	s = Marshal.load(Marshal.dump(S))

	(S.size-1).times do |i|
		s[2*i+1] = "," if bit & 1 == 1
		bit >>= 1
	end

	ans += s.join.split(",").map(&:to_i).inject(:+)
end

print ans


Measured memory_bytes: 1916
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let a: u32 = sc.read();
    let b: u32 = sc.read();
    let c: u32 = sc.read();

    let ans = if a < b && b < c {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head


// calculate the size of the largest rectangle
struct LargestRectangle{
  vector<vector<int>> a;
  int n, m;
  void init(int arg_n, int arg_m){
    n = arg_n;
    m = arg_m;
    a.assign(n, vector<int>(m+1, 0));
  }
  void put(int i, int j){
    // (i, j) can be a part of the rectangle
    a.at(i).at(j) = 1;
  }
  int query(){
    vector<int> b(m+1, 0);
    int ans = max(n + 1, m + 1); // 0;
    REP(i, n){
      stack<pair<int, int>> st;
      st.emplace(-1, -1);
      REP(j, m+1){
        b[j] += a[i][j];
        if(a[i][j] == 0){
          b[j] = 0;
        }
        int p = j;
        while(st.top().first >= b[j]){
          p = st.top().second;
          // ans = max(ans, st.top().first * (j - p));
          ans = max(ans, (st.top().first + 1) * ((int)j - p + 1));
          st.pop();
        }
        st.emplace(b[j], p);
      }
    }
    return ans;
  }
};

LargestRectangle lr;

int n, m;

int a[2010][2010];

int main(){

  n = in();
  m = in();
  REP(i, n){
    string s = stin();
    REP(j, m){
      if(s[j] == '.'){
        a[i][j] = 1;
      } else {
        a[i][j] = 0;
      }
    }
  }

  lr.init(n-1, m-1);
  REP(i, n-1){
    REP(j, m-1){
      if((a[i][j] + a[i][j+1] + a[i+1][j] + a[i+1][j+1]) % 2 == 0){
        lr.put(i, j);
      }
    }
  }
  
  int ans = lr.query();

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


Measured memory_bytes: 32384
#include<bits/stdc++.h>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define PB push_back
using namespace std;

template <typename tn> void read (tn & a) {
	tn x = 0, f = 1; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = 0; c = getchar(); }
	while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	a = f ? x : -x;
}

int n;
const int MAXN = 100100;
int a[MAXN], b[MAXN], v[MAXN];
int maa, m2a, ax, a2x, bx, b2x, mab, m2b;

int main() {
	read(n);
	rep(i, 1, n) {
		read(v[i]);
		if (i & 1) ++a[v[i]]; else ++b[v[i]];
	}
	rep(i, 1, MAXN - 1) {
		if (a[i] > m2a) {
			m2a = a[i];
			a2x = i;
			if (m2a > maa) {
				swap(m2a, maa);
				swap(a2x, ax);
			}
		}
		if (b[i] > m2b) {
			m2b = b[i];
			b2x = i;
			if (m2b > mab) {
				swap(m2b, mab);
				swap(b2x, bx);
			}
		}
	}
	if (ax != bx) {
		printf("%d\n", n - maa - mab);
	}
	else {
		int ans = n - maa - max(m2a, m2b);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	long long mn = 1e12;
	int j = 0;
	cin >> n;
	for (long long i = 2; i <= sqrt(n); i++)
	{
		if (n % i == 0)
		{
			long long m = n / i;
			mn = mn < (m + i - 2) ? mn : (m + i - 2);
			j = 1;	
		}
	}
	if (j == 1)
		cout << mn;
	else
	cout << n - 1;
	return 0;
	
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

struct graph
{
  int n;
  vector<vector<int>> g, c, used;
  vector<int> par;

  graph(int n):n(n),g(n),c(n){
    used.assign(n, vector<int> (n,1));
  }

  void add_edge(int u, int v, int w){
    g[u].push_back(v);
    c[u].push_back(w);
    g[v].push_back(u);
    c[v].push_back(w);
    used[u][v]=0;
    used[v][u]=0;
  }

  void dijkstra(int s){
    vector<int> dis(n,1e9);
    dis[s]=0;
    par.assign(n, -1);
    par[s]=s;
    auto comp = [&dis](int x, int y){return dis[x]>dis[y];};
    priority_queue <int, vector<int>, decltype(comp)> pq(comp);
    pq.push(s);
    while (!pq.empty()){
      int v=pq.top(); pq.pop();
      int sz = g[v].size();
      for (int i = 0; i < sz; ++i){
        int u=g[v][i];
        if(dis[u] > dis[v]+c[v][i]){
          dis[u] = dis[v]+c[v][i];
          used[u][v]=1;
          used[v][u]=1;
          if(par[u]!=-1){
            used[u][par[u]]=0;
            used[par[u]][u]=0;
          }
          par[u]=v;
          pq.push(u);
        }
      }
    }
  }

  int solve(){
    vector<vector<int>> usedall(n,vector<int> (n,0));
    for (int i = 0; i < n; ++i){
      dijkstra(i);
      for (int i = 0; i < n; ++i){
        for (int j = 0; j < n; ++j){
          if(used[i][j])  usedall[i][j]=1;
        }
      }
    }
    int ret = 0;
    for (int i = 0; i < n; ++i){
      for (int j = 0; j < n; ++j){
        if(!usedall[i][j]){
         ret++;
        }
      }
    }
    return ret/2;
  }
};


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

  int n, m; cin >> n >> m;
  graph g(n);
  for (int i = 0; i < m; ++i){
    int u, v, c; cin >> u >> v >> c;
    g.add_edge(u-1, v-1, c);
  }
  cout << g.solve() << endl;
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;




public class Main {

	static class Node{
		int val;
		Node p,left,right;
		Node(int val){
			this.val=val;
			this.left=null;
			this.right=null;
		}
	}
	static Node root;
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		for(int i=0;i<n;i++){
			String  str=scanner.next();
			if(str.equals("insert")){
				int val=scanner.nextInt();
				root=insert(root,val);
				//System.out.println(root.val);
			}
			else if(str.equals("print")){
				inorder(root);
				System.out.println();
				preorder(root);
				System.out.println();
			}
		}
	}
	private static void preorder(Node node) {
		// TODO Auto-generated method stub
		if(node==null)
			return;
		else{
			System.out.print(" "+node.val);
			preorder(node.left);
			preorder(node.right);
		}
	}
	private static void inorder(Node node) {
		// TODO Auto-generated method stub
		if(node==null)
			return;
		else{
			inorder(node.left);
			System.out.print(" "+node.val);
			inorder(node.right);
		}
	}
	private static Node insert(Node node,int val) {
		// TODO Auto-generated method stub
		if(node==null){
		
			node=new Node(val);
			
		}
		else{
			if(val<node.val){
				node.left=insert(node.left,val);
			}
			else node.right=insert(node.right,val);
		}
		
		return node;
	}

}



Measured memory_bytes: 201352
#include <cstdio>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int rs[180020];
int cs[180020];
int as[180020];

int main(void) {
  int nRow, nCol, dist;
  scanf("%d%d%d", &nRow, &nCol, &dist);
  REP(i, nRow) {
    REP(j, nCol) {
      int v;
      scanf("%d", &v);
      --v;
      rs[v] = i;
      cs[v] = j;
    }
  }
  REP(i, nRow*nCol) {
    as[i+dist] = as[i] + abs(rs[i]-rs[i+dist]) + abs(cs[i]-cs[i+dist]);
  }
  int nQuery;
  scanf("%d", &nQuery);
  REP(iQuery, nQuery) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", as[r-1] - as[l-1]);
  }
  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n,k=2,l;
    cin>>n>>k;
    ll dp[n+1];
    ll h[n+1];
    rep(i,1,n+1)cin>>h[i];
    dp[n]=0;
    for(int i=n-1;i>0;i--)
    {
        dp[i]=hell;
        rep(j,1,k+1)
        {
            l=min(n,i+j);
            dp[i]=min(dp[i],dp[l]+abs(h[i]-h[l]));
        }
    }
    // rep(i,1,n+1)
    // {
    //     cout<<dp[i]<<" ";
    // }
    cout<<dp[1]<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5160
x = input()
min = 0
for i in range(0, len(x) - 2):
    a = x[i] + x[i + 1] + x[i + 2]
    b = abs(753 - int(a))
    if i == 0:
        min = b
    elif b < min:
        min = b
print(min)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
 
    
    int ans = T.size();
 
    //Brute force through all initial position in S
    for (int start = 0; start <= S.size() - T.size(); start++)
    {
        int diff = 0;
        for (int i = 0; i < T.size(); i++)
        {
            if (T[i] != S[start + i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3576
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

d,t,s=map(int,input().split())
YesNo(-(-d//s)<=t)

Measured memory_bytes: 61736
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N,M,X;
    cin >> N >> M >> X;
    ll left = 0;
    ll right = 0;
    ll n;
    rep(i,M){
        cin >> n;
        if(n < X)left++;
        else right++;
    }
    cout << min(left,right) << endl;
}

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

public class Main {	
	private static void solve(){
		//Implement solution here.
		System.out.println(ni() <= ni() ? "Yes" : "No");
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 22100
#!/usr/bin/env python3

import sys
from collections import defaultdict

def main():
    n, m = map(int, input().split())
    a = []
    b = []
    atoi = defaultdict(list)
    btoi = defaultdict(list)
    for i in range(m):
        aa, bb = map(int, sys.stdin.readline().split())
        a.append(aa - 1)
        b.append(bb - 1)
        atoi[aa - 1].append(i)
        btoi[bb - 1].append(i)

    achieved = [False for i in range(m)]
    res = 0
    aptr = -1  # Already achieved
    for x in range(n - 1):
        tobreak = False
        for i in btoi[x + 1]:
            if not achieved[i]:
                tobreak = True
        if tobreak:
            res += 1
            while aptr < x:
                aptr += 1
                for j in atoi[aptr]:
                    achieved[j] = True
    print(res)

if __name__ == "__main__":
    main()


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

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

const int MAX_DIGIT = 50;
ll dp[100][2];

int main () {
  cin.tie(0);
  cout << setprecision(10);

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

  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for(int d=0;d<MAX_DIGIT;d++) {
    ll mask = 1ll<<(MAX_DIGIT - d - 1);

    int num = 0;
    for(int i=0;i<n;i++) {
      if(a[i] & mask) num++;
    }

    ll cost0 = mask * num;
    ll cost1 = mask * (n - num);

    if(dp[d][1] != -1) {
      chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1));
    }

    if(dp[d][0] != -1) {
      if(k & mask) {
        chmax(dp[d+1][1], dp[d][0] + cost0);
      }
    }

    if(dp[d][0] != -1) {
      if(k & mask) chmax(dp[d+1][0], dp[d][0] + cost1);
      else chmax(dp[d+1][0], dp[d][0] + cost0);
    }
  }
  cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,s,t) for (int i = s; i < t; ++i)

int main() {
	int n, m; scanf("%d%d", &n, &m);
	int sum = 0, a;
	rep(i,m) scanf("%d", &a), sum += a;
	if (n >= sum) printf("%d\n", n - sum);
	else printf("%d\n", -1);
}

Measured memory_bytes: 3816
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e50)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    H, W, K = l_inpl()
    dp = create_grid(H+1, W)
    for i in range(W):
        dp[0][i] = 0
    dp[0][0] = 1

    for i in range(H):
        for j in range(W):
            for k in range(0, 2**(W-1)): # 引ける横線の数
                ok = True
                for l in range(W-2):
                    if (k >> l) & 1 and (k >> (l+1)) & 1:
                        # 隣に線が引かれている
                        ok = False
                if not ok:
                    continue
                if j > 0 and (k >> (j-1)) & 1:
                    # jの左に横線が引かれるケース
                    dp[i+1][j-1] += dp[i][j]
                    dp[i+1][j-1] %= MOD
                elif j < W-1 and (k >> j) & 1:
                    # jの右側に横線が引かれるケース
                    dp[i+1][j+1] += dp[i][j]
                    dp[i+1][j+1] %= MOD
                else:
                    # jの両側に横線が引かれないケース
                    dp[i+1][j] += dp[i][j]
                    dp[i+1][j] %= MOD

    print(dp[H][K-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 42608