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

const int maxn=500010, inf=1e9;
struct edge{int too, pre;}e[maxn];
int n, m, x, y, tot;
int fa[maxn], a[maxn], b[maxn], last[maxn], pos[maxn];
ll ad[maxn], sum[maxn];
bool v[maxn];
template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;
}
inline void add(int x, int y){e[++tot]=(edge){y, last[x]}; last[x]=tot;}
inline bool cmp(int x, int y){return a[x]<a[y];}
int gf(int x){return fa[x]==x?x:fa[x]=gf(fa[x]);}
int main()
{
	read(n); read(m);
	for(int i=1;i<=n;i++) read(a[i]), read(b[i]), a[i]=max(a[i]-b[i], 0);
	for(int i=1;i<=m;i++) read(x), read(y), add(x, y), add(y, x);
	for(int i=1;i<=n;i++) pos[i]=i, fa[i]=i, ad[i]=a[i], sum[i]=b[i];
	sort(pos+1, pos+1+n, cmp);
	for(int i=1;i<=n;i++)
	{
		int x=pos[i]; v[x]=1;
		for(int j=last[x], too;j;j=e[j].pre)
		if(v[too=e[j].too])
		{
			int fx=gf(x), fy=gf(too);
			if(fx==fy) continue;
			sum[fx]+=sum[fy]; fa[fy]=fx;
			ad[fx]=min(ad[fx], ad[fy]+max(0ll, a[x]-ad[fy]-sum[fy]));
		}
	}
	printf("%lld\n", sum[pos[n]]+ad[pos[n]]);
	return 0;
}

Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
         
    int main() {
        int N;
        cin >> N;

        for(int i = 1; i < 10; i++){
            for(int j = 1; j < 10; j++){
                if(i*j == N){
                cout << "Yes" << endl;
                return 0;
                }
            }
        }

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

Measured memory_bytes: 256
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                sc.nextLine();
                for(int i = 0 ; i < n ; i++){
                        System.out.println(sc.nextLine().replaceAll("Hoshino", "Hoshina"));
                }   
                sc.close();
        }   
}

Measured memory_bytes: 12000
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int x; cin >> x;
  if (x < 600) cout << 8 << '\n';
  else if (x < 800) cout << 7 << '\n';
  else if (x < 1000) cout << 6 << '\n';
  else if (x < 1200) cout << 5 << '\n';
  else if (x < 1400) cout << 4 << '\n';
  else if (x < 1600) cout << 3 << '\n';
  else if (x < 1800) cout << 2 << '\n';
  else if (x < 2000) cout << 1 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

// array pointer = *a, num of element = n, key key
int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]) % mod;
        }
    }
}*/
long long mod = 1000000007;

//x ^ n
long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}


int x[55];
int y[55];
int cx[55];
int cy[55];

int main(void){
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++){
        scanf("%d %d", &x[i], &y[i]);
        cx[i] = x[i];
        cy[i] = y[i];
    }
    qsort(cx, n, sizeof(int), ascending_compare);
    qsort(cy, n, sizeof(int), ascending_compare);
    long long ans = 4000000000000000000;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            for (int o = 0; o < n; o++){
                for (int l = o+1; l < n; l++){
                    int hx = cx[j];
                    int lx = cx[i];
                    int hy = cy[l];
                    int ly = cy[o];
                    int cnt = 0;
                    for (int m = 0; m < n; m++){
                        if (lx <= x[m] && hx >= x[m] && ly <= y[m] && hy >= y[m]) cnt++;
                    }
                    if (cnt >= k) ans = ans>llabs(hx-lx)*llabs(hy-ly)?llabs(hx-lx)*llabs(hy-ly):ans;
                }
            }
        }
    }


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

}


Measured memory_bytes: 128
s = input()
q = int(input())

sei_or_gyaku = 1
mae = ''
ato = ''

for i in range(q):
    sirei = input()
    if len(sirei) == 1:
        ti = int(sirei)
        sei_or_gyaku *= -1
    else:
        ti, fi, ci = map(str, sirei.split())
        ti, fi = int(ti), int(fi)
        if fi == 1:
            if sei_or_gyaku == 1:
                mae += ci
            else:
                ato += ci
        else:
            if sei_or_gyaku == 1:
                ato += ci
            else:
                mae += ci

mae = mae[::-1]
ans = mae + s + ato
if sei_or_gyaku == 1:
    print(ans)
else:
    print(ans[::-1])

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

using namespace std;

int arr[101];

