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

typedef long long ll;
#define fore(i,ii,iii) for(int i=ii;i<iii;i++)
#define pb push_back

typedef ll tc;
struct Line{tc m,h;};
struct CHT { // for minimum (for maximum just change the sign of lines)
	vector<Line> c;
	int pos=0;
	tc in(Line a, Line b){
		tc x=b.h-a.h,y=a.m-b.m;
		return x/y+(x%y?!((x>0)^(y>0)):0); // ==ceil(x/y)
	}
	void add(tc m, tc h){ // m's should be non increasing
		Line l=(Line){m,h};
		if(c.size()&&m==c.back().m){
			l.h=min(h,c.back().h);c.pop_back();if(pos)pos--;
		}
		while(c.size()>1&&in(c.back(),l)<=in(c[c.size()-2],c.back())){
			c.pop_back();if(pos)pos--;
		}
		c.pb(l);
	}
	inline bool fbin(tc x, int m){return in(c[m],c[m+1])>x;}
	tc eval(tc x){
		if(!c.size())return 0;
		// O(log n) query:
		int s=0,e=c.size();
		while(e-s>1){int m=(s+e)/2;
			if(fbin(x,m-1))e=m;
			else s=m;
		}
		return c[s].m*x+c[s].h;
		// O(1) query (for ordered x's):
		while(pos>0&&fbin(x,pos-1))pos--;
		while(pos<c.size()-1&&!fbin(x,pos))pos++;
		return c[pos].m*x+c[pos].h;
	}
};

const int N=2e5+15;
ll n,C,h[N],dp[N];
int main() {
	ios::sync_with_stdio(false);
	CHT cht;
	cin>>n>>C;
	fore(i,0,n)cin>>h[i];
	//for(int i=n-1;i>=0;i--) {
	fore(i,0,n) {
		if(i)dp[i]=(h[i]*h[i])+(cht.eval(h[i]));
		cht.add(-2*h[i],((h[i]*h[i])+C+dp[i]));
		//cout<<h[i]<<" : "<<cht.eval(h[i])<<endl;
	}
	//fore(i,0,n)cout<<dp[i]<<" ";cout<<endl;
	cout<<dp[n-1]<<endl;
}
/*
        i-1
dp[i] = min (h[i]-h[j])^2 + C + dp[j]
        j=0
______________________________________
        i-1
dp[i] = min h[i]^2-2h[i]h[j]+h[j]^2+C+dp[j]
        j=0
_____________________________________
                 i-1
dp[i] = h[i]^2 + min -2h[i]h[j]+h[j]^2+C+dp[j]
                 j=0
*/

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <algorithm>

int n;
std::vector<int> vec;

int c = 0;
int main() {
    std::cin >> n;
    vec.assign(n, 0);
    for (int i = 0; i < n; i++) {
        std::cin >> vec[i];
    }
    for (int i = 0; i < n; i++) {
        while (vec[i] % 2 == 0) {
            vec[i] /= 2;
            c++;
        }
    }
    std::cout << c << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 100005
#define trace(x) cout<<#x<<" = "<<x<<'\n'
#define trace2(x, y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<'\n'
#define trace3(x, y, z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<'\n'
#define sz(x) (int)(x).size()
using namespace std;
struct ii {
	int a, b;
	bool operator < (ii o) const { return tie(a, b) < tie(o.a, o.b); }
};
struct iii {
	int a, b, c;
	bool operator < (iii o) const { return tie(a, b, c) < tie(o.a, o.b, o.c); }
};
int TC, N, M, K, Q, x, y, z;

vector<int> edge[MAXN];
bool sudah[MAXN];
deque<int> deq;

int main() {
	#ifdef FAIRUZI10
	freopen("/home/fairuzi/Documents/CP/input.in", "r", stdin);
	#endif
	
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &x, &y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	deq.push_back(1);
	deq.push_back(edge[1][0]);
	sudah[1] = sudah[edge[1][0]] = 1;
	while (1) {
		bool suc = 1;
		for (auto i: edge[deq.front()]) {
			if (!sudah[i]) {
				suc = 0;
				deq.push_front(i);
				sudah[i] = 1;
				break;
			}
		}
		for (auto i: edge[deq.back()]) {
			if (!sudah[i]) {
				suc = 0;
				deq.push_back(i);
				sudah[i] = 1;
				break;
			}
		}
		if (suc) {
			printf("%d\n", sz(deq));
			printf("%d", deq.front());
			for (int i = 1; i < sz(deq); i++) printf(" %d", deq[i]);
			puts("");
			return 0;
		}
	}
			
	return 0;
}


Measured memory_bytes: 6784
import bisect

n=int(input())
L=list(map(int,input().split()))

L.sort()

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        idx=bisect.bisect_left(L,L[i]+L[j])
        ans+=idx-(j+1)
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

void quick_sort(int a[][2], int first, int last);
void array_copy(int a[], int b[], int n);

int main(void){
  int n; //仕事数
  scanf("%d",&n); //仕事数
 
  int works[n][2]; //仕事のデータ
  int i, sum = 0, flag = 1; //ループ変数，仕事時間の和，YesかNoか
  for(i=0 ; i<n ; i++)
    scanf("%d %d",&works[i][0] , &works[i][1]); //仕事のデータ

  quick_sort(works, 0, n-1);

  for(i=0 ; i<n ; i++){
    sum += works[i][0];
    if(sum > works[i][1]){
      flag = 0;
      break;
    }
  }

  if(flag == 1)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


void quick_sort(int a[][2], int first, int last){
  int tmp[2];
  int k;
  int flag = 1;
  int p = a[first][1];
  int i = first , j = last;

  while(flag){
    while(a[i][1] < p)
      i++;
    
    while(p < a[j][1])
      j--;
    
    if(i<j){
      array_copy(tmp, a[i], 2);
      array_copy(a[i], a[j], 2);
      array_copy(a[j], tmp, 2);
      i++;
      j--;
    }
    else
      flag = 0;
  }

  if(first < i-1)
    quick_sort(a, first, i-1);
  
  if(j+1 < last)
    quick_sort(a, j+1, last);
  
}

void array_copy(int a[], int b[], int n){
  for(int i=0 ; i<n ; i++)
    a[i] = b[i];
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), x.end()

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122) return char(x-32);
    if( 65 <= int(x) && int(x) <= 90) return x;
    return -1;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122) return x;
    if( 65 <= int(x) && int(x) <= 90) return char(x+32);
    return -1;
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57) return int(x-'0');
    if( 97 <= int(x) && int(x) <= 122) return int(x-96);
    if( 65 <= int(x) && int(x) <= 90) return int(x-64);
    return -1;
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1%MOD;
    else if(num2==1)return num1%MOD;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
