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

int main() {
    long long int l, n, max=0;
    cin >> l >> n;
    long long int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=1; i<n; i++) {
        if(a[i]-a[i-1]>max) {
            max=a[i]-a[i-1];
        }
    }
    if(l-a[n-1]+a[0]>max) {
        max=l-a[n-1]+a[0];
    }
    cout << (l-max) << endl;
	return 0;
}

Measured memory_bytes: 1920
a,b,c,k = map(int, input().split())

ans = 0
if a >= k:
    ans += k
    k = 0
else:
    ans += a
    k -= a

if b >= k:
    k = 0
else:
    k -= b

if c >= k:
    ans -= k
    k = 0
else:
    ans -= c
    k -= c

print(ans)

Measured memory_bytes: 61592
import sys,itertools
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
dp = {}
for i in range(N):
    dp[i] = list(map(int, input().split()))

MAP = [None]*N
for i in range(N):
    MAP[i] = [0]*N

for i in range(N):
    x_1,y_1 = dp[i]
    for j in range(N):
        x_2,y_2 = dp[j]
        if i==j:
            continue
        else:
            MAP[i][j] =((x_1-x_2)**2+(y_1-y_2)**2)**.5

cnt = 0
k = 0
for i in itertools.permutations(range(N)):
    tmp = 0
    c = 0
    for j in i:
        if c:
            tmp += MAP[pre][j]
        pre = j
        c += 1
    cnt += tmp
    k += 1
print(cnt/k)

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