int main(){
	int n;
	cin>>n;
	int count=0;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
		if(arr[i]%2==1&&i%2==1){
			count++;
		}
		
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int main(){
	int a;
	double b,c;
	while(scanf("%d,%lf,%lf",&a,&b,&c)!=EOF){
		if(25<=(b/(c*c)))cout<<a<<endl;
	}
}

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

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll N, M;
    cin >> N >> M;
    vector<vector<int>> a(N, vector<int>(N,0));
    rep(i, M) {
        int ai, bi;
        cin >> ai >> bi;
        a[ai-1][bi-1] = 1;
        a[bi-1][ai-1] = 1;
    }
    vector<int> node;
    FOR(i, 1, N) node.push_back(i);
    int ans=0;
    do{
        int prev=0;
        int flag=1;
        for(auto &x : node){
            if(!a[prev][x]){
                flag=0;
                break;
            }
            prev=x;
        }
        if(flag) ans++;
    }while(next_permutation(all(node)));
    out(ans);
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	while (a != 0 || b != 0) {
		if(a>b)
		swap(a, b);
		cout << a << " " << b << endl;
		cin >> a >> b;
	}
	return 0;
}

Measured memory_bytes: 3000
def gcd(a, b):
    if(b == 0):
        return a
    else:
        return gcd(b, a % b)

def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
a = input().split()

for i in range(n):
    a[i] = int(a[i])

l = 1
for i in range(n):
    l = lcm(l, a[i])

l -= 1
s = 0

for i in range(n):
    s += l % a[i]

print(s)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int md = 1e9+7;
const int mx = 2005;
int n, m, s[mx] = {-1}, t[mx] = {-2};
long long dp[mx][mx];
int main(){
    scanf("%d%d", &n, &m);
    rep(i,n) scanf("%d", s+i+1);
    rep(i,m) scanf("%d", t+i+1);
    rep(i,n+1) dp[i][0] = 1;
    rep(i,m+1) dp[0][i] = 1;
    for(int i = 1; i <= n; i++){
        long long tmp = 0;
        for(int j = 1; j <= m; j++){
            if(s[i] == t[j]) (tmp += dp[i-1][j-1]) %= md;
            dp[i][j] = (dp[i-1][j] + tmp) % md;
        }
    }
    printf("%lld\n", dp[n][m]);
}

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

using namespace std;

const int INF = 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N;
        cin >> N;
        if(!N) break;
        vector<int> field(N);
        for(int i = 0; i < N; ++i) {
            int pat = 0;
            for(int j = 0; j < N; ++j) {
                int v;
                cin >> v;
                pat <<= 1;
                pat |= v;
            }
            field[i] = pat;
        }
        vector<int> myons; // ティツ。ツ古」ツ?ォテ」ツ?凝」ツ?凝」ツつ砧yon
        for(int c = 0; c < N; ++c) { // テ・ツ渉ウテァツォツッテ」ツ?ョテ、ツスツ催ァツスツョ
            for(int w = 1; w <= N-c; ++w) {
                int mask = ((1<<w)-1) << c;
                myons.push_back(mask);
                //cout << mask << endl;
            }
        }
        const int M = myons.size();
        // 0: prev
        // 1: cur
        vector<int> valid_pats[2];
        vector<int> dp[2];
        dp[0].resize(1<<M, INF);
        dp[1].resize(1<<M, INF);
        for(int r = 0; r < N; ++r) {
            valid_pats[1].clear();
            fill(dp[1].begin(), dp[1].end(), INF);
            for(int pat = 0; pat < (1<<M); ++pat) {
                int mask = 0;
                for(int i = 0, ord = 1; i < M; ++i, ord <<= 1) {
                    if(pat & ord) mask ^= myons[i];
                }
                if(mask == field[r]) {
                    // Valid pattern
                    int cost = INF;
                    const int bits = __builtin_popcount(pat);
                    if(r != 0) {
                        for(vector<int>::iterator it = valid_pats[0].begin(); it != valid_pats[0].end(); ++it) {
                            cost = min(cost, dp[0][*it] + bits - __builtin_popcount(pat & *it));
                        }
                    } else {
                        cost = bits;
                    }
                    //cout << r << ' ' << pat << ' ' << cost << endl;
                    dp[1][pat] = cost;
                    valid_pats[1].push_back(pat);
                }
            }
            valid_pats[0].swap(valid_pats[1]);
            dp[0].swap(dp[1]);
        }
        int ans = INF;
        for(vector<int>::iterator it = valid_pats[0].begin(); it != valid_pats[0].end(); ++it) {
            ans = min(ans, dp[0][*it]);
        }
        for(int i = 0; i < ans; ++i) {
            cout << "myon";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i < n; i++)
#define ALL(n) begin(n), end(n)

