akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<climits>
using namespace std;
static const int MAX_N = 50;

int N, M;
int num[3][MAX_N];

int main(){
	cin >> N >> M;
	fill(num[0], num[3], 0);
	for(int i = 0; i < N; i++){
		string s;
		cin >> s;
		for(int j = 0; j < s.length(); j++){
			if(s[j] == 'W') num[0][i]++;
			else if(s[j] == 'B') num[1][i]++;
			else if(s[j] == 'R') num[2][i]++;
		}
	}
	for(int i = 0; i < N; i++){
		if(i == 0) continue;
		for(int j = 0; j < 3; j++) num[j][i] += num[j][i - 1];
	}
	int ans = INT_MAX;
	for(int i = 1; i < N - 1; i++){
		for(int j = i + 1; j < N; j++){
			int cnt = (i * M - num[0][i - 1]) + ((j - i) * M - (num[1][j - 1] - num[1][i - 1])) + ((N - j) * M - (num[2][N - 1] - num[2][j - 1]));
			ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  1 2 3
  1   2
  }*/

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

  vi c(n);
  rep(i, 0, n) cin >> c[i];

  vi dp(n+1); 
  vi prev(200001, -1);
  dp[0] = 1;
  rep(i, 1, n+1){
    (dp[i] += dp[i-1]) %= mod;
    
    int &p = prev[c[i-1]];
    if(p != -1 and i-p > 1){
      (dp[i] += dp[p]) %= mod;
    }

    p = i;
  }

  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define mod 1000000007

bool vis[200005];
vector<int> vec[2000005], v1;
int child[2000005];
int parent[2000005];
int div1[100005];
int min_indx[200005];
int count1 = 0;
int height = 0;
int max_indx[200005];
void dfs(int node)
{

    vis[node] = 1;

    min_indx[count1] = node;
    max_indx[node] = min(max_indx[node], count1);
    count1++;

    //  count1++;
    child[node] = height++;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            min_indx[count1] = node;
            max_indx[node] = min(max_indx[node], count1);
            count1++;
        }
    }
    height--;
}
int MAXN = 200005;
int LOGMAXN = (int)log2(200005) + 1;
int M[200005][60];
int ans[200005];
void fun(int a, int b, int c)
{
    //ll val = 1;

    while (a <= b)
    {
        ans[a] += c;
        int p = -a;
        a += (a & p);
    }
}
int find1(int a)
{
    int sum = 0;
    while (a != 0)
    {
        sum += ans[a];
        int p = -a;
        a -= (a & p);
    }
    return sum;
}
void process2(int A[], int N)
{
    int i, j;

    for (i = 0; i < N; i++)
        M[i][0] = i;
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (find1(M[i][j - 1]) < find1(M[i + (1 << (j - 1))][j - 1]))
                M[i][j] = M[i][j - 1];
            else
                M[i][j] = M[i + (1 << (j - 1))][j - 1];
}

