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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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 ll mod = 998244353;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

ll modpow(ll a, ll n){
  ll ans = 1;
  while(n > 0){
    if(n & 1) ans = ans * a % mod;
    n >>= 1;
    a = a * a % mod;
  }
  return ans;
}

const ll MAX = 1234567;
vll fac(MAX), finv(MAX), inv(MAX);
void cominit() {
    fac.at(0) = fac.at(1) = 1;
    finv.at(0) = finv.at(1) = 1;
    inv.at(1) = 1;
    for (int i = 2; i < MAX; i++){
        fac.at(i) = fac.at(i - 1) * i % mod;
        inv.at(i) = mod - inv.at(mod % i) * (mod / i) % mod;
        finv.at(i) = finv.at(i - 1) * inv.at(i) % mod;
    }
}
ll com(ll n, ll k){
  if(n < k || n < 0 || k < 0) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n - k) % mod) % mod;
}

int main(){
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  cominit();
  rep(i, 0, k + 1){
    ans = (ans + com(n - 1, i) * modpow(m - 1, n - 1 - i) % mod * m % mod) % mod; 
  }
  cout << ans << endl;
}

Measured memory_bytes: 32152
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	//ll a[200] = {};
	//ll b[200] = {};
	//ll v[3] = {};
	//ll *a, *b, *x;
	string S,T,U[52];
	ll count = 0;
	ll count2 = 0;
	ll sum = 0;
	//ll min = 100000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	
	//char p;


	

	

	//cin >> S;
	
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	
	cin >> A >> B;
	//a = (ll *)malloc(A * sizeof(ll));
	vector<ll> a(A);
	rep(i,0,A){
		cin >> a[i];
	}


	sort(a.begin(),a.end());
	
	rep(i, A-B, A) {
		sum += a[i];
	}

	cout << sum << endl;
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	

	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	return 0;

}

ll gcd(ll a, ll b) {
	ll x = a * b;

	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return x/b;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string S;
    cin >> S;
    S.erase(S.begin()+7);
    S.erase(S.begin()+4);
    cout << ((stoi(S) <= 20190430) ? "Heisei" : "TBD") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int a,b,c,d,e,f,n=0;
    int T,N,S,E,W,B;
    char A;
    cin >> a >> b >>c >> d >> e >>f;
    while(n<=100){
        T=a;S=b;E=c;W=d;N=e;B=f;
  //   printf("%d\n",T);
        cin >> A;
        if(A=='N'){
          // p=a;a=e;e=f;f=b;b=p;
            f=N;e=T;a=S;b=B;A=0;
        }else if(A=='S'){
         // p=f;f=e;e=a;a=b;b=p;
            a=N;e=B;f=S;b=T;A=0;
        }else if(A=='E'){
          //  p=d;d=a;a=c;c=f;f=p;
            c=T;a=W;d=B;f=E;A=0;
        }else if(A=='W'){
          //  p=c;c=a;a=d;d=f;f=p;
            d=T;a=E;c=B;f=W;A=0;
        }
        n=n+1;
//printf("%d",a);
  //      printf(" %d\n",T);
  
    }
    printf("%d\n",T);
}



Measured memory_bytes: 3228
#include<stdio.h>
#define N 100000
#define node0 -1
int depth(int);
int degree(int);
 typedef struct {
  int  parent;
  int  right;
  int  left;
}tree_node;
  
tree_node tree[N];
 
int main(){
  int i,j,n;
  int id,deg,child,keep;
  scanf("%d", &n);
  for(i=0;i<n;i++){
      tree[i].parent=node0;
      tree[i].left=node0;
      tree[i].right=node0;
    }
   for(i=0; i<n; i++){
     scanf("%d",&id);
     scanf("%d",&deg);
    for(j=0;j<deg;j++){
      scanf("%d",&child);
      tree[child].parent=id;
      if(j==0){
        tree[id].left=child;
      }
      else{
        tree[keep].right=child;
      }
      keep=child;
         }
  }
    for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,tree[i].parent,depth(i));
    if(tree[i].parent==node0){
      printf("root, [");
    }
    else if(tree[i].left==node0){
      printf("leaf, [");
    }
    else{
      printf("internal node, [");
    }
    degree(tree[i].left);
    printf("]\n");
  }
  return 0;
}
  
int depth(int nodeNum){
 int count = 0;
 if(tree[nodeNum].parent==node0){
     return 0;
   }
 else {
   count=depth(tree[nodeNum].parent)+1;
   return count;
   }
}
  int degree(int treeNum){
  if(treeNum==node0){
    return 0;
  }
  else {
    if(tree[treeNum].right==node0){
   printf("%d",treeNum); 
   }
  else{
    printf("%d, ",treeNum);
    degree(tree[treeNum].right);
  }
}
}

Measured memory_bytes: 1784
#include<iostream>

using namespace std;

int main() {

    long long a;
    double b;
    scanf("%lld %lf", &a, &b);

    long long  b2, ans;
    b2 = (long long)(b*100+0.5);
    ans = a * b2 / 100;

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 3836
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int height[N];
    for (int i = 0; i < N; ++i) {
        cin >> height[i];
    }

    int tmp = 0;
    int ans = 1;
    bool flag = false;
    for (int j = 1; j < N; ++j) {
        for (int i = tmp; i < j; ++i) {
            if (height[j] < height[i]) {
                flag = false;
                break;
            }
            flag = true;
        }
        if (flag) {
            tmp = j;
            ans++;
        }
    }
    cout << ans;
}

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

