akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

typedef long LONG;

LONG memo[10][1001][101];

LONG comb(int *use, int n, int s, int m)
{
	int i;
	LONG c;

// printf("<%d %d %d>\n", n, s, m);
    
	if (memo[n][s][m] != -1){
		return (memo[n][s][m]);
	}
	
	if (n == 1){
    	if (0 <= s && s <= 100 && s >= m && use[s] == 0){
//			printf("[");
//			for (i = 0; i <= 100; i++){
//				if (use[i])printf("%d ", i);
//			}
//			printf("%d]", s);

			memo[n][s][m] = 1;
			return (1);
		}
		memo[n][s][m] = 0;
		return (0);
	}
	
	c = 0;
	for (i = m; i <= 100; i++){
		if (use[i] == 0){
			use[i] = 1;
			if (s - i >= 0){
				c += comb(use, n - 1, s - i, i + 1);
			}
			use[i] = 0;
		}
	}
	
	memo[n][s][m] = c;
	return (c);
}

int main(void)
{
	int n, s;
	int use[101];
	int c;
	int i;
	
    
	while (1){
		scanf("%d%d", &n, &s);
		if (n == 0 && s == 0){
			break;
		}
		memset(use, 0, sizeof(use));
		memset(memo, -1, sizeof(memo));

		printf("%ld\n", comb(use, n, s, 0));
	}
	
	return (0);
}

Measured memory_bytes: 8504
// AOJ Volume 0 Problem 0040

#include <stdio.h>
#include <string.h>

void cipher(char *out, char *in, int a, int b)
{
	int i;
	
	i = 0;
	while (in[i] != '\0'){
		out[i] = ((a * (in[i] - 'a') + b) % 26) + 'a';
		i++;
	}
	out[i] = '\0';
}
	
void search_key(char *str, int *key_a, int *key_b)
{
	int a, b;
	char key_word[5];
	
	for (a = 1; a < 100; a += 2){
		for (b = 0; b < 100;  b++){
			cipher(key_word, "this", a, b);
			if (strstr(str, key_word) != NULL){
				*key_a = a;
				*key_b = b;

// printf("<%s, %d, %d>", key_word, a,  b);

				return;
			}
			cipher(key_word, "that", a, b);
			if (strstr(str, key_word) != NULL){
				*key_a = a;
				*key_b = b;
// printf("[%s, %d, %d]", key_word, a,  b);
				return;
			}
		}
	}
}

void make_decode_table(char *table, int a, int b)
{
	int c;
	
	for (c = 0; c < 26; c++){
		table[(a * c + b) % 26] = c + 'a';
	}
	table[26] = '\0';
}

void decode(char *in, char *table)
{
	int i;
	
	i = 0;
	while (in[i] != '\n'){
		if (in[i] == ' '){
			printf(" ");
		}
		else {
			printf("%c", table[in[i] - 'a']);
		}
		i++;
	}
	printf("\n");
}
	
int main(void)
{
	int n;
	int a, b;
	char str[300];
	char decode_table[27];
	int i;
	
	scanf("%d", &n);
	fgets(str, 90, stdin);
	for (i = 0; i < n; i++){
		fgets(str, 300, stdin);
		search_key(str, &a, &b);
		make_decode_table(decode_table, a, b);

//		printf("<%s>", decode_table);

		decode(str, decode_table);
	}
	
	return (0);
}

Measured memory_bytes: 0
#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 a, b, c;
    cin >> a >> b >> c;
    if (a+b+c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 3528
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)
#define N_MAX 100000+10

using namespace std;

typedef long long int Int;

class UnionFind {
    private:
        int par[N_MAX];
        int rank[N_MAX];
    public:
        UnionFind(int n) {
            for(int i = 1;i <= n;i++) {
                par[i] = i;
                rank[i] = 0;
            }
        }

        int root(int x) {
            return x == par[x] ? par[x] : par[x] = root(par[x]);
        }

        bool same(int x,int y) {
            return par[x] == par[y];
        }

        void merge(int x,int y) {
            x = root(x);
            y = root(y);
            if(x == y)
                return;

            if(rank[x] < rank[y]) {
                par[x] = y;
            } else {
                par[y] = x;
                if(rank[x] == rank[y])
                    rank[y]++;
            }

            return;
        }

        int num_cls(int n) {
            int ans = 0;
            for(int i = 1;i <= n;i++) {
                if(i == root(i))
                    ans++;
            }

            return ans;
        }
};

int main(void) {
    int n,m;
    cin>>n>>m;

    UnionFind uf(n);

    for(int i = 0;i < m;i++) {
        int x,y,z;
        cin>>x>>y>>z;
        uf.merge(x,y);
    }

    cout<<uf.num_cls(n)<<endl;

    return 0;
}



Measured memory_bytes: 1152
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int L=sc.nextInt();

		int min = 200005;
		int sum = 0;
		int sign = 1;
		for(int i=1; i<=N; i++) {
			if(Math.abs(L+i-1)<min) {
				min = Math.abs(L+i-1);
				sign = L+i-1<0 ? -1 : 1;
			}
			sum += L+i-1;
		}
		System.out.println(sum-min*sign);
		sc.close();
	}
}