ll n,a,b;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n>>a>>b;
    ll ans = 0;
    ans += (n / (a+b)) * a;
    ans += min(a,(n % (a+b)));
    cout<<ans<<newl;
}


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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair<long double,int>
using namespace std;
using ll = long long;
using T = tuple<long double, int, int>;

int main(void) {



	int n; cin >> n;
	int k; cin >> k;
	
	vector<int> a(n);
	int m = 0;
	rep(i, n) {
		cin >>a[i];
		m = max(m, a[i]);
	}
	
	
	
	
	int l = 0;
	int r = m;

	while (r-l > 1){

		int c = (r + l) / 2;

		int tmp = 0;
		rep(i, n) {
			tmp += a[i] / c;
			if (a[i] % c == 0) tmp--;
			
			if (tmp > k) break;

		}

		if (tmp > k) l = c;
		else r = c;
	}

	int tmp = 0;
	rep(i, n) {
		tmp += a[i] / r;
		if (a[i] % r == 0) tmp--;
	}

	if (tmp <= k) cout << r << endl;
	else cout << l << endl;

	



	return 0;
}


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

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

using Edge = pair<int, ll>;
using Graph = vector<vector<Edge> >;

int N;
Graph G;
vector<int> dir;

void dfs(int v, int p, int c) {
  dir[v] = c;
  for (auto e : G[v]) {
    if (e.first == p) continue;
    if (e.second & 1) dfs(e.first, v, 1 - c);
    else dfs(e.first, v, c);
  }
}

int main() {
  while (cin >> N) {
    G.assign(N, vector<Edge>());
    rep(i, N-1) {
      int u, v;
      ll w;
      cin >> u >> v >> w;
      u--, v--;
      G[u].push_back(Edge(v, w));
      G[v].push_back(Edge(u, w));
    }
    dir.assign(N, 0);
    dfs(0, -1, 1);
    for (auto v : dir) cout << v << endl;
  }
}


Measured memory_bytes: 10496
S = STDIN.gets.chomp

set = ['dream', 'dreamer', 'erase', 'eraser']

# erasedream
#
len = S.size
current = 0
flg = true
S.reverse!

while len > current
  if S[current..current + 6] == 'remaerd'
    current += 7
  elsif S[current..current + 4] == 'maerd'
    current += 5
  elsif S[current..current + 5] == 'resare'
    current += 6
  elsif S[current..current + 4] == 'esare'
    current += 5
  else
    flg = false
    break
  end
end

if flg
  puts 'YES'
else
  puts 'NO'
end

Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>

using namespace std;

int day_count(int Y, int M, int D) {
  int res = 0;

  for (int y=1; y<=Y; y++) {
    for (int m=1; m<=10; m++) {
      int D_MAX = (m%2? 20 : 19);
      if (y%3 == 0) D_MAX = 20;

      for (int d=1; d<=D_MAX; d++) {
        if (y == Y && m == M && d == D) return res; 
        res++;
      }
    }
  }
  return -1;
}

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

  for (int t=0; t<N; t++) {
    int Y, M, D;
    cin >> Y >> M >> D;

    cout << day_count(1000, 1, 1) - day_count(Y, M, D) << endl;
  }
}

