akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
public class ABC124D {
    public static void Main() {
        int N, K, ans = 0, blockAns = 0;
        List<int> List0 = new List<int>(), List1 = new List<int>();
        string[] str = System.Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        K = int.Parse(str[1]);
        string Sstr = System.Console.ReadLine();
        int strLeng = 0;
        bool startIs0 = Sstr[0] == '0', endIs0 = Sstr[Sstr.Length - 1] == '0';
        bool was0 = startIs0;
        for (int i = 0; i < Sstr.Length; i++) {
            if (Sstr[i] == '0') {
                if (was0) {
                    strLeng++;
                } else {
                    was0 = true;
                    List1.Add(strLeng);
                    strLeng = 1;
                }
            } else {
                if (!was0) {
                    strLeng++;
                } else {
                    was0 = false;
                    List0.Add(strLeng);
                    strLeng = 1;
                }
            }
        }
        if (was0) List0.Add(strLeng);
        else List1.Add(strLeng);
        if (startIs0) {
            for (int j0 = 0; j0 < K; j0++) {
                if (j0 < List0.Count) blockAns += List0[j0];
            }
            for (int j1 = 0; j1 < K; j1++) {
                if (j1 < List1.Count) blockAns += List1[j1];
            }
            ans = blockAns;

            // start1 = 0
            if (K < List0.Count && K < List1.Count) blockAns += -List0[0] + List0[K] + List1[K];
            if (ans < blockAns) ans = blockAns;

            for (int start1 = 1; start1 < List1.Count - K; start1++) {
                blockAns += -List1[start1 - 1] - List0[start1] + List1[start1 + K] + List0[start1 + K];
                if (ans < blockAns) ans = blockAns;
            }
            if (endIs0 && List1.Count >= K + 1) {
                blockAns += -List1[List1.Count - K - 1] - List0[List1.Count - K] + List0[List1.Count];
                if (ans < blockAns) ans = blockAns;
            } else if (endIs0 && List1.Count == 1) {
                blockAns += -List0[0] + List0[1];
                if (ans < blockAns) ans = blockAns;
            }
        } else {
            // start1 = 0
            for (int j0 = 0; j0 < K; j0++) {
                if (j0 < List0.Count) blockAns += List0[j0];
            }
            for (int j1 = 0; j1 < K + 1; j1++) {
                if (j1 < List1.Count) blockAns += List1[j1];
            }
            ans = blockAns;

            for (int start1 = 1; start1 < List1.Count - K; start1++) {
                blockAns += -List1[start1 - 1] - List0[start1 - 1] + List1[start1 + K] + List0[start1 - 1 + K];
                if (ans < blockAns) ans = blockAns;
            }
            if (endIs0 && List1.Count >= K + 1) {
                blockAns += -List1[List1.Count - K - 1] - List0[List1.Count - K - 1] + List0[List1.Count - 1];
                if (ans < blockAns) ans = blockAns;
            }
        }
        System.Console.WriteLine(ans);
    }
}

Measured memory_bytes: 12312
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    string s;
    cin >> s;
    if(s=="keyence"){
        puts("YES");
        return 0;
    }
    int n = s.size();
    //cout << n;
    rep(i,n){
        srep(j,i,n){
            string a;

            rep(x,i){
                a+=s[x];
            }
            srep(x,j+1,n){
                a+=s[x];
            }

            if(a=="keyence"){
                puts("YES");
                return 0;
            }
        }
    }


    ll ans = 0;
    
    puts("NO");
    return 0;
}
 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int w, h, n;
    cin >> w >> h >> n;
    vector<vector<int>> ret(h, vector<int>(w, 1));
    for (int i = 0; i < n; ++i) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            for (int j = 0; j < h; ++j) {
                for (int k = 0; k < w; ++k) {
                    if (k < x)
                        ret[j][k] = 0;
                }
            }
        } else if (a == 2) {
            for (int j = 0; j < h; ++j) {
                for (int k = 0; k < w; ++k) {
                    if (k >= x)
                        ret[j][k] = 0;
                }
            }
        } else if (a == 3) {
            for (int j = 0; j < h; ++j) {
                for (int k = 0; k < w; ++k) {
                    if (j < y)
                        ret[j][k] = 0;
                }
            }
        } else if (a == 4) {
            for (int j = 0; j < h; ++j) {
                for (int k = 0; k < w; ++k) {
                    if (j >= y)
                        ret[j][k] = 0;
                }
            }
        }
    }
    lint cnt = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cnt += ret[i][j];
        }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)


int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    char s[n+1];
    scanf("%s",s);
    int sum[n];
    F(i,0,n) sum[i]=0;
    for(int i=0; i<n;i++){
        if(i+1<n && s[i]=='A' && s[i+1]=='C'){
            sum[i+1]=sum[i]+1;
        }else{
            sum[i+1]=sum[i];
        }
    }
    int l,r;
    F(j,0,q){
        scanf("%d%d",&l,&r);
        printf("%d\n",sum[r-1]-sum[l-1]);
    }
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e10;