Measured memory_bytes: 35744
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
int r,g,b,k;

int main(){
  cin>>r>>g>>b>>k;
  int count=0;
  while(g<=r){
    g*=2;
    count++;
  }
  while(b<=g){
    b*=2;
    count++;
  }
  cout<<(count<=k?"Yes":"No");
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  auto it = max_element(a.begin(), a.end());
  int a_max = *it;
  *it = a_max + 1;
  vector<double> a_double(a.begin(), a.end());
  for (auto& x : a_double) {
    x = abs(x - a_max / 2);
  }
  int index = distance(a_double.begin(), min_element(a_double.begin(), a_double.end()));
  cout << a_max << " " << a[index] << endl;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	Scanner input = new Scanner(System.in);
    	while(input.hasNextDouble()){
    		double x = input.nextDouble();
    		double t = x/9.8;
    		int num = (int)(Math.ceil((4.9*Math.pow(t, 2)+5)/5));
    		System.out.println(num);
    	}
    }
}

Measured memory_bytes: 18696
# coding:utf-8

import sys
from collections import deque, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, c, k = LI()
    T = deque(sorted([II() for _ in range(n)]))

    p = T.popleft()
    t = p + k
    res = 0
    while T:
        cnt = 1
        while T and cnt < c and T[0] <= t:
            cnt += 1
            T.popleft()
        res += 1
        p = 0
        if T:
            p = T.popleft()
            t = p + k

    if p:
        res += 1

    return res


print(main())


Measured memory_bytes: 8512
#include<iostream>
#include<cstdio>
using namespace std;
long long n,sum,a[13];
long long dfs(long long x,long long sum,long long sum1)
{
	if(x==1)
		return 2*sum+sum1+a[x]+sum1*10+a[x];
		
	return dfs(x-1,sum,sum1*10+a[x])+dfs(x-1,sum+sum1,a[x]);
}
int main()
{
	cin>>n;
	while(n!=0)
		sum++,a[sum]=n%10,n/=10;
	cout<<dfs(sum,0,0)/2;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Say(a) cout <<(a);
#define Sal(a) cout <<(a)<<endl;

const ll MOD = 1e9+7;
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    int can=1,zencnt=0;
    string S,T;
    cin >>S;

    FOR(i,0,S.size()-1){
        if(S[i]!='x') T.pb(S[i]);
    }
    
    if(T.size()>=2) {
        FOR(i,0,(T.size()/2)-1){
            if(T[i]!=T[T.size()-i-1]) {
                can=0;
                break;
            }
        }
    }
    if(T.size()==0) {
        Sal(0);
        can=2;
    }
    if(can==0) Sal(-1);
    if(can==1) {
        vvi Sx(2,vi((T.size()+1)/2,0));
        int xcnt=0;
        int ind=0;
        int rind=0;
        FOR(i,0,((T.size()+1)/2)-1){
            while(1){
                if(S[ind]==T[i]) {
                    Sx[0][i]=xcnt;
                    xcnt=0;
                    ind++;
                    break;
                }
                if(S[ind]!=T[i]) {
                    xcnt++;
                    ind++;
                }
            }
            while(1){
                if(S[S.size()-rind-1]==T[i]) {
                    Sx[1][i]=xcnt;
                    xcnt=0;
                    rind++;
                    break;
                }
                if(S[S.size()-rind-1]!=T[i]) {
                    xcnt++;
                    rind++;
                }
            }
            zencnt+=abs(Sx[0][i]-Sx[1][i]);
        }
        Sal(zencnt);
    }

    return 0;
}

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

typedef long long ll;

ll modnum=7+1000000000;

ll modpow(ll a, ll n, ll mod){
    if(n==0) return 1;
    if(n%2==0){
        return modpow(a*a%mod, n/2, mod);
    }else{
        return a*modpow(a, n-1, mod)%mod;
    }
}