int main() {
    int t=1;
    //cin >> t;
    while(t--){
        ll n,i,j,sum=0;
        cin >> n;
        vector<ll>v(n);
        for(i=0;i<n;i++)cin >> v[i];
        for(i=1;i<n;i++){
            if(v[i]<v[i-1]){
                sum+=v[i-1]-v[i];
                v[i]=v[i]+v[i-1]-v[i];
            }
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 4784
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable MO = 10L^^9 + 7;

int N;
long K;
long[][] A;

long[][] multiply(long[][] a, long[][] b) {
  auto c = new long[][](N, N);
  foreach (u; 0 .. N) foreach (w; 0 .. N) foreach (v; 0 .. N) {
    (c[u][v] += a[u][w] * b[w][v]) %= MO;
  }
  return c;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      K = readLong();
      A = new long[][](N, N);
      foreach (u; 0 .. N) foreach (v; 0 .. N) {
        A[u][v] = readLong();
      }
      auto x = new long[][](N, N);
      auto y = new long[][](N, N);
      foreach (u; 0 .. N) foreach (v; 0 .. N) {
        x[u][v] = A[u][v];
        y[u][v] = (u == v) ? 1 : 0;
      }
      for (long k = K; k; k >>= 1) {
        if (k & 1) {
          y = multiply(y, x);
        }
        x = multiply(x, x);
      }
      long ans;
      foreach (u; 0 .. N) foreach (v; 0 .. N) {
        (ans += y[u][v]) %= MO;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


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

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

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)

int main()
{
	string a;
	cin >> a;
	ff(i, 0, a.size()) {
		int x = 0;
		ff(j, 0, a.size()) {
			if (a.at(i) == a.at(j)) {
				x++;
			}
		}
		if (x % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static char[][] t;
	static int[] dx = {0, 1};
	static int[] dy = {1, 0};

	static String[][] dp;
	static int h, w;

	static String rec(int cy, int cx) {
		if (dp[cy][cx].length() > 0) return dp[cy][cx];
		String max = "";
		for (int k=0; k<2; k++) {
			int ny = cy + dy[k];
			int nx = cx + dx[k];
			if (h <= ny || w <= nx) continue;
			if ('0' <= t[ny][nx] && t[ny][nx] <= '9') {
				String tmp = rec(ny, nx);
				if (tmp.length() > max.length()) max = tmp;
				else if (tmp.length() == max.length() && tmp.compareTo(max) > 0) max = tmp;
			}
		}
		if (max.equals("")) return dp[cy][cx] = String.valueOf(t[cy][cx]);
		return dp[cy][cx] = t[cy][cx] + max;
	}

	static boolean solve() {
		w = in.nextInt();
		h = in.nextInt();
		if (w + h == 0) return false;

		t = new char[h][w];
		for (int i=0; i<h; i++) {
			t[i] = in.next().toCharArray();
		}

		dp = new String[h][w];
		for (int i=0; i<h; i++) {
			Arrays.fill(dp[i], "");
		}

		String ans = "";
		for (int i=0; i<h; i++) {
			for (int j=0; j<w; j++) {
				if ('0' <= t[i][j] && t[i][j] <= '9') {
					String tmp = rec(i, j);
					int pos = 0;
					while (pos < tmp.length() && tmp.charAt(pos) == '0') pos++;
					tmp = tmp.substring(pos, tmp.length());
					if (tmp.length() > ans.length()) ans = tmp;
					else if (tmp.length() == ans.length() && tmp.compareTo(ans) > 0) ans = tmp;
				}
			}
		}

		out.println(ans);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 54768
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

void printM(vector<vector<long> > &vec, long height, long width){
    F(i, 0, height){
        F(j, 0, width){
            cout << vec[i][j] << space;
        }
        cout << endl;
    }
}

ll flo(ull a, ull b, ull x){
    ull first = a*x;
    first = first/b;
    ull second = x/b;
    second = second * a;
    ll hoge = first  - second;
    return hoge;
}

#define TST 0
int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    string str;
    cin >> str;
    if(str == "ABC"){
        cout << "ARC" << endl;
    }else
        cout << "ABC" << endl;


#if TST==1

#endif
}


Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <iterator>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <unordered_map>
#include <iomanip>

using namespace std;

bool acgt(string s){
    return s == "A" || s == "C" || s == "G" || s == "T";
}

void solve() {
    string s; cin >> s;
    int count = 0;
    int maxcount = 0;
    for(int i = 0; i < s.length(); i++){
        if(acgt(s.substr(i,1))) count++;
        else {
            maxcount = max(maxcount, count);
            count = 0;
        }
    }
    maxcount = max(maxcount, count);
    cout << maxcount << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
        Yes;
    }else if (s[0] == s[2] && s[1] != s[2] && s[1] == s[3]) {
        Yes;
    } else if (s[0] == s[3] && s[0] != s[1] && s[1] == s[2]) {
        Yes;
    }else{
        No;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
static const int INF = 1e+9+7;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int count = 0;
    erep(i,a,b){
      if(c%i == 0) count++;
    }
    print(count);

  return 0;
}





Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
const double eps=1e-10;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	ll w,h,x,y;
	cin>>w>>h>>x>>y;
	double x1=1.0*w/2,y1=1.0*h/2;
	if(w%2==0&&h%2==0&&x==w/2&&y==h/2){
		printf("%.9f %d\n",1.0*w*h/2,1);
		return 0;
	}
	double k=1.0*(y1-y)/(x1-x);
	double ta=k*(w-x1)+y1;
	double sa=-y1/k+x1;
	double tb=k*(-x1)+y1;
	double sb=(h-y1)/k+x1;
	double ans;
	if(ta>=0&&ta<=h&&tb>=0&&tb<=h){
		ans=min(1.0*(ta+tb)*w/2,1.0*w*h-(ta+tb)*w/2);
	}else{
		ans=min(1.0*(sa+sb)*h/2,1.0*w*h-(sa+sb)*h/2);
	}
	printf("%.9f %d\n",ans,0);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> 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;
}
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;



int main(){
  //input
  string s, t; 
  cin >> s >> t;
  int ns = s.size();
  int nt = t.size();
  
  //initialization
  int dp[ns+1][nt+1];
  int prev[ns+1][nt+1];
  rep(i, ns+1){
    rep(j, nt+1){
      dp[i][j] = 0;
    }
  }
  //compute
  rep(i,ns){
    rep(j,nt){
      if(s[i]==t[j])dp[i+1][j+1] = dp[i][j]+1;
      else dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
    }
  }
  
  //output
  string lcs = "";
  while(ns > 0 && nt > 0){
    if(dp[ns][nt] == dp[ns-1][nt]) ns--;
    else if(dp[ns][nt] == dp[ns][nt-1])nt--;
    else{
      lcs += s[ns-1];
      ns--;
      nt--;
    }
  }
  
  reverse(lcs.begin(),lcs.end());
  cout << lcs << endl;
}
    


Measured memory_bytes: 35456
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut ans = vec![0; n + 1];
    for (i, s) in it.enumerate() {
        let a: usize = s.parse().unwrap();
        ans[a] = i + 1;
    }
    let mut s = String::new();
    for &v in &ans[1..] {
        s.push_str(&format!("{} ", v));
    }
    s.pop();
    println!("{}", s);
}

fn main() {
    run();
}

Measured memory_bytes: 6908
let get_index = function
    "A" -> 0
  | "B" -> 1
  | "C" -> 2
  | _ -> -1

let swap a i j =
  let temp = a.(i) in
  a.(i) <- a.(j);
  a.(j) <- temp;;

let () =
  let cup = [|1;0;0|] in
  let rec read () =
    try let l = read_line ()
                |> Str.split (Str.regexp_string ",")
        in
        swap cup (get_index (List.nth l 0)) (get_index (List.nth l 1));
        read ()
    with End_of_file ->
      if cup.(0) = 1 then
        print_endline "A"
      else if cup.(1) = 1 then
        print_endline "B"
      else if cup.(2) = 1 then
        print_endline "C"
      else
        print_endline ""
  in read ()
;;

Measured memory_bytes: 2020
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void sumitrust2019E();

int main()
{
	sumitrust2019E();
	fflush(stdout);
	return 0;
}

static void sumitrust2019E()
{
	int N;
	getint(N);

	std::vector<LLONG> member(3, 0);
	LLONG ans = 1;
	for (int i = 1; i <= N; i++) {
		int ai;
		getint(ai);

		int ptn = 0;
		for (int m = 0; m < 3; m++) {
			if (ai == member[m]) {
				ptn++;
			}
		}
		ans = (ans * ptn) % MOD_NUM;
		for (int m = 0; m < 3; m++) {
			if (ai == member[m]) {
				member[m]++;
				break;
			}
		}
	}
	printf("%lld\n", ans);
}


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

int main(){
  
  int a, b, cnt = 0;
  
  cin >> a >> b;
  
  for(int i = a;i <= b;i++){
    if(i / 10000 == i % 10 && i % 10000 / 1000 == i % 100 / 10) cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


ll A,B,N;

void input() {
  cin >>A >>B >>N;
}

int main() {
  input();
  ll res = 0;
  ll x = min(B-1, N);
  res = A*x/B - A*(x/B);
  cout <<res <<endl;
}

/*

Ax/B <= [Ax/B] < Ax/B + 1

Ax/B <= A*[x/B] < A(x/B-1)


*/


Measured memory_bytes: 3632
//Author : Ayush Jain

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007

int main()
{
	ios_base::sync_with_stdio(false);
	char s[200005];
	ll c[30],ans=0;
	int i,n;
	for(i=0;i<30;i++) c[i]=0;
	cin>>s;
	n=strlen(s);
	for(i=0;i<n;i++){
		c[s[i]-'a']++;
	}
	ll N=(ll)n;
	ans++;
	ans+=(N*(N-1))/2;
	for(i=0;i<30;i++){
		if(c[i]>1){
			ans-=(c[i]*(c[i]-1))/2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){

  int a, b;

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

  if(a < b){
    printf("a < b\n");
  }else if(a > b){
    printf("a > b\n");
  }else{
    printf("a == b\n");
  }
    
  return 0;
}


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

long long a[100010];

int main(){
	ios::sync_with_stdio(false);
	int n;
	map<long long,int> s;
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(s[a[i]]==0){
			ans++;
			s[a[i]]++;
		}
		else{
			s[a[i]]--;
			ans--;
		}
		 
	}
	cout<<ans<<endl;
	return 0;
}

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

using ll = long long;
const ll M = 1e9 + 7;

ll pow_mod(ll x, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) res = res * x % M;
        x = x * x % M;
        n /= 2;
    }
    return res;
}

int main(int argc, char *argv[])
{
    int N;
    cin >> N;
    vector<vector<int>> tree(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<ll> p2(N + 1);
    p2[0] = 1;
    for (int i = 1; i <= N; i++) {
        p2[i] = 2 * p2[i - 1] % M;
    }
    vector<ll> size(N, 1);
    ll res = 0;
    function<void(int, int)> dfs = [&](int v, int p) {
        res = (res + p2[N - 1]) % M;
        for (int u : tree[v]) {
            if (u == p) continue;
            dfs(u, v);
            size[v] = (size[v] + size[u]) % M;
            res = (res - p2[size[u]] + 1 + M) % M;
        }
        if (p != -1) {
            res = (res - p2[N - size[v]] + 1 + M) % M;
        }
        res = (res - 1 + M) % M;
    };
    dfs(0, -1);
    res = res * pow_mod(p2[N], M - 2) % M;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 29952
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    sc.close();

    List<Long> l = new ArrayList<>();
    for (long n = 1; n < 10; n++) l.add(n);

    int ni = 0;
    long n = 0;
    for (int i = 10; i < K + 1; i++) {
      long n1 = l.get(ni);
      if (n == 0) {
        n = n1 * 10 + n1 % 10;
        if (0 < n % 10) n--;
      }

      l.add(n++);

      if (n % 10 == 0 ||
          1 < n - (n1 * 10 + n1 % 10)) {
        n = 0;
        ni++;
      }
    }

    long ans = l.get(K - 1);
    System.out.println(ans);
  }
}

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

int main(){
  string O, E;
  cin >> O >> E;

  int n = E.size() + O.size();
  int x=0, y=0;

  for (int i=0; i<n; i++){
    if (i%2==0){
      cout << O.at(x);
      x++;
    }
    else {
      cout << E.at(y);
      y++;
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, tot;
int a[101], ans;

int main() {
  scanf("%d%d", &n, &m); ans = n;
  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]),
      tot += a[i];
  sort(a + 1, a + n + 1);
  m -= tot;
  ans += m / a[1];
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
 
int b[55];

int main(){
  int n, i, j = 0;
  long long ans;
  string s;
  cin >> n >> s;
  for(i = 1; i < n; i++){
    if(s[i-1] == s[i]) b[j]++;
    else j++;
  }
  ans = (b[0] ? 6 : 3);
  for(i = 0; i < j; i++)
    ans = (ans * (b[i] ? b[i+1] ? 3 : 1 : 2)) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int N,max,count,j,i;
	scanf("%d",&N);
	int h[N];
	count = 1;
	for (int i = 0; i < N; i++)
	{
		scanf("%d",&h[i]);
	}
	max = h[0];
	for (int j = 1; j <N ; j++)
	{
		if(h[j]>=max){
			count = count + 1;
			max = h[j];
		}else{continue;}
	}
	printf("%d\n",count );
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define r(i,n) for(long long i = 0; i<n; i++)
typedef long long ll;
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  r(i,s.length()){
    cout<<char((s[i]-'A'+n)%26+'A');
  }
  cout<<endl;
}

Measured memory_bytes: 256
N = int(input())
d = []
d.append(int(input()))
a = 1
for _ in range(N-1):
    i = int(input())
    w = True
    for j in range(a):
        if i == d[j]:
            w = False
    if w:
        d.append(i)
        a += 1
print(a)


Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c;
    while(cin>>a>>b>>c){
        if(a==b&& a!=c || a==c&&a!=b || b==c&&b!=a)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  string S;
  cin >> S;
  map<char, ll> m;
  rep(i, S.size()) {
    m[S[i]]++;
  }

  rep(i, 26) {
    char c = 'a' + i;
    if (m[c] == 0) {
      COUT(c);
      return 0;
    }
  }
  COUT("None");
  return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

std::vector<long long> Eratosthenes(long long N) {
  std::vector<long long> arr(N+1);
  for(long long i = 0; i <= N; i++) arr[i] = 1;
	for(long long i = 2; i <= std::sqrt(N); i++) {
    if(arr[i]) for(long long j = 0; i * (j + 2) <= N; j++) arr[i *(j + 2)] = 0;
  }

  std::vector<long long> rtn;
	for(long long i = 2; i <= N; i++){
		if(arr[i]) rtn.push_back(i);
	}
  return rtn;
}

template<typename T> class BinaryIndexedTree {
  private:
    int S;
    std::vector<T> v;
  public:
    BinaryIndexedTree<T> (int _S) {
      S = _S;
      v.resize(S+1);
    }
    void update(int i, T k) {
      for(i++; i <= S; i += i&-i) v[i] = v[i] + k;
    }
    T read(int i) {
      T sum = 0;
      for(i++; i; i -= i&-i)  sum = sum + v[i];
      return sum;
    }
    T read(int l, int r) {
      return read(r) - read(l-1);
    }
};

//N = (2p-1)

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  auto A = Eratosthenes(100001);
  BinaryIndexedTree<int> bit(100001);
  for(auto&& a : A) {
    if (std::binary_search(all(A), (a+1)/2)) bit.update(a,1);
  }

  int Q; std::cin >> Q;
  std::vector<int> ans(Q);
  rep(i,Q) {
    int l, r; std::cin >> l >> r;
    ans[i] = bit.read(l,r+1);
  }
  
  rep(i,Q) std::cout << ans[i] << std::endl;
  return 0;
}


Measured memory_bytes: 1520
#include <iostream>

int main()
{
	int data[3][3];
	for(int i = 0; i < 3; ++i)
	{
		for(int j = 0; j < 3; ++j)
		{
			std::cin >> data[i][j];
		}
	}

	int N, inp;
	std::cin >> N;
	for(int i = 0; i < N; ++i)
	{
		std::cin >> inp;
		for(int j = 0; j < 3; ++j)
		{
			for(int k = 0; k < 3; ++k)
			{
				if(data[j][k] == inp) data[j][k] = 0;
			}
		}
	}

	int flag = 0;
	for(int i = 0; i < 3; ++i)
	{
		if(data[i][0] == 0 && data[i][1] == 0 && data[i][2] == 0) flag = 1;
		if(data[0][i] == 0 && data[1][i] == 0 && data[2][i] == 0) flag = 1;
	}

	if(data[0][0] == 0 && data[1][1] == 0 && data[2][2] == 0) flag = 1;
	if(data[0][2] == 0 && data[1][1] == 0 && data[2][0] == 0) flag = 1;

	if(flag == 1) std::cout << "Yes" << std::endl;
	else 		  std::cout << "No" << std::endl;
	return 0;
}

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


int main()
{
	int n; cin >> n;
	int ok = 1;
	int X = 0, Y = 0, T = 0;
	for (int i = 0; i < n; ++i)
	{
		int t, x, y; cin >> t >> x >> y;
		X = abs(x - X);
		Y = abs(y - Y);
		T = t - T;
		if (X + Y > T) ok = 0;
		if ((X + Y) % 2 != T % 2) ok = 0;
	}
	cout << (ok ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3612
N, M = map(int, input().split())

switch = [list(map(int, input().split())) for _ in range(M)]
B = []
for K, *S in switch:
    b = 0
    for k in range(K):
        b += (1 << (S[k] - 1))
    B.append(b)

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

ans = 0
for i in range(2 ** N):
    on = True
    for j, b in enumerate(B):
        cnt = 0
        state = b & i
        while state > 0:
            cnt += state & 1
            state >>= 1
        on &= (cnt % 2 == P[j])
    ans += on

print(ans)


Measured memory_bytes: 3188
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const MOD: i64 = 1_000_000_007;

fn dfs(n: usize, i: usize, m: usize, v: &mut Vec<usize>) {
    if i >= n {
        for j in 0..n {
            let c = ('a' as u8 + v[j] as u8) as char;
            print!("{}", c);
        }
        println!();
        return;
    }

    for j in 0..m + 2 {
        v[i] = j;
        dfs(n, i + 1, if m > j { m } else { j }, v)
    }
}

fn main() {
    input! {
        n: usize
    }

    let mut v = vec![0; n];
    dfs(n, 1, 0, &mut v)
}


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

const int DIM = 1e3 + 5;
const int MOD = 1e9 + 7;

int cnt[DIM];

int main( void ) {
    
    int n;
    cin >> n;
    
    for( int i = 2; i <= n; i ++ ) {
        int aux = i;
        
        for( int j = 2; aux != 1; j ++ ) {
            while( aux % j == 0 ) {
                cnt[j] ++;
                aux /= j;
            }
        }
    }
    
    int ans = 1;
    for( int i = 2; i <= n; i ++ )
        ans = ( 1LL * ans * (cnt[i] + 1) ) % MOD;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M, K = map(int, input().split())
    num_friends = [0 for _ in range(N)]
    blocks = [set() for _ in range(N)]
    uf = UnionFind(N)

    for _ in range(M):
        a, b = map(int, input().split())
        num_friends[a-1] += 1
        num_friends[b-1] += 1
        uf.union(a-1, b-1)
    for _ in range(K):
        a, b = map(int, input().split())
        blocks[a-1].add(b-1)
        blocks[b-1].add(a-1)

    ans = []
    for i in range(N):
        cnt = uf.size(i) - 1 - num_friends[i]
        for j in blocks[i]:
            if uf.same(i, j):
                cnt -= 1
        ans.append(cnt)
    
    print(*ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 44396
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int main()
{
  int n,q;
  int day;
  while(cin>>n>>q,n||q){
    int date[110]={0};
    for(int i = 0;i < n;i++){
      int m;
      cin >>m;
      for(int j = 0;j < m;j++){
	cin >>day;
	date[day]++;
      }
    }
    int cday= 0;
    int ans = 0;
    for(int i = 1; i <110;i++){
      if(date[i] > cday&&date[i]>=q){
	cday =date[i];
	ans =i;
      }
    }
    cout <<ans<<endl;
  }
  return 0;
}

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

int main() {
	int n, k, x, y;

	cin >> n >> k >> x >> y;

	if (n>k) {
		cout << k*x + (n - k)*y << endl;
	}
	else {
		cout << n*x << endl;
	}


	return 0;

}

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

typedef long long int   ll;
#define cases           int t;cin>>t;while(t--)
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
#define scan(n)         scanf("%d",&n)
#define PI              3.1415926535897932384626433832795
#define int             ll
#define loop0           for(int i=0;i<n;i++)
#define loop1           for(int i=1;i<=n;i++)
#define inpar0(ar)      for(int i=0;i<n;i++)cin>>ar[i];
#define inpar1(ar)      for(int i=1;i<=n;i++)cin>>ar[i];
#define showar0(ar)     for(int i=0;i<n;i++)cout<<ar[i]<<" ";
#define showar1(ar)     for(int i=1;i<=n;i++)cout<<ar[i]<<" ";
#define manu            cout<<(checkerCounter++)<<endl;
int checkerCounter = 1;
int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}

signed main(){
    int n,w;
    cin>>n>>w;
    int we[n],val[n];
    for(int i=0;i<n;i++){
        cin>>we[i]>>val[i];
    }
    int dp[n+1][w+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            dp[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<we[i-1];j++){
            dp[i][j]=dp[i-1][j];
        }
        for(int j=we[i-1];j<=w;j++){
            dp[i][j]=max(dp[i-1][j-we[i-1]]+val[i-1],dp[i-1][j]);
        }
    }
    cout<<dp[n][w];
}


Measured memory_bytes: 79104
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef unsigned long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const ll MOD = 1LL<<32;

int main(){
  int M; cin>>M;
  while(M--){
    ll a[9];
    REP(i, 9){
      scanf("%llx", &a[i]);
    }
    ll S = 0;
    REP(i, 32){
      ll sum = 0;
      REP(j, 8){
        sum += a[j] ^ S;
      }
      if((sum ^ a[8]) & (1LL<<i)){
        S ^= 1LL<<i;
      }
    }
    printf("%llx\n", S);
  }
  return 0;
}

Measured memory_bytes: 1232
from itertools import product

n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

bit = [0, 1]
ans = float('inf')
for l in product(bit, repeat=n):
    a = [0] * m
    cnt = 0
    for i, buy in enumerate(l):
        if buy == 1:
            cnt += ca[i][0]
            for j in range(1, m + 1):
                a[j - 1] += ca[i][j]
    if all(i >= x for i in a):
        ans = min(ans, cnt)

print(-1 if ans==float('inf') else ans)



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

const int m = 1e5, M = 1e9+7;
ll inverse[3*m], fact[3*m], invfact[3*m];

ll nCr(ll n, ll r){
    ll ans = fact[n]*invfact[r]%M;
    return (ans*invfact[n-r]%M); 
}

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

    //good luck kittu!

    inverse[1] = 1;
    for(ll i = 2; i<3*m; i++) inverse[i] = M - M/i * inverse[M%i]%M;
    fact[0] = invfact[0] = 1;
    for(ll i = 1; i<3*m; i++){
        fact[i] = fact[i-1]*i%M;
        invfact[i] = invfact[i-1]*inverse[i]%M;
    }

    int n, k; cin>>n>>k;
    vector<int> a(n);
    for(int i = 0; i<n; i++) cin>>a[i];

    sort(a.begin(), a.end());
    ll sum = 0, x, y;

    for(int i = 0; i<n-k+1; i++){
        x = nCr(n-1-i, k-1);
        y = a[i]+M;
        y %= M;
        x = x*y;
        x %= M;
        sum += M - x;
        sum %= M;
    }

    for(int i = k-1; i<n; i++){
        x = nCr(i, k-1);
        y = a[i]+M;
        y %= M;
        x = x*y;
        x %= M;
        sum += x;
        sum %= M;
    }
    
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 12000000000000

using namespace std;

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> f[i][j];
        }
    }
    vector<vector<LL>> p(n, vector<LL>(11));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> p[i][j];
        }
    }

    LL mx = -INF;
    for (int i = 1; i < 1024; i++) {
        int tmp = i;
        vector<int> cnt(n, 0);
        for (int j = 0; j < 10; j++) {
            // cout << tmp % 2 << " ";
            if (tmp % 2 == 1) {
                for (int k = 0; k < n; k++) {
                    cnt[k] += f[k][j];
                }
            }
            tmp /= 2;
        }
        // cout << endl;

        LL sum = 0;
        for (int j = 0; j < n; j++) {
            sum += p[j][cnt[j]];
        }
        // cout << sum << endl;
        mx = max(mx, sum);
    }

    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    long long n, d;
    cin >> n >> d;
    set<double>s;
    int Count = 0;
    for(int i = 1; i <= n; i++)
    {
        long long a, b; cin >> a >> b;
        double dd = sqrt((double)(a*a)+(double)(b*b));
        if(dd <= (double)d)
        {
            Count++;
        }
    }
    cout << Count << endl;
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3616
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	static double[] dp;
	static int[] pow;
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		String N = sc.next();
		int num = 0;
		for(int i = 0; i < N.length(); i++) if(N.charAt(i) == '2') num++;
		System.out.println(num);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

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

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile(" ");
      int[] arrayS = delim
        .splitAsStream(line)
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 180232
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		double[][] colors = new double[n][3];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++)
				colors[i][j] = sc.nextDouble();
		}
		double result = 0;
		for (int i = (1 << m) - 1; i < 1 << n; i++)
			if (Integer.bitCount(i) == m) {
				result = Math.max(result, calc(i, m, colors));
			}
		System.out.println(result);
		sc.close();
	}

	static double calc(int i, int m, double[][] colors) {
		int counter = 0;
		double result = 0;
		double[][] v = new double[m][3];
		for (int j = 0; j < colors.length; j++)
			if ((i & 1 << j) != 0) {
				v[counter] = colors[j];
				counter++;
			}
		for (int j = 0; j < v.length; j++)
			for (int k = j + 1; k < v.length; k++) {
				double[] d = { v[j][0] - v[k][0], v[j][1] - v[k][1],
						v[j][2] - v[k][2] };
				result += d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
			}
		return result;
	}
}

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

int main(){
int a,b,c,d,e;
cin >> a >>b >> c >> d >> e;
if(a == 0){
 cout << 1<< endl; 
}
else if(b == 0){
    cout << 2<< endl; 
}
else if(c == 0){
    cout << 3 << endl;
}
else if(d == 0){
    cout << 4 << endl;
}
else if(e == 0){
    cout << 5 << endl;
}
}

Measured memory_bytes: 3628
/*
 * omg.cpp
 *
 *  Created on: 2019/06/03
 *      Author: J01003
 */
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
	char A,T;
	cin>>A;
	if(A=='A'){
		cout<<'T'<<endl;
	}else if(A=='T'){
		cout<<'A'<<endl;
	}else if(A=='C'){
		cout<<'G'<<endl;
	}else if(A=='G'){
		cout<<'C'<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
c = list(input())
c = c[::-1]
w = c.count("W")
r = c.count("R")
ans = 0
for i in c:
    if w == 0 or r == 0:
        print(ans)
        break
    if i == "R":
        w -= 1
        r -= 1
        ans += 1
    else:
        w -= 1


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

int main(){
    int n, x;
    cin >> n >> x;

    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    
    int ans = 0;
    for(int i = 0; i < n && x > 0; i++){
        if(a[i] <= x) ans++;
        x -= a[i];
        if(i == n - 1 && x > 0) ans--;
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256