Measured memory_bytes: 3048
ac = 0
wa = 0
tle = 0
re = 0

n = int(input())
for i in range(n):
  x = input()
  if x=='AC':
    ac = ac+1
  elif x=='WA':
    wa = wa+1
  elif x=='TLE':
    tle = tle+1
  else:
    re = re+1
print('AC'+' x '+str(ac))
print('WA'+' x '+str(wa))
print('TLE'+' x '+str(tle))
print('RE'+' x '+str(re))

Measured memory_bytes: 9216
#include <stdio.h>

int abs(int a){
  if(a<0) return -a;
  else return a;
}
int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if(abs(c-a)<=d||(abs(b-a)<=d&&abs(c-b)<=d)) printf("Yes");
  else printf("No");
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, x, y, z[2020] = {}, a[2020] = {}, b[2020] = {};
    cin >> n >> x >> y;
    for (int i = 1; i < x; i++) a[i] = x - i, b[i] = y - i;
    for (int i = y + 1; i <= n; i++) a[i] = i - x, b[i] = i - y;
    for (int i = x; i <= y; i++) a[i] = min(i - x, x + y + 1 - i + x), b[i] = min(y - i, x + y + 1 - y + i);
    for (int i = 1; i <= n; i++) for (int j = 1; j < i; j++) {
        z[min({i - j, a[i] + a[j], b[i] + b[j], a[i] + b[j] + 1, b[i] + a[j] + 1})]++;
    }
    for (int i = 1; i < n; i++) cout << z[i] << '\n';
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define sf(n) scanf("%f",&n)
#define pf(n) printf("%.12f",n)
#define psp printf(" ")
#define endc printf("\n")

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

const int maxn = 1e5 + 7; 
const int inf = 1e9 + 7;
const pii shit = mp(-inf,-inf);

vector<int> G[maxn];
int fld[maxn];
int v[maxn];
pii pos[maxn];

void dfs1(int x,int pi) {
	fld[x] = false;
	if (v[x] != -inf) fld[x] = true;
	for (int j = 0; j < G[x].size(); j++) {
		int y = G[x][j];
		if (y == pi) continue;
		dfs1(y,x);
		fld[x] |= fld[y];
	}
}

bool ok = true;

/*vector<int> manip(vector<int> z) {
	vector<int> w;
	for (int j = 0; j < z.size(); j++) {
		w.pb(z[j]-1); w.pb(z[j]+1);
	}
	sort(w.begin(), w.end());
	w.resize(unique(w.begin(), w.end()) - w.begin());	
	return w;
}

vector<int> cap(vector<int> v, vector<int> w) {
	vector<int> ans(v.size());
	ans.resize(set_intersection(v.begin(),v.end(),w.begin(),w.end(),ans.begin()) - ans.begin());
	return ans;
}*/

inline pii cap(pii p, pii q) {
	return mp(max(p.first, q.first), min(p.second, q.second));
}

inline bool equiv(pii p, pii q) {
	pii z = cap(p,q);
	return ( ((p.first - q.first)%2 == 0) && (z.first <= z.second) );
}
inline pii manip(pii p) {
	return mp(p.first-1,p.second+1);
}

void dfs(int x,int pi) {
	pos[x] = shit;
	if (v[x] != -inf) pos[x] = mp(v[x],v[x]);
	for (int j = 0; j < G[x].size(); j++) {
		int y = G[x][j];
		if (y == pi) continue;
		if (!fld[y]) continue;
		dfs(y,x); if (!ok) return; pii z = manip(pos[y]);
		if (pos[x] == shit) pos[x] = z;
		else { 
			if (equiv(pos[x], z)) pos[x] = cap(pos[x], z);
			else { ok = false; return; }
		}
	}
}

void dfs2(int x,int pi, int a,int b) {
	if (!fld[x]) v[x] = a;
	else {
		if (equiv(pos[x], mp(a,a))) v[x] = a;
		else v[x] = b;
	}
	for (int j = 0; j < G[x].size(); j++) {
		int y = G[x][j];
		if (y == pi) continue;
		dfs2(y,x,v[x]-1,v[x]+1);
	}
}

int main() {
	int n; sd(n);
	fill(v, v+n+1, -inf);
	for (int i = 1; i < n; i++) {
		int x,y; sd(x); sd(y); G[x].pb(y);
		G[y].pb(x);
	}
	int K; sd(K);
	for (int i = 1; i <= K; i++) {
		int x; sd(x); sd(v[x]);
	}
	dfs1(1,-1);
	if (!fld[1]) {
		printf("Yes\n");
		dfs2(1,-1,0,0);
	} else {
		dfs(1,-1);
		if (!ok) { printf("No\n"); return 0; }
		printf("Yes\n");
		dfs2(1,-1,pos[1].first, pos[1].second);
	}
	for (int i = 1; i <= n; i++) {
		pd(v[i]); endc;
	}

}


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