int main(void){
    ll X, Y;
    ll a, b;
    ll ans=0;
    ll XpY=1;
    ll Xa=1;
    ll Ya=1;
    ll Xinv;
    ll Yinv;
    

    scanf("%lld %lld", &X, &Y);

    if((2*X-Y)%3!=0 || (2*Y-X)%3!=0 || (2*X-Y)<0 || (2*Y-X)<0){
        printf("0");
        return 0;
    }
    a=(2*X-Y)/3;
    b=(2*Y-X)/3;


    ll i;
    for(i=1; i <= a; i++){
        Xa=(Xa*i)%modnum;
    }
    for(i=1; i <= b; i++){
        Ya=(Ya*i)%modnum;
    }
    for(i=1; i <= a+b; i++){
        XpY=(XpY*i)%modnum;
    }
    
    Xinv=modpow(Xa, modnum-2, modnum);
    Yinv=modpow(Ya, modnum-2, modnum);

    ans = (XpY*Xinv)%modnum;
    ans = (ans*Yinv)%modnum;

    printf("%lld", ans%modnum);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    string S;
    cin >> S;

    if((find(S.begin(), S.end(), 'A')!=S.end()) && (find(S.begin(), S.end(), 'B')!=S.end())){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import math
n, d = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(n)]
def dist(x, y):
    return math.sqrt(x**2 + y**2)


count = 0
for i in range(n):
    dis = dist(data[i][0], data[i][1])
    if dis <= d:
        count += 1

print(count)


Measured memory_bytes: 45332
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable {
	public static void main(String[] args) throws FileNotFoundException {
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).run();
	}

	int N, M;
	int[] A, B;
	int[] col;
	int[][] cnt;
	ArrayList<Integer>[] g;

	public void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		A = new int[M];
		B = new int[M];
		col = new int[N];
		g = new ArrayList[N];
		boolean[][] connect = new boolean[N][N];
		cnt = new int[N][2];
		for (int i = 0; i < N; ++i)
			g[i] = new ArrayList<>();
		Arrays.fill(col, -1);
		for (int i = 0; i < M; ++i) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			--A[i];
			--B[i];
			connect[A[i]][B[i]] = true;
			connect[B[i]][A[i]] = true;
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i != j && !connect[i][j]) {
					g[i].add(j);
				}
			}
		}
		for (int i = 0; i < N; ++i) {
			if (col[i] == -1) {
				col[i] = 0;
				dfs(i, -1);
				++p;
			}
		}

		boolean[][] ok = new boolean[1000][1000];
		ok[0][0] = true;
		for (int i = 0; i + 1 <= N; ++i) {
			for (int j = 0; j < 1000; ++j) {
				if (ok[i][j]) {
					if (ok[i + 1].length > j + cnt[i][0])
						ok[i + 1][j + cnt[i][0]] = ok[i][j];
					if (ok[i + 1].length > j + cnt[i][1])
						ok[i + 1][j + cnt[i][1]] = ok[i][j];
				}
			}
		}

		long ans = Long.MAX_VALUE / 3;
		for (int i = 0; i < ok[p].length; ++i) {
			if (ok[p][i]) {
				ans = Math.min(ans, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
			}
		}
		System.out.println(ans);
	}

	int p = 0;

	void dfs(int cur, int par) {
		cnt[p][col[cur]]++;
		for (int dst : g[cur]) {
			if (dst == par)
				continue;
			if (col[dst] == -1) {
				col[dst] = col[cur] ^ 1;
				dfs(dst, cur);
			} else {
				if (col[dst] != (col[cur] ^ 1)) {
					System.out.println(-1);
					System.exit(0);
				}
			}
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 151772
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int x, y, a, b, c;
int p[N], q[N], r[N];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        cin >> x >> y >> a >> b >> c;
        for(int i = 0; i < a; i++){
            cin >> p[i];
        }
        for(int i = 0; i < b; i++){
            cin >> q[i];
        }
        for(int i = 0; i < c; i++){
            cin >> r[i];
        }
        sort(p, p + a, greater<int>());
        sort(q, q + b, greater<int>());
        sort(r, r + c);
        multiset<int> ans;
        for(int i = 0; i < x; i++){
            ans.insert(p[i]);
        }
        for(int i = 0; i < y; i++){
            ans.insert(q[i]);
        }
        int pos = c - 1;
        while(pos >= 0 and *ans.begin() < r[pos]){
            ans.erase(ans.begin());
            ans.insert(r[pos]);
            pos--;
        }
        int sum = 0;
        for(int i : ans){
            sum += i;
        }
        cout << sum << '\n';
    }
}

Measured memory_bytes: 49792
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<bitset>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>
#include<bitset>


using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))

const ll MOD = 1e+9+7;
const double PI  = acos(-1.0);


