akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int N, W;
vector<int> weight(1100), value(1100);

vector<vector<bool>> done(110, vector<bool>(10100, false)); // search(i,u)を実行したかどうかのメモ
vector<vector<int>> memo(110, vector<int>(10100));          // search(i,u)のメモ

int search(int i, int W);

int main()
{
    cin >> N >> W;
    rep(0, i, N)
    {
        cin >> value.at(i) >> weight.at(i);
    }

    cout << search(0, W) << endl;
}

// メモ化再帰的な考え方のDP
int search(int i, int u)
{
    if (done.at(i).at(u)) // すでに探索済みならメモしてある値を返す
    {
        return memo.at(i).at(u);
    }
    if (i == N) // 探索終了
    {
        done.at(i).at(u) = true;
        return 0;
    }
    else if (u < weight.at(i)) // 重すぎて入らない
    {
        done.at(i).at(u) = true;
        return memo.at(i).at(u) = search(i + 1, u);
    }
    else // 入れる時と入れない時で試して大きい方を返そう
    {
        int res1 = search(i + 1, u);
        int res2 = search(i + 1, u - weight.at(i)) + value.at(i);
        done.at(i).at(u) = true;
        return memo.at(i).at(u) = max(res1, res2);
    }
}

/* 全探索の書き方だと指数時間(2^N)かかってしまうね
int search(int i, int u)
{
    if (i == N) // 探索終了
    {
        return 0;
    }
    else if (u <= weight.at(i)) // 重すぎて入らない
    {
        return search(i + 1, u);
    }
    else // 入れる時と入れない時で試して大きい方を返そう
    {
        int res1 = search(i + 1, u);
        int res2 = search(i + 1, u - weight.at(i)) + value.at(i);
        return max(res1, res2);
    }
}
*/



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

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> c(10, vector<int>(10));
    rep(i, 10) rep(j, 10) cin >> c[i][j];
    rep(k, 10) rep(i, 10) rep(j, 10) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }

    int ans = 0;
    rep(i, h) rep(j, w) {
        int tmp_a;
        cin >> tmp_a;
        if ( tmp_a == -1 ) continue;
        ans += c[tmp_a][1];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main (void) {
	int n; cin >> n;
	vector<char> v;
	for (int i = 0; i < n; i++)
	{
		char num; cin >> num;
		v.push_back(num);
	}

	for (int i = 0; ; i++)
	{
		string str = to_string(i);
#ifdef D
		cout << "search num is " << str << endl;
#endif
		bool found = false;
		for (int j = 0; j < v.size(); j++) {
			auto isNum = [](string num, vector<char> v, int suffix) {
				for (int i = 0; i < num.size(); i++) {
					if (num[i] != v[suffix + i])
						return false;
				}
				return true;
			};

			if (v[j] == str[0])
				if (isNum(str, v, j))
				{
					found = true;
					break;
				}
		}
		if (!found) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}



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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T1,typename T2> using M = map< T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

int main(){
    int n;
    cin>>n;
    Msi ss;
    REP(i,n){
        string s;
        cin>>s;
        ss[s]++;
    }

    int max_num = 0;
    for(auto p : ss){
        max_num = max(max_num,p.se);
    }

    for(auto p : ss){
        if(p.se == max_num){
            cout<<p.fi<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=n*n*n;
    cout<<ans<<"\n";



    return 0;
}

Measured memory_bytes: 764
A={}
R={}
for i=1,9 do
  A[io.read"*n"]=i
end
N=io.read"*n"
function bingo(t)
  for i=1,3 do
    if(t[i]and t[i+3]and t[i+6])then return true end
  end
  for i=1,3 do
    if(t[i*3-2]and t[i*3-1]and t[i*3])then return true end
  end
  return (t[1]and t[5]and t[9]or t[3]and t[5]and t[7])and true or false
end
for i=1,N do
  local k=A[io.read"*n"]
  if(k)then R[k]=0 end
end
print(bingo(R)and"Yes"or"No")

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

int main() {
int N;
  cin >> N;
 
  int A,B,C,D;
    A=N/1000;
    B=(N/100)%10;
    C=(N/10)%10;
    D=N%10;

  if(A==B||B==C||C==D){
    cout<<"Bad"<<endl;}
  else{
    cout<<"Good"<<endl;}
    

}


Measured memory_bytes: 384
#include <stdio.h>

  int main()
  {
    int a,b,c;
    int ans = 0;
    scanf("%d %d %d",&a,&b,&c);
    if(a < b){
      if(b < c){
        ans = 1;
      }
    }

    if(ans == 1){printf("Yes\n");}else{printf("No\n");}
    return 0;
  }


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

int main() {

    // 1. input.
    int n;
    cin >> n;
    
    // 2. output answer.
    for(int i = 1; i <= n; i++){
        if(i % 3 == 0){
            cout << " " << i;
        }
        if(i % 3 != 0){
            string s = to_string(i);
            for(int j = 0; j < s.size(); j++){
                if(s[j] == '3'){
                    cout << " " << i;
                    break;
                }
            }
        }
    }
    
    cout << endl;
    return 0;
    
}


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

int main() {
  string C1, C2;
  cin >> C1 >> C2;

  if (C1[0] == C2[2] && C1[1] == C2[1] && C1[2] == C2[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

using namespace std;
main(){
	int a;
	cin >> a;
	int s=a-1;
	int A[a];
	for(int c=0; c<a; c++){
		cin >> A[c];
	}
	while(s >=0){
		printf("%d",A[s]);
		if (s != 0){
		printf(" ");
	}
		s=s-1;
	}
	printf("\n");
}


Measured memory_bytes: 3156
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n;
  cin >> n;
  int odd = n/2 + n%2;
  double ans = (double)odd / (double)n;
  printf("%.10f",ans);
  return 0;
}

Measured memory_bytes: 256
X,Y = map(int,input().split()) #input number of animals and legs

crane_legs = 2
turtle_legs = 4

answer = "No"

for i in range(X+1): #X+1 because it will only consider 0,1,2
    remaining = X-i
    if crane_legs*i + turtle_legs*remaining == Y:
        answer = "Yes"
#Loop to check combinations of animals is correct

print(answer)

Measured memory_bytes: 8688
#include <iostream> 
#include <cstdlib>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++) 

int main() {
    int A, B;
    string op;
    cin >> A >> op >> B;
    if (op == "+") {
        cout << A+B << endl;
    } else cout << A-B << endl;
}



Measured memory_bytes: 256
from collections import defaultdict as dd
n = int(input())
ng = set(["AGC", "GAC", "ACG", "AGGC", "ACGC", "ATGC", "AGAC", "AGGC", "AGTC"])
#moji_count[str] => num_of_moji
moji_count = dd()
moji_count[""] = 1
cand = ["A", "G", "C", "T"]
mod = 10**9 + 7

for i in range(n):
    temp = dd(int)
    for base_moji, num_moji in moji_count.items():
        if len(base_moji) >= 4:
            base_moji = base_moji[1:]
        for add_moji in cand:
            new_moji = base_moji + add_moji
            for ng_word in ng:
                if ng_word in new_moji:
                    break
            else:
                temp[new_moji] += num_moji % mod
        moji_count = temp

print(sum(moji_count.values()) % mod)

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

total = sum(A)
A.sort()
A.reverse()
com = 0
for i in A:
    if(i < total/(4*m)):
        break
    else:
        com += 1
if(com>=m):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
int main(){
  int g,p,s;
  cin >> g >> p >>s;
  cout << (g * p) / 2 << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	if(n>=400&&n<=599) cout << 8 << endl;
	else if(n>=600&&n<=799) cout << 7 << endl;
	else if(n>=800&&n<=999) cout << 6 << endl;
	else if(n>=1000&&n<=1199) cout << 5 << endl;
	else if(n>=1200&&n<=1399) cout << 4 << endl;
	else if(n>=1400&&n<=1599) cout << 3 << endl;
	else if(n>=1600&&n<=1799) cout << 2 << endl;
	else if(n>=1800&&n<=1999) cout << 1 << endl;
	return 0;
} 

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	int N, M; cin >> N >> M;
	int sum = 0;

	REP(i,M){
		int A; cin >> A;
		sum += A;
	}
	
	int ans = 0;
	if(sum > N) ans = -1;
	else ans = N - sum;

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 3608
K,N=map(int,input().split())
A=list(map(int,input().split()))
a=A[N-1]-A[0]
for i in range(1,N):
    if i!=N-1:
        a=min(a,K+A[i-1]-A[i],K+A[i+1]-A[i])
    else:
        a=min(a,K+A[i-1]-A[i])
print(a)

Measured memory_bytes: 26436
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final int MAX = 1000000;

		Scanner sc = new Scanner(System.in);

		boolean primes[] = new boolean[MAX];
		primes[1] = true;
		for (int i = 2; i * i < MAX; i++) {
			for (int j = 2; i * j < MAX; j++) {
				primes[i * j] = true;
			}
		}

		while (true) {
			int a = sc.nextInt();
			int d = sc.nextInt();
			int n = sc.nextInt();
			if (a == 0)
				break;
			while (n != 0) {
				if (!primes[a])
					n--;
				a += d;
			}
			System.out.println(a - d); // while??§?¶??????????????????§
		}
	}
}

Measured memory_bytes: 30336
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int len = s.length();
    unordered_map<char, char> mp;
    unordered_set<char> st;
    for (int i = 0; i < len; i++) {
        char sc = s[i], tc = t[i];
        if (mp.find(sc) == mp.end() && st.find(tc) == st.end()) {
            mp[sc] = tc;
            st.insert(tc);
        } else {
            if (mp[sc] != tc) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main()
{
  int a,b,k;
  cin>>a>>b>>k;
  vector<int> s;
  for(int i=1;i<=min(a,b);i++)
    if(a%i==0&&b%i==0) s.push_back(i);
  sort(s.rbegin(),s.rend());
  cout<<s[k-1]<<"\n";
  
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  string s, t;
  cin >> s;
  cin >> t;
  cout << t << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 3e5;
const int mod = 998244353;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int arr[N];
int cnt[2000000];

void solve()
{
	int n;
	cin >> n;
	set<int> s;
	map<int, int> mp;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		mp[arr[i]]++;
		s.insert(arr[i]);
	}
	for(int i = 0; i < n; i++)
	{
		if(cnt[arr[i]]) continue;
		if(mp[arr[i]] > 1)
		{
			if(s.count(arr[i])) s.erase(arr[i]);
		}
		int no = arr[i];
		cnt[no] = 1;
		for(int j = no * 2; j <= 1e6; j += no)
		{
			if(s.count(j)) s.erase(j);
		}
	}
	cout << s.size() << endl;
}
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main() {
    ll n;cin >>n;
    vector<ll>p;
    vector<bool>isprime(n+1,true);
    for (ll i = 2; i <=n; ++i) {
        if(isprime[i]){
            p.push_back(i);
            for (ll j = i*2;j <=n; j+=i) {
                isprime[j]=false;
            }
        }
    }
    map <ll ,int>mp;
    for (int i = 2; i <=n; ++i) {
        for (auto prime:p) {
            int c=i;
            while(c%prime==0){
                mp[prime]++;
                c/=prime;
            }
        }
    }
    ll ans=1;
    for(auto co:mp){
        ans*=(co.second+1)%mod;
        ans%=mod;
    }
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
edges = [[] for i in range(n)]
counter = [0] * n
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x
def dfs(now, prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next, now)
dfs(0, -1)
print(*counter)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	string s; cin >> s;
	int n = sz(s);
	vector<int> v(n);
	for (int i = n - 1; i >= 0; i--) {
		v[i] = s.back() - '0';
		s.pop_back();
	}

	ll sum = 0;
	for (int i = 0; i < (1 << (n - 1)); i++) {
		ll cur = 0;
		for (int j = 0; j < n; j++) {
			cur = cur * 10 + v[j];
			if (i & (1 << j)) {
				sum += cur;
				cur = 0;
			}
		}
		sum += cur;
	}

	die(sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;
int gcd(int x,int y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
int lcm(int x, int y)
{
	return (x * y / gcd(x, y));
}
 
signed main(){
	IOS();
	cin>>A>>B>>C>>D;
	int c = (B/C*C - (A+C-1)/C*C)/C+1;
	int d = (B/D*D - (A+D-1)/D*D)/D+1;
	int g = lcm(C,D);

	int cd = (B/g*g - (A+g-1)/g*g)/g+1;
	cout<<B-A+1-(c+d-cd)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int n, C;
bool flag = false;
int total = 0;
int dp[31][100002] = {};
int x[100002] = {};
int s[100001];
int t[100001];
int c[100001];

int main(void) {
	

	cin >> n >> C;

	FOR(i, 1, n) {
		cin >> s[i] >> t[i] >> c[i];
		//if (c[i] == 1) {
			dp[c[i]][s[i]]++;
			dp[c[i]][t[i]+1]--;
		//}
		//else {
			//dp[c[i]][s[i]-1]++;
			//dp[c[i]][t[i]]--;
		//}
		

	}

	FOR(i, 1, C) {
		FOR(t, 1, 100001) {
			dp[i][t] += dp[i][t - 1];
			/*if (dp[i][t] == 1 && flag == false) {
				cout << "a " << t << endl;
				dp[i][t - 1]++;
				flag == true;
			}
			if (flag == true && dp[i][t] <= 0) {
				flag == false;
			}*/
		}
		FOR(t, 1, 100001) {
			if (dp[i][t] >= 2) {
				dp[i][t] = 1;
			}
		}
	}

	FOR(i, 1, C) {
		FOR(t, 1, 100001) {
			x[t] += dp[i][t];
			if (x[t] > total) {
				total = x[t];
			}
		}
	}

	cout << total << endl;
	return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <functional>

using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	vector<int> x;
	cin >> n >> m;
	x.resize(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());
	vector<int> dist(m - 1);
	for (int i = 0; i < m - 1; i++) {
		dist[i] = -x[i] + x[i + 1];
	}
	sort(dist.begin(), dist.end());
	int sum = 0;
	for (int i = 0; i < m - n; i++) {
		sum += dist[i];
	}
	cout << sum;

	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
long long a[100010];
//本层可拓展节点的个数 
long long canExtend[100010];
//实际拓展了多少节点 
long long realNode[100010];

bool doExtend() {
	canExtend[0] = 1;
	if (canExtend[0] < a[0]) {
		return false;
	}
	
	for (int i = 0 ; i < n - 1 ; i++) {
		canExtend[i] = canExtend[i] - a[i];
		canExtend[i + 1] = canExtend[i] * 2;
		if (canExtend[i + 1] >= 1152921504606846976) {
			canExtend[i + 1] = 1152921504606846976;
		}
		if (canExtend[i + 1] < a[i + 1]) {
			return false;
		}
	}
	
	return true;
}


int main()
{
	scanf("%d", &n);
	n++;
	
	for (int i = 0 ; i < n ; i++)
		scanf("%lld", &(a[i]));
		
	if (doExtend() == false) {
		printf("-1\n");
		return 0;
	}
	
	long long sum = 0;
	sum = sum + a[n - 1];
	if (canExtend[n - 1] > a[n - 1])
		realNode[n - 1] = a[n - 1];
	else
		realNode[n - 1] = canExtend[n - 1];
		
	for (int i = n - 2 ; i >= 0 ; i--) {
		if (canExtend[i] > realNode[i + 1]) {
			canExtend[i] = realNode[i + 1];			
		} else if ((canExtend[i] * 2) < realNode[i + 1]) {
			printf("-1\n");
			return 0;
		}
			
		realNode[i] = a[i] + canExtend[i];
		sum = sum + realNode[i];
	}
	
	printf("%lld\n", sum);
	
	return 0;
}


Measured memory_bytes: 4072
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    string s;
    cin >> s;
    vector<bool> used(26, false);
    for (auto c : s)
        used[c - 'a'] = true;

    if (s.size() <= 25) {
        cout << s;
        for (int i = 0; i < 26; i++) {
            if (!used[i]) {
                cout << (char)(i + 'a') << endl;
                return 0;
            }
        }
    }
    else {
        for (int i = 25; i >=0; i--) {
            int minidx = -1;
            for (int j = i + 1; j < 26; j++) {
                if (s[i] < s[j]) {
                    if (minidx == -1 || s[minidx] > s[j]) {
                        minidx = j;
                    }
                }
            }
            if (minidx == -1)
                continue;
            swap(s[i], s[minidx]);
            cout << s.substr(0, i + 1) << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define what_is(x) cerr<<#x <<" is "<<x<<endl;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define pi 2*acos(0.0)
//use emplace_back() instead of push_back()
template<typename T>
void print(T t)
{
    for(const auto& e:t)cout<<e<<" ";
    cout<<endl;
}
ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll x,n,y;
    cin>>x>>n;
    ll pp,nn;
    pp=nn=x;
    map<ll,ll>a;
    for(ll i=0;i<n;i++)
    {
        cin>>y;
        a[y]++;
    }
    while(1)
    {
        if(a[nn]==0)
        {
            cout<<nn<<endl;
            break;
        }
        if(a[pp]==0)
        {
            cout<<pp<<endl;
            break;
        }
        pp++;
        nn--;
    }
    return 0;
}



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



int main(){
	int a,x,y;
	for(int i=0;i<6;i++){
		cin >> a;
		if(i==0) x=a;
		if(i==4) y=a;
	}
	if(y-x>a) cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX_N 50001
using namespace std;
int n, m;
int dp[MAX_N];//I think that when i use dp, using one demention array is too difficult to coding for me.


int knapsack() {
    //cout << "let's napsack!" << endl;
    //initialize
    memset(dp, 0, sizeof(dp));
    
    //input
    int value[m];
    for(int r = 0; r < m; r++){ cin >> value[r]; dp[value[r]]++; }
    
    
    //calculate
    //for(int r = 0; r < m; r++) { //Usually, I confuse about roop's end. -> unnecessary
        for(int c = 1; c < n; c++) {
            //This 'if' statement's contents usually complecated
            if(dp[c] != 0) {
                for(int k = 0; k < m; k++) {
                    if(c + value[k] > n) continue;
                    if(dp[c + value[k]] == 0){ dp[c + value[k]] = dp[c] + 1; continue;}
                    dp[c + value[k]] = min(dp[c + value[k]], dp[c] + 1);
                }
            }
        }
    //}
    return(dp[n]);
}

int main(void) {
    //cout << "start" << endl;
    cin >> n >> m;
    
    cout << knapsack() << endl;
    return(0);
}

Measured memory_bytes: 1368
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = N/100;
		int b = (N - a*100)/10;
		if (a > b) {
			System.out.println(a*100 + a*10 + a);
		} else if(a == b) {
			int c = N -a*100 -b*10;
			if (b >= c) {
				System.out.println(a*100 + a*10 + a);
			}else {
				a ++;
				System.out.println(a*100 + a*10 + a);
			}
		} else {
			a++;
			System.out.println(a*100 + a*10 + a);
		}
	}
}


Measured memory_bytes: 23764
N = int(input())
P_list = [int(_) for _ in input().split()]

count = 0
min_value_dic = {}
min_value_so_far =1e6
for i in range(N):
    if P_list[i] < min_value_so_far:
        min_value_dic[i] = P_list[i]
        min_value_so_far = P_list[i]
    else:
        min_value_dic[i] = min_value_so_far

# print(min_value_dic)

for i in range(N):
    if P_list[i] <= min_value_dic[i]:
        count +=1

print(count)

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

int main()
{
  int n, i, count = 0;
  int a[10000];

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
  }

  for(i=0; i<n; i++){
    while(a[i]%2==0){
      count++;
      a[i] = a[i]/2;
    }
  }

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


Measured memory_bytes: 256
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
def ggcd(a,b):
    if(b==0):
        return a
    return ggcd(b,a%b)
import math
import fractions
import collections
import itertools
import pprint
N=int(input())
l1=[]
adivb=[]
bis0=0
bdiva=[]
ais0=0
both0=0
p=10**9+7
fish=[list(map(int,input().split())) for _ in range(N)]
fishcomp=[]
d={}
for i in range(N):
    #イメージ的にはa/bを格納していく感じ
    #ai/bi==-bj/ajならダメ
    a=fish[i][0]
    b=fish[i][1]
    g=ggcd(abs(a),abs(b))
    if g!=0:        #ggcdの定義よりa=b=0なら0になりそう(a=0,b!=0ならb,逆もしかり)
        a=a//g
        b=b//g
    #ここらへんで、a,bをそのgcdで割ることによる正規化が完了しているはず
    if b<0:
        a=-a
        b=-b
    #b<0の時に強制的にbを正の値に変換しても影響はない(これを噛ませると後々嬉しい)
    if (a!=0)or(b!=0):
        if d.get(a)==None:
            d[a]={}
            d[a][b]=1
        else:
            if d[a].get(b)==None:
                d[a][b]=1
            else:
                val=d[a].get(b)
                d[a][b]=val+1
        fishcomp.append([a, b])
    else:
        both0=both0+1
#print(d)
#print(fishcomp)
fishcomp=list(map(list,set(map(tuple,fishcomp))))   #二次元配列のset(地味にreferenceがないやつ)
#print(fishcomp)
length=N-both0
sets=[]
#以下ではai/bi==-bj/ajの組みを探している。d[a][b]の個数とd[-b][a]の個数のみ探せば良い
#実はbを正に固定したのがここで生きる。[a b]→[-b a][b,-a]と2つ候補が出るが、
#a>0なら[-b a]に、a<0なら[b,-a]の一つになり、a=0なら[±b 0]だが、これは上で一括して1にまとめているため無問題
#同時にd[a][b]と合わせてダメなのはd[b][-a],d[-b][a]であるが、一方のみ取れば大丈夫
for i in fishcomp:
    a=i[0]
    b=i[1]
    val1=d[a][b]
    #print(a,b,val1)
    if d.get(-b)!=None:
        if d[-b].get(a)!=None:
            val2=d[-b][a]
            sets.append([val1,val2])
            length=length-(val2+val1)
#print(sets,length)
pro=1
for i in sets:
    pro=(pro*(pow(2,i[0],p)+pow(2,i[1],p)-1))%p
#print(pro)
print((pow(2,length,p)*pro-1+both0)%p)

Measured memory_bytes: 228404
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, a, b;
  cin >> n >> a >> b;

  ll yuta = 0;
  repLRE(i, 1, n) {
    string s = to_string(i);
    ll su = 0;
    rep(j, (ll)s.size()) { su += s[j] - '0'; }
    if (a <= su && su <= b) yuta += i;
  }

  cout << yuta << endl;

  return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

int extgcd(int a, int b, int &x, int &y) {
  int d = a;
  if (b != 0) {
    d = extgcd(b, a%b, y, x);
    y -= (a/b)*x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

// m is a large prime integer. Usually 1000000007 is used.
int mod_inverse(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x%m)%m;
}

signed main() {

  int n, x; cin >> n >> x;
  vector<int> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  //s.erase(unique(s.begin(), s.end()), s.end());

  vector<ll> fact(n+1);
  fact[0] = 1;
  for(int i=1; i<=n; i++) {
    fact[i] = fact[i-1]*i;
    fact[i] %= mod;
  }
  vector<ll> modinv(n+1);
  for(int i=1; i<=n; i++) {
    modinv[i] = mod_inverse(i, mod);
  }

  map<int, ll> mp;
  map<int, ll> mp2;

  rep(i, n) {
    int r = x%s[i];
    mp[-r] += fact[n-1];
    mp[-r] %= mod;
    //debugln(r);
  }

  bool flag = true;
  while(flag) {
    flag = false;
    for(auto e: mp) {
      int r = -e.first;
      auto it = upper_bound(s.begin(), s.end(), r);
      auto k = distance(s.begin(), it);
      if (k==0) {
        mp2[e.first] += mp[e.first];
        mp2[e.first] %= mod;
        continue;
      }
      for(int i=0; i<k; i++) {
        flag = true;
        int pos = -(r%s[i]);
        mp2[pos] += e.second * modinv[k];
        mp2[pos] %= mod;
        //debug(pos);debugln(mp2[pos]);
      }
    }
    mp = mp2;
    mp2.clear();
  }

  ll ans = 0;
  for(auto e: mp) {
    ans += (-e.second*e.first);
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std; 
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> Graph(n);
  int a, b;
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    Graph[b-1].emplace_back(a-1);
    Graph[a-1].emplace_back(b-1);
  }
  queue<int> q;
  vector<int> route(n, -1);
  route[0] = 0;
  q.push(0);
  while(!q.empty()){
    int now = q.front();
    q.pop();
    for(int next : Graph[now]){
      if(route[next] == -1){
        q.push(next);
        route[next] = now;
      }
    }
  }
  for(int i = 0; i < n; i++){
    if(route[i] == -1) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  for(int i = 0; i < n-1; i++){
    cout << route[i+1] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 10220
n = int(input())
*a, = map(int, input().split())

s = 0
ans = [0, 0]
for i in range(n):
    s += a[i]
    if (i+1)%2 == 0 and s >= 0:
        ans[0] += s+1
        s -= s+1
    elif (i+1)%2 == 1 and s <= 0:
        ans[0] += abs(s)+1
        s += abs(s)+1

s = 0
for i in range(n):
    s += a[i]
    if (i+1)%2 == 1 and s >= 0:
        ans[1] += s+1
        s -= s+1
    elif (i+1)%2 == 0 and s <= 0:
        ans[1] += abs(s)+1
        s += abs(s)+1

print(min(ans))


Measured memory_bytes: 14468
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class DAG:
    def __init__(self, n, AB):
        self.n = n
        self.G = [[] for _ in range(n)]
        self.revG = [[] for _ in range(n)]
        self.AB = AB
        for a, b in AB:
            self.G[a].append(b)
            self.revG[b].append(a)

    def scc(self):
        visited = [False] * self.n
        order = []
        for i in range(self.n):
            if visited[i]: continue

            q = deque([i])
            visited[i] = True
            while q:
                v = q[-1]
                for u in self.G[v]:
                    if not visited[u]:
                        q.append(u)
                        visited[u] = True
                        break
                else:
                    #全て訪問済みの時
                    q.pop()
                    order.append(v)

        visited = [False] * self.n
        scc = []
        for i in order[::-1]:
            if visited[i]: continue
            tmp = [i]
            visited[i] = True
            q = deque([i])

            while q:
                v = q.pop()
                for u in self.revG[v]:
                    if visited[u]: continue
                    visited[u] = True
                    tmp.append(u)
                    q.append(u)
            scc.append(tmp)

        return scc



def main():
    N, M = LI()
    AB = LIR(M)
    g = DAG(N, AB)
    scc = g.scc()
    print(len(scc))
    for es in scc:
        print(len(es), *es)


if __name__ == '__main__':
    main()

Measured memory_bytes: 290372
#include <cstdio>
using namespace std;

const int S = 10000;
int N, dp[S+10], ans;
int main() {
    scanf("%d", &N);

    dp[0] = 1;
    for(int i=0; i<N; i++) {
        int point; scanf("%d", &point);

        for(int j=S; j>=point; j--) {
            dp[j] |= dp[j-point];
            if(dp[j] && ans < j && j%10) ans = j;
        }
    }

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

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    vector<pair<int, int>> cb(m); 
    int bi, ci;
    for (int i = 0; i < m; i++)
    {
        cin >> bi >> ci;
        cb.at(i) = make_pair(ci, bi);
    }
    
    sort(a.begin(), a.end());
    sort(cb.begin(), cb.end());
    reverse(cb.begin(), cb.end());

    int b, c;
    int right = 0;
    bool flag;
    for (int i = 0; i < m; i++)
    {
        flag = false;
        b = cb.at(i).second;
        c = cb.at(i).first;

        for (int j = 0; j < b; j++)
        {
            if (a.at(min(right + j, n - 1)) >= c) {
                right += j;
                flag = true;
                break;
            }

            a.at(min(right + j, n - 1)) = c;
        }
        if (!flag) right += b;
    }
    
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += (long long)a.at(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h> 
using namespace std; 
void CountTriangles(int n,int a[])
{  
    sort(a,a+n);
    int count = 0; 
    for( int i = n-1; i >= 1; i--)
    { 
        int l = 0, r = i-1; 
        while( l < r)
        { 
            if( a[l] + a[r] > a[i])
            { 
                // If it is possible with a[l], a[r] 
                // and a[i] then it is also possible 
                // with a[l+1]..a[r-1],a[r] and a[i] 
                count += r - l ;  
  
                //checking for more possible solutions 
                r--;   
            } 
            else 
  
                // if not possible check for  
                // higher values of arr[l] 
                l++;   
        } 
    } 
    cout<<count; 
} 
int main()
{ 
    int n,i,x;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
      cin>>a[i];
    }
    CountTriangles(n,a); 
    
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N;cin>>N;
	int A=0,B=0,BA=0;
	int base=0;
	rep(i,N){
		string s;cin>>s;
		if(s[0]=='B'&&s.back()=='A')BA++;
		else if(s[0]=='B')B++;
		else if(s.back()=='A')A++;

		rep(j,s.size()-1){
			if(s.substr(j,2)=="AB")base++;
		}
	}

	int ans=base;
	if(A==0&&B==0){
		ans+=max(BA-1,0ll);
	}
	else{
		ans+=min(A,B)+BA;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    
    if(A == B){
        if(A != C){
            cout << "Yes" << endl;
            return 0; 
        }
    }

    if(A == C){
        if(A != B){
            cout << "Yes" << endl;
            return 0;
        }
    }

    if(B == C){
        if(A != B){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long N, M;
	cin >> N >> M;

	long long ans = 0;
	if(N > M/2){
		ans =  M / 2;
	}
	else{
		ans = (M + 2 * N) / 4;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
   if (s == "SUN") cout << 7 << endl;
   else if (s == "MON") cout << 6 << endl;
   else if (s == "TUE") cout << 5 << endl;
   else if (s == "WED") cout << 4 << endl;
   else if (s == "THU") cout << 3 << endl;
   else if (s == "FRI") cout << 2 << endl;
   else if (s == "SAT") cout << 1 << endl;
}


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

using namespace std;

map<long long, long long> mem;

long long dp(long long h) {
    if (h == 1) {
        return 1;
    }
    if (mem.count(h) == 0) {
        mem[h] = 2*dp(h/2) + 1;
    }
    return mem[h];
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long h;
    cin >> h;
    cout << dp(h) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
typedef __int128 LG;
const int N=105,mod=998244353;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int n;
char s[N];
int a[N];
int pw2[N];
map <LG,int> dp,vis;
void write(LG x){
	if (x>9)
		write(x/10);
	putchar('0'+x%10);
}
LG Get(LG a,int L,int R){
	return a>>L&(((LG)1<<(R-L+1))-1);
}
int DP(LG K){
	if (vis[K])
		return dp[K];
	vis[K]=1;
	int ans=0,k=K>>n;
	if (!k)
		return dp[K]=1;
	LG S=Get(K,0,n-1);
	For(i,0,k-1)
		if (S>>i&1)
			ans++;
	ans=pw2[ans];
	int cnt=0;
	For(i,0,k-1){
		For(j,i,k-1){
			int len=j-i+1;
			if (j+len>k-1)
				break;
			LG v=Get(S,i,j);
			for (int t=i+len;t+len-1<k;t+=len){
				v&=Get(S,t,t+len-1);
				Add(ans,(LL)pw2[cnt]*DP(v|(LG)len<<n)%mod
						*DP(Get(S,t+len,k-1)|(LG)(k-(t+len))<<n)%mod);
			}
		}
		if (S>>i&1)
			cnt++;
	}
	return dp[K]=ans;
}
int main(){
	cin>>s;
	n=strlen(s);
	pw2[0]=1;
	For(i,1,n)
		pw2[i]=Add(pw2[i-1]<<1);
	For(i,0,n-1)
		a[i]=s[i]-'0';
	LG S=0;
	For(i,0,n-1)
		S|=(LG)a[i]<<i;
	S|=(LG)n<<n;
	write(DP(S));
	puts("");
	return 0;
}

Measured memory_bytes: 6528
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

S = input()
T = input()
L=len(S)

dds = defaultdict(int)
ddt = defaultdict(int)
for i in range(L):
  s = S[i]
  t = T[i]
  if dds[s] == 0:
    dds[s] = t
  else:
    if dds[s] == t:
      continue
    else:
      print("No")
      sys.exit()
      
  if ddt[t] == 0:
    ddt[t] = s
  else:
    if ddt[t] == s:
      continue
    else:
      print("No")
      sys.exit()
      
print("Yes")
      
        

Measured memory_bytes: 4912
use std::str::FromStr;
use std::fmt::Debug;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<usize>();
    let n = line[0];
    let m = line[1];

    let mut diffs: Vec<i64> = Vec::new();
    let mut x: Vec<i64> = read_as_vec();
    x.sort();
    
    for i in 1..x.len(){
        diffs.push(x[i] - x[i-1]);
    }
    diffs.sort_by_key(|elem| -*elem);
    let diff_sum: i64 = diffs.iter().sum();
    //println!("{:?}", diffs);
    //println!("{:?}", diff_sum);
    let wasted_cost = diffs.into_iter().take(n-1).sum::<i64>();
    println!("{}", diff_sum - wasted_cost);
        
}


Measured memory_bytes: 8444