using namespace std;

long long inf=1000000007;

int main(){
	long long a,b;
	cin>>a>>b;
	if(a<b) swap(a,b);

	while(a%b!=0){
		long long c=a%b;
		a=b;
		b=c;
	}

	long long ans=1;
	set<long long> S;

	for(long long i=2;i*i<=b;i++){
		if(b%i!=0) continue;

		while(b%i==0){
			b/=i;
			S.insert(i);
		}
	}

	if(b>1) S.insert(b);

	cout<<ans+S.size()<<endl;

	return 0;
}


Measured memory_bytes: 256
import numpy as np

n, a, b = map(int, input().split())

nl = np.array([i for i in range(1, n + 1)])
sumlist = np.array([sum(map(int, str(i))) for i in range(1, n + 1)])
# sumlist = np.array(sumlist)

mask = (sumlist >= a) & (sumlist <= b)

ans = sum(nl[mask])

print(ans)

Measured memory_bytes: 18368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
ll INF=9210000000000000000;
int main(){
    int n,m;cin>>n>>m;
    vector<vector<bool>>path(n,vector<bool>(n,false));
    int x,y;
    rep(i,m){
        cin>>x>>y;x--;y--;
        path[x][y]=true;
        path[y][x]=true;
    }
    vector<int>v(n-1);rep(i,n-1)v[i]=i+1;
    int count=0;
    do{
        bool judge=true;
        judge&=path[0][v[0]];
        rep(i,n-2)judge&=path[v[i]][v[i+1]];
        if(judge)count++;
    }while(next_permutation(all(v)));
    cout<<count;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

#ifdef LOCAL  //デバッグ出力
#define dout cout
#define debug() if (true)
#else
#define dout \
  if (false) cout
#define debug() if (false)
#endif

using namespace std;
int main() {
  string S;
  cin >> S;
  if (S == "Sunny") {
    cout << "Cloudy";
  } else if (S == "Cloudy") {
    cout << "Rainy";
  } else {
    cout << "Sunny";
  }
  
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc174/tasks/abc174_f

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)

#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

//------------------------------------------------------------------------------
template<typename T>
class BinaryIndexedTree {
public:
  BinaryIndexedTree() : _n(0) {}
  BinaryIndexedTree(int n) : _n(n), data(n) {}

  void add(int p, T x) {
    assert(0 <= p && p < _n);
    p++;
    while (p <= _n) {
      data[p - 1] += x;
      p += p & -p;
    }
  }

  T sum(int l, int r) {
    assert(0 <= l && l <= r && r <= _n);
    return sum(r) - sum(l);
  }

private:
  int _n;
  vector<T> data;

  T sum(int r) {
    T s = 0;
    while(r > 0) {
      s += data[r - 1];
      r -= r & -r;
    }
    return s;
  }
};

//------------------------------------------------------------------------------
const int N_MAX = 5*1e5;
const int Q_MAX = 5*1e5;

int N, Q;
vector<int> c;
vector<int> l;
vector<int> r;

map<int, vector<int>> qs;
map<int, int> mp;
BinaryIndexedTree<int> bit;
vector<int> ans;

int main() {
  cin >> N >> Q;
  c = vector<int>(N);
  REP(i, N) cin >> c[i];
  l = vector<int>(Q);
  r = vector<int>(Q);
  REP(i, Q) {
    cin >> l[i] >> r[i];
    l[i]--; r[i]--;
  }

  ans = vector<int>(Q, 0);
  REP(i, Q) qs[r[i]].push_back(i);
  bit = BinaryIndexedTree<int>(N);

  REP(i, N) {
    if (mp.count(c[i])) bit.add(mp[c[i]], -1);
    mp[c[i]] = i;
    bit.add(mp[c[i]], 1);;
    for (int j :qs[i]) ans[j] = bit.sum(l[j], i + 1);
  }

  REP(i, Q) cout << ans[i] << endl;
}


Measured memory_bytes: 85088
import java.util.*;

public class Main{
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int sum = 0;
    String arrayN = String.valueOf(n);
    String[] box  = arrayN.split("");
    for (String box1 : box) {
      sum += Integer.parseInt(box1);
    }
    if(n%sum == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22868
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int mo = 1000000007;
using namespace std;
int n, A, B, C; ll c[5010][5010];
int main() {
	scanf("%d%d%d%d", &n, &A, &B, &C);
	if (B & 1) { printf("0"); return 0; }
	rep(i, 0, n) c[i][0] = 1; ll ans = 0;
	rep(i, 1, n) rep(j, 1, i) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mo;
	rep(p, 0, min(A, C)) rep(q, 0, (C - p) / 3) {
		int x = A - p;
		if (!B && C - p - 3 * q) continue;
		ll ret = c[x + p][x] % mo * c[x + p + q][q] % mo * c[x + p + q + B / 2][B / 2] % mo;
		if (B) ret = ret * c[C - p - 3 * q + B / 2 - 1][B / 2 - 1] % mo;
		ans = (ans + ret) % mo;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 116992
#include <stdio.h>

int main(void)
{
	int value,value_2;
	
	while(scanf("%d %d",&value,&value_2) != EOF)
	{
		int count = 1;
		int sum = value + value_2;
		
		while(sum / 10 != 0)
		{
			sum /= 10;
			count++;
		}
		
		printf("%d\n",count);
	}
	return 0;
}

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

int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;

  if (A >= K) {
    cout << K << endl;
  }
  else {
    K = K - A;
    if (B >= K) {
      cout << A << endl;
    }
    else {
      K = K - B;
      cout << A - K << endl;
    }
  }
}

Measured memory_bytes: 3636
#  --*-coding:utf-8-*--

MOD = 10**9 + 7

Factors = [0]*(10**5+1)
Factors[0] = 1
x = 1

for i in range(1, 10**5+1):
    x = x*i%MOD;
    Factors[i] = x

def getModInv(a, b):
    return 1 if (a == 1) else int((1-b*getModInv(b%a, a))/a%b)


def getComb(n, r):
    return (Factors[n]*
            getModInv(Factors[r], MOD)%MOD*
            getModInv(Factors[n-r], MOD)%MOD)



def main():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))

    S = 0
    for i in range(N-K+1):
        c = getComb(N-1-i, K-1)
        S += (A[-i-1] - A[i])*c%MOD

    print(S%MOD)



        


if __name__ == '__main__':
    main()


Measured memory_bytes: 18768
N = int(input())
WList = list(map(int, input().split()))

ansList=[0]*(N-1)

ansList[0] = sum(WList)-2 * WList[0]

for i in range(N-2):
    ansList[i+1] = ansList[i] - 2 * WList[i+1]

for i in range(N-1):
    ansList[i] = abs(ansList[i])

print(min(ansList))


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

    ll ans = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int l = 1; l <= k; l++) {
                int tmp = gcd(i, j);
                ans += gcd(tmp, l);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int i,j,k,n,m,l,x,y,z; string s;
	cin >> n >> m;

	double f;

	f = pow(100, n);
	if(m == 100) m++;
	cout << (int)f*m << endl;
}

Measured memory_bytes: 256
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());