int main(){
  int h,w,k;
  cin>>h>>w>>k;
  vi bar;
  REP(i,1<<w-1){
    bool flag=true;
    REP(j,w-1){
      if(((i&(1<<j))>0)&((i&(1<<(j+1)))>0)){
        flag=false;
      }
    }
    if(flag) bar.push_back(i);
  }
  ll dp[h+1][w];
  CLR(dp);
  dp[0][0]=1;
  REP(i,h){
    REP(j,w){
      ll base=dp[i][j];
      for(int b:bar){
          if((j-1>=0)&((b&(1<<(j-1)))>0)){
            dp[i+1][j-1]=(dp[i+1][j-1]+base)%MOD;
          }else if((j<w-1)&((b&(1<<j))>0)){
            dp[i+1][j+1]=(dp[i+1][j+1]+base)%MOD;
          }else{
            dp[i+1][j]=(dp[i+1][j]+base)%MOD;
          }
        }
    }
  }
  cout<<dp[h][k-1]<<"\n";
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B_lst = list(map(int, input().split()))
ans = 0

for i in range(N):
    ttl = C
    A_lst = list(map(int, input().split()))
    for j in range(M):
        ttl += A_lst[j] * B_lst[j]
    if ttl > 0:
        ans += 1

print(ans)

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

int main()
{
	int a;
	cin >> a;

	vector< uint64_t > vec( a );

	for( auto &it : vec )
	{
		cin >> it;
	}

	int cnt = 0;

	while(1)
	{
		bool end = false;

		for( auto &it : vec )
		{
			if( it & 1 )
			{
				end = true;
				break;
			}

			it /= 2;
		}

		if( end ) break;

		cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  
  long Input,j,sum;
  
  scanf("%ld",&Input);
  
  for(sum=0,j=1;j<=Input;j++){
    if(j%3!=0){
      if(j%5!=0){
        sum+=j;
      }
    }
  }
  printf("%ld",sum);
  
  return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;  
  }else if(a+b<c+d){
    cout<<"Right"<<endl;
  }else{
    cout<<"Balanced"<<endl;
  }
}

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

using namespace std;

int main(void)
{
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;

    if(A1 + A2 + A3 >= 22){
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int h,n;
vector<pair<int,int>>v;
int cache[1001][10001];
int dp(int pos,int hl)
{
    if(hl<=0)
        return 0;
    if(pos==n)
        return 1e18;
    int &ans=cache[pos][hl];
    if(ans!=-1)
        return ans;
    ans=dp(pos+1,hl);
    ans=min(ans,v[pos].second+dp(pos,hl-v[pos].first));
    return ans;
}
int32_t main() 
{
    IOS
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    memset(cache,-1,sizeof(cache));
    print(dp(0,h));
}   


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

#ifdef LOCAL
  #include <contest/local.hpp>
#else
  #define LOG(...) do {} while (false)
#endif

using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int a;
  cin >> a;
  cout << 3 * (a * a) << endl;
}



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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll price[3];
  rep(i, 3) cin >> price[i];
  sort(price, price + 3);
  ll result = price[0] + price[1];
  cout << result << endl;
}

Measured memory_bytes: 256
import sys
#import numpy as np
import math
import itertools
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
n,m=map(int,input().split())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(m))

node=[[] for _ in range(n)]
for pair in v:
    node[pair[0]].append(pair[1])
    node[pair[1]].append(pair[0])
c=0
p=list(itertools.permutations(list(range(1,n))))
for res in p:
    for i in range(n-1):
        if i==0:
          if res[0] in node[0]:
            continue
          else:
            break
        if res[i] in node[res[i-1]]:
            continue
        else:
            break
    else:
        c+=1
print(c)

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

int main(){
    int N, M; cin >> N >> M;
    priority_queue<ll> pq;
    for(int i = 0; i < N; i++){
        ll A; cin >> A;
        pq.push(A);
    }

    for(int i = 0; i < M; i++){
        ll price = pq.top() / 2;
        pq.pop();
        pq.push(price);
    }
    ll sum = 0;
    for(int i = 0; i < N; i++){
        sum += pq.top();
        pq.pop();
    }

    cout << sum << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define ll long long int
#define ve vector<int>
#define vl vector<long long int>
#define vs vector<string>
#define vve vector<vector<int>>
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  char f=s.at(0),l=s.at(n-1);
  cout<<f<<n-2<<l<<endl;
}

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

int cost[8][8] = 
{
{},
{0,0,300,500,600,700,1350,1650},
{0,6,0,350,450,600,1150,1500},
{0,13,7,0,250,400,1000,1350},
{0,18,12,5,0,250,850,1300},
{0,23,17,10,5,0,600,1150},
{0,43,37,30,25,20,0,500},
{0,58,52,45,40,35,15,0}
};

int l,lh,lm,a,ah,am;

int main(){
	while(true){
		cin >> l;
		if(!l)
			return 0;
		cin >> lh >> lm;
		lm+=lh*100;
		cin >> a;
		cin >> ah >> am;
		am+=ah*100;
		if(cost[max(l,a)][min(l,a)] > 40)
			cout << cost[min(l,a)][max(l,a)] << endl;
		else if((lm>=1730&&lm<=1930)||(am>=1730&&am<=1930)){
			bool flag = false;
			if((cost[min(l,a)][max(l,a)]/2)%50)
				flag = true;
			int ans = cost[min(l,a)][max(l,a)]/2-((cost[min(l,a)][max(l,a)]/2)%50);
			if(flag)
				ans+=50;
			cout << ans << endl;
		}else
			cout << cost[min(l,a)][max(l,a)] << endl;
	}
}

Measured memory_bytes: 0
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    S_ = S()
    if S_ == 'AAA' or S_ == 'BBB':
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    main()


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

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  string s; cin >> s;
  int ans=0;
  for(int i=0;i<(int)s.size()/2;i++){
    if(s[i] != s[s.size()-i-1]) ans++;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]
    As = sorted(As)

    turn = 0
    A = 0
    B = 0
    while As:
        if turn % 2 == 0:
            A += As.pop()
        else:
            B += As.pop()

        turn += 1
    print(A-B)