int main()
{
  vector<int> n ={
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  };
  int k;
  cin >> k;

  cout << n[k-1];
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
vector<int> v;
int dp[100005];
int DP(int x){
    if(x==0)return 0;
    if(x<0)return 1;
    if(dp[x]!=-1)return dp[x];
    int ok=0;
    for(auto it:v){
        if(DP(x-it)==0)
        ok=1;
    }
    return dp[x]=ok;
}
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        v.pb(x);
    }
    MEMS(dp);
    if(DP(k)){
        printf("First\n");
    }
    else{
        printf("Second\n");
    }
}


Measured memory_bytes: 4352
a,b,c,d = map(int,input().split())
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


def lcm(a, b):
    return a * b // gcd(a, b)

ans = b - (b//c + b//d - b//lcm(c, d))
ans1 = (a-1) - ((a-1)//c + (a-1)//d - (a-1)//lcm(c,d))

print(ans - ans1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef double ld;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f,mo=1e9+7;
template<typename A,typename B>inline bool upmx(A&x,const B&y){return x<y?x=y,1:0;}
template<typename A,typename B>inline bool upmn(A&x,const B&y){return x>y?x=y,1:0;}
template<typename T>inline T gcd(T x,T y){for(;y;swap(x,y))x%=y;return x;}
inline int Pow(int a,int b,int p=mo){int r=1;for(;b;b>>=1,a=1ll*a*a%p)if(b&1)r=1ll*r*a%p;return r;}
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
const int N=1e5+11;
int n;
ll a[N];
int b[N];
ll f[N],g[N],ff[N],gg[N];
ll C;
int read()
{
    char ch=getchar();int f=0,x=1;
    while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
    return f*x;
}
int main(){
	n=read();scanf("%lld",&C);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		b[i]=read();
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		f[i]=f[i-1]+b[i];
		
	}
	for(int i=1;i<=n;i++)f[i]-=a[i];
	for(int i=1;i<=n;i++){
		ff[i]=max(f[i],ff[i-1]);
	}
	ans=ff[n];
	for(int i=n;i;i--){
		g[i]=g[i+1]+b[i];
		
	}
	for(int i=n;i;i--){
		g[i]-=(C-a[i]);
		upmx(ans,g[i]);
		upmx(ans,g[i]-(C-a[i])+ff[i-1]);
	}
	for(int i=n;i;i--)gg[i]=max(gg[i+1],g[i]);
	for(int i=1;i<=n;i++){
		upmx(ans,f[i]-a[i]+gg[i+1]);
	}
	cout<<ans;
}


Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    ll ans[ll(1e5) + 1] = {};
    ll bad[ll(1e5) + 1] = {};
    ll n,m;
    cin >> n >> m;
    for (ll i=0;i<m;i++){
        ll tmp;
        cin >> tmp;
        bad[tmp] = -1;
    }
    ans[0] = 1;
    if(bad[1] != -1){
        ans[1] = 1;
    }
    for(ll i=2;i<=n;i++){
        if(bad[i] != -1) {
            ans[i] = (ans[i - 2] + ans[i - 1]) % mop;
        }
//        cout << ans[i] << endl;
    }
    cout << ans[n] << endl;
}

Measured memory_bytes: 1792
n, k = map(int, input().split())
mod = 10**9 + 7

tmp = sum(range(k-1))

ans = 0
for x in range(k, n+2):
  ans += x*n + 1
  if x >= 2:
      tmp += x-1
      ans -= 2*tmp
  ans %= mod

print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
long long mod_pow(long long x, long long n, long long mod) {// O(log(n))
    long long res = 1;
    while (n > 0) {//繰り返し二乗法
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元を計算する
long long mod_inv(long long x, long long mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}
long long find_numerator(long long n,long long a){
    long long p=1;
    for(long long i=0;i<=(a-1);i++){
        (p*=(n-i)) %=MOD;
    }
    return p;
}
long long find_denominator(long long n, long long a){
    long long q=1;
    for(long long i=1;i<=a;i++){
        (q*=i) %=MOD;
    }
    return q;
}
int main() {
long long n,a,b;
cin >> n >> a >> b;
long long all=mod_pow(2,n,MOD) - 1 + MOD;
all%=MOD;
long long c,d,e,f;
c=find_numerator(n,a);
d=find_denominator(n,a);
e=find_numerator(n,b);
f=find_denominator(n,b);
d=mod_inv(d,MOD);
f=mod_inv(f,MOD);
long long flowerofa=c*d%MOD;
long long flowerofb=e*f%MOD;
long long ans=(all - flowerofa - flowerofb + MOD + MOD)%MOD;
cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        
        for(int i = 0;i<s.length();i++){
            char c = s.charAt(i);
            if(Character.isUpperCase(c)){
            c += 32;
            System.out.print(c);
        }else if(Character.isLowerCase(c)){
            c -= 32;
                System.out.print(c);
            }
            else
                System.out.print(c);
               }
        System.out.println();
        sc.close();
    }
}



Measured memory_bytes: 26772
import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		if(A + B <= K) {
			A = 0;
			B = 0;
		}else if(A <= K && K < A + B) {
			B = A + B - K;
			A = 0;
		} else {
			A = A - K;
		}
		System.out.println(A + " " + B);
	}
}

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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