int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		// ll a[n];
		c=n+(n*n)+(n*n*n);
		cout<<c;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int[] counts = new int[4];
        while (true) {
            String line = reader.readLine();
            if (line == null || line.isEmpty()) {
                break;
            }
            String[] values = line.split(",");
            String type = values[1];
            if (type.equals("A")) {
                counts[0]++;
            } else if (type.equals("B")) {
                counts[1]++;
            } else if (type.equals("AB")) {
                counts[2]++;
            } else {
                counts[3]++;
            }
        }
        for (int count : counts) {
            out.println(count);
        }
    }
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    LL N;
    cin >> N;
    LL cnt = 0;

    // N-1の約数.
    // NとN-1は互いに素なので、
    // N-1の約数は必ずNを割り切らず、かつ 1 余す

    for (LL i = 1; i * i <= N - 1; i++)
    {
        if ((N - 1) % i == 0)
        {
            cnt += 2;
        }
        if (i * i == N - 1)
            cnt--;
    }
    // 1は除外
    cnt--;

    // Nの約数をためす
    for (LL i = 2; i * i <= N; i++)
    {
        LL n = N;

        if (n % i == 0)
        {
            while (n % i == 0)
            {
                n /= i;
            }
            if (n % i == 1)
                cnt++;
        }
    }

    // N 自身
    cnt++;

    cout << cnt << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

using namespace std;

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

    if (n == 1) {
        cout << "Hello World" << endl;
    } else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a, b, max;

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

  max = a+b;
  if (max < a*2-1) {
    max = a*2-1;
  }
  if (max < b*2-1) {
    max = b*2-1;
  }

  printf("%d", max);

  return 0;
}


Measured memory_bytes: 128
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b = inpl()
if a == b == 1:
    print(1,2)
    print('.#')
    quit()
rev = False
if a < b:
    rev = True
    a,b = b,a
a -= 1
res = [[None] * 100 for _ in range(100)]
r = 0
ok = True
while ok:
    for c in range(100):
        if r%2:
            res[r][c] = 0
        else:
            if not ok or c%2:
                res[r][c] = 1
                b -= 1
                if b == 0:
                    ok = False
            else:
                res[r][c] = 0
    r += 1