if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9128
class Dice
  def initialize(faces)
    @top = faces.shift
    @front = faces.shift
    @right = faces.shift
    @left = faces.shift
    @back = faces.shift
    @bottom = faces.shift
  end

  def turn_to_n
    old_top = @top
    @top = @front
    @front = @bottom
    @bottom = @back
    @back = old_top
  end

  def turn_to_e
    old_top = @top
    @top = @left
    @left = @bottom
    @bottom = @right
    @right = old_top
  end

  def turn_to_w
    old_top = @top
    @top = @right
    @right = @bottom
    @bottom = @left
    @left = old_top
  end

  def turn_to_s
    old_top = @top
    @top = @back
    @back = @bottom
    @bottom = @front
    @front = old_top
  end

  attr_reader :top
end

faces = gets.split(" ").map(&:to_i)
turns = gets.chomp.split("")

dice = Dice.new(faces)
turns.each {|t|
  case t
    when "N" then dice.turn_to_n
    when "E" then dice.turn_to_e
    when "W" then dice.turn_to_w
    when "S" then dice.turn_to_s
  end
}
puts dice.top

Measured memory_bytes: 8652
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string imp="Impossible\n";

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
// const int N=11;
const int N=5e6+5;
ll MOD=1e9+7;
ll n,m,k,i,j;
bool f0,f1,f2;
const int MAXN=2e3;

int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
	cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    while(tests--){
		int n;	cin>>n;
		int f[n+1];
		mem(f,0);
		for(int i=1;i<=100;i++){
			for(int j=1;j<=100;j++){
				for(int k=1;k<=100;k++){
					int v=i*i+j*j+k*k+i*j+j*k+k*i;
					if(v<=n){
						f[v]++;
					}
				}
			}
		}
		for(int i=1;i<=n;i++){
			cout<<f[i]<<"\n";
		}
    }
    return 0;
}



 



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

using namespace std;

#define int long long

main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
		
	int nr = 0;
	int p = 0;
	
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'A')
			p++;
		else
		{
			if(i + 1 < s.size() && s[i] == 'B' && s[i + 1] == 'C')
			{
				nr += p;
				i++;
			}
			else
				p = 0;
		}
    }
	
	cout << nr;
}


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

using namespace std;

int main() {
    string s;
    int m, h, len;
    cin >> s;
    while (s != "-") {
        len = s.length();
        cin >> m;
        for (int i = 0; i < m; ++i) {
            cin >> h;
            s = s.substr(h, len - h) + s.substr(0, h);
        }
        cout << s << endl;
        cin >> s;
    }
    return 0;
}


Measured memory_bytes: 3212
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def main():
    k = int(input())
    a = 7
    x = 1
    while a % k != 0 and x <= k + 10:
        x += 1
        a = (a * 10 + 7) % k
    if x < k + 5:
        print(x)
    else:
        print(-1)
main()


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

ans=False
for p in range(0,k):
    for q in range(0,k-p+1):
        for r in range(0,k-p-q+1):
            if a*(2**p) < b*(2**q) and b*(2**q) < c*(2**r):
                ans= True
                break
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n,A,B,C;
vector<int> l;

void input(){
    cin >> n >> A >> B >> C;
    l.resize(n);
    for(int i=0;i<n;i++) cin >> l[i];
}