using namespace std;

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

const int MOD = 1e9 + 7;

void add_self(int& a, int b)
{
	a += b;
	if (a >= MOD)
	{
		a -= MOD;
	}
}

void sub_self(int& a, int b)
{
	a -= b;
	if (a < 0)
	{
		a += MOD;
	}
}

set<ll> s;
ll maxn = 400000000;
void dfs(ll x) {
	if (s.find(x) != s.end())
		return;
	s.insert(x);
	if (x >= maxn)
		return;
	if (x == 0) {
		for (int i = 1; i <= 9; ++i)
			dfs(i);
	}
	else {
		int digit = x % 10;
		if (digit > 0)
			dfs(x * 10 + (digit - 1));
		dfs(x * 10 + digit);
		if (digit < 9)
			dfs(x * 10 + (digit + 1));
	}
}
 

int main()
{
//#ifndef ONLINE_JUDGE
//	(void)freopen("input.txt", "r", stdin);
//	(void)freopen("output.txt", "w", stdout);
//#endif
	FAST_IO;

	int k;
	cin >> k;
	dfs(0);
	while (k) {
		s.erase(s.begin());
		--k;
	}
	cout << *s.begin();
	return 0;

}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;
using Graph = vector<vector<int>>;
const int MAX = 510000;
const int MOD = 1000000007;
 const int NINE=1000000000;
 
 
int main(){
ll a;
  cin>>a;
  string b;
cin>>b;
  ll c=b.size();
if(c<=a) cout<<b;
  else {
  rep(i,a){
  cout<<b.at(i);
  
  }
  cout<<"...";
  
  }
}

Measured memory_bytes: 3628
A, B, C, D = map(int, input().split())

cc = B // C - (A-1) // C
dd = B // D - (A-1) // D

import math
l = C * D // math.gcd(C, D)
cd = B // l - (A-1) // l

print(B - A + 1 - (cc + dd - cd))

Measured memory_bytes: 61984
n = int(input())
s = input()
def output():
    left, right = 0, n//2+1
    while left < right-1:
        mid = (left+right)//2
        if check(mid):
            left = mid
        else:
            right = mid
    return left
def check(x):
    hashes = set()
    for i in range(n - 2*x + 1):
        hashes.add(s[i: i+x])
        if s[i+x: i+2*x] in hashes:
            return True
    return False
print(output())

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  string s1; cin >> s1;
  string s2 = s1;
  int sz = s1.size();
  int ans1 = 0, ans2 = 0;
  char now1 = '0';
  char now2 = '1';
  for(int i=0;i<sz;++i) {
    if(s1[i] != now1) {
      ans1++;
    }
    if(s2[i] != now2) {
      ans2++;
    }
    swap(now1, now2);
  }
  cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;
//�I�[�o�[�t���[�ɋC������您����������
//�m�F�Y���Ȃ您����������

int main() {
    string s; cin >> s;
    int ans = 0;
    rep(i,s.size()){
        if(s[i]=='+') ans += 1;
        else ans -= 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//c++

#include <bits/stdc++.h>
#define F_I ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
typedef long long ll;

int main()
{
	F_I;
	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll one = a * d;
	ll two = a * c;
	ll three = b * c;
	ll four = b * d;
	cout << max({ one,two,three,four }) << '\n';

	return 0;
}

Measured memory_bytes: 3636
n = gets.to_i

h = Hash.new(0)
m = Math.sqrt(n).to_i+1
(1..m).each{|x|
  (1..m).each{|y|
    (1..m).each{|z|
      t = x**2+y**2+z**2+x*y+y*z+z*x
      if t <= n
        h[t] += 1
      end
    }
  }
}

(1..n).each{|i|
  p h[i]
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll N, K;
	cin >>N >>K;
	N %=K;
	N=min(N, K-N);
	cout <<N <<endl;
	return 0;
}



Measured memory_bytes: 256
#![allow(unused_imports)]

mod pcl {

}




fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let l = s.trim().parse::<f64>().unwrap();
    let a = l / 3.0;
    println!("{:.6}", a * a * a);
}


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

int n;
bool isPrime[10000010];

void setPrime(int n) {
	int i, j;
	
	for (i = 2; i <= n; i++) isPrime[i] = true;
	isPrime[0] = isPrime[1] = false;
	
	for (i = 2; i <= n; i++) {
		if (isPrime[i]) {
			for (j = i * 2; j <= n; j += i) {
				isPrime[j] = false;
			}
		}
	}
}

int main() {
	cin >> n;
	setPrime(n + 2);
	
	int i, ans = 0;
	for (i = 2; i <= n; i++) {
		if (isPrime[i] && isPrime[i + 2]) ans++;
	}
	cout << ans * 2 << endl;
	return 0;
}


Measured memory_bytes: 12876
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

R = [0] * N
for i, b in enumerate(B[::-1], start=1):
    R[-i] = R[-(i - 1)] + b

ans = 0
S = 0
for i, a in enumerate(A):
    S += a
    ans = max(ans, S + R[i])
print(ans)


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

using namespace std;

#define ll  long long
#define ld  double

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

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<ll,int>    ii;

ii  a[N];
int s[N];

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

    int n;  cin >> n;

    for(int i = 1 ; i <= n ; ++i)   {
        ll  x;  cin >> x;
        a[i].X = x;
        a[i].Y = i;
    }
    sort(a + 1,a + 1 + n);
    fill(s + 1,s + 1 + n,1);

    vector<ii>  res;

    ll  Sum = 0;

    for(int i = n ; i >= 2 ; --i)   {
        ll  val = a[i].X + s[i] + s[i] - n;
        int pos = lower_bound(a + 1,a + 1 + n,ii(val,0)) - a;

        if (a[pos].X != val)    {
            cout << "-1";
            return  0;
        }
        s[pos] += s[i]; res.pb(a[pos].Y,a[i].Y);
        Sum += s[i];
    }
    if (Sum != a[1].X)  {
        cout << "-1";
        return  0;
    }
    for(ii  e : res)
        cout << e.X << " ",
        cout << e.Y << "\n";
}


Measured memory_bytes: 5104
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long ll;

int dp[100][2][100];//dp[keta][未満である][0でない数の個数]

struct UnionFind {
  vi parent;
  UnionFind(int N) : parent(N) {
    rep(i, N)parent[i] = i;
  }

  int getRoot(int child){
    return ((parent[child] == child) ? child : parent[child] = getRoot(parent[child]));
  }
  void unite(int x, int y){
    int root_x = getRoot(x);
    int root_y = getRoot(y);
    if(root_x == root_y)return;
    parent[root_x] = parent[root_y];
  }
  bool isSame(int x, int y){
    return getRoot(x) == getRoot(y);
  }
};
int main(){
    int N;cin >> N;
    int A, B;cin >> A >> B;
    int P[N];rep(i, N)cin >> P[i];
    int count1 = 0, count2 = 0, count3 = 0;
    rep(i, N){
        if(P[i] <= A)count1++;
        else if(P[i] <= B)count2++;
        else count3++;
    }
    cout << min(count1, min(count2, count3));
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        scanner.nextLine();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            list.add(scanner.nextLine());
        }
        Map<String, Long> grouped = list.stream().collect(Collectors.groupingBy(x -> x, Collectors.counting()));
        Map<Long, List<String>> map = grouped.keySet().stream().collect(Collectors.groupingBy(grouped::get));
        long max = map.keySet().stream().mapToLong(m -> m).max().getAsLong();
        map.get(max).stream().sorted().forEach(System.out::println);
    }
}