for c in range(100):
    res[r][c] = 1 if c == 99 else 0
r += 1
for c in range(100):
    res[r][c] = 1
r += 1
ok = True
while ok:
    for c in range(100):
        if r%2:
            res[r][c] = 1
        else:
            if not ok or c%2:
                res[r][c] = 0
                a -= 1
                if a <= 0:
                    ok = False
            else:
                res[r][c] = 1
    r += 1
for i in range(r,100):
    for j in range(100):
        res[i][j] = res[i-1][j]
print(100,100)
for i in range(100):
    for j in range(100):
        if rev:
            res[i][j] = '.' if res[i][j] else '#'
        else:
            res[i][j] = '#' if res[i][j] else '.'
    print(''.join(res[i]))

Measured memory_bytes: 65772
#include <iostream>
using namespace std;
int main()
{
	auto findSumOfDigits = [](int n)
	{
		int sum = 0;
		while (n > 0)
		{
			sum += n % 10;
			n /= 10;
		}
		return sum;
	};
	int N, A, B;
	cin >> N >> A >> B;
	int total = 0;
	for (int i = 1; i <= N; ++i)
	{
		int sum = findSumOfDigits(i);
		if (A <= sum && sum <= B)
		{
			total += i;
		}
	}
	cout << total << endl;
  	return 0;
}

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