int main() {
  while(1){
    int m,w,bm[12],bw[12];
    cin >> m >> w;
    if(m==0 && w==0) break;
    for(int i=0;i<m;i++) cin >> bm[i];
    for(int i=0;i<w;i++) cin >> bw[i];
    int dp[(1<<12)]={},ans=0;
    for(int i=0;i<m;i++)
      for(int S=(1<<w)-1;S>=0;S--)
	for(int k=0;k<w;k++){
	  if((S&(1<<k))!=0)continue;
	  int t = abs(bm[i]-bw[k])*(abs(bm[i]-bw[k])-30)*(abs(bm[i]-bw[k])-30);
	  dp[S+(1<<k)] = max(dp[S+(1<<k)],dp[S]+t); 
	  ans = max(ans,dp[S+(1<<k)]);
	}
    cout << ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1184
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    if S == N:
        return N + 1

    def f(b, n):
        if n < b:
            return n
        return f(b, n//b) + n % b

    for b in range(2, int(math.sqrt(N)) + 1):
        s = f(b, N)
        if s == S:
            return b

    cnd = []
    for p in range(1, int(math.sqrt(N))+1):
        b = (N - S) // p + 1
        if b < 2:
            continue
        s = f(b, N)
        if s == S:
            cnd.append(b)

    if cnd:
        return min(cnd)

    return -1


def main():
    N = read_int()
    S = read_int()

    print(slv(N, S))


if __name__ == '__main__':
    main()


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

typedef pair<int,int> PII;
typedef long long ll;

int main(){
	int n,a[200000];
	cin>>n;

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


	ll sum=0,ans=1e+18;
	for (int i = 0; i < n-1; ++i){
		sum+=a[i];
		ans=min(ans,abs(sum-(total-sum)));
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 1024
import functools
import operator
M = 10**9 + 7
n, k = map(int, input().split())
if k == 1:
    print(0)
    __import__('sys').exit(0)
a = list(map(int, input().split()))
a.sort(reverse=True)

def mul(a, b):
    return mod(a * b)

def powmod(a, n):
    if n == 0:
        return 1
    if n % 2:
        ans = a * powmod(a, n - 1)
    else:
        ans = powmod(a, n // 2) ** 2
    return mod(ans)

def mod(a):
    if a >= M:
        a %= M
    return a
deno = functools.reduce(mul, range(n, n - (k - 1), -1))
nume = functools.reduce(mul, range(1, k))

# max_sum = 0
# min_sum = 0
result = 0
for i, left in enumerate(range(n, k - 1, -1)):
    # print(deno // left * (left - (k - 1)))
    deno = mod(mod(deno * powmod(left, M - 2)) * (left - (k - 1)))
    # print(deno // nume)
    c = mod(deno * powmod(nume, M - 2))

    result += mod(c * a[i]) - mod(c * a[-(i + 1)])
    # max_sum += c * a[i]
    # min_sum += c * a[-(i + 1)]


# print((max_sum - min_sum) % M)
print(result % M)


Measured memory_bytes: 70312
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int main(void){
        int n, m;
        cin >> n >> m;
        vector<int> c(m);
        for(int i = 0; i < m; i++) cin >> c[i];

        // sort(c.begin(), c.end());
        
        vector<vector<int>> dp(m+1, vector<int>(n+1, INF));
        dp[0][0] = 0;
        for(int i = 0; i < m; i++){
            for(int j = 0; j <=n; j++){
                dp[i+1][j] = dp[i][j];
                if(j >= c[i]) dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-c[i]]+1);
                // printf("dp[%d][%d] = %d\n", i+1, j, dp[i+1][j]);
            }
        }

        int res = INF;
        for(int i = 0; i <= m; i++){
            res = min(res, dp[i][n]);
        }

        cout << res << '\n';

    return 0;
}


Measured memory_bytes: 7056
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define sl(x) scanf("%ld", &x)
#define ss(x) scanf("%s", x)
#define pl(x) printf("%ld\n", x)
#define ps(x) printf("%s\n", x)
 
#define INF 100000000000
#define MOD 1000000007
 
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
 
int main() {
	char S[100010];
	long i, j;
	long ans = 0;
	long state = 1;
	long len;
	
	ss(S);
	len = strlen(S);
	S[len] = S[len+1] = S[len+2] = S[len+3] = S[len+4] = 'z';
	S[len+5] = '\0';
	i = 0;
	while(i < len) {
		//printf("%ld: %ld (%c)->", state, i, S[i]);
		switch(state) {
		  case 1:
			if(S[i] == 'd' && S[i+1] == 'r' && S[i+2] == 'e' && S[i+3] == 'a' && S[i+4] == 'm') {
				state = 3;
				i += 5;
			} else if(S[i] == 'e' && S[i+1] == 'r') {
				state = 2;
				i += 2;
			} else {
				ps("NO");
				return 0;
			}
			break;
		  case 2:
			if(S[i] == 'a' && S[i+1] == 's' && S[i+2] == 'e' && S[i+3] == 'r') {
				state = 1;
				i += 4;
			} else if(S[i] == 'a' && S[i+1] == 's' && S[i+2] == 'e') {
				state = 3;
				i += 3;
			} else {
				ps("NO");
				return 0;
			}
			break;
		  case 3:
			if(S[i] == 'd' && S[i+1] == 'r' && S[i+2] == 'e' && S[i+3] == 'a' && S[i+4] == 'm') {
				state = 3;
				i += 5;
			} else if(S[i] == 'e' && S[i+1] == 'r' && S[i+2] == 'a') {
				state = 2;
				i += 2;
			} else if(S[i] == 'e' && S[i+1] == 'r') {
				state = 1;
				i += 2;
			} else {
				ps("NO");
				return 0;
			}
			break;
		}
		//printf("%ld: %ld\n", state, i);
	}
	
	if(state == 1 || state == 3) {
		ps("YES");
	} else {
		ps("NO");
	}
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
string st;
int getnum(int l) {
	int num = 0;
	while (isdigit(st[l])) {
		num = num * 10 + st[l] - '0';
		l++;
	}
	return num;
}
int calc(const int a,const int b,const char type) {
	if (type == '+')return a + b;
	else if (type == '-')return a - b;
	else if (type == '*')return a*b;
	else return a / b;
}
set<int> getexpr(const int l,const int r) {
	set <int>aset;
	int depth = 0;
	bool flag = false;
	for (int x = l; x <= r; ++x) {
		if (st[x] == '(') {
			depth++;
		}
		else if (st[x] == ')') {
			depth--;
		}
		else if (st[x] == '+' || st[x] == '-' || st[x] == '*' || st[x] == '/') {
			if (!depth) {
				flag = true;
				const set<int> lset = getexpr(l, x - 1);
				const set<int> rset = getexpr(x + 1, r);
				for (auto a : lset) {
					for (auto b : rset) {
						if (st[x] == '/'&&!b)continue;
						else {
							aset.emplace(calc(a, b, st[x]));
						}
					}
				}
			}
		}
	}
	if (!flag) {
		if (st[l] == '(')return getexpr(l + 1, r - 1);
		aset.emplace(getnum(l));
	}
	return aset;
}
int main() {
	while (1) {
		cin >> st;
		if (st == "#")break;
		set<int>aset=getexpr(0,st.size()-1);	
		cout << aset.size() << endl;
	}
	return 0;
}

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


int V, E, u, v, w, in[101][101], visited[101], cache[101];

int DFS_has_cycle(int cur_v) {
    if (cache[cur_v] != INT_MAX) return cache[cur_v];
    visited[cur_v] = 1;
    for (int i = 0; i < V; i++) {
        if (in[cur_v][i]){
            if (visited[i]) return cache[cur_v] = 1;  //back-edge발견, 사이클!
            if (DFS_has_cycle(i)) return cache[cur_v] = 1;
        }
    }
    visited[cur_v] = 0;  // 이부분이 중요(back track한다음에는 0으로 만들어줘야 트리구조로 들어간다.)
    return cache[cur_v] = 0;
}

int main()
{
    const int INF = INT_MAX / 4;
    scanf("%d%d", &V, &E);
    fill(&in[0][0], &in[V][V], 0);
    for (int i = 0; i < E; i++) {
        scanf("%d%d", &u, &v);
        in[u][v] = 1;
    }
    
    bool ans = false;
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < 101; j++)visited[j]=0, cache[j]=INT_MAX;
        if (DFS_has_cycle(i)) { ans = true; break; }
    }

    printf("%d\n", ans ? 1 : 0);
    return 0;
}



Measured memory_bytes: 3256
#include <stdio.h>
int main(void){
    char ch[1001];
    int s, i;
    while(1){
       s = 0;
       scanf("%s",&ch);
       if(ch[0] == '0'){
           break;
       }
        for(i = 0; ch[i] != '\0'; i++){
        s = s + ch[i] - '0';
       }
       printf("%d\n",s);
   }
   return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; ++i)
    {
        int comp = (x - i);
        if(i * 4 + comp * 2 == y) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int a,b;
	cin>>a>>b;
	if(a+b==15)cout<<"+"<<endl;
	else if(a*b==15)cout<<"*"<<endl;
	else cout<<"x"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define ll long long
    using namespace std;
    const int MAX =1e5+9;
    int main(){
    	int n;
    	string s;
    	cin>>n;
    	cin>>s;
    	int k;
    	cin>>k;
    	char c=s[k-1];
    	for(int i=0;i<n;i++){
    		if(c!=s[i])
    			cout<<'*';
    		else
    			cout<<s[i];
    	}
    	
    }

Measured memory_bytes: 256
n, m  = gets.strip.split.map(&:to_i)
kk = m.times.map { [gets.strip.split.map(&:to_i).first, gets.strip.split.map(&:to_i).inject(0) {|m, e| m+2**(e-1) } ] }
INF = 10**10

dp = [INF] * (2**n)
dp[0] = 0

kk.each do |price, boxes|
  dp.each_with_index do |tmp_price, opened_boxes|
    current_opened = (opened_boxes | boxes)
    current_price = tmp_price + price
    dp[current_opened] = current_price if dp[current_opened] > current_price
  end
end

#p dp

if dp.last==INF
  p -1
else
  p dp.last
end


Measured memory_bytes: 3836
// In the name of Allah
    // There is no power but from God the Almighty
    // No God except Allah
    #include <bits/stdc++.h>
    #define mp make_pair
    #define f1 first
    #define f2 second
    #define pb push_back
    #define pii pair<int ,int>
    #define ios  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    using namespace std;
    const int mox=1e5+9;
    int na[mox];
    main()
    {
        int n;
        cin>>n;
        int x=0;
        int o=0;
        int w=0;
        for(int i=0 ;i<n ; i++)
          {
          cin>>na[i];
          x+=na[i];
          if((na[i]%2))
            {
            o+=1;
            w=na[i];
            }
          }
          if((x%2)==0)
          {
             if((n%2))
             {
                cout<<"First";
             }
             else
             cout<<"Second";
             exit(0);
          }
          if((n%2)==0)
          {
            cout<<"First";
            exit(0);
          }
          if(o>1||w==1)
          {
            cout<<"Second";
             exit(0);
          }
          int a=0;
          while(o==1&&w>1)
          {
               int b=0;
               o=0;
            for(int i=0 ; i<n ; i ++)
            {
               if(na[i]==w)
                  na[i]-=1;
            }
            w=0;
            for(int i=0 ; i<n ; i ++)
            {
               b=__gcd(b,na[i]);
            }
            for(int i=0 ; i<n ; i++)
            {
               na[i]/=b;
               if(na[i]%2)
               {
                  o+=1;
                  w=na[i];
               }
            }
            a+=1;
          }
          if(o%2)
          {
            if(a%2)
            {
              cout<<"First";
            }
            else
            cout<<"Second";
            exit(0);
          }
          else
          {
              if(!(a%2))
             {
                cout<<"First";
             }
             else
             cout<<"Second";
             exit(0);
          }
    }


Measured memory_bytes: 4024
#include <stdio.h>
 int main(){
 int n,i,a[10000];
 scanf("%d",&n);
 for (i = 0; i < n; i++){
 a[i]=i+1;
 } 
 for (i = 0; i < n; i++){
 if (a[i]%3 == 0){
 printf(" %d",a[i]);
 }else if (a[i]%10 == 3){
 printf(" %d",a[i]);
 } else if (30 <= a[i]%100 && a[i]%100 <= 39){
 printf(" %d",a[i]);
 } else if (300 <= a[i]%1000 && a[i]%1000 <= 399){
 printf(" %d",a[i]);
 } else if (3000 <= a[i]%10000 && a[i]%10000 <= 3999){
 printf(" %d",a[i]); 
} 
} 
printf("\n");
 return 0;
 } 


Measured memory_bytes: 2140
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

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

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


map<pii,int> mp;
int main(){
	ll H, W, N;
	ll ans[10]={};

	cin >> H >> W >> N;
	ans[0] = (H-2)*(W-2);
	rep(i,N){
		int a, b;
		cin >> a >> b;
		a--; b--;
		rep(vx,3) rep(vy,3){
			int x = b - vx;
			int y = a - vy;
			if( x < 0 || y < 0 || x > W-3 || y > H-3 ) continue;
			pii p = pii(x,y);
			if( !mp.count( p ) ){
				mp[p] = 0;
			}
			ans[ mp[p] ]--;
			mp[p]++;
			ans[ mp[p] ]++;
			//cout << x << " " << y << " : " << mp[p] << endl;
		}
	}

	rep(i,10){
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 56448
#include<stdio.h>

int main(){

int i,j;
int H,W;
int x,y;
int square[100][2]={0};

for(i=0;i<100;i++){
	scanf("%d %d",&square[i][0],&square[i][1]);
	if(square[i][0] == 0 && square[i][1] == 0){
		break;
	}
}

for(j=0;j<i;j++){
	for(y=0;y<square[j][0];y++){
		for(x=0;x<square[j][1];x++){
			if(y == 0 || y == square[j][0]-1){
				printf("#");
			}else{
				if(x > 0 && x < square[j][1]-1){
					printf(".");
				}else{
					printf("#");
				}
			}
		}
		printf("\n");
	}
	printf("\n");
}	
return 0;
}


Measured memory_bytes: 2036
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

struct Edge { int to, cap, rev; };

#define MAX_N 30000
class Dinic {
public:
  vector<Edge> G[MAX_N];
  int level[MAX_N], iter[MAX_N];

  void add_edge(int from, int to, int cap) {
    G[from].pb((Edge) { to, cap, (int)G[to].size() });
    G[to].pb((Edge) { from, 0, (int)G[from].size() - 1 });
  }

  void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (Edge e : G[x]) {
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[x] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int x, int t, int f) {
    if (x == t) return f;
    for (int &i=iter[x]; i<G[x].size(); i++) {
      Edge &e = G[x][i];
      if (e.cap > 0 && level[x] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      int f;
      while (true) {
        f = dfs(s, t, INF);
        if (f <= 0) break;
        flow += f;
      }
    }
  }
};

int W, H;
int SX, SY, TX, TY;
char A[100][100];

int WI[100], HI[100];
int IN[100][100], OUT[100][100];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W;
  rep(y, H) {
    rep(x, W) {
      cin >> A[x][y];
      if (A[x][y] == 'S') SX = x, SY = y;
      if (A[x][y] == 'T') TX = x, TY = y;
    }
  }
  rep(i, W) WI[i] = 2*W*H + i;
  rep(i, H) HI[i] = 2*W*H + W + i;
  rep(x, W) {
    rep(y, H) {
      IN[x][y] = 2*(y*W+x);
      OUT[x][y] = 2*(y*W+x)+1;
    }
  }

  Dinic dinic;
  rep(x, W) {
    rep(y, H) {
      if (A[x][y] == '.') continue;
      // (x,y) <-> WI[x]
      dinic.add_edge(OUT[x][y], WI[x], INF);
      dinic.add_edge(WI[x], IN[x][y], INF);
      // (x,y) <-> HI[x]
      dinic.add_edge(OUT[x][y], HI[y], INF);
      dinic.add_edge(HI[y], IN[x][y], INF);

      // in -> out
      dinic.add_edge(IN[x][y], OUT[x][y], 1);
    }
  }
  int ans = dinic.max_flow(OUT[SX][SY], IN[TX][TY]);
  if (ans >= INF) cout << -1 << "\n";
  else cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 5120
#include<stdio.h>
int main(void)
{
  int a,b,c,i;
  while(  scanf("%d %d",&a,&b)!=EOF)
  {
    c=a+b;
    for(i=1;c>=10;i++)
      c=c/10;
    printf("%d\n",i);
  }
}

Measured memory_bytes: 1792
n,a,b = (int(i) for i in input().split())
if n==1 and a!=b: answer = 0
elif n==1 and a==b: answer = 1
elif n!=1 and a>b: answer = 0
elif n!=1:
	x,y = a*(n-1)+b,a+b*(n-1)
	answer = (y-x+1)
print(answer)

Measured memory_bytes: 3060
import scala.math

object Main extends App {
  def divisors(n: Int): List[Int] =
    for (i <- (1 to n).toList if n % i == 0) yield i
  val sc = new java.util.Scanner(System.in)
  var d = sc.nextInt()
  var s = List.fill(26)(sc.nextInt())
  var c = Array.ofDim[Int](d,26)
  for (i <- 0 until d){
    c(i) = Array.fill(26)(sc.nextInt())
  }
  for (i <- 0 until d){
    for(j <- 0 until 26){
      c(i)(j) *= s(j)
    }
  }
  for(i <- 0 until d){
    println( c(i).indexOf(c(i).max) + 1)
  }
}


Measured memory_bytes: 58068
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 INF = 2e9;
const int MOD = 1e9 + 7;

int dp[105][4][2];
int main() {
   string N;
   int K;
   cin >> N >> K;
   int n = N.size();
   dp[0][0][0] = 1;
   rep(i, 0, n) rep(j, 0, 4) rep(sm, 0, 2) {
      rep(d, 0, 10) {
         int ni = i + 1, nj = j, nsm = sm;
         if (d != 0) nj++;
         if (nj > K) continue;
         if (nsm == 0) {
            if (d > N[i] - '0') continue;
            if (d < N[i] - '0') nsm = 1;
         }
         dp[ni][nj][nsm] += dp[i][j][sm];
      }
   }
   cout << dp[n][K][1] + dp[n][K][0] << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

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

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
questions = [list(map(int, input().split())) for _ in range(q)]

ac_sum = [0]
for i in range(1, n + 1):
    ac_sum.append(ac_sum[i-1] + 1 if s[i-1 : i+1] == 'AC' else ac_sum[i-1])

for l, r in questions:
    print(ac_sum[r-1] - ac_sum[l-1])


Measured memory_bytes: 30672
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n = I()
    s = S()
    a = [2] + [None if s[i] == '>' else 1 for i in range(n)] + [2]

    def f(i):
        if i < 0 or i > n+1:
            return (0, None)
        c = 0
        nl = i-1
        nr = i+1
        ni = i
        while a[ni] != 2:
            if a[ni] is None:
                ni = nr
                nr += 1
            else:
                ni = nl
                nl -= 1
            c += 1
        return (c, ni == 0)

    ma = n+1
    mi = 0
    mm = (ma+mi) // 2
    r = 0
    while ma > mi:
        mm = (ma+mi) // 2
        c,ff = f(mm)
        if r < c:
            r = c
        if ff:
            mi = mm + 1
        else:
            ma = mm
    for i in range(mm-1,mm+2):
        c,ff = f(i)
        if r < c:
            c = r

    return r



print(main())




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

int count_bits(int b) {
    int cnt = 0;
    for (int i = 0; i < 32; ++i) {
        if ((b >> i) & 1) {
            ++cnt;
        }
    }

    return cnt;
}

int main() {
    int N;
    std::cin >> N;

    int A[N] = {0};
    int x[N][N];
    int y[N][N];

    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];

        for (int j = 0; j < A[i]; ++j) {
            std::cin >> x[i][j] >> y[i][j];
            x[i][j] -= 1;
        }
    }

    int max = 0;
    for (int i = 1; i < (1 << N); ++i) {
        int bits[N] = {0};
        for (int j = 0; j < N; ++j) {
            bits[j] = ((i >> j) & 1);
        }

        bool ok = true;
        for (int j = 0; j < N; ++j) {
            if (bits[j]) {
                for (int k = 0; k < A[j]; ++k) {
                    int man = x[j][k];
                    if (bits[man] != y[j][k]) {
                        ok = false;
                        break;
                    }
                }
            }
        }

        if (ok) {
            max = std::max(max, count_bits(i));
        }
    }

    std::cout << max << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;


int main() {
	ll X, Y;
	cin >> X >> Y;
	
	ll a = X;
	ll c = 0;
	while (a <= Y) {
		c += 1;
		a = 2 * a;
	}
	cout << c << endl;
	//cin >> X;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sort(v) sort(all(v))
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define MODE 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    IOS
    int n;
    cin>>n;
    vector<int> a(n);
    int s=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    int mi=INT_MAX;
    int s1=0;
    for(int i=0;i<n;i++)
    {
        s1+=a[i];
        mi=min(mi,abs(s1-s+s1));
    }
    cout<<mi;
    return 0;
}


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

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = h[0], x = h[1], y = h[2];

		var r = new int[n];
		for (int i = 1; i <= n; i++)
			for (int j = i + 1; j <= n; j++)
				r[Math.Min(j - i, Math.Abs(i - x) + 1 + Math.Abs(j - y))]++;
		Console.WriteLine(string.Join("\n", r.Skip(1)));
	}
}


Measured memory_bytes: 28392
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <map>


using namespace std;


bool pairCompare(const  pair<int, int>& firstElof, const pair<int, int>& secondElof)
{
  return firstElof.second < secondElof.second;
}

int main()
{
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> r(M);
  vector <bool> li(N , false);//Nを代入


  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    r[i] = make_pair(a, b);
  }

  sort(r.begin(), r.end(), pairCompare);//２つ目が小さい順にソート

  int count = 0;

  int p=0;
  for (int i = 0; i < M; i++) {
    int f, e;
    f = r[i].first;
    e = r[i].second;
    bool iscover = false;

    for (int j = max(f,p); j <= e-1 ; j++) {
      if (li[j] >0) {
        iscover = true;
        break;
      } else {
        // li[j]-=N-(e-1);
      }
    }

    if (iscover == false) {
      li[e-1] = true;
      p = e-1;
      count++;
    }



    // cout <<f <<"-" << e;
    // if (iscover==false)cout << "**";
    // cout << endl;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
long long c[55][55];
int a[55], b[55];
int andBit[20], orBit[20];
int curBit[20];
long long count0[1<<20], count1[1<<20];
long long sign[1<<20];
long long sum[55][55];

long long getC(int n,int m){
	if(m>n || m<0) return 0;
	else return c[n][m];
}

void preWork(int n){
	c[0][0] = 1;
	for(int i = 1; i <= n; i++){
		c[i][0] = 1;
		for(int j = 1; j <= i; j++){
			c[i][j] = c[i-1][j]+c[i-1][j-1];
		}
	}
	for(int i = 0; i < (1<<18); i++){
		sign[i] = 1;
		int mask = i;
		for(int j = 0; j < 18; j++){
			if(mask%2) sign[i] *= -1;
			mask /= 2;
		}
	}
	for(int i = 0; i <= n; i++){
		sum[i][0] = 0;
		for(int j = 1; j <= n; j++){
			sum[i][j] = sum[i][j-1]+getC(i,j);
		}
	}
}

int translate(int n){
	int count = 0;
	for(int i = 1; i <= n; i++){
		int u = a[i], size = -1;
		int ok = 1;
		for(int j = 0; j < 18; j++){
			if(andBit[j]){
				if(u%2==0){ 
					ok = 0; 
					break;
				}
			}
			else if(orBit[j]==0){
				if(u%2!=0){
					ok = 0;
					break;
				}
			}
			else curBit[++size] = u%2;
			u /= 2;
		}
		if(ok){
			int add = 0;
			for(int j = size; j >= 0; j--) add = add*2+curBit[j];
			b[++count] = add;
		}
	}
	return count;
}

void calCount(int n,int bitCnt){
	for(int i = 0; i < (1<<bitCnt); i++){
		count0[i] = count1[i] = 0;
		for(int j = 1; j <= n; j++){
			count0[i] *= 2, count1[i] *= 2;
			if((b[j]&i)==0) count0[i]++;
			if((b[j]&i)==i) count1[i]++;
		}
	}
}

int popCount(long long u){
	return __builtin_popcountll(u);
}

int main(){
	preWork(50);
	int n,k,s,t;
	scanf("%d%d%d%d",&n,&k,&s,&t);
	for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
	if((s&t)!=s) printf("0\n");
	else{
		int bitCnt = 0;
		for(int i = 0; i < 18; i++){
			andBit[i] = s%2, orBit[i] = t%2;
			if(andBit[i]==0 && orBit[i]!=0) bitCnt++;
			s /= 2, t /= 2;
		}
		int size = translate(n);
		/*printf("bitCnt = %d, size = %d\n",bitCnt,size);
		for(int i = 1; i <= size; i++) printf("%d ",b[i]);
		printf("\n");*/
		calCount(size,bitCnt);
		long long ans = 0;
		for(int i = 0; i < (1<<bitCnt); i++){
			for(int j = i; ; j = i&(j-1)){
				long long have = popCount(count0[i^j]&count1[j]);
				ans += sign[i]*sum[have][k];
				if(j==0) break;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 8008
#include<bits/stdc++.h>
using namespace std;
int main(){
    string st;
    cin>>st;
    reverse(st.begin(),st.end());
    for(int i=0;i<st.length();){
        if(st.length()>=5&&st.substr(i,5)=="maerd"){
            i+=5;
        }else if(st.length()>=5&&st.substr(i,5)=="esare"){
            i+=5;
        }else if(st.length()>=7&&st.substr(i,7)=="remaerd"){
            i+=7;
        }else if(st.length()>=7&&st.substr(i,6)=="resare"){
            i+=6;
        }else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
 
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e18

 
typedef long long ll;
ll mod = 998244353;

 long long fast_exp(long long a, long long b)
{
    if(b <= 0)
       return 1;
    else
    {
       long long res = 1;
       res = fast_exp(a,b/2);
       res = (res*res)%mod;
       if(b%2 == 1)
          res = (res*a)%mod;
       return res;
 
    }
}
typedef long double ld;
const long long N = 2e5+5;
struct ed{
    ll u,v,a,b;
};
vector <ed> edge[51];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, m, s, u, v, a, b;
    cin >> n >> m >> s;
    for(ll i = 0; i<m ; i++)
    {
        cin >> u >> v >> a >> b;
        ed e1;
        e1.u = u, e1.v = v, e1.a = a, e1.b = b;
        edge[u].pb(e1);
        e1.u = v;
        e1.v = u;
        edge[v].pb(e1);
    }
    ll c[n+1], d[n+1];
    for(ll i = 1; i<=n ; i++)
        cin >> c[i] >> d[i]; 
    ll dp[n+1][2501];
    ll vis[n+1][2501] = {};
    for(ll i = 0; i<=n ; i++)
        for(ll j = 0; j<2501 ; j++)
            dp[i][j] = INF;
    
    s = min(s,2500LL);
    dp[1][s] = 0;
    set< pair<ll,pair<ll,ll>> > q;
    q.insert({0,{1,s}});
    while(!q.empty())
    {
        pair<ll,pair<ll,ll>> cur = *q.begin();
        q.erase(cur);
        ll i = cur.ss.ff, j = cur.ss.ss;
        for(auto e: edge[i])
        {
            if(j >= e.a && dp[e.v][j-e.a] > dp[i][j] + e.b)
            {
                if(q.find({dp[e.v][j-e.a],{e.v,j-e.a}}) != q.end())
                    q.erase({dp[e.v][j-e.a],{e.v,j-e.a}});
                    dp[e.v][j-e.a] = dp[i][j] + e.b;
                    q.insert({dp[e.v][j-e.a],{e.v,j-e.a}});
            }
        }

        ll ni = i, nj = min(j + c[i],2500LL);
        if(dp[ni][nj] > dp[i][j] + d[i])
        {
            if(q.find({dp[ni][nj],{ni,nj}}) != q.end())
                q.erase({dp[ni][nj],{ni,nj}});
            dp[ni][nj] = dp[i][j] + d[i];
            q.insert({dp[ni][nj],{ni,nj}});
        }    
    }

    ll ans[n+1];
    for(ll i = 2; i<=n ; i++)
    {
        ans[i] = INF;
        for(ll j = 0; j<=2500; j++)
            ans[i] = min(ans[i],dp[i][j]);
    } 

    for(ll i = 2; i<=n ; i++)
        cout<< ans[i] << '\n';





  
    return 0;
 
 
}

Measured memory_bytes: 9004
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll unsigned long long int
//int nck(int n, int k) {
//    double res = 1;
//    for (int i = 1; i <= k; ++i)
//        res = res * (n - k + i) / i;
//    return (int)(res + 0.01);
//}
ll choose(ll N)
{
	return N*(N-1)/2;
}
int main()
{
	int t = 1;
//	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		map<ll, ll> mp;
		vector<ll> vect(n);
		ll ans = 0;
		REP(i,n)
			cin>>vect[i], mp[vect[i]]++;
		for(auto m: mp)
		{
			ans+= choose(m.second);
		}
		REP(i, n)
		{
			cout<<ans+choose(mp[vect[i]]-1)-choose(mp[vect[i]])<<"\n";
		}
	}
}

Measured memory_bytes: 12800
#include<stdio.h>
int main()
{
	int n,m,s=0;
	scanf("%d%d",&n,&m);
	if(n>=2)
	s+=(n*(n-1)/2);
	if(m>=2)
	s+=(m*(m-1)/2);
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 128
def solve():
    N, M, *a = map(int, open(0).read().split())
    ok = [True for _ in range(N+1)]
    for i in range(M):
        ok[a[i]] = False
    MOD = 1000000007

    dp = [0 for _ in range(N+1)]
    dp[0] = 1
    for i in range(N):
        for j in range(i+1, min(N+1, i+3)):
            if ok[j]:
                dp[j] += dp[i]
                dp[j] %= MOD
    print(dp[N])


if __name__ == '__main__':
    solve()

Measured memory_bytes: 13940
#include <iostream>

using namespace std;

typedef long long ll;


bool func(int n, ll k, ll *a, ll x) {
    ll tmp = 0;
    for (int i = 0; i < n; i++) {
        tmp += (a[i]+x-1)/x - 1;
    }

    return tmp <= k;
}

int main() {
    int n;  ll k;   cin >> n >> k;
    ll *a = new ll[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    ll l = 0, r = 1e9, mid;
    while (r - l > 1) {
        mid = (l + r) / 2;

        if (func(n, k, a, mid))
            r = mid;
        else
            l = mid;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 5164
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)
dp = np.zeros(N, dtype=int)

dp[0] = 0
for i in range(1, N):
    l = max(0, i - K)
    H = A[i]
    dp[i] = np.min(np.abs(H-A[l:i])+dp[l:i])
print(dp[N - 1])


Measured memory_bytes: 21904
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define pbb pair<bool,bool>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod (ll)(1e9+7) 
#define hmod 1286031825167LL
using namespace std;

ll k,s,ans;
int main(){	
    ios::sync_with_stdio(false);
    cin >> k >> s;
    for (int i=0;i<=k;i++){
    	for (int j=0;j<=k;j++){
    		if (i+j <= s && s-i-j <= k)
    		ans++;
		}
	}
	cout << ans << "\n";
    return 0;
}	

Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 20

struct Node{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
};

typedef struct Node Node;

Node *sum,*num;

void jastin(int hum)
{
  Node *a = sum;
  Node *b = num;
  Node *c;

  c=(Node *)malloc(sizeof(Node));
  c->key = hum;
  c->right = num;
  c->left = num;

  while(a!=num)
    {
      b=a;
      if(c->key<a->key) a=a->left;
	else a=a->right;
    }
  c->parent=b;
  if(b==num)sum=c;
  else{
    if(c->key<b->key)b->left=c;
    else b->right=c;
  }
}
void zin(Node *rum)
{
  if(rum==num)return;
  zin(rum->left);
  printf(" %d",rum->key);
  zin(rum->right);
}
void xu(Node *yum)
{
  if(yum==num)return;
  printf(" %d",yum->key);
  xu(yum->left);
  xu(yum->right);
}
int main(void)
{
  int i,j,k;
  char tum[N];
  
  scanf("%d",&i);
  
  for(j=0;j<i;j++)
    {
      scanf("%s",tum);
      if(!strcmp(tum,"insert")) {
	  scanf("%d",&k);
	  jastin(k);
	}else if(!strcmp(tum,"print")) {
	  zin(sum);
	  printf("\n");
	  xu(sum);
	  printf("\n");
	  }
    }
	return 0;
}
      
  
  



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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    long long ans = 0, sum = 0;
    int right = 0;
    
    for (int left = 0; left < N; left++) {
        while (right < N && (sum+A[right]) == (sum^A[right])) {
            sum += A[right];
            right++;
        }
        
        ans += right - left;
        if (left == right) right++;
        else sum -= A[left];
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1e9+7
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int a, b; cin >> a >> b;
    if (a+b==3) cout << 3 << endl;
    else if (a+b==4) cout << 2 << endl;
    else cout << 1 << endl;

}

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

ll GCD(ll a,ll b){
    if(a>b){
        return GCD(b,a);
    }
    else{
    ll r=b%a;
    while(r!=0){
        b=a;
        a=r;
        r=b%a;
    }
    return a;
    }
}

int main(){
    ll n;cin>>n;
    ll an=n*360/GCD(n,360);
    cout<<an/n<<endl;
}

    









Measured memory_bytes: 3576
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);      
        List<Integer> m = new ArrayList<Integer>();
        List<Integer> f = new ArrayList<Integer>();
        List<Integer> r = new ArrayList<Integer>();
        List<Character> ranks = new ArrayList<Character>();
         
        for (;;) {
            int _m = scan.nextInt();
            int _f = scan.nextInt();
            int _r = scan.nextInt();
             
            if (_m == -1 && _f == -1 && _r == -1) {
                break;
            }
             
            m.add(_m);
            f.add(_f);
            r.add(_r);
        }
 
        for (int i = 0; i < m.size(); i++) {
            char rank;
            int _m = m.get(i);
            int _f = f.get(i);
            int _r = r.get(i);
             
            if (_m == -1 || _f == -1) 
                rank = 'F';
            else if (_m + _f >= 80) 
                rank = 'A';
            else if (_m + _f >= 65) 
                rank = 'B';
            else if (_m + _f >= 50) 
                rank = 'C';
            else if (_m + _f >= 30) 
                if (_r >= 50)
                    rank = 'C';
                else
                    rank = 'D';
            else
                rank = 'F';
             
            ranks.add(rank);
        }
 
        for (Character character : ranks) {
            System.out.println(character);
        }
         
        scan.close();
    }
 
}

Measured memory_bytes: 19872
n = int(input())
t, a = map(int, input().split())
h = list(map(int,input().split()))
temp = [0] * n
def func(x) :
    return abs(x-a)
for i in range(n) :
    temp[i] = t - h[i] * 0.006
diff = list(map(func, temp))
mn_index = diff.index(min(diff))
print(mn_index+1)


Measured memory_bytes: 9240
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll t = 1, n;
const ll inf = hell, N=200005;
inline ll mult(ll x,ll y){return (x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
vector<ll> dp(N,0), stsz(N,0), fact(N,0), inv(N,0), adj[N], ans(N,0);
inline ll powMod(ll base,ll expo){
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base);
		expo>>=1;
	}
	return ans;
}
inline ll invMod(ll x){
	return powMod(x,hell-2);
}
void dfs(ll node,ll par){
	stsz[node]=1;
	dp[node]=1;
	for(auto x : adj[node])
		if(x!=par){
			dfs(x,node);
			stsz[node]+=stsz[x];
			dp[node]=mult(dp[node],mult(dp[x],inv[stsz[x]]));
		}
	dp[node]=mult(dp[node],fact[stsz[node]-1]);
	//cout<<"node: "<<node<<" dp: "<<dp[node]<<"\n";
}
void go(ll node,ll par){
	ll parDp=1, tmp=dp[node];
	if(par){
		parDp=mult(dp[par],mult(fact[stsz[node]],mult(invMod(dp[node]),mult(fact[n-stsz[node]-1],inv[n-1]))));
		dp[node]=mult(dp[node],mult(parDp,mult(inv[n-stsz[node]],mult(fact[n-1],inv[stsz[node]-1]))));
	}
	ans[node]=dp[node];
	for(auto x : adj[node])
		if(x!=par)
			go(x,node);
	dp[node]=tmp;
}
void solve(){
	ll x, y;
	cin>>n;
	rep(i,1,n){
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dfs(1,0);
	go(1,0);
	rep(i,1,n+1)cout<<ans[i]<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    fact[0]=1;
    rep(i,1,N)fact[i]=mult(fact[i-1],i);
    inv[N-1]=invMod(fact[N-1]);
    for(ll i=N-2;i>=0;i--)
    	inv[i]=mult(inv[i+1],i+1);
//    cin >> t;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 22512