Measured memory_bytes: 170776
n=int(input())
C=[]
S=[]
F=[]
for i in range(n-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

ans=[0]*n
for i in range(n-1):
    t=0
    for j in range(i, n-1):
        if t<=S[j]:
            t=S[j]
        elif t%F[j]==0:
            pass
        else:
            t=(t//F[j]+1)*F[j]
        t+=C[j]
    ans[i]=t

for i in range(n):
    print(ans[i])  

Measured memory_bytes: 40176
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main()
{
    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll r = 0;
    ll g = 0;
    ll b = 0;
    rep(i, n) {
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++; 
    }
    ll ans = r * g * b;
    rep(i, n) {
        for(int j = 0; i - j >= 0 && i + j < n; j++) {
            if(s[i - j] != s[i] && s[i] != s[i + j] && s[i - j] != s[i + j]) {
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
using System;
using System.IO;
using System.Linq;

namespace AtCoder {
	class Program {
		public static void Main() {
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

			long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long n = input[0];
			long k = input[1];
			long mod = n % k;
			Console.WriteLine(Math.Min(mod, k - mod));

			Console.Out.Flush();
		}
	}
}

Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

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

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
    int a,b;
    cin >> a >> b ;
    int max;
    max = a + b;
    if (max<a - b)
        max = a - b;
    if (max<a * b)
        max = a * b;
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
int main(void){
  char s[110],t[110];
  scanf("%s %s",s,t);
  int i,j,m=strlen(s);
  for(i=0;i<m;i++){
    if(strcmp(s,t)==0) {printf("Yes");return 0;}
    for(j=m;j>0;j--){
      t[j]=t[j-1];
    }
    t[0]=t[m];
    t[m]=0;
  }
  printf("No");
  return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long n;
    cin >> n;
    string res;
    int sz = 'z'-'a'+1;
    while (n > 0) {
        res += 'a' + (n-1)%sz;
        n = (n-1)/sz;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}



Measured memory_bytes: 3648
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148
using namespace std;

int main()
{
    double l,d,k,s,c,h,p,q;
	while(cin>>l>>d>>k)
	{
		k=(k/180)*PI;
		s=l*d*sin(k)/2;
		q=l*l+d*d-2*d*l*cos(k); 
		p=sqrt(q);
		c=l+d+p;
		h=(2*s)/l;
		cout<<setiosflags(ios::fixed)<<setprecision(8);
		cout<<s<<" "<<c<<" "<<h;
	
	
	
	
	}
	
		




}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    string s;
    cin >> s;

    for (int i = 0; i < (int)s.size()-1; i++) {
        if (s[i] == 'C'){
            for (int j = i+1; j < (int)s.size(); j++) {
                if (s[j] == 'F') {
                    cout << "Yes" << endl;
                    return;
                }
            }
        }
    }

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

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

using namespace std;

void toUpperString(string& upper_str, const string& src_str)
{
  bool is_under_score = false;

  if (src_str[0] >= 0x61 && src_str[0] <= 0x7A) {
    upper_str += src_str[0] - 0x20;
  } else {
    upper_str += src_str[0];
  }
  
  for (int i = 1; i != src_str.size(); i++) {
    if (src_str[i] == '_') {
      is_under_score = true;
      continue;
    }
    if (!is_under_score) {
      upper_str += src_str[i];
    } else {
      upper_str += src_str[i] - 0x20;
      is_under_score = false;
    }
  }
}

void toLowerString(string& lower_str, const string& src_str)
{
  bool is_under_score = false;

  if (src_str[0] >= 0x41 && src_str[0] <= 0x5A) {
    lower_str += src_str[0] + 0x20;
  } else {
    lower_str += src_str[0];
  }

  for (int i = 1; i != src_str.size(); i++) {
    if (src_str[i] == '_') {
      is_under_score = true;
      continue;
    }
    if (!is_under_score) {
      lower_str += src_str[i];
    } else {
      lower_str += src_str[i] - 0x20;
      is_under_score = false;
    }
  }
}

void toSnakeString(string& snake_str, const string& src_str)
{
  if (src_str[0] >= 0x41 && src_str[0] <= 0x5A) {
    snake_str += src_str[0] + 0x20;
  } else {
    snake_str += src_str[0];
  }

  for (int i = 1; i != src_str.size(); i++) {
    if (src_str[i] == '_' ||
        (src_str[i] >= 0x61 && src_str[i] <= 0x7A)) {
      snake_str += src_str[i];
    } else {
      snake_str += '_';
      snake_str += src_str[i] + 0x20;
    }
  }
}

  
int main()
{
  string name;
  string output;
  char type;

  while (1) {
    cin >> name >> type;
    cin.ignore();

    output.clear();
    if (type == 'U') {
      toUpperString(output, name);
      cout << output << endl;
    } else if (type == 'L') {
      toLowerString(output, name);
      cout << output << endl;
    } else if (type == 'D') {
      toSnakeString(output, name);
      cout << output << endl;
    } else if (type == 'X') {
      break;
    }
  }
}



Measured memory_bytes: 3160
# ARC072C - Sequence (ABC059C)
def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    
    # start with positive number
    cur, cnt_1 = 0, 0
    for i, j in enumerate(lst):
        new = cur + j
        if i % 2 == 0 and new <= 0:
            cnt_1 += abs(new) + 1
            cur = 1
        elif i % 2 == 1 and new >= 0:
            cnt_1 += abs(new) + 1
            cur = -1
        else:
            cur += j

    # start with negative number
    cur, cnt_2 = 0, 0
    for i, j in enumerate(lst):
        new = cur + j
        if i % 2 == 0 and new >= 0:
            cnt_2 += abs(new) + 1
            cur = -1
        elif i % 2 == 1 and new <= 0:
            cnt_2 += abs(new) + 1
            cur = 1
        else:
            cur += j
    
    print(min(cnt_1, cnt_2))


if __name__ == "__main__":
    main()

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){



}


void solve(){

    ll n,k;
    cin >> n >> k;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
        cin >> a[i];
    sort(a+1,a+n+1,greater<ll>());
    ll ans=0;
    if(k >= n){
        ans = 0;
    }else{
        for(ll i=k+1;i<=n;i++){
            ans += a[i];
        }
    }
    cout << ans;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

int main(){
  int n, t=0;
  string s;
  cin >> n;
  char c[n], m=' ';
  rep(i,0,n) cin >> c[i];
  rep(i,0,n){
    if(m!=c[i]){
      t++;
      m=c[i];
    }
  }
  cout << t << endl;;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define M_PI acos(-1)

main()
{
   string s;
   cin>>s;
   for (int i=0;i<s.size();i++)
    for (int j=i;j<s.size();j++)
        if (s[i]=='C' && s[j]=='F')
            return cout<<"Yes"<<endl,0;
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <string>
//#include <functional>
//#include <cmath>


int main(){
    int32_t N;
    std::cin >> N;
    std::vector<int32_t> d(N);
    for(auto& i : d){
        std::cin >> i;
    }

    int64_t res = 0;
    for(int32_t i = 0; i < N - 1; i++){
        for(int32_t j = i+1; j < N; j++){
            res += d[j] * d[i];
        }
    }
    
    std::cout << res;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> b(n+1);
    vector<int> ans;
    for (int i = n; i >= 1; i--) {
        int sum = 0;
        for (int j = i; j <= n; j += i) {
            sum += b[j];
        }
        if (sum % 2 != a[i]) {
            b[i]++;
            ans.push_back(i);
        }
    }
    cout << (int)ans.size() << endl;
    for (int x : ans) {
        cout << x << " ";
    }
    cout << endl;
}

Measured memory_bytes: 5284
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int ans = 0;
    char c;
    int temp = 0;
    for(int i=0; i<3; ++i){
        cin>>c;
        if(c=='R'){
            temp++;
            ans = max(ans,temp);
        }
        else
            temp = 0;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3592
import math
# import bisect
import sys
# from collections import Counter
input = sys.stdin.readline
def inp():
	return(int(input()))
def inlt():
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(s[:len(s)-1])
def invr():
	return(map(int,input().split()))
def print_fract(p,q):
	g = math.gcd(p,q)
	p//=g
	q//=g
	print(str(p)+"/"+str(q))
# list1, list2 = zip(*sorted(zip(list1, list2)))
X = inp()
if X >= 30:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    for(int i=0;i<n;i++) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};
int main(){
    cin>>n>>m;
    vector<pair<int,int>> bridge(m);
    for(ll i=0;i<m;i++){
        ll a,b;cin>>a>>b;a--;b--;
        bridge.at(m-1-i)=make_pair(a,b);
    }
    UnionFind tree(n);
    vector<ll> ans(m);
    ans.at(0)=(n*(n-1))/2;
    for(ll i=0;i<m-1;i++){
        int x=bridge.at(i).first,y=bridge.at(i).second;
        if(tree.same(x,y)){
            ans.at(i+1)=ans.at(i);
        }
        else{
            ans.at(i+1)=ans.at(i)-tree.size(x)*tree.size(y);
        }
        tree.unite(x,y);
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<m;i++){
        cout<<ans.at(i)<<endl;
    }
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<pii> vii;
typedef priority_queue<piii, vector<piii>, greater<piii> > pque;

const int MOD = 1e9+7;
const int INF = 1e9;
const int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
const int MAX_NW = 50;

int H, W, map[MAX_NW][MAX_NW];
int sum_black, ans;
string field[MAX_NW];

bool check(int y, int x) {
  return (0<=y && y<H) && (0<=x && x<W);
}

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> field[i];
  }
  
  sum_black = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      map[i][j] = INF;
      if (field[i][j] == '#') sum_black++;
    }
  }
  map[0][0] = 0;
  pque que;
  que.push(MP(0, MP(0, 0)));
  while (!que.empty()) {
    piii tmp = que.top(); que.pop();
    int y = tmp.S.F, x = tmp.S.S, dist = tmp.F;
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (!check(ny, nx) || field[ny][nx]=='#') continue;
      if (dist + 1 < map[ny][nx]) {
        map[ny][nx] = dist + 1;
        que.push(MP(dist+1, MP(ny, nx)));
      }
    }
  }
  if (map[H-1][W-1] == INF) {
    ans = -1;
  } else {
    ans = H * W - sum_black - map[H-1][W-1] - 1;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n,C,len[40],p[40];
ll f[310][1<<6][310];
void upd(ll&a,ll b){a+=b;}
int main(){
	read(n);read(C);
	for(int i=0;i<n;i++)
		read(len[i]);
	sort(len,len+n);
	for(int i=1;i<n;i++) p[i]=i-1;
	p[0]=n-1;
	long double ans=0;
	do{
		int m=n*C;
		memset(f,0,sizeof(f));
		f[0][1<<n-1][len[n-1]*n]=1;
		for(int i=0;i<m;i++)
			for(int j=0;j<1<<n;j++)
				for(int k=i;k<=m;k++)
					if(f[i][j][k]){
						upd(f[i+1][j][k],f[i][j][k]);
						int x=p[i%n];
						if(~j>>x&1)
							upd(f[i+1][j|1<<x][min(m,max(k,i+n*len[x]))],f[i][j][k]);
					}
		ll coe=1;
		for(int i=1;i<n;i++) coe*=C;
		for(int i=1;i<n;i++) coe*=i;
		ans+=1.l*f[m][(1<<n)-1][m]/coe;
	}while(next_permutation(p+1,p+n));
	printf("%.14Lf\n",ans);
	return 0;
}


Measured memory_bytes: 48384
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include <cmath>
#include <set>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define all(a) a.begin(), a.end()
#define N 5000000

const long long int  inf = 1e15 ;
const int M = 1e9+7;

typedef long long int LL;
typedef pair<LL,LL>pii;
int n,w;
std::vector<pii> v;
LL  dp[200][200000];
int done[200][200000];

LL solve(int a,LL left)
{
	if(a==n)
	{
		return 0;
	}
	if(v[a].first <= left)
	{
		if(done[a][left]==0)
		{
			done[a][left]=1;
			dp[a][left]=max(solve(a+1,left-v[a].first)+v[a].second,solve(a+1,left));
		}
		return dp[a][left];
	}
	else
	{
		if(done[a][left]==0)
		{
			done[a][left]=1;
			dp[a][left]=solve(a+1,left);
		}
		return dp[a][left];

	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>w;
	for (int i = 1; i <= n; ++i)
	{
		LL a,b;
		cin >>a>>b;
		v.push_back(make_pair(a,b));
	}

	cout << solve(0,w)<<endl;
	return 0;
}

Measured memory_bytes: 233728
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
#define pi 3.14159265359
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n;
    ll arr[n];
    for(i = 0; i < n; i++){
        cin >> arr[i];
    }
    for(i = 1; i < n; i++){
        if(arr[i] >= arr[i-1]){
            continue;
        }
        sum += arr[i-1] - arr[i];
        arr[i] = arr[i-1];
    }
    cout << sum;

    return 0;
}


Measured memory_bytes: 5196
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//solve

//FUNCTION
//solve

void solve(void)
{
  int K,T;
  cin>>K>>T;
  if(T == 1)
  {
    cout<<K-1<<endl;
    return;
  }
  map<int,int> mp;
  int MAX = 0;
  for (int i = 0; i < T; i++)
  {
    int X;cin>>X;
    chmax(MAX,X);
  }
  cout<<max(0LL,MAX - (K - MAX)-1)<<endl;
  
  return;
}

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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

using namespace std;

int main() {
    int a, b;
    char c[10];
    while (cin >> a >> b) {
        sprintf(c, "%d", a+b);
        int i = 0;
        while (c[i] != '\0') {
            ++i;
        }

        cout << i << endl;
    }

    return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	private static final int MOD = 2019;

	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var s = sc.next();
		var chars = s.toCharArray();
		var numbers = IntStream.range(0, chars.length).map(i -> Integer.valueOf(chars[i] - '0')).toArray();
		sc.close();

		var calc = new int[MOD][10];
		for (var i = 0; i < MOD; i++) {
			for (var j = 0; j < 10; j++) {
				calc[i][j] = (i * 10 + j) % MOD;
			}
		}

		var count = 0L;
		var init = new long[MOD];
		var set1 = new long[MOD];
		var set2 = new long[MOD];
		for (var i = 0; i < numbers.length; i++) {
			for (var j = 0; j < MOD; j++) {
				if (set1[j] > 0) {
					var number = calc[j][numbers[i]];
					if (number == 0) {
						count += set1[j];
					}
					set2[number] += set1[j];
				}
			}
			set2[numbers[i]]++;
			System.arraycopy(set2, 0, set1, 0, MOD);
			System.arraycopy(init, 0, set2, 0, MOD);
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 42228