int dfs(int cur, int a, int b, int c){
    if(cur == n){
        int tmp = min(a, b);
        tmp = min(tmp, c);
        if(tmp > 0) return abs(a-A) + abs(b-B) + abs(c-C) - 30;
        else return INF;
    }

    int rec0, rec1, rec2, rec3;
    rec0 = dfs(cur+1, a + l[cur], b, c) + 10;
    rec1 = dfs(cur+1, a, b + l[cur], c) + 10;
    rec2 = dfs(cur+1, a, b, c + l[cur]) + 10;
    rec3 = dfs(cur+1, a, b, c);
    chmin(rec0, rec1);
    chmin(rec0, rec2);
    chmin(rec0, rec3);
    return rec0;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, x;
    cin>>n;

    vector<int> a;

    rep(i,n)
    {
        cin>>x;
        a.push_back(x);
    }
    
    stable_sort(a.begin(), a.end());

    int ans;

    ans = a.at(n-1) - a.at(0);

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string s;
char ansOp[3];
int num[4];

void check(int n, bool tmpOp[3]) {
    if (n == 3) {
        int tmp = num[0];
        rep(i, 3) {
            if (tmpOp[i])
                tmp += num[i + 1];
            else
                tmp -= num[i + 1];
        }
        if (tmp == 7) {
            rep(i, 3) {
                if (tmpOp[i])
                    ansOp[i] = '+';
                else
                    ansOp[i] = '-';
            }
        }
    } else {
        tmpOp[n] = true;
        check(n + 1, tmpOp);
        tmpOp[n] = false;
        check(n + 1, tmpOp);
    }
}

int main() {
    bool tmpOp[3];
    cin >> s;
    rep(i, 4) num[i] = s[i] - '0';
    check(0, tmpOp);
    rep(i, 3) cout << s[i] << ansOp[i];
    cout << s[3] << "=7" << endl;
}

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

int main(){
    int h,w,k;
    bool isempty[330];
    char s[330][330];
    int a[330][330];
    cin>>h>>w>>k;
    rep(i,h) cin >> s[i];
    rep(i,h){
        isempty[i] = true;
        rep(j,w) if(s[i][j]=='#') isempty[i] = false;
    }
    int cnt = 0;
    rep(i,h){
        if(isempty[i]) continue;
        rep(j,w){
            if(s[i][j]=='#') a[i][j] = ++cnt;
        }
        rep(j,w){
            if(a[i][j]==0 && (j>0 && a[i][j-1]!=0)) a[i][j] = a[i][j-1];
        }
        for(int j=w-2; j>=0; j--){
            if(a[i][j]==0 && a[i][j+1]!=0) a[i][j] = a[i][j+1];
        }
    }
    for(int i=1;i<h;i++){
        if(isempty[i] && !isempty[i-1]){
            isempty[i] = false;
            rep(j,w) a[i][j]=a[i-1][j];
        }
    }
    for(int i=h-2;i>=0;i--){
        if(isempty[i] && !isempty[i+1]){
            isempty[i] = false;
            rep(j,w) a[i][j]=a[i+1][j];
        }
    }
    rep(i,h){
        rep(j,w){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
//#include<bits/stdc++.h>
#include<tuple>
#include<queue>
#include<map>
#include<algorithm>
//#include <bits/stdc++.h>


#define rep(i,n) for(ll i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	COMinit();
	ll s;
	cin >> s;
	
	
	ll mod = 1e9+7;
	ll ans = 0;
	for (ll i = 1; i <= s/3; i++) {
		ll S = s - i * 3;
		//cout <<i<<"  :"<< COM(S + i-1, i-1) << endl;
		ans += COM(S + i-1, i-1);
		ans += mod;
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 15120
#include <iostream>
#include <stdlib.h>
using namespace std;

int f[8],n[8],v[8];
int d[24][6],da[6][6]={{1,2,3,5,4,6},{2,3,1,4,6,5},{3,2,6,5,1,4},{4,2,1,5,6,3},{5,4,1,3,6,2},{6,5,3,2,4,1}};
char pd[8][7];

int check(int k) {
	int i,j,s;
	for (i=1;i<8;i++) {
		if (f[i]==1) continue;
		f[i]=1; n[k]=i; 
		for (j=0;j<24;j++) {
			v[k]=j; s=0;
			switch(k) {
				case 1: if (abs(pd[0][d[v[0]][3]]-pd[i][d[j][1]]) == 32) s=check(2); break;
				case 2: if (abs(pd[0][d[v[0]][2]]-pd[i][d[j][4]]) == 32) s=check(3); break;
				case 3: if (abs(pd[0][d[v[0]][0]]-pd[i][d[j][5]]) == 32) s=check(4); break;
				case 4: if (abs(pd[n[1]][d[v[1]][2]]-pd[i][d[j][4]]) == 32 && abs(pd[n[2]][d[v[2]][3]]-pd[i][d[j][1]]) == 32) s=check(5); break;
				case 5: if (abs(pd[n[3]][d[v[3]][3]]-pd[i][d[j][1]]) == 32 && abs(pd[n[1]][d[v[1]][0]]-pd[i][d[j][5]]) == 32) s=check(6); break;
				case 6: if (abs(pd[n[3]][d[v[3]][2]]-pd[i][d[j][4]]) == 32 && abs(pd[n[2]][d[v[2]][0]]-pd[i][d[j][5]]) == 32) s=check(7); break;
				case 7: if (abs(pd[n[6]][d[v[6]][3]]-pd[i][d[j][1]]) == 32 &&
				             abs(pd[n[5]][d[v[5]][2]]-pd[i][d[j][4]]) == 32 &&
				             abs(pd[n[4]][d[v[4]][0]]-pd[i][d[j][5]]) == 32 ) s=1;
				            break;
						}
						if (s==1) return 1;
			}
			f[i]=0;
		}
	return 0;
}

int main() {
	int i,j,k,m;
	for (i=0;i<6;i++) {
		for (j=0;j<4;j++) {
		 for (k=0;k<6;k++) d[i*4+j][k]=da[i][k]-1;
		 m=da[i][1]; 
		 for (k=1;k<4;k++) da[i][k]=da[i][k+1];
		 da[i][4]=m;
	 }
 }	
 
	while(cin >> pd[0]) {
		if (pd[0][0]=='0') break;
		for (i=1;i<8;i++) { cin >> pd[i]; f[i]=0;}
		for (i=0;i<24;i++) { v[0]=i; if (check(1)==1) break; }
		if (i==24) cout << "NO" << endl; else cout << "YES" << endl;
	}	
	return 0;
}

Measured memory_bytes: 1136
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import Data.Ord
import Data.Time
import qualified Data.Vector as VC
import qualified Data.Vector.Mutable as VM

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n = replicateM n (map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine)

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n = replicateM n (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n (map BS.unpack . BS.words <$> BS.getLine)

main :: IO ()
main = do
  [h, n] <- readInts
  a <- readInts
  putStrLn $ solve h a

solve h n
  | h <= foldl1' (+) n = "Yes"
  | otherwise = "No"

Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(a<b)return gcd(b,a);
  else if(a%b)return gcd(b,a%b);
  else return b;
}
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0; i<n; i++){
    cin>>a[i];
  }
  int x=a[0];
  for(int i=0; i<n; i++){
    x=gcd(x,a[i]);
  }
  cout<<x<<endl;

}


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

typedef vector <long long> vi;
typedef vector <vi> vvi;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ll long long
#define mod (ll)(1e9 + 7)

int main(void)
{
    ll x, y;
    cin >> x >> y;
    ll dp[x][y];
    memset(dp, -1, sizeof(dp));

    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            char c;
            cin >> c;
            if (c == '#')
                dp[i][j] = 0;
        }
    }

    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            if (dp[i][j] == -1)
            {
                if (i == 0 && j == 0)
                    dp[i][j] = 1;
                else if (i == 0)
                    dp[i][j] = dp[i][j - 1];
                else if (j == 0)
                    dp[i][j] = dp[i - 1][j];
                else
                    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            }
        }
    }

    cout << dp[x - 1][y - 1] << "\n";
}


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