signed main() {
    int N, M;
    cin >> N >> M;
    V(P) keys(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        int s = 0;
        rep(j, b) {
            int c;
            cin >> c;
            --c;
            s |= 1<<c;
        }
        keys[i] = P(s, a);
    }

    vi dp(1<<N, INF);
    dp[0] = 0;

    //すべての宝箱の開閉の状態を走査する。
    rep(s, 1<<N) {

        //ある状態からi番目の鍵を購入した時の遷移先の状態の、最小コストを更新する。
        rep(i, M) {
            int t = s | keys[i].fi; //遷移先の状態
            int cost = dp[s] + keys[i].se; //i番目の鍵のコストを足したもの
            dp[t] = min(dp[t], cost); //遷移先のコスト
        }
    }

    int res = dp.back();
    if(res == INF) cout << -1 << endl;
    else cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int H,W;
  scanf("%d%d",&H,&W);

  char data[H+2][W+2];
  char ans[H+2][W+2];
  char sample[W];

  for(int i = 0;i < H+2;i++){
    for(int j = 0;j < W+2;j++){
      data[i][j] = '.';
      ans[i][j] = '#';
    }
  }
  for(int i = 1;i < H+1;i++){
    scanf("%s",sample);
    for(int j = 0;j < W;j++){
      data[i][j+1] = sample[j];
    }
  }

  for(int i = 1;i < H+1;i++){
    for(int j = 1;j < W+1;j++){
      if(data[i][j] != '#'){
        int counter = 0;
        if(data[i-1][j-1] == '#')
          counter++;
        if(data[i-1][j] == '#')
          counter++;
        if(data[i-1][j+1] == '#')
          counter++;
        if(data[i][j-1] == '#')
          counter++;
        if(data[i][j+1] == '#')
          counter++;
        if(data[i+1][j-1] == '#')
          counter++;
        if(data[i+1][j] == '#')
          counter++;
        if(data[i+1][j+1] == '#')
          counter++;
        ans[i][j] = counter;
      }
    }
  }


  for(int i = 1;i < H+1;i++){
    for(int j = 1;j < W+1;j++){
      if(ans[i][j] == '#')
        printf("#");
      else
        printf("%d",ans[i][j]);
    }
    printf("\n");
  }


  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b,h[100005],ans[100005];
bool check(ll x)
{
	for(int i=1;i<=n;i++)
	{
		ll val=h[i];
		val-=x*b;
		if(val>0)
		{
			ans[i]=(val-1)/(a-b)+1;
		}
		else ans[i]=0;
	}
	ll tot=0;
	for(int i=1;i<=n;i++) tot+=ans[i];
	return tot<=x;
}
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
	ll l=1,r=1e9;
	while(r-l>1)
	{
		//printf("l=%lld r=%lld\n",l,r);
		ll mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid;
	}
	if(check(l)) printf("%lld\n",l);
	else printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] time = new long[n];
		long[] c = new long[n];
		long[] s = new long[n];
		long[] f = new long[n];
		for(int i = 0; i < n; i++) {
			time[i] = 0;
		}
		for(int i = 0; i < n - 1; i++) {
			c[i] = sc.nextLong();
			s[i] = sc.nextLong();
			f[i] = sc.nextLong();
		}
		for(int i = n - 2; i > -1; i--) {
			long ans = s[i] + c[i];
			for(int j = i + 1; j < n - 1; j++) {
				if(ans <= s[j]) {
					ans = time[j];
					break;
				} else {
					if(ans % f[j] != 0)
						ans += f[j] - ans % f[j];
					ans += c[j];
				}
			}
			time[i] = ans;
		}
		for(int i = 0; i < n; i++) {
			System.out.println(time[i]);
		}

	}

}