int32_t main()
{
    int n;
    cin >> n;
    int arr1[n], arr2[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr1[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> arr2[i];
    }
    int sum1[n], sum2[n];
    sum1[0] = arr1[0];
    sum2[0] = arr2[0];
    for (int i = 1; i < n; i++)
    {
        sum1[i] = sum1[i - 1] + arr1[i];
        sum2[i] = sum2[i - 1] + arr2[i];
    }
    int max1 = 0;
    for (int i = 0; i < n; i++)
    {
        if (sum1[i] - sum2[i] + sum2[n - 1] + arr2[i] > max1)
        {
            max1 = sum1[i] - sum2[i] + sum2[n - 1] + arr2[i];
        }
        //   cout << max1 << "\n";
    }
    cout << max1 << "\n";

    return 0;
}

Measured memory_bytes: 50480
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int imos(vector<int> &num){
	vector<int>cnt(num.size()+5);
	int maxv=0;
	cnt[0]=num[0];
	if(cnt[0]<0)cnt[0]=0;
	for(int i=1;i<num.size();++i){
		cnt[i]=cnt[i-1]+num[i];
		maxv=max(maxv,cnt[i]);
	}
	return maxv;
}


signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	string s;
	cin>>s;
	rep(i,s.size()){
		if(i%2==0){
			if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		else {
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int parent(int i){
return i/2;
}

int left(int i){
return 2*i;
}

int right(int i){
return 2*i+1;
}

int main(void){

int n,i,A[MAX+1];
	
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&A[i]);	
}	
for(i=1;i<=n;i++){
printf("node %d: key = %d, ",i,A[i]);
if(parent(i)>=1){
printf("parent key = %d, ",A[parent(i)]);
}
if(left(i)<=n){
printf("left key = %d, ",A[left(i)]);
}
if(right(i)<=n){
printf("right key = %d, ",A[right(i)]);
}
printf("\n");
}

return 0;
}

Measured memory_bytes: 608
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int a[10],w[10],i,m[2],cnt,n,x;
	scanf("%d",&n);
	m[0]=9999;	m[1]=9999;
	cnt=0;
	for(i=0;i<n;i++)	{
		scanf("%d",&a[i]);
		cnt+=a[i];
	}
	for(i=0;i<n;i++)	{
		scanf("%d",&w[i]);
		m[a[i]]=min(m[a[i]],w[i]);
	}
	if(cnt==n || cnt==0)	x=0;
	else x=m[0]+m[1];
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 2732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1e9;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int par[100010]; //親
int deep[100010]; //木の深さ

//ｎ要素で初期化
void init(int n) {
	for(int i = 0;i < n;i++) {
		par[i] = i;
		deep[i] = 0;
	}
}

//木の根を求める
int find(int x) {
	if(par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

//ｘとｙの属する集合を併合
void unite(int x,int y) {
	x = find(x);
	y = find(y);
	if(x == y) {
		return;
	}
	if(deep[x] < deep[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if(deep[x] == deep[y]) {
			deep[x]++;
		}
	}
}

//ｘとｙが同じ集合に属するか否か
bool same(int x,int y) {
	return find(x) == find(y);
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<tuple<int,int,int>> vec(M);
    for(int i = 0;i < M;i++) {
        int A,B,C;
        cin >> A >> B >> C;
        A--;
        B--;
        C %= 2;
        vec.at(i) = make_tuple(A,B,C);
    }
    init(N);
    for(int i = 0;i < M;i++) {
        unite(get<0>(vec.at(i)),get<1>(vec.at(i)));
    }
    map<int,int> ma;
    for(int i = 0;i < N;i++) {
        ma[find(i)]++;
    }
    int ret = 0;
    for(auto x:ma) {
        ret++;
    }
    cout << ret << endl;
}

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

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

  string S;
  cin >> S;

  string result = "";

  char previous = S[0];
  result += previous;

  for (int i = 1; i < N; i++) {
    if (previous == S[i]) {
      // 融合
    } else {
      // 別の色
      previous = S[i];
      result += previous;
    }
  }

  cout << result.length() << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  // 配列にすべて入力
  for(int i=0; i<vec.size(); i++){
    cin >> vec.at(i);
  }
  
  //sort関数を使ってからではないとreverse関数が使えない(reverseするだけなので)
  //多い方から順にする
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  //点数の初期化
  int aliceTotal = 0;
  int bobTotal = 0;
  for(int i=0; i<vec.size(); i++){
    //先手はアリス
    if(i % 2){
      bobTotal += vec.at(i);
    }else{
      aliceTotal += vec.at(i); 
    }
  }
  
  int sabun;
  sabun = aliceTotal - bobTotal;
  cout << sabun;
}

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

int main(){
    int n, l;
    cin  >> n >> l;
    int A[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
        A[i] = l + i;
        sum += A[i];
    }
    sort(A, A+n);
    int min = 100000000;
    int judge = 0;
    for(int i = 0 ; i < n ; i++){
        if(abs(A[i])< min){
            min = abs(A[i]);
            judge = A[i];
        }
    }
    if(judge >= 0){
        cout << sum - min << endl;
    }else{
        cout << sum + min << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N, W = map(int,input().split())
ls = []
for i in range(N):
  w, v = map(int, input().split())
  ls += [[w,v]]
w1 = ls[0][0]
for i in range(N):
  ls[i][0] -= w1
ans = 0
M = 3*N
dp = [[-1]*(M+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
  w, v = ls[i]
  for h in range(N,0,-1):
    for j in range(M,-1,-1):
      if j-w>=0 and dp[h-1][j-w]!=-1:
        dp[h][j] = max(dp[h][j], dp[h-1][j-w]+v)
for i in range(1,N+1):
  B = i*w1
  m = 0
  for j in range(M+1):
    if B+j<=W:
      m = max(m,dp[i][j])
  if ans<m:
    ans = m
print(ans)

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

const int maxn = 3e5+10;

int n, a, cnt[maxn], ccnt[maxn], len, cur, ans, tot, i, sum;

int main() {
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> a;
		cnt[a]++;
	}
	for (i = 1; i <= n; ++i) ccnt[cnt[i]]++;
	for (cur = 1, ans = n+1; cur <= n; ++cur) {
		while (ans && tot < cur && (n-sum)/(cur-tot) < ans) {
			ans--;
			tot += ccnt[ans];
			sum += ccnt[ans]*ans;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000;
int gcd(int a, int b)
{
    if (a < b)
        return gcd(b, a);
    if (a % b)
        return gcd(b, a % b);
    return b;
}
int main()
{

    int n, Q;
    cin >> n >> Q;
    string s;
    cin >> s;
    int S[100010] = {0};
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] == 'A' && s[i + 1] == 'C')
        {
            S[i + 2]++;
        }
    }
    for (int i = 0; i < n; i++)
    {
        S[i + 1] += S[i];
    }
    for (int i = 0; i < Q; i++)
    {
        int l, r;
        cin >> l >> r;
        cout << S[r] - S[l] << endl;
    }
}


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

int main(void){
  int N,i,j;
  long Y,money,buff;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  N=atoi(p);
  p=strtok(NULL," \n");
  Y=atol(p);
  
  money=Y-1000*N;
  
  for(i=0;i<=N;i++){
    Y=money;
    Y-=9000*i;
    buff=Y;
    if(Y<0){
      break;
    }
    for(j=0;j<=N-i;j++){
      Y=buff;
      Y-=4000*j;
      if(Y<0){
        break;
      }
      if(Y==0){
        printf("%d %d %d\n",i,j,N-i-j);
        return 0;
      }
    }
  }
  
  printf("%d %d %d\n",-1,-1,-1);
  
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    VL a(n);
    VL b(n);
    VL c(n-1);
    REP(i,n)cin>>a[i];
    REP(i,n)cin>>b[i];
    REP(i,n-1)cin>>c[i];

    LL ans = 0;
    REP(i,n){
        int index = a[i] - 1;
        ans += b[index];
        if(i != 0 && (a[i] - a[i-1]) == 1) {
            ans += c[a[i-1] - 1];
        }
    }
    PUTS(ans);
}

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

int main(){
    string aaa;
    cin >> aaa;
    if (aaa[0] == aaa[1] && aaa[0] == aaa[2] && aaa[1] == aaa[2]){
        printf("Yes");
    }
    else if (aaa[3] == aaa[1] && aaa[3] == aaa[2] && aaa[1] == aaa[2]){
        printf("Yes");
    }
    else{
        printf("No");}}

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

using namespace std;

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

int main(){
  int n,m;
  while(cin>>n>>m,n){
    string str;
    cin>>str;
    int ans = 0;
    int count = 0;
    FOR(i,1,m){
      if(count == 0){
        if(str[i]=='O'&&str[i-1]=='I')count = 1;
      }else{
        if(str[i]!=str[i-1]){
          count++;
        }else{
          if(count/2 >= n)ans += (count/2)+1-n;
          count = 0;
        }
      }
    }
    if(count/2 >= n)ans += (count/2)+1-n;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1904
#include <stdio.h>
#include <math.h>

int main(void)
{
  while(1){
		int a, b, ans;
		char op;
		scanf("%d %c %d\n", &a, &op, &b);
		switch (op) {
			case '?':
				return 0;
			case '/':
				ans = a/b;
				break;
			case '*':
				ans = a*b;
				break;
			case '+':
				ans = a+b;
				break;
			case '-':
				ans = a-b;
				break;

		}
		printf("%d\n", ans);
	}

  return 0 ;
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <stack>
#include <utility>
using namespace std;
// int synthesize_mizutamari(int m, int n)
// {
// 	return m + n;
// }
int main()
{
	stack<int> kudari;
	stack<pair<int, int>> mizutamari;

	string str;
	cin >> str;

	int S = 0; //総面積

	for (size_t i = 0; i < str.size(); i++)
	{
		if (str.at(i) == '\\')
		{
			kudari.push(i);
		}
		else if (!kudari.empty() && str.at(i) == '/')
		{
			int s = i - kudari.top();
			S += s;
			pair<int, int> new_mizutamari = make_pair(kudari.top(), s);
			kudari.pop();
			while (!mizutamari.empty() && new_mizutamari.first < mizutamari.top().first)
			{
				new_mizutamari.second = new_mizutamari.second + mizutamari.top().second;
				mizutamari.pop();
			}
			mizutamari.push(new_mizutamari);
		}
	}

	cout << S << endl; //総面積
	int count = mizutamari.size();
	cout << count; //水たまりの数
	stack<int> area;
	for (int i = 0; i < count; i++) //各面積
	{
		area.push(mizutamari.top().second);
		mizutamari.pop();
	}
	for (int i = 0; i < count; i++)
	{
		cout << ' ' << area.top();
		area.pop();
	}

	cout << endl;
}



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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng(static_cast<uint32_t>(chrono::steady_clock::now().time_since_epoch().count()));

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

  #ifdef EntityIT
  freopen("input.txt", "r", stdin);
  #endif // EntityIT

  int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;

  vec<bool, 1> w(f / 100 + 1);
  for (int i = 0; i * a < sz(w); ++i) {
    for (int j = 0; j * b + i * a < sz(w); ++j) {
      w[j * b + i * a] = true;
    }
  }

  vec<bool, 1> s(f + 1);
  for (int i = 0; i * c < sz(s); ++i) {
    for (int j = 0; j * d + i * c < sz(s); ++j) {
      s[j * d + i * c] = true;
    }
  }

  tuple<double, int, int> ans{-1e9, -1, -1};
  for (int i = 0; i < sz(w); ++i) {
    if (!w[i]) {
      continue;
    }
    for (int j = 0; j < sz(s); ++j) {
      if (!s[j] || 100 * i + j > f || e * i < j) {
        continue;
      }
      asMx(ans, {static_cast<double>(100) * j / (100 * i + j), i, j});
    }
  }
  cout << 100 * get<1>(ans) + get<2>(ans) << ' ' << get<2>(ans) << '\n';

  return 0;
}


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

int main()
{
    double a,b,c,C,h,S,L;
    cin >> a >> b >> C;
    double radC= C * M_PI / 180.0;
    h = b * sin(radC);
    S = a * h / 2.0;
    c = sqrt(a*a+b*b-2*a*b*cos(radC));
    L = a + b + c;
    cout << fixed;
    cout << S << endl;
    cout << L << endl;
    cout << h << endl;

    return 0;
}


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

#define ll long long
#define ii pair<int,int>
#define INF 1e9 + 7
#define vi vector<int>
#define add emplace_back

const int N = 1e5+5;

int dist[N], in_degree[N];
bool visited[N];
vi adj[N];

void dfs(int u){
    assert(!visited[u]);
    visited[u] = true;
    for(int v: adj[u]){
        dist[v] = max(dist[v], dist[u]+1);
        --in_degree[v];
        if(!in_degree[v])
            dfs(v);
    }
}

int main(){
    int n, m, x, y;
    scanf("%d %d", &n, &m);
    for(int i=0; i<m; ++i){
        scanf("%d %d", &x, &y);
        adj[x].add(y);
        ++in_degree[y];
    }

    for(int i=1; i<=n; ++i){
        if(!in_degree[i] && !visited[i]){
            dfs(i);
        }
    }
    
    int ans = 0;

    for(int i=1; i<=n; ++i)
        ans = max(ans, dist[i]);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9728
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ans=power(10, n, mod);
    int sub=power(9, n, mod);
    int ad=power(8, n, mod);
    //cout<<ans<<" "<<sub<<" "<<ad<<"\n";
    cout<<(ans-(2*sub)+ad+(3*mod))%mod;
}

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

int main() {
    int N , M ;
    cin >> N >> M ; // 1 ≤ N ≤ 100 ; 1 ≤ M ≤ N
    if (N == M) cout << "Yes" << endl ;
    else cout << "No" << endl ;
	return 0;
}

Measured memory_bytes: 3648
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val w, h, x, y = sc.nextLong

    var area = w.toDouble * h / 2
    var lineNum = if (w == x * 2 && h == y * 2) 1
    else 0

    printf("%f %d\n", area, lineNum)
  }
}


Measured memory_bytes: 27320
/*  -*- coding: utf-8 -*-
 *
 * 2953.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 30;
const int MAX_W = 30;
const int MAX_N = MAX_H * MAX_W;

/* typedef */

template <typename T>
struct Pt {
  T x, y;

  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt<T> &pt) : x(pt.x), y(pt.y) {}

  Pt<T> operator+(const Pt<T> pt) const { return Pt<T>(x + pt.x, y + pt.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt<T> pt) const { return Pt<T>(x - pt.x, y - pt.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt<T> v) const { return x * v.x + y * v.y; }
  T cross(Pt<T> v) const { return x * v.y - y * v.x; }

  bool operator==(const Pt<T> pt) const { return x == pt.x && y == pt.y; }
  bool operator<(const Pt<T> &pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }

  int md(const Pt<T> p) const { return abs(x - p.x) + abs(y - p.y); }

  void print() { printf("(%d,%d)", x, y); }
};

typedef Pt<int> pt;
typedef vector<pt> vpt;

/* global variables */

char s[MAX_W + 4];

/* subroutines */

// convex_hull()
//   make a convex_hull 'chs' from a set of points 'ps'
//   Note: ps must be sorted, and must contain at least 2 points
void convex_hull(const vpt& ps, vpt& chs) {
  int n = ps.size();
  vpt lhs, uhs;

  lhs.push_back(ps[0]);
  lhs.push_back(ps[1]);
  for (int i = 2; i < n; i++) {
    while (lhs.size() >= 2) {
      int ln = lhs.size();
      pt &lh0 = lhs[ln - 2], &lh1 = lhs[ln - 1];
      if ((lh1 - lh0).cross(ps[i] - lh1) > 0) break;
      lhs.pop_back();
    }
    lhs.push_back(ps[i]);
  }

  uhs.push_back(ps[n - 1]);
  uhs.push_back(ps[n - 2]);
  for (int i = n - 3; i >= 0; i--) {
    while (uhs.size() >= 2) {
      int un = uhs.size();
      pt &uh0 = uhs[un - 2], &uh1 = uhs[un - 1];
      if ((uh1 - uh0).cross(ps[i] - uh1) > 0) break;
      uhs.pop_back();
    }
    uhs.push_back(ps[i]);
  }

  lhs.pop_back();
  uhs.pop_back();

  chs.clear();
  chs.reserve(lhs.size() + uhs.size());
  chs.assign(lhs.begin(), lhs.end());
  chs.insert(chs.end(), uhs.begin(), uhs.end());
}

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);

  vpt ps;
  for (int y = 0; y < h; y++) {
    scanf("%s", s);
    for (int x = 0; x < w; x++)
      if (s[x] == 'B') ps.push_back(pt(x, y));
  }

  vpt chs;
  convex_hull(ps, chs);
  //printf("ps=%lu, chs=%lu\n", ps.size(), chs.size());

  int maxd = 0, n = chs.size();
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      int d = chs[i].md(chs[j]);
      if (maxd < d) maxd = d;
    }

  printf("%d\n", maxd);
  return 0;
}



Measured memory_bytes: 11172
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , m , x = 1;
    cin >> n >> m;
    for( int i = 1 ; i <= m ; i++ ) x *= 2;
    cout << x * ( 1900 * m + 100 * ( n - m ) );
}

Measured memory_bytes: 3656
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int main() {
	int A, B, T;
	cin >> A >> B >> T;

	cout << (int)((T + 0.5) / A) * B << endl;

	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL c[5] = {};
    int N;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        if(s[0] == 'M') c[0]++;
        if(s[0] == 'A') c[1]++;
        if(s[0] == 'R') c[2]++;
        if(s[0] == 'C') c[3]++;
        if(s[0] == 'H') c[4]++;
    }

    LL res = 0;
    for(int i = 0; i < 5; ++i) {
        for(int j = i + 1; j < 5; ++j) {
            for(int k = j + 1; k < 5; ++k) {
                res += c[i] * c[j] * c[k];
            }
        }
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 3652
from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = list(accumulate(A))
b = list(accumulate(B))

result = 0
j = bisect_left(b, K)
if j == M:
  result = M
elif b[j] == K:
    result = j + 1
else:
    result = j
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M:
        result = max(result, i + 1 + M)
    elif b[j] == t:
        result = max(result, i + 1 + j + 1)
    else:
        result = max(result, i + 1 + j)
print(result)


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

int main(){
	int a,b,c,i,ans=0;
	cin>>a>>b>>c;
	
	for(i=0;i<=10000;i++){
		if(c%a==0)ans++;
		if(a==b)break;
		a++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args){
        new Main().run();
    }
    TreeSet<Integer> set;

    private void run() {
        Scanner scanner = new Scanner(System.in);
        Integer N = scanner.nextInt();
        int K = scanner.nextInt();
        set = new TreeSet<>();
        for(int i = 0; i < 10; i++) {
            set.add(i);
        }
        for(int i = 0; i < K; i++) {
            set.remove(scanner.nextInt());
        }
        for(int i = N; i < Integer.MAX_VALUE; i++) {
            if(correct(i)){
                System.out.println(i);
                return;
            }
        }
    }

    private boolean correct(Integer i) {
        for(char c : i.toString().toCharArray()){
            if(!set.contains(c - '0')) return false;
        }
        return true;
    }
}

Measured memory_bytes: 45276
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

ll N, ans;

int main()
{
	cin >> N;
	for (ll i = 2, M = N; i * i <= M; i++)
	{
		ll z = i;
		while (N % z == 0)
			ans++, N /= z, z *= i;
		while (N % i == 0)
			N /= i;
	}

	cout << ans + (N != 1) << "\n";
}

Measured memory_bytes: 3648
/* #                          */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
void sol() {
    int n; cin >> n;
    vi input(n);
    vi num(n + 1, 0);
    vl same(n + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> input[i];
        num[input[i]]++;
    }

    ll sum(0);
    for (int i = 1; i <= n; i++)
        if (num[i] > 0) {
            ll x = ll(num[i]);
            same[i] = x * (x - 1) / 2LL;
            sum += same[i];
        }

    for (int i = 0; i < n; i++) {
        int x = input[i];
        ll newSum = sum - same[x];
        ll newNum = num[x] - 1;
        newSum += newNum * (newNum - 1) / 2;
        cout << newSum << '\n';
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    int T(1);
    while (T--)
        sol();


    return 0;
}

Measured memory_bytes: 5760
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int d = 25 - sc.nextInt();
        String s = "Christmas";
        for (int i = 0; i < d; i++) {
            s += " Eve";
        }
        System.out.println(s);
    }

}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 998244353
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li dp1[3030][3030]; // 最初に取るやつが決まってるやつ
li dp2[3030][3030]; // 最後に取るやつが決まってるやつ
li n, s;
li a[3030];

int main() {
    cin >> n >> s;
    li res = 0;

    rin{
        cin >> a[i];
        dp1[i + 1][0] = dp1[i][0] + 1;
        dp2[i + 1][0] = dp1[i][0] + 1;
        if (a[i] <= s) {
            dp1[i + 1][a[i]] = dp1[i][0] + 1;
            dp2[i + 1][a[i]] = dp1[i][0] + 1;
        }
        repp(j, 1, s + 1) {
            dp1[i + 1][j] = (dp1[i + 1][j] + dp1[i][j]) % MOD;
            dp2[i + 1][j] = (dp2[i + 1][j] + dp2[i][j] + dp1[i][j]) % MOD;
            if (j + a[i] <= s) {
                dp1[i + 1][j + a[i]] = (dp1[i + 1][j + a[i]] + dp1[i][j]) % MOD;
                dp2[i + 1][j + a[i]] = (dp2[i + 1][j + a[i]] + dp1[i][j]) % MOD;
            }
        }
    }

    cout << dp2[n][s] << endl;

    return 0;
}

Measured memory_bytes: 143616
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define DSORT(c, type) sort(ALL(c), greater<type>())

#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SUM(v) accumulate(ALL(v), 0)
#define SUM2(v, operation) accumulate(ALL(v), 0, operation)
#define AVG(v) SUM(v) / SZ(v)
#define COUNT(v, e) count(ALL(v), e)

using namespace std;


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

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

  double avg = SUM(a) * 1.0 / SZ(a);
  int ceil_avg = ceil(avg);
  int floor_avg = floor(avg);

  int ccost = 0, fcost = 0;
  for(int i=0; i<n; ++i){
    ccost += pow(abs(a[i]-ceil_avg), 2);
    fcost += pow(abs(a[i]-floor_avg), 2);
  }

  int cost = ccost < fcost ? ccost : fcost;
  cout << cost << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

        int a, b, c, s;

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

        if(a > b){
                s = a;
                a = b;
                b = s;
        }
        if(b > c){
                s = b;
                b = c;
                c = s;
        }
        if(a > b){
                s = a;
                a = b;
                b = s;
        }

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

        return 0;
}

Measured memory_bytes: 596
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
int main() {
  int n;
  cin >> n;
  ll ans = 1LL;
  rep(i, n) {
    ll a;
    cin >> a;
    ans = lcm(ans, a);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int max;
        int m;
        int n;
        if(a>=b){
            if(a>=c){
                max = a;
                m = b;
                n = c;
            }
            else{
                max = c;
                m = a;
                n = b;
            }
        }
        else{
            if(b>=c){
                max = b;
                m = a;
                n = c;
            }
            else{
                max = c;
                m = a;
                n = b;
            }
        }
        max = max - m + max - n;
        if(max%2==0){
            System.out.println(max/2);
        }
        else{
            System.out.println((max+3)/2);
        }
    }
}

Measured memory_bytes: 23124
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int N;
int64 arr[101010];


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

    int64 ans = 1LL<<62;
    {
        int64 rec = 0;
        int64 acc = 0;
        if (arr[0] <= 0) {
            rec += 1 - arr[0];
            acc = 1;
        } else {
            acc = arr[0];
        }

        int sign = -1;
        for (int j = 1; j < N; ++j, sign *= -1) {
            if ((acc + arr[j]) * sign <= 0) {
                rec += abs(acc + arr[j]) + 1;
                acc = sign;
            } else {
                acc += arr[j];
            }
        }
        ans = min(ans, rec);
    }
    {
        int64 rec = 0;
        int64 acc = 0;
        if (arr[0] >= 0) {
            rec += 1 + arr[0];
            acc = -1;
        } else {
            acc = arr[0];
        }

        int sign = 1;
        for (int j = 1; j < N; ++j, sign *= -1) {
            if ((acc + arr[j]) * sign <= 0) {
                rec += abs(acc + arr[j]) + 1;
                acc = sign;
            } else {
                acc += arr[j];
            }
        }
        ans = min(ans, rec);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
// use std::cmp;
// use std::collections::HashMap;
// use std::collections::HashSet;
// use std::collections::VecDeque;
use std::collections::BTreeSet;


// const INF: i64 = 1_000_000_000;
// const MOD: i64 = 998244353;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut lrcs = vec![];
    for _ in 0..m {
        let l: usize = sc.read();
        let r: usize = sc.read();
        let c: i64 = sc.read();
        lrcs.push((l, r, c));
    }

    lrcs.sort_by_key(|&(l, r, c)| l);
    let mut setc = BTreeSet::new();
    let mut setx = BTreeSet::new();
    setc.insert((0, 1, 0));
    setx.insert((1, 0, 0));

    // let inf = 1_000_000_000_000_000_000i64;
    // let mut ans = vec![inf; n+1];
    // ans[0] = 0;
    let mut i = 0;
    for (l, r, c) in lrcs {
        // println!("{:?}", (l, r, c));
        let setx_ok = setx.split_off(&(l, 0, 0));
        for (x, cost, nonce) in setx.into_iter() {
            setc.remove(&(cost, x, nonce));
        }
        setx = setx_ok;
        if let Some(&(cost, _, _)) = setc.iter().next() {
            let new_cost = cost + c;
            i += 1;
            setc.insert((new_cost, r, i));
            setx.insert((r, new_cost, i));
        }
    }

    {
        let setx_ok = setx.split_off(&(n, 0, 0));
        for (x, cost, nonce) in setx.into_iter() {
            setc.remove(&(cost, x, nonce));
        }
        setx = setx_ok;
    }
    let tmp = setc.iter().next();
    let ans = if let Some(&(cost, _, _)) = tmp {
        cost
    } else {
        -1
    };
    println!("{}", ans);
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

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

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


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

long long n, k;
vector<long long> a;

long long solve();
bool ch(long long x);

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long l = 0, r = 1e16;
  while (r - l > 1) {
    long long mid = (l + r) >> 1;
    if (ch(mid))
      r = mid;
    else
      l = mid;
  }
  return r;
}

bool ch(long long x) {
  long long cnt = 0;
  for (int i = 0; i < n; ++i) cnt += (a[i] - 1) / x;
  return cnt <= k;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

ll par[100005];
ll Rank[100005];
ll num[100005];

ll root(ll x)
{
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

bool same(ll x, ll y)
{
	return root(x) == root(y);
}

void unite(ll x, ll y)
{
	ll rx = root(x), ry = root(y);
	if (rx == ry) return;
	if (Rank[rx]<Rank[ry]) swap(rx, ry);
	if (Rank[rx]==Rank[ry]) Rank[rx]++;
	par[ry] = rx;
	num[rx] += num[ry];
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m; cin >> n >> m;
	vector<pll> ab(m);
	rep(i, m) cin >> ab[i].fi >> ab[i].se;

	rep(i, n+1) par[i]=i, Rank[i]=0, num[i]=1;

	ll ans = n*(n-1)/2;
	vll v;
	v.pb(ans);

	rep(i, m-1){
		ll a = ab[m-i-1].fi;
		ll b = ab[m-i-1].se;
		if (!same(a, b)){
			ans -= num[root(a)]*num[root(b)];
			unite(a, b);
		}
		v.pb(ans);
	}

	RITR(itr, v) cout << *itr << "\n";

	return 0;
}

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

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

    long long ans = 0;
    for (long long i = 0; i < s.length(); i++)
    {
        ans += s[i] - '0';
        ans %= 9;
    }

    cout << (ans % 9? "No\n":"Yes\n");
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+20;
long long v[N], c[51][51];
void init()
{
	memset(c, 0, sizeof(c));
	c[0][0] = 1;
	for (int i = 1; i <= 50; i++)
	{
		c[i][0] = 1;
		for (int j = 1; j <= i; j++)
			c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
	}
}
int main()
{
	int n, a, b;
	init();
	cin >> n >> a >> b;
		double ave;
		for (int i = 0; i < n; i++)
			cin >> v[i];
		sort(v, v + n);
		reverse(v, v + n);
		for (int i = 0; i < a; i++) 
			ave += v[i];
		ave /= a;
		int num = 0, k = 0;
		for (int i = 0; i < n; i++)
		{
			if (v[i] == v[a - 1])
			{
				num++;
				if (i < a) k++;
			}
		}	
		long long ans = 0; 
		if (k == a)
		{
			for (int i = a; i <= b; i++)
				ans += c[num][i];
		}
		else ans += c[num][k];
        cout.precision(20);
 		cout << fixed << ave << endl << ans;
}


Measured memory_bytes: 3772
#include <cstdio>
#include <algorithm>

using namespace std;

const int NMAX = 1e5;
int n;
int b[NMAX + 5];
int dp[(1 << 15)];

int main(){
	
	scanf("%d",&n);
	
	for(int i = 1;i < n;i++){
		int x,y,z;
		scanf("%d %d %d",&x,&y,&z);
		x++;
		y++;
		b[x] ^= z;
		b[y] ^= z;
	}
	
	int ans = n;
	int mask = 0;
	
	
	for(int i = 1;i <= n;i++){
		if(b[i] == 0){
			ans--;
		}
		else if((mask >> (b[i] - 1)) & 1){
			mask ^= (1 << (b[i] - 1));
			ans--;
		}
		else{
			mask ^= (1 << (b[i] - 1));
		}
	}
		
	dp[0] = 0;
	
	for(int i = 1;i <= mask;i++){
		dp[i] = -(1 << 28);
		for(int j = i;j;j = (j - 1) & i){
			int xo = 0;
			
			for(int b = 0;b < 15;b++){
				if((j >> b) & 1){
					xo ^= (b + 1);///cause i subtracted 1 before to make them in [0,15) range
				}
			}
			
			if(xo == 0){
				dp[i] = max(dp[i],1 + dp[i ^ j]);
			}
		}
	}
	
	ans -= dp[mask];
	
	printf("%d",ans);
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#define nmax_def 22
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	ll i, j;
	int A[nmax_def], B[nmax_def], C[nmax_def];
	int N;
	int ans = 0;
	cin >> N;
	rep(i, N) {
		cin >> A[i];
	}
	rep(i, N) {
		cin >> B[i];
		ans += B[i];
	}
	rep(i, N-1) {
		cin >> C[i];
	}
	rep(i, N - 1) {
		if (A[i + 1] == A[i] + 1)
			ans += C[A[i]-1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long mypow(long long x, long long y)
{
	long long result = 1;
	while (y != 0) {
		if (y%2 != 0) {
			result *= x;
			y -= 1;
		}	
		x *= x;
		y /= 2;
	}
	return result;
}
int main(void)
{
	long long n;
	cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}

	long long base = 0;
	for (int i = 0; i <= 31; i++) {
		if (i % 2 == 1)
			base -= mypow(2, i);
	}
	long long m = n-base;
	string s;
	for (int i = 0; i <= 31; i++) {
		if (m % mypow(2, i+1) != 0) {
			if (i % 2 == 0) {
				s.push_back('1');
			} else {
				s.push_back('0');
			}
			m -= mypow(2, i);
		} else {
			if (i % 2 == 0)
				s.push_back('0');
			else
				s.push_back('1');
		}
	}
	reverse(s.begin(), s.end());
	int i;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == '1')
			break;
	}
	cout << s.substr(i) << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

const int MAX = 200000;

int main() {
  int M; cin >> M;
  int d[MAX];
  long long c[MAX];
  for (int i = 0; i < M; i++) cin >> d[i] >> c[i];

  long long D = 0;
  long long S = 0;
  for (int i = 0; i < M; i++) {
    S += d[i] * c[i];
    D += c[i];
  }

  long long ans = (D - 1) + (S - 1) / 9;

  cout << ans << endl;
}

Measured memory_bytes: 5976
#include <stdio.h>

int main(void){
    int a, b;

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

    if(a * b > 81 || (a > 9 || b > 9))
    {
        printf("%d\n", -1);
    }else
    {
        printf("%d\n",a * b);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
 
int main(){
	long long n,k,q;
	vector<long long> p;
	
	cin >> n >> k;

	for(int i = 0; i < n; i++){
		cin >> q;
		p.push_back(q);
	}

    //昇順ソート（#include<algorithm>）
	sort(p.begin(), p.end());

    //一番安くなるようにK種類を購入するので、買わないのは値段が高い順にN-K種類
    //pop_back()で末尾をN-K回削除する（昇順ソートしたので末尾が一番高価）
	for(int j = 0; j < n - k; j++){
		p.pop_back();
	}

    //vectorに残ってる果物の合計価格をaccumulate()で出力（#include<numeric>）
	cout << std::accumulate(p.begin(), p.end(), 0) << endl;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,i;
	cin>>n>>k;
	long long int arr[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(i=k;i<n;i++)
	{
		if(arr[i-k]<arr[i])
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
}

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

using namespace std;

int main(){
  int N; cin >> N;  int sum = 0; int tmp = N;
  while(tmp > 0){ sum += tmp%10; tmp /= 10;}
  if( N % sum == 0){ cout << "Yes" << endl;} else{ cout << "No" << endl;}
  return 0;}

Measured memory_bytes: 380