long N, M;
priority_queue<long> PQ;

int main() {
  scanf("%ld%ld", &N, &M);
  long x;
  for (int i = 0; i < N; i++) {
    scanf("%ld", &x);
    PQ.push(x);
  }

  long tmp;
  for (int i = 0; i < M; i++) {
    tmp = PQ.top(); PQ.pop();
    PQ.push(floor(tmp / 2));
  }

  long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += PQ.top(); PQ.pop();
  }
  
  printf("%ld\n", ans);
  return 0;
}

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

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>> A;

	for(int i = 0; i < N; ++i){
		int a;
		cin >> a;
		A.push_back(make_pair(a, i + 1));
	}

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

	for(int i = 0; i < N; ++i){
		cout << A[i].second << " ";
	}

	cout << endl;
	return 0;
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
ll a[222222],n,q,from,to,cnt[111111],ans;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        cnt[a[i]]++;
        ans+=a[i];
    }
    cin>>q;
    while(q--){
        cin>>from>>to;
        if(cnt[from]){
            ans -= cnt[from] * from;
            ans += to * cnt[from];
            cnt[to] += cnt[from];
            cnt[from] = 0;
        }
        cout<<ans<<'\n';
    }
}


Measured memory_bytes: 5172
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define size sz
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN=200005;

int n,len;
int color[MAXN],head[MAXN],size[MAXN],num[MAXN];
ll ans[MAXN];

struct node{
	int to,next;
} e[MAXN * 2];

void add(int u,int v){
	e[++len].to = v;
	e[len].next = head[u];
	head[u] = len;
}

ll f(ll n){
	return 1ll * n * (n + 1) / 2;
}

void dfs(int u,int fa){	
	int c = color[u];
	int lst,d;
	size[u] = 1;
	ll tmp = num[c];
	for(int i = head[u];i != -1;i = e[i].next){
		int v = e[i].to;
		if(v == fa)
			continue;
		lst = num[c];
		dfs(v,u);
		d = num[c] - lst;
		ans[c] -= f(size[v] - d);
		size[u] += size[v];
	}
	num[c] = tmp + size[u];
}

int main(){
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&color[i]);
		ans[i] = f(n);
	}
	for(int i = 1;i < n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs(1,0);
	for(int i = 1;i <= n;i++){
		ans[i] -= f(n - num[i]);
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 26996
#include<iostream>
#include<cmath>
#include<cctype>
#include<vector>
#include<numeric>
using namespace std;
int main(){
        while(1){
                int n;
                scanf("%d",&n);
                if(n==0) break;
                vector<double>s(n);
                for(auto&e:s){
                        scanf("%lf",&e);
                }
                double av=accumulate(s.begin(),s.end(),0.0)/n;
                double h=0;
                for(int i=0;i<n;i++){
                        h+=(s[i]-av)*(s[i]-av);
                }
                printf("%lf\n",sqrt(h/n));

        }
        return 0;
}

Measured memory_bytes: 1240
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		var uf = new UnionFind(N);
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			int a1 = int.Parse(str2[0])-1;
			int a2 = int.Parse(str2[1])-1;
			uf.Unite(a1,a2);
		}
		int[]D = new int[N];
		for(var i=0;i<N;i++){
			D[uf.Root(i)]++;
		}
		int ans = -1;
		for(var i=0;i<N;i++){
			if(D[i]>0){
				ans++;
			}
		}
		Console.WriteLine(ans);
	}
}