Measured memory_bytes: 26760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define LINF 0x3f3f3f3f3f3f3f3f
#define int long long 
typedef pair<int,int>pii;
const int mxN=110,M=1e9+1,mxV=1e5+5;
int n,w;
pii v[mxN];
int dp[mxV];
// LONG LONG CASE
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);    
    cin>>n>>w;
    for(int i=0;i<=mxV;i++){
        dp[i]=LINF;
    }
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=mxV-1;j>=v[i].second;j--){
            if(dp[j-v[i].second]!=LINF){
                dp[j]=min(dp[j],dp[j-v[i].second]+v[i].first);
                //cout<<j<<" "<<dp[j]<<"\n";
            }
        }
    }
    int ans=0LL;
    for(int i=100000;i>=1;i--){
        if(dp[i]<=w){
            ans=i;
            break;
        }
    }
    cout<<ans;
    

}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int N, i, sum=0, x;
    cin >> N;
    for(i=0; i<N; i++){
        cin >> x;
        if(x % 2 == 0){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}



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

#define y1 dmytxdy
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int a[200005];

bool check(int x){
	vector<pii> v(0);
	for(int i=1;i<=n;i++){
		if(a[i]>a[i-1]) v.push_back(mp(a[i-1]+1,1));
		else{
			while(v[v.size()-1].fi>a[i]) v.pop_back();
			if(v[v.size()-1].se<x){
				if(v[v.size()-1].fi==a[i]) v[v.size()-1].se++;
				else v.push_back(mp(a[i],v[v.size()-1].se+1));
			}
			else{
				int pl=v[v.size()-1].fi,now=v.size()-1;
				vector<pii> tmp(0);
				while(now>0&&v[now-1].fi==pl-1&&v[now-1].se==x) tmp.push_back(v[now]),pl--,now--,v.pop_back();
				if(!now&&pl==1&&v[now].se==x) return false;
				tmp.push_back(v[now]),v.pop_back();
				if(v[v.size()-1].fi==pl-1) v[v.size()-1].se++;
				else v.push_back(mp(pl-1,v[v.size()-1].fi+1));
				for(int j=tmp.size()-1;j>=0;j--) v.push_back(mp(tmp[j].fi,1));
			}
		}
	}
	return true;
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	int l=1,r=1e9,ans=0;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

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

namespace abc115_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = new int[n];
            for (int i = 0; i < n; i++) x[i] = int.Parse(Console.ReadLine());
            Console.WriteLine(x.Sum() - x.Max() / 2);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int lim;
    string s;
    cin >> lim >> s;
    if(s.size() > lim){
        for(int i=0; i<lim; i++){
            cout << s[i];
        }
        cout << "...";
    }else{
        cout << s;
    }
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vector<int>> mi;
typedef vector<vector<pair<int, int>>> w_graph;
typedef vector<vector<int>> uw_graph;

uw_graph G(1e5 + 5);
int dp[(int)1e5 + 5];


int dfs(int v){
	if (dp[v] != -1) return dp[v];
	int mx = 0;
	for (int i = 0; i < G[v].size(); i++){
    	mx = max(mx, 1 + dfs(G[v][i]));
	}
	return dp[v] = mx;
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	#ifdef DEBUG
		freopen("out.txt", "w", stdout);
	#endif

	int n, m;
	cin >> n >> m;
	
	for (int i = 0; i < 1e5 + 5; i++) {
		dp[i] = -1;
	}
	for (int i = 0; i < m; i++){
		int v1, v2; cin >> v1 >> v2;
		G[v1].push_back(v2);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		if (dp[i] == -1)
		   ans = max(ans, dfs(i));
	}
	cout << ans << endl;

	return 0;
}


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

int n, p = -1;
map <int, int> mp;

int main(){
   cin >> n;
   for (int i = 0, a; i < n; i++){
      cin >> a, mp[a]++;
   }

   for (auto it = mp.rbegin(); it != mp.rend(); it++){
      if (p != -1) {
         if (it->second >= 2) {
            cout << p * 1LL * it->first << endl;
            return 0;
         }
      }
      
      if (it->second >= 4) {
         cout << 1LL * (it->first) * (it->first) << endl;
         return 0;
      }

      if (it->second >= 2) p = it->first;
   }

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

Measured memory_bytes: 4992
package main

import (
	"fmt"
	"math"
)

var indices = [][]int{}

func main() {
	var N int
	fmt.Scan(&N)
	x := make([]int, N)
	y := make([]int, N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&x[i], &y[i])
		a[i] = i
	}

	perm([]int{}, a)

	sum := 0.0
	for i := 0; i < len(indices); i++ {
		idx := indices[i]
		for k := 0; k < N-1; k++ {
			k1 := idx[k]
			k2 := idx[k+1]
			tx := x[k1] - x[k2]
			ty := y[k1] - y[k2]
			t := math.Sqrt(float64(tx*tx + ty*ty))
			sum += t
		}
	}

	fmt.Println(sum / float64(len(indices)))
}

func perm(head []int, rest []int) {
	if len(rest) == 0 {
		a := make([]int, len(head))
		copy(a, head)
		indices = append(indices, a)
	} else {
		for i, v := range rest {
			restx := make([]int, len(rest))
			copy(restx, rest)
			restx = append(restx[:i], restx[i+1:]...)
			headx := append(head, v)
			perm(headx, restx)
		}
	}
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
string str[100005];
vector<char> vec;
int main()
{
	ios;
	char ch,ch1,nch,nch1;
	map<char,ll> mp;
	ll n,a,b,c,i,g=0,z;
	cin>>n>>a>>b>>c;
	for(i=1;i<=n;i++)
		cin>>str[i];
	mp['A']=a;mp['B']=b;mp['C']=c;
	if(a+b+c==0)
	{
		g=1;
		goto z;
	}
	else if(a+b+c==1)
	{
		for(i=1;i<=n;i++)
		{
			ch=str[i][0];
			ch1=str[i][1];
			if(mp[ch]==1)
			{
				vec.push_back(ch1);
				mp[ch]--;
				mp[ch1]++;
			}
			else if(mp[ch1]==1)
			{
				mp[ch]++;
				vec.push_back(ch);
				mp[ch1]--;
			}
			else
			{
				g=1;
				goto z;
			}
		}
	}
	else
	{
		for(i=1;i<n;i++)
		{
			ch=str[i][0];
			ch1=str[i][1];
			nch=str[i+1][0];
			nch1=str[i+1][1];
			if(mp[ch]==0&&mp[ch1]==0)
			{
				g=1;
				goto z;
			}
			else if(mp[ch]==0)
			{
				mp[ch]++;
				vec.push_back(ch);
				mp[ch1]--;
			}
			else if(mp[ch1]==0)
			{
				mp[ch1]++;
				vec.push_back(ch1);
				mp[ch]--;
			}
			else if(ch==nch||ch==nch1)
			{
				mp[ch]++;
				vec.push_back(ch);
				mp[ch1]--;
			}
			else
			{
				mp[ch]--;
				vec.push_back(ch1);
				mp[ch1]++;
			}
		}
		ch=str[n][0];
		ch1=str[n][1];
		if(mp[ch]==0&&mp[ch1]==0)
		{
			g=1;
			goto z;
		}
		else if(mp[ch]==0)
		{
			mp[ch]++;
			vec.push_back(ch);
			mp[ch1]--;
		}
		else
		{
			mp[ch1]++;
			vec.push_back(ch1);
			mp[ch]--;
		}
	}
	z:{}
	if(g==1)
		cout<<"No"<<endl;
	else
	{
		cout<<"Yes"<<endl;
		for(i=0;i<vec.size();i++)
			cout<<vec[i]<<endl;
	}
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int N, D, tmp;
  cin >> N >> D;
  vector<vector<int>> points;
  for (int i=0; i<N; i++){
    vector<int> p;
    for (int i=0; i<D; i++){
      cin >> tmp;
      p.push_back(tmp);
    }
    points.emplace_back(p);
  }
  int ret = 0;
  
  for (int i=0; i<N - 1; i++){
    for (int j=i + 1; j<N; j++){
      int dis = 0;
      for (int a=0; a<D; a++){
        dis += (int)pow(abs(points[i][a] - points[j][a]), 2);
      }
      for (int b=1; b<(int)(40*pow(10, 0.5)); b++){
        if (dis == pow(b, 2)){
          ret++;
          break;
        }
      }
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int n;
    cin >> n;
    int a[n], x = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x ^= a[i];
        a[i] ^= a[i] - 1;
    }

    sort(a, a+n, greater<int>());

    int ret = 0;
    for (int i = 0; i < n; i++) {
        if ((x ^ a[i]) < x) {
            x ^= a[i];
            ret++;
        }
    }

    cout << (x > 0 ? -1 : ret) << "\n";
    return 0;
}


Measured memory_bytes: 640
from operator import itemgetter

H,W,D = [int(x) for x in input().split()]
a = []

for i in range(H):
    x = [int(x) for x in input().split()]
    for ind,j in enumerate(x):
        a.append([j,i,ind])
a.sort(key=itemgetter(0))
Q = int(input())
LR = [[int(x) for x in input().split()]for _ in range(Q)]
#%%
stims = [[[0,0,0]]for _ in range(D)]
dinds = [{}for _ in range(D)]
for i in a:
    d = i[0]%D
    stims[d].append([stims[d][-1][0]+abs(i[1]-stims[d][-1][1])+abs(i[2]-stims[d][-1][2]),i[1],i[2]])
    dinds[d][i[0]]=len(stims[d])-1

for i in LR:
    dnum = i[0]%D
    l = dinds[dnum][i[0]]
    r = dinds[dnum][i[1]]
    print(stims[dnum][r][0]-stims[dnum][l][0])


Measured memory_bytes: 91568
#include <bits/stdc++.h>
#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 PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
#define INF 1000000000;
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll a[100010],b[100010];
int main(){
    int n;
    cin >> n;
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,n){
        if (a[i]>=b[i]){
            ans += b[i];
        }else if(b[i]<=a[i]+a[i+1]){
            ans += b[i];
            a[i+1] -= b[i] - a[i];
        }else{
            ans += a[i] + a[i+1];
            a[i+1] = 0;
        }
    }
    PRINT(ans);
}


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

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<int> B(N-1);
    for(int i=0;i<N-1;i++){
        cin>>B[i];
    }
    long long result=0;
    result+=B[0];
    for(int i=0;i<N-2;i++){
        result+=min(B[i],B[i+1]);
    }
    result+=B[N-2];
    cout<<result<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;

void solve() {
    int l, r, d;
    cin >> l >> r >> d;
    cout << (r / d) - (l / d) + (l % d == 0);
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=3010;

inline void read(int &x) {
    x=0;
    int f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {
        if (ch=='-') {
            f=-1;
        }
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') {
        x=x*10+ch-'0';
        ch=getchar();
    }
    x*=f;
}

struct note {
    int t;
    int next;
};

int cnt;
int head[N];
note e[N<<1];

inline void add(int x,int y) {
    e[++cnt].t=y;
    e[cnt].next=head[x];
    head[x]=cnt;
}

int v[N];
int n;

bool dfs(int p,int fa) {
    for(int i=head[p];i+1;i=e[i].next) {
        int t=e[i].t;
        if (t==fa) {
            continue;
        }
        if (v[p]>v[t]&&!dfs(t,p)) {
            return 1;
        }
    }
    return 0;
}

int main() {
    memset(head,-1,sizeof(head));
    read(n);
    for(int i=1;i<=n;i++) {
        read(v[i]);
    }
    for(int i=1;i<n;i++) {
        int x,y;
        read(x),read(y);
        add(x,y);
        add(y,x);
    }
    for(int i=1;i<=n;i++) {
        if (dfs(i,-1)) {
            printf("%d ",i);
        }
    }
    printf("\n");
    return 0;
}


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

int main() {
	long int n,m;

    while(cin>>n>>m,n){
        long int p = 0;
        vector< pair<int,int> > dp;
        dp.resize(n);
        for(int i=0;i<n;i++){
            cin >> dp[i].second >> dp[i].first;
        }

        sort(dp.begin(),dp.end(),greater< pair<int,int> >());

        for(int i=0;i<n;i++){
            if(m==0){
                p+=dp[i].second * dp[i].first;
            }else{
                if(m>=dp[i].second) m-=dp[i].second;
                else{
                    p+=(dp[i].second-m)*dp[i].first;
                    m=0;
                }
            }
        }

        cout << p << endl;
    }

	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std; 
using namespace __gnu_pbds;
 
typedef long long ll;
typedef double db;
typedef long double ld;
typedef string str;
 
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<str, str> pstr;
 
typedef vector<int> vi; 
typedef vector<ll> vll; 
typedef vector<db> vdb; 
typedef vector<ld> vld;
typedef vector<str> vstr; 
typedef vector<pi> vpi;
typedef vector<pll> vpll; 
typedef vector<pdb> vpdb; 
 
#define fi first
#define se second
#define mp make_pair
#define pf push_front 
#define pb push_back
#define ins insert 
#define eb emplace_back 
#define fbo find_by_order
#define ook order_of_key
#define rsz resize
#define lb lower_bound 
#define ub upper_bound 

#define len(s) (int)s.length()
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define srt(v) sort(all(v))

#define rep(a, b, c) for(a=b; a<c; a++) 
#define per(a, b, c) for(a=b; a>c; a--) //do not include boundaries on the right
#define repn(a, b, c) for(a=b; a<=c; a++) 
#define pern(a, b, c) for(a=b; a>=c; a--) //include boundaries on the right
 
#define yes cout << "YES"<< "\n" 
#define no cout << "NO" << "\n" 
#define out(x) cout << x << "\n"
#define outs(x) cout << x << " "
#define el cout << "\n"

#define navi ios_base::sync_with_stdio(false); cin.tie(NULL)    
 
const ll mod = 1e9+7;
const double eps = 1e-9;

int main(){
  navi;
  int x; cin >> x;
  int ans=1;
  while((ans*x) % 360 != 0) ans++;
  out(ans);
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    
    switch (n%10)
    {
    case 3:
        cout << "bon" << endl;
        break;
    
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;

    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    
    }

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

const int OVER_N=300000;

int main(){
    string S,T;
    int q;
    cin >> S >> T >> q;
    int s=S.size(),t=T.size();
    vector<int> sa(s+1,0),sb(s+1,0),ta(t+1,0),tb(t+1,0);
    rep(i,s){
        sa[i+1]=sa[i],sb[i+1]=sb[i];
        if (S[i]=='A') ++sa[i+1];
        else ++sb[i+1];
    }
    rep(i,t){
        ta[i+1]=ta[i],tb[i+1]=tb[i];
        if (T[i]=='A') ++ta[i+1];
        else ++tb[i+1];
    }
    rep(i,q){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        --a,--c;
        int sc=(sa[b]-sa[a]-sb[b]+sb[a]+OVER_N)%3;
        int tc=(ta[d]-ta[c]-tb[d]+tb[c]+OVER_N)%3;
        if (sc==tc) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

int main(){
    int H, W;
    bool s = true;
    
    while(s){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        for(int i = 0; i < W; i++){
            cout << "#";
        }
        cout << endl;
        for(int k = 0; k < H - 2; k++){
        cout << "#";
        for(int j = 0; j < W - 2; j++){
            cout << ".";
        }
        cout << "#" << endl;
        }
        for(int i = 0; i < W; i++){
            cout << "#";
        }
        cout << endl;
        cout << endl;
    }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout<<"debuglandınız\n";
#define md 1000000007
#define MP make_pair
ll int n,m;
ll int ar[200005][2],vt[500010][3],i,j,mx,x,y;
void bul(ll int node){
	if(vt[node][1]>=x and vt[node][2]<=y){
		mx=max(mx,vt[node][0]);
		return;
	}
	if(vt[node][2]<x or vt[node][1]>y)return;
	bul(2*node);
	bul((2*node)+1);
}
void ekle(ll int x, ll int y){
	if(x>1)ekle(x/2,y);
	vt[x][0]=max(vt[x][0],y);
	return;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> n;
	m=1;
	while(n>m)m*=2;
	for(i=0;i<m;i++){
		vt[i][1]=2*m;
		vt[i][2]=m;
	}
	for(i=m;i<2*m;i++){
		for(j=i;j>0;j/=2){
			vt[j][1]=min(vt[j][1],i);
			vt[j][2]=max(vt[j][2],i);
		}
	}
	for(i=m;i<2*m;i++)vt[i][1]=vt[i][2];
	for(i=0;i<n;i++)cin>>ar[i][0];
	for(i=0;i<n;i++)cin>>ar[i][1];
	for(i=0;i<n;i++){
		mx=0;
		x=m;
		y=m+ar[i][0]-1;
		bul(1);
		ekle(m+ar[i][0]-1,mx+ar[i][1]);
	}
	cout<<vt[1][0];
	//for(i=0;i<2*m;i++)cout<<vt[i][0]<<" "<<vt[i][1]<<" "<<vt[i][2]<<" "<<endl;
}

Measured memory_bytes: 15104
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;


/** 組み合わせテーブル計算

    ret[n][r]: nCr
*/
std::vector<std::vector<int64_t>>
comb(int n) {
    std::vector<std::vector<int64_t>> v(n + 1, std::vector<int64_t>(n + 1, 0));
    for (size_t i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (size_t j = 1; j < v.size(); j++) {
        for (size_t k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
        }
    }
    return v;
}


int main()
{
    int64_t N, A, B;
    std::cin >> N >> A >> B;

    std::vector<int64_t> V;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        V.push_back(t);
    }

    std::sort(std::begin(V), std::end(V),
              [](const auto& a, const auto& b) {
                  return a > b;
              });

    auto sum = std::accumulate(std::begin(V), std::begin(V)+A, 0LL);
    auto count = std::count(std::begin(V), std::end(V), V[A-1]);

    cout.precision(20);
    std::cout << (double)sum / A << std::endl;


    auto vaSel = std::count(V.begin(), V.begin()+A, V[A-1]);

    std::vector<std::vector<int64_t>> c = comb(count);

    int64_t ret = 0;
    if (V[0] == V[A-1]) {
        for (size_t i = A; i <= std::min(count, B); ++i) {
            ret += c[count][i];
        }
    }
    else {
        ret = c[count][vaSel];
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  vi vector<long long int>
#define  set1 set<long long int>
#define  pb push_back
#define  map1 map<long long int,long long int>
#define  ll    long long int
#define  mp make_pair
#define  inf 1e17
#define  minf INT_MIN
#define  setbits(x) __builtin_popcountll(x)
#define  pres(x,y) fixed<<setprecision(y)<<x
#define  pair1 pair<long long int,long long int>
#define  mk(arr,n,type) type *arr=new type[n];
#define  mod 1000000007
#define  pi  3.1415926535897932384626433832
#define  ins insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//find_by_order() --> returns an iterator to the k-th largest element (counting from zero)
//order_of_key()  --> the number of items in a set that are strictly smaller than our item.
#define  w(t) long long int t;t=1;while(t--)

void solve() {

	ll n, k;
	cin >> n >> k;
	ll a[n + 1];
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
	}

	ll dp[n + 1][k + 1];



	for (ll i = 0; i <= k; i++) {
		if (i <= a[1]) {
			dp[1][i] = 1;
		}
		else {
			dp[1][i] = 0;
		}
	}


	for (ll i = 2; i <= n; i++) {
		for (ll j = 0; j <= k; j++) {

			if (j == 0) {
				dp[i][j] = dp[i - 1][j];
			}
			else {
				dp[i][j] = ((dp[i][j - 1] + dp[i - 1][j] + mod) - ((j - a[i] - 1 >= 0 ) ? dp[i - 1][j - a[i] - 1] : 0)) % mod;
			}

		}
	}

	cout << dp[n][k] << "\n";

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("inp.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	w(t) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 81656
N, T = map(int, input().split())
keiro = [[0, 0] for i in range(N)]

for i in range(N):
    keiro[i] = list(map(int, input().split()))

keiro_sorted = sorted(keiro, key=lambda x: x[1])

if keiro_sorted[0][1] > T:
    print("TLE")
    exit()
ans = 1000
for i in range(N):
    if keiro_sorted[i][1] > T:
        break
    ans = min(keiro_sorted[i][0], ans)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#define MAX 100000
using namespace std;
int A[MAX],n;

int partition(int p,int r){
    int x,i,j,t;
    x = A[r];
    i = p - 1;
    for(j = p;j < r;j++){
        if(A[j] <= x){
        i++;
        t = A[i];A[i] = A[j];A[j] = t;
        }
    }
    t = A[i+1];A[i+1] = A[r];A[r] = t;
    return i+1;
}

int main(){
    int q,i;
    cin >> n;
    for(i = 0; i < n; i++)cin >> A[i];
    q = partition(0,n - 1);
    for(i = 0;i < n; i++){
        if(i)cout << " ";
        if(i == q)cout << "[";
        cout << A[i];
        if(i == q)cout << "]";
    }
    cout << endl;
    return 0;
}



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

using namespace std;
typedef pair<int, long long> ii;

const long long INF = 1e18L + 9;

int main() {
    int n, W; cin >> n >> W;
    map<int, long long> ss;

    vector<long long> dp(100009, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        int w, v; cin >> w >> v;

        for(int j = 100001; j - v >= 0; --j) {
            dp[j] = min(dp[j], dp[j - v] + w);
        }

    }
    int ans = 0;

    for(int i = 0; i < 100001; ++i) {
        if(dp[i] > W) continue;
        ans = max(ans, i);
    }

    cout << ans;

    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define pb(x) push_back(x)
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
#define eps 1e-8 
#define ll long long
#define ull unsigned long long
using namespace std;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f,maxn=1e5+100;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
ll n,m,k,t,dp[maxn];
vector<ll> g[maxn];
void dfs(int u,int fa)
{
	ll num=0;
	for(int i=0;i<g[u].size();i++)
	{
		int v=g[u][i];
		if(v==fa) continue;
		num++;
		if(u==1) dp[v]=max(0LL,m-num);
		else dp[v]=max(0LL,m-num-1);
		dfs(v,u);
	}
}
int main()
{
	fast;cin>>n>>m;
	FOR(i,1,n-1)
	{
		int u,v;cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dp[1]=m;
	dfs(1,0);
	int ans=1;
	FOR(i,1,n)
	ans=(ans*dp[i])%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 11264
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl;
#define wa() cout<<"No"<<endl;
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed long long (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed long long (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//


signed main(){
    int n=re;
    db t=n;
    printf("%.12f\n",n*n*n/3.0/3/3);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll minsum = a * (n - 1) + b;
    ll maxsum = a + b * (n - 1);
    ll ans = maxsum - minsum + 1;
    if (ans < 0) ans = 0;
    cout << ans << endl;
    return 0;
}


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

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

int main() {
  string s ;cin >> s;
  s.erase(std::unique(s.begin(), s.end()), s.end());
  cout << (int)s.size() - 1 << endl;
}


Measured memory_bytes: 512
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    x %= 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)


Measured memory_bytes: 9324
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct edge{ int to,cost; };
vector<int> dikstra(int s,vector<vector<edge>> G){
  typedef pair<int, int> P;
  const int INF = 1LL << 60;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(G.size(),INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  return d;
}

signed main(){

  int n, x, y; cin >> n >> x >> y;
  x--, y--;
  vector<vector<edge>> G(n);
  for(int i = 0; i < n-1; i++){
    G[i].push_back({i+1, 1});
    G[i+1].push_back({i, 1});
  }
  G[x].push_back({y, 1});
  G[y].push_back({x, 1});

  vector<vector<int>> dp(n);
  for(int i = 0; i < n; i++){
    dp[i] = dikstra(i, G);
    sort(dp[i].begin(),dp[i].end());
  }
  for(int i = 0; i < n-1; i++){
    int ans = 0;
    for(int j = 0; j < n; j++){
      ans += upper_bound(dp[j].begin(),dp[j].end(),i+1) - lower_bound(dp[j].begin(),dp[j].end(),i+1);
    }
    cout << ans / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 31872
#include <iostream>

using namespace std;

const int N = 100000;

int main(void){
  int a, b;
  cin >> a >> b;
  int ret = -1;
  for(int i = 0; i < N; i++){
    if((int)(i * 0.08) == a && (int)(i * 0.1) == b){
      ret = i;
      break;
    }
  }
  cout << ret << endl;
  return 0;
}


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

int p10[10];

int solve(int x, int y, int n) {
	if (x == 0) return 0;
	
	int ret = 0;
	
	//1桁
	if (x == y && x <= n) ret++;
	
	//2桁
	if (10 * x + y <= n) ret++;
	
	//3桁以上. x[]y. [0-9], [00-99], [000-999], …
	for (int i = 1; ; i++) {
		if (x * p10[i + 1] + (p10[i] - 1) * 10 + y <= n) {
			ret += p10[i];
		}
		else {
			int val = n - x * p10[i + 1] - y;
			if (val >= 0) {
				ret += val / 10 + 1;
			}
			break;
		}
	}
	return ret;
}

signed main() {
	int n;
	cin >> n;
	
	p10[0] = 1;
	for (int i = 1; i < 10; i++) p10[i] = p10[i - 1] * 10;
	
	int ans = 0;
	
	for (int x = 0; x <= 9; x++) {
		for (int y = 0; y <= 9; y++) {
			//a = x..y
			int cntA = solve(x, y, n);
			
			//b = y..x
			int cntB = solve(y, x, n);
			
			ans += cntA * cntB;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,K;
  cin>>N>>K;
  vector<int> S(N);
  int sum=0;
 for(int i=0;i<N;i++){
   cin>>S.at(i);
   sum+=min(S.at(i),K-S.at(i));
 }
  cout<<2*sum<<endl;
}

Measured memory_bytes: 256
#include<functional>
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

template <typename T>
class BIT {
    // 1-indexed
    private:
        size_t node_size_;
        T identity_;
        function<T(T, T)> operation_;
        function<T(T, T)> update_;
        vector<T> node_;
    public:
        BIT(size_t node_size, T identity, function<T(T, T)> operation, function<T(T, T)> update):
            node_size_(node_size), identity_(identity), operation_(operation), update_(update), node_(vector<T>(node_size + 1, identity)) {}
        void change(int idx, T new_value) {
            node_[idx] = update_(node_[idx], new_value);
            while (idx <= (int)node_size_) {
                idx += idx & -idx;
                if (idx > (int)node_size_) {
                    break;
                }
                node_[idx] = operation_(node_[idx], new_value);
            }
        }
        T query(int idx) {
            T res = identity_;
            while (idx > 0) {
                res = operation_(res, node_[idx]);
                idx -= idx & -idx;
            }
            return res;
        }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    BIT<ll> bit(N, 0, [](ll a, ll b) {return a + b;}, [](ll a, ll b) {return a + b;});
    ll a;
    rep(i, 0, N) {
        cin >> a;
        bit.change(i + 1, a);
    }
    int q, p, l, r;
    ll x;
    rep(i, 0, Q) {
        cin >> q;
        if (q) {
            cin >> l >> r;
            cout << bit.query(r) - bit.query(l) << endl;
        } else {
            cin >> p >> x;
            bit.change(p + 1, x);
        }
    }
    return 0;
}

Measured memory_bytes: 8240
#include <string>
#include <vector>
#include <numeric>
#include <iostream>

#include<algorithm>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)





int main(){
    int N, a[200100], c = 1;
    cin >> N;
    rep(i,N) cin >> a[i];
    rep(j,N){
        if(a[j] == c){
            c++;
        }
    } 
    if (c == 1){
        cout << -1 << endl;
    }
    else{ 
        cout << N - c + 1 << endl;
    }
}

Measured memory_bytes: 1024
#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++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	if(y==0) return x;
	return gcd(y,x%y);	
}

ll lcm(ll x, ll y) {
	ll z=gcd(x,y);
	return x/z*y;
}

int main()
{
	int c[9];
	rep(i,9) cin >> c[i];
	int a=c[0]+c[4]+c[8];
	int b=c[1]+c[5]+c[6];
	int d=c[2]+c[3]+c[7];
	if(a==b && b==d) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


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

using namespace std;

int main(){

    string S;
    cin >> S;

    int a, b;
    a = 0;
    b = 0;

    for( int i = 0; i < S.size(); i++)
    {
        
        if (i%2 == 0) {

            if(S[i] == '0'){
                ++a;
            }else{
                ++b;
            }

        }else{

            if(S[i] == '1'){
                ++a;
            }else{
                ++b;
            }
        }

    }

    if(a < b){
        cout << a << endl;
    }else{
        cout << b << endl;
    }

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
	~debug(){cerr<<endl;}
	template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
	template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
	template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
	template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
	template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;
ll a, b, n;

ll f(ll x) {
    return (a*x)/b - a*(x/b);
}

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

    cin >> a >> b >> n;
    ll x = b*(n/b)-1;
    cout << max(f(n), f(x)) << endl;
}


Measured memory_bytes: 3612
n=int(input())
z=[[[0 for y in range(10)]for i in range(3)]for j in range(4)]
for x in range(n):
	a,b,c,d=map(int,input().split())
	z[a-1][b-1][c-1]+=d
	
for j in range(4):
	for i in range(3):
		for h in range(10):
			print(" "+str(z[j][i][h]),end="")
		print()
	if j!=3:
		print("#"*20)



Measured memory_bytes: 5624