const int MAX = 2100;
const int MOD = 1000000000 + 7;

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 < 0 || k < 0 || k > n) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main () {
  
  long long N, K;
  cin >> N >> K;
  
  COMinit();
  
  for (long long i = 1; i <= K; i++) {
    cout << COM(N - K + 1, i) * COM(K - 1, i - 1) % MOD << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	string s;
	cin >> s;
	for (auto& i : s) {
		i = 'x';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;

int main() {
	string s;
	cin >> s;
	bool alp[26];
	for (int i = 0; i < 26; i++)
		alp[i] = false;
	for (int i = 0; i < s.length(); i++) {
		if (alp[s[i] - 'a'] == false)
			alp[s[i] - 'a'] = true;
		else alp[s[i] - 'a'] = false;
	}
	for (int i = 0; i < 26; i++)
		if (alp[i] == true) {
			cout << "No" << endl;
			return 0;
		}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;

string s[10];

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    for(int i = 0; i < H; ++i){
        cin >> s[i];
    }
    int ans = H * W + 1;
    for(int i = 0; i < (1 << (H - 1)); ++i){
        vector<int> partition;
        for(int j = 0; j < H - 1; ++j){
            if(i >> j & 1){
                partition.push_back(j);
            }
        }
        partition.push_back(H-1);
        const int m = (int)partition.size();
        vector<int> white(m, 0);
        int res = 0;
        bool possible = true;
        for(int j = 0; j < W; ++j){
            vector<int> cur_white(m, 0);
            bool update = false;
            for(int k = 0, cur = 0; k < m; ++k){
                for(; cur <= partition[k]; ++cur){
                    if(s[cur][j] == '1'){
                        ++cur_white[k];
                    }
                }
                if(cur_white[k] > K){
                    possible = false;
                    break;
                }else if((white[k] += cur_white[k]) > K){
                    update = true;
                }
            }
            if(!possible) break;
            if(update){
                white = cur_white;
                ++res;
            }
        }
        if(!possible) continue;
        ans = min(ans, res + m - 1);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
hight = []
width = []
num = 0

while True:
    H,W = list(map(int,input().split()))
    if H==0 and W==0:
      break
    else:
      hight.append(H)
      width.append(W)
      num += 1

for i in range(num):
    for j in range(1,hight[i]+1):
      if j==1 or j==hight[i]:
        for k in range(width[i]):
           print("#",end="")
        print("")
      else:
        for k in range(1,width[i]+1):
            if k==1 or k==width[i]:
              print("#",end="")
            else:
              print(".",end="")
        print("")
    print("")


Measured memory_bytes: 7016
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
    FOR(i,2,p) {
      if (p%i==0) return false;
    }
  return true;
}

int main(){
  int n,p[200010],k[200010],m;
  cin >> n;
  REP1(i,n){
    cin >> p[i];
    k[i] = 0;
  }
  k[0]=0;
  m=0;
  REP1(i,n){
    if (k[p[i]-1]==0){
      k[p[i]]=p[i];
    } else {
      k[p[i]]=k[p[i]-1];
      if (p[i]-k[p[i]]>m) m=p[i]-k[p[i]];
    }
  }
  cout << n-m-1;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int64_t f(int64_t x){
  int64_t ans=0;
  if(x%4==1 || x%4==2)
    ans+=1;
for(int64_t i=2;i<=41;i++){
  int64_t k=pow(2,i);
  int64_t mod=x%k;
  if(k/2<=mod){
  if(mod%2==0)
    ans+=(k/2);
  }
} return ans;
}
int main(){
int64_t A,B;
  cin>>A>>B;
  int64_t a=f(A-1);
  int64_t b=f(B);
  int64_t ans=a^b;
  cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//#define LOCAL

#include <cstdio>

#define M 100010
#define NIL -1
struct Node { int p, l, r; };
Node T[M]; int A[M];

void print(int u) {
	int i, c;
	printf("node %d: parent = %d, depth = %d, ", u, T[u].p, A[u]);
	if(T[u].p == NIL) printf("root, ");
	else if(T[u].l == NIL) printf("leaf, ");
	else printf("internal node, ");
	printf("[");
	for(i=0, c=T[u].l; c!=NIL; ++i, c=T[c].r) {
		if(i) printf(", ");
		printf("%d", c);
	}
	printf("]\n");
}

int rec(int u, int p) {
	A[u] = p;
	if(T[u].r != NIL) rec(T[u].r, p);
	if(T[u].l != NIL) rec(T[u].l, p+1);
}

int main()
{
	#ifdef LOCAL
		freopen("E:\\Temp\\input.txt", "r", stdin);
		freopen("E:\\Temp\\output.txt", "w", stdout);
	#endif

	int a, b, c, d, i, j, n, r;
	scanf("%d", &n);
	for(i=0; i<n; ++i) T[i].p = T[i].l = T[i].r = NIL;

	for(i=0; i<n; ++i) {
		scanf("%d%d", &a, &b);
		for(j=0; j<b; ++j) {
			scanf("%d", &c);
			if(!j) T[a].l = c;
			else T[d].r = c;
			d = c;
			T[c].p = a;
		}
	}
	for(i=0; i<n; ++i)
		if(T[i].p == NIL) r = i;
	rec(r, 0);

	for(i=0; i<n; ++i) print(i);

	return 0;
}

Measured memory_bytes: 7276
a, b, c, x = int(raw_input()), int(raw_input()), int(raw_input()), int(raw_input())
def calc(a, b, c, x, m) :
    if not x : 
        return 1

    result = 0
    if m >= 500 and x >= 500 and a :
        result += calc(a - 1, b, c, x - 500, 500)
    if m >= 100 and x >= 100 and b :
        result += calc(a, b - 1, c, x - 100, 100)
    if x >= 50 and c:
        result += calc(a, b, c - 1, x - 50, 50)
    
    return result


print calc(a, b, c, x, x)





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

 using namespace std;
 int main() {
   string S;
   int i, out;
   cin >> S;
   out = 0;
   for (i = 0; i < 4; i++){
     if (S.at(i) == '+') out++;
     else out--;
   }
   cout << out << endl;
 }


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

int main()
{	
  string s;
  cin >> s;
  if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    string str;
    set<char>s;
    cin>>str;
    for(auto x : str){
        s.insert(x);
    }
    for(char i='a';i<='z';i++){
        if(!s.count(i)){
            cout<<i;
            return 0;
        }
    }
    cout<<"None";
}



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

int main()
{
	int n;
	map<int, int> M;
	cin >> n;
	for (int i = 1;;i++)
	{
		if (M[n] != 0)
		{
			cout << i << endl;
			break;
		}
		M[n] = i;
		n = (n%2==0?n/2:3*n+1);
	}
	return 0;
}


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

int n;
ll dp[100100];
int h[100100];
bool vis[100100];

ll func( int pos ) {
    if (pos == n) return 0;
    if ( vis[pos] ) return dp[pos];
    vis[pos] = 1;

    ll p = 2e9, q = 2e9;
    if ( pos + 1 <= n ) p = abs(h[pos] - h[pos + 1]) + func(pos + 1);
    if ( pos + 2 <= n ) q = abs(h[pos] - h[pos + 2]) + func(pos + 2);

    return dp[pos] = min(p, q);
}


int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> h[i];
    cout << func(1) << endl;
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> a(Q), b(Q), c(Q), d(Q);
    rep(i,Q) {
        // int ai, bi, ci, di;
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    int ans = 0;
    vector<int> arr(N,1);
    while (arr[0] <= M) {
        int sum = 0;
        rep(j,Q) {
            if ((arr[b[j]-1] - arr[a[j]-1]) == c[j]) sum += d[j];
        }
        // cout << arr << ", sum: " << sum << "\n";
        ans = max(ans, sum);
        int k = N - 1;
        arr[k]++;
        while (k >= 1 && arr[k] > M) {
            k--;
            arr[k]++;
        }
        if (arr[0] > M) break;
        repSE(j,k+1,N) arr[j] = arr[k];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3600
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = scan.nextInt();
        }
        Arrays.sort(h);
        long min = Long.MAX_VALUE;
        for (int i = 0; i <= n-k; i++) {
            min = Math.min(min, h[i+(k-1)] - h[i]);
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 52428
n,m = list(map(int, input().split()))

class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n

    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

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

    def size(self, x):
        return -self.d[self.root(x)]

u = UnionFind(n)

for _ in range(m):
    a,b = map(int, input().split())
    u.unite(a-1,b-1)

print(-min(u.d))

Measured memory_bytes: 78100
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, C = LI()

    s = set()
    ans = 0
    while A % 2 == B % 2 == C % 2 == 0:
        s.add((A, B, C))
        tmp_A = A
        tmp_B = B
        tmp_C = C
        A = tmp_B // 2 + tmp_C // 2
        B = tmp_C // 2 + tmp_A // 2
        C = tmp_A // 2 + tmp_B // 2
        if (A, B, C) in s:
            ans = -1
            break
        ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10056
# ABC 105: B – Cakes and Donuts
n = int(input())
canDo = 'No'

for i in range(n // 4 + 1):
    for j in range(n // 7 + 1):
        if 4 * i + 7 * j == n:
            canDo = 'Yes'
            break

print(canDo)

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


int main() {
    char a[10];
    rep(i,10) cin>>a[i];

    string year,month,day;
    
    rep(i,4) year += a[i];
    rep2(i,5,7) month += a[i];
    rep2(i,8,10) day += a[i];

    if(stoi(year)>=2020 || ( stoi(year)>=2019 && stoi(month)>=5 )) cout<<"TBD";
    else cout<<"Heisei"<<endl;
        
    return 0;
}

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

int main(){
  int X,Y;
  int A=0;
  cin>>X;
  cin>>Y;
  if(X==1)A+=300000;
  if(X==2)A+=200000;
  if(X==3)A+=100000;
  if(Y==1)A+=300000;
  if(Y==2)A+=200000;
  if(Y==3)A+=100000;
  if(X==1&&Y==1)A+=400000;
  cout<<A<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL <class T = int> inline T IN() { T x; cin >> x; return x; }
TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> vector<T> make_v(size_t a) { return vector<T>(a); }
TPL<TNM T, TNM... Ts> auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }

TPL<TNM T> using vec2 = decltype(make_v<T>(0, 0));
TPL<TNM T> using vec3 = decltype(make_v<T>(0, 0, 0));
TPL<TNM T> using vec4 = decltype(make_v<T>(0, 0, 0, 0));
TPL<TNM T> using vec5 = decltype(make_v<T>(0, 0, 0, 0, 0));

int main(void) {
	string S;
	cin >> S;
	int x = count(ALL(S), 'o');
	OUT(700 + x * 100);
	return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> v(m);
  for(int i=0;i<m;i++){
    cin >> v[i];
  }
  int sum=0;
  for(int i=0;i<m;i++){
    sum+=v[i];
  }
  if(sum>n){
    cout << -1;
  }else{
    cout << n-sum;
  }
}


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

using namespace std;
typedef long long ll;

int main(){
    int N, K;
    cin >> N >> K;

    int max_val = ((N-1)*(N-2))/2;
    if(K > max_val){
        cout << -1 << endl;
        return 0;
    }

    vector<pair<int, int>> edges;
    for(int i=2;i<=N;i++) edges.push_back(make_pair(1, i));

    int excess = max_val - K;
    int cnt = 0;
    for(int i=2;i<=N;i++){
        for(int j=i+1;j<=N;j++){
            if (cnt == excess){
                cout << edges.size() << endl;
                for(auto edge : edges) {
                    cout << edge.first << " " << edge.second << endl;
                }

                return 0;
            }
            edges.push_back(make_pair(i, j));
            cnt++;
        }
    }

    cout << edges.size() << endl;
    for(auto edge : edges) {
        cout << edge.first << " " << edge.second << endl;
    }
    
}


Measured memory_bytes: 384
{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace
import Data.List (sort)

main = do
  [a,b] <- getInts
  putStrLn $ if a*b*(a+b) `mod` 3 == 0 then "Possible" else "Impossible"
  
-- util
getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine


Measured memory_bytes: 380
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N, M = I()
a = []
c = [1]*N
red = [0]*N
red[0] = 1

for i in range(M):
    x = l()
    a.append(x)
    c[x[0]-1] -= 1
    c[x[1]-1] += 1
    if red[x[0]-1]:
        red[x[1]-1] = 1
    if not c[x[0]-1]:
        red[x[0]-1] = 0


print(sum(red))


Measured memory_bytes: 29424
#include <iostream>
#include <vector>

using namespace std;

int main(void){
int n, m;
vector<int> G[100];
cin >> n >> m;
for(int i = 0;i < m;i++){
int a, b;
cin >> a >> b; a--;b--;
G[a].push_back(b);
G[b].push_back(a);
}
for(int i = 0;i < n;i++)
cout << G[i].size() << endl;
}

Measured memory_bytes: 256