public class UnionFind
{
    private int[] data;
	public UnionFind(int size){
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y){
        x = Root(x);
        y = Root(y);
        if (x != y){
            if (data[y] < data[x]){
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
	public bool IsSameGroup(int x, int y){
        return Root(x) == Root(y);
    }
    public int Root(int x){
        return data[x] < 0 ? x : data[x] = Root(data[x]);
    }
}

Measured memory_bytes: 22172
#include<bits/stdc++.h>
 
#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
 
using namespace std;
 
typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;
 
const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;
 
template <typename T> inline void scf(T &x) {
	bool f = 0;
	x = 0;
	char c = getchar();
	while(c != '-' && (c < '0' || c > '9')) c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	if(f) x = -x;
	return;
}
 
template <typename T1, typename T2> void scf(T1 &x, T2 &y) {
	scf(x);
	return scf(y);
}
 
template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z) {
	scf(x);
	scf(y);
	return scf(z);
}
 
template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
	scf(x);
	scf(y);
	scf(z);
	return scf(w);
}
 
inline char mygetchar() {
	char c = getchar();
	while(c == ' ' || c == '\n') c = getchar();
	return c;
}
 
template <typename T> inline bool chkmax(T &x, const T &y) {
	return y > x ? x = y, 1 : 0;
}
 
template <typename T> inline bool chkmin(T &x, const T &y) {
	return y < x ? x = y, 1 : 0;
}
 
#ifdef King_George
#define DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
 
//---------------------------------------------------------head----------------------------------------------------
 
const int maxn = 1e5 + 10;
 
int n;
vi g[maxn];
unsigned int dp[maxn];
 
void dfs(int u = 1, int par = 0) {
	unsigned int s1 = 0, s2 = 0, &s = dp[u];
	for (int v: g[u]) {
		if(v != par) {
			dfs(v, u);
			s2 |= (dp[v] & s1);
			s1 |= dp[v];
		}
	}
	s = 1;
	while(s <= s2) {
		s <<= 1;
	}
	while(s & s1) {
		s <<= 1;
	}
	s = ((s > 1) ? (s1 & ~(s - 1)) : s1) | s;
	return;
}
 
int main() {
	scf(n);
	rep (i, n - 1) {
		int u, v;
		scf(u, v);
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs();
	unsigned int s = 1;
	int ans = -1;
	while(s <= dp[1]) {
		s <<= 1;
		++ans;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11776
N=int(input())
keta=len(str(N))
keta2=len(str(N+1))
alpha=int(str(N)[0])-1
beta=int(str(N+1)[0])-1
a=(keta-1)*9
if keta==1:
    print(N)
elif alpha==beta:
    print(a+alpha)
elif keta==keta2:
    print(a+beta)
else:
    print(keta*9)

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

const ll mod = 1e9+7;

int main(){
  ll n,l;
  cin >> n >> l;
  vector<ll> x(n),a(n);
  rep(i,n)cin >> x[i];
  rep(i,n)cin >> a[i];

  vector<ll> cur(l+1,0);
  cur[l] = 1;

  rrep(i,n){
    vector<ll> nxt(l+1,0);
    ll sum = cur[l];
    rrep(j,l){
      if(j<x[i])break;
      if( a[i]>0 && (j-x[i])%a[i] == 0 )(nxt[j] += sum) %= mod;
      else if(a[i]==0 && j==x[i])(nxt[j] += sum) %= mod;
      (sum += cur[j]) %= mod;
    }
    cur = nxt;
  }

  ll res = 0;
  rep(i,l)(res += cur[i]) %= mod;
  cout << res << endl;
}

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

int main()
{
    /*
    string s;
    cin>>s;
    string t;
    cin>>t;
    bool flag = true;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        {
            flag = false;
        }
    }

    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    */

    ll a,b,c;
    ll k;
    cin>>a>>b>>c>>k;
   
    if(k>a+b)
    {
        cout<<a-(k-(a+b))<<endl;
    }
    else if(k<a)
    {
        cout<<k<<endl;
    }
    else
    {
        cout<<a<<endl;
    }

    return 0;
}

Measured memory_bytes: 3636
Scanf.scanf "%d" (fun n ->
    let z = 1_000_000_007 in
    let ( +@) a b = (a + b) mod z in

    let dp = Array.make 2001 (-1) in
    dp.(0) <- 0;
    dp.(1) <- 0;
    dp.(2) <- 0;
    
    let rec calc q =
        if dp.(q) >= 0 then dp.(q) else (
            let rec loop i acc =
                if i > q then acc else
                    loop (i + 1) (acc +@ calc (q - i))
            in
            let r = loop 3 1 in
            dp.(q) <- r;
            r
        )
    in
    calc n |> Printf.printf "%d\n"
)

Measured memory_bytes: 3928
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 
 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
 
#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl
 
const int INF = 1e9+7;
const ll INFL = 9*1e18;
 
// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };
 
const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};
 
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}
 
// TODO: write
int main() {
  int n,k;cin>>n>>k;
  vector<int> a(n);rep(i,n)cin>>a[i];
  sort(all(a));
 
  int all = 0;
  rep(i,k)all += a[i];
  print(all);
  return 0;
}

Measured memory_bytes: 3600