akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010, inf=1e9;
int n, ans, l, r;
char s[maxn];
inline void read(int &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;	
} 
int main()
{
	scanf("%s", s); int n=strlen(s);
	bool flag=0;
	for(int i=0;i<n;i++)
	if(s[i]!='0') flag=1;
	if(!flag) return printf("%d\n", n), 0;
	for(int i=(n>>1)+(n&1);i<n;i++)
	if(s[i]!=s[n-i-1] || s[i]!=s[i-1]) return printf("%d\n", i), 0;
	printf("%d\n", n);
}

Measured memory_bytes: 384
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,R;
    cin >> N >> R;
    if(N >= 10){
        print(R);
    }else{
        print(R + 100 * (10 - N));
    }


    

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int n,k,q,i,j;
	cin>>n>>k>>q;
	int a[q];
	for (i=0;i<q;i++) cin>>a[i];
	int cnt[n];
	for (i=0;i<n;i++) cnt[i]=k-q;
	for (i=0;i<q;i++) cnt[a[i]-1]+=1;
	for(j=0;j<n;j++){
		if (cnt[j]<=0) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1408
n = input()
#print(type(n))
a = n[-1]
#print(a)

if a == "2" or a =="4" or a =="5" or a =="7" or a =="9":
    print("hon")
elif a =="0" or a == "1" or a =="6" or a =="8":
    print("pon")
elif a =="3":
    print("bon")

Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> red(n),blue(n);
    rep(i,0,n){
        int a,b;
        cin>>a>>b;
        red.at(i)=make_pair(a,b);
    }
    
    rep(i,0,n){
        int c,d;
        cin>>c>>d;
        blue.at(i)=make_pair(c,d);
    }
    sort(all(blue));
    
    int ans=0;
    rep(i,0,n){
        int a,b;
        tie(a,b)=blue.at(i);
        
        int max_d=-1;
        int max_j=-1;
        rep(j,0,n){
            int c,d;
            tie(c,d)=red.at(j);
            
            if(c>a) continue;
            if(d>b) continue;
            if(c==-1) continue;
            
            if(d>=max_d){
                max_d=d;
                max_j=j;
            }
        }
        if(max_j!=-1){
            red.at(max_j)=make_pair(-1,-1);
            ans++;
        }
    }
    
    cout<<ans<<endl;
}



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

long ne(long a,int l)
{
    int i,j,t,s[7]={0};
    double x=0,y=0;
    for(i=0;i<l;i++)
    {
        if(a>0)
        {
            s[i]=a%10;
            a=a/10;
        }
    }
    for(i=0;i<l;i++)//sheng
        for(j=i+1;j<l;j++)
        if(s[i]>=s[j])
        {
            t=s[i];s[i]=s[j];s[j]=t;
        }
    for(i=0;i<l;i++)
    x=x*10+s[i];//min
    //printf("x===%ld\n",x);
    for(i=l-1;i>=0;i--)
    y=y*10+s[i];//max
    //printf("y===%ld\n",y);
    return y-x;
}

int main()
{
    long a[21];
    int l,i,j,tag;
    //freopen("in.txt","r",stdin);
    while(scanf("%ld%d",&a[0],&l))
    {

        if(a[0]==0 && l==0)break;
        tag=0;
        for(i=1;i<=20;i++)
        {
            if(tag)break;
            a[i]=ne(a[i-1],l);
            //printf("%ld\n",a[i]);
            for(j=0;j<i;j++)
            if(a[i]==a[j])
            {
                printf("%d %ld %d\n",j,a[i],i-j);
                tag=1;
                break;
            }
        }
        //puts("");
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<ll>vec(N);
	ll sum = 0;
	rep(i, 0, N) {
		cin >> vec[i];
		sum += vec[i];
	}
	ll cnt = 0;
	int x = 1;
	rep(i, 1, N) {
		cnt += 2 * vec[i - 1];
		++i;
	}
	ll dN = sum - cnt;
	vector<ll>ans(N);
	ans[N - 1] = dN;
	rREP(i, 0, N - 1) {
		ans[i] = 2 * vec[i] - ans[i + 1];
	}
	rep(i, 0, N) {
		cout << ans[i];
		if (i < N - 1)cout << " ";
		else cout << "\n";
	}


	return 0;
}

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

using namespace std;

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

	unordered_set<char> vowels = { 'a', 'e', 'i', 'o', 'u' };
	char c;
	cin >> c;
	if (vowels.find(c) == vowels.end()) {
		cout << "consonant\n";
	} else {
		cout << "vowel\n";
	}
	

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll choose2(ll n) {
  return n*(n-1)/2;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  REP(i, n) a[i]--;
  vector<int> cnt(n);
  REP(i, n) cnt[a[i]]++;
  ll tot = 0;
  REP(i, n) {
    tot += choose2(cnt[i]);
  }
  REP(i, n) {
    ll ans = tot;
    ans -= choose2(cnt[a[i]]);
    ans += choose2(cnt[a[i]]-1);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iterator>
#include<algorithm>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;

	std::vector<unsigned long long int> v(n);
	unsigned long long int ans = 1;
	for (int i = 0; i < n; ++i)
	{
		cin>>v[i];
	}
	for(int i = 0; i < n; i++) {
		if(v[i] == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 0; i < n; ++i)
	{
		// ans *= v[i];
		unsigned long long temp = ans * v[i];
		// cout << temp << endl;
		if(temp > 1000000000000000000ULL || temp / ans != v[i]){
			// cout << temp << " " << v[i] << endl;
			cout<<"-1"<<endl;
			return 0;
		}
		ans = temp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3992
#include<stdio.h>
 
void visit(int);
int dequeue(void);
void enqueue(int);
 
int map[101][101];
int Q[101],n,head=0,tail=0,color[101],d[101];
int main()
{
  int i,j,v,vv,m,u,k;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    color[i]=0;
    for(j=0;j<n;j++){
      map[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&m);
    for(j=0;j<m;j++){
      scanf("%d",&vv);
      map[v-1][vv-1]=1;
    }
  }
 
  for(j=0;j<n;j++){
    if(map[0][j]==1){
      color[j]=0;
    }
  }
  color[0]=1;
  d[0]=0;
  enqueue(0);
  while(head!=tail){
    u=dequeue();
    for(k=0;k<n;k++){
      if(map[u][k]==1 && color[k]==0){
    color[k]=1;
    d[k]=d[u]+1;
    enqueue(k);
      }
      color[u]=2;
    }
  }
   
 
   
  for(i=0;i<n;i++){
    if(color[i]==2)printf("%d %d\n",i+1,d[i]);
    else printf("%d -1\n",i+1);
  }
  return 0;
}
 
int dequeue()
{
  int x;
  x=Q[head];
  if(head+1==100)head=0;
  else head=head+1;
  return x;
}
 
void enqueue(int x)
{
  Q[tail]=x;
  if(tail+1==100)tail=0;
  else tail=tail+1;
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	ll N, min_sum=10000000000000, a, b;
	cin >> N;
	for(ll i = 1; i<=N/i; i++)
	{
		if (N%i==0)
		{
			if (min_sum>i+N/i)
			{
				a = i;
				b = N/i;
			}
		}
	}
	cout << (a-1)+(b-1) << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

const int mod=1000000007;

const int INF=1001001001001001001ll;

inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}

int N,M;
int S,T;
vpint G[222222];
int U[222222],V[222222],D[222222];

vpint dijkstra(int s){
    vpint dist(N,pint(INF,1));
    dist[s]={0,1};
    priority_queue<pint,vector<pint>,greater<pint>>que;
    que.push({0,s});
    while(que.size()){
        int c,v;
        tie(c,v)=que.top();
        que.pop();
        if(dist[v].fi<c)continue;
        for(auto &e:G[v]){
            if(dist[e.fi].fi<c+e.se)continue;
            if(dist[e.fi].fi==c+e.se){
                add(dist[e.fi].se,dist[v].se);
            }
            else{
                dist[e.fi]=dist[v];
                dist[e.fi].fi+=e.se;
                que.push({dist[e.fi].fi,e.fi});
            }
        }
    }
    return dist;
}

signed main(){
    cin>>N>>M>>S>>T;S--;T--;
    rep(i,M){
        cin>>U[i]>>V[i]>>D[i];
        U[i]--;V[i]--;
        G[U[i]].pb({V[i],D[i]});G[V[i]].pb({U[i],D[i]});
    }

    vpint distS=dijkstra(S);
    vpint distT=dijkstra(T);

    int ans=distS[T].se;
    ans=ans*ans%mod;

    rep(i,N){
        if(distS[i].fi+distT[i].fi!=distS[T].fi||distS[i].fi!=distT[i].fi)continue;
        int tmp=distS[i].se*distT[i].se%mod;
        ans=(ans-tmp*tmp%mod+mod)%mod;
    }

    rep(i,M){
        int u,v,d;
        u=U[i];
        v=V[i];
        d=D[i];
        rep(ei,2){
            swap(u,v);
            if(distS[u].fi+distT[v].fi+d!=distS[T].fi)continue;
            if(!(distS[u].fi*2<distS[T].fi&&distS[v].fi*2>distS[T].fi))continue;
            int tmp=distS[u].se*distT[v].se%mod;
            ans=(ans-tmp*tmp%mod+mod)%mod;
        }
    }

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


Measured memory_bytes: 26708
#include <cstdio>

using namespace std;

int fromf(char c){
	if('0' <= c && c <= '9'){
		return c - '0';
	}else{
		return 10 + c - 'a';
	}
}

char tof(int i){
	if(i < 10){
		return '0' + i;
	}else{
		//printf("\n!!%d!!\n",i);
		return 'A' + (i - 10);
	}
}

int main(){
	int data;
	int self;
	char c[256];
	char ans[256];
	char *pt,*ptt;
	while(scanf("%d",&data) && data != -1){
		sprintf(c,"%x",data);
		ptt = ans;
		pt = c;
		while(*pt != '\0'){
			
			self = fromf(*pt);
			self /= 4;
			//printf("!%d->%d\n",self,self/4);
			*ptt = tof(self);
			ptt++;
			self = fromf(*pt) % 4;
			*ptt = tof(self);
			ptt++;
			pt++;
		}
		*ptt = '\0';
		ptt = ans;
		if(*ptt == '0'){
			ptt++;
		}
		printf("%s\n",ptt);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    ll num[200001], A[200001];
    cin>>N;
    MEMSET(num, 0);
    rep(i, N){
        cin>>A[i];
        num[A[i]]++;
    }
    ll count=0;
    rep1(i, N){
        count+=num[i]*(num[i]-1)/2;
    }
    rep(i, N){
        cout<<count-(num[A[i]]-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOPSIC2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(2 * Math.PI * double.Parse(Console.ReadLine()));
        }
    }
}


Measured memory_bytes: 18460
import copy
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
Hch=copy.copy(H)
for i in range(0,M):
    A,B=list(map(int,input().split()))
    if H[A-1]>H[B-1]:
        Hch[B-1]=0
    elif H[A-1]<H[B-1]:
        Hch[A-1]=0
    elif H[A-1]==H[B-1]:
        Hch[A-1]=0
        Hch[B-1]=0
print(len(H)-Hch.count(0))

Measured memory_bytes: 20928
S = input()
T = input()

min_count = 1000
for idx in range(len(S) - len(T) + 1):
    s = S[idx:idx+len(T)]
    count = sum([1 if tc!=sc else 0 for tc, sc in zip(T, s)])
    min_count = min(min_count, count)

print(min_count)

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define MAXN 11111

const int INF = 1 << 29 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
    int n ,  a, b ;
    cin >> n >> a >> b ;
    cout << min(n*a  , b) << endl ;
    return 0 ;
}

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

int main()
{
  int n, d, a[10][10], ans = 0;
  cin >> n >> d;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < d; j++)
      cin >> a[i][j];
    for (int ii = 0; ii < i; ii++)
    {
      int sqrDist = 0;
      for (int j = 0; j < d; j++)
        sqrDist += (a[i][j] - a[ii][j]) * (a[i][j] - a[ii][j]);
      int dist = int(sqrt(sqrDist));
      ans += dist * dist == sqrDist;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int x[5];
    for (int i = 0;i < 5;i++){
        scanf("%d",&x[i]);
    }
    for (int i = 0;i < 5;i++){
        if (x[i] != i + 1) printf("%d\n",i + 1);
    }
    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
int a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    int ma=0;
    for(int i=1;i<=n;i++){
        if(a[i]>a[ma])
            ma=i;
    }
    int ma2=0;
    for(int i=1;i<=n;i++){
        if(a[i]>a[ma2]&&i!=ma)
            ma2=i;
    }
    for(int i=1;i<=n;i++){
        if(i!=ma){
            cout << a[ma] << endl;
        }
        else
            cout << a[ma2]<< endl;
    }
    return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
int getkey(char []);
int h1(int);
int h2(int);
int Getc(char);
#define M 1046527
#define L 14
typedef struct a{
  char H[L];
  bool X;
}has;
has hash[M];
void insert(char []);
bool find(char []);
int main(){
  int n,i;
  char X[L],command[7];
  for(i=0;i<M;i++){
    hash[i].X=false;
    hash[i].H[0]='\0';
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",command,X);
    if(command[0]=='i'){
      insert(X);
    }
    else{
      if(find(X))printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}
int Getc(char str){
  if(str=='A')return 1;
  else if(str=='C')return 2;
  else if(str=='G')return 3;
  else if(str=='T')return 4;
  else return 0;
}
int h1(int x){
  return x%M;
}
int h2(int x){
  return 1+(x%(M-1));
}
int getkey(char str[]){
  int sum=0,i,p=1;
  for(i=0;i<strlen(str);i++){
    sum+=p*Getc(str[i]);
    p*=3;
  }
  return sum;
}
void insert(char str[]){
  
  int num,i,h;
  num=getkey(str);
  for(i=0;;i++){
    h=(h1(num)+i*h2(num))%M;
    if(!hash[h].X){
      strcpy(hash[h].H,str);
      hash[h].X=true;
      return;
    }
  }
}
bool find(char str[])
{
  int i,num,h;
  num=getkey(str);
  for(i=0;;i++){
     h=(h1(num)+i*h2(num))%M;
     if(!strcmp(hash[h].H,str))return true;
     else if(strlen(hash[h].H)==0)return false;
  }
  return false;
}



Measured memory_bytes: 17068
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
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; }
int main(){
    int N,T;
    cin>>N>>T;
vector<pair<int,int>> P(N);
for(int i=0;i<N;i++){
    cin>>P.at(i).first;
    cin>>P.at(i).second;
}
sort(P.begin(),P.end());
for(int i=0;i<N;i++){
    if(P.at(i).second<=T){
        cout<<P.at(i).first;
        return 0;
    }
}
cout<<"TLE"<<endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "math.h"
#include "vector"
using namespace std;

bool jadge(int n){
	if (n == 1)return false;
	if (n == 3)return true;
	if (n == 2)return true;
	if (n % 2 == 0)return false;
	int r = sqrt(n);
	for (int i = 3; i <= r; i+=2){
		if (n % i == 0)return false;
	}
	return true;
}

int solve(vector<int> &v){
	int result = 0;
	for (int i = 0; i < v.size(); ++i){
		if (jadge(v[i]))result++;
	}
	return result;
}

int main(){
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; ++i){
		cin >> v[i];
	}
	cout << solve(v) << endl;
}

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

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int k;
    cin >> k;
    int sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                int temp = __gcd(a, b);
                sum += __gcd(temp, c);
            }
        }
    }
    cout << sum;
}


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

int main() {
 int N,A = 0;
 cin >> N;
 for(int i=1; i<=N; i++){
   if (i>0 && i<10 ){
     A++;
   }
   else if (i>99 && i<1000){
     A++;
   }
   else if (i>9999 && i<100000){
     A++;
   }
 }
   cout << A << endl;
}


Measured memory_bytes: 3640
N, K = map(int, input().split())
x = list(map(int, input().split()))

lst = []
for i in range(N-K+1):
    if x[i] <= 0 and x[i+K-1] <= 0:
        lst.append(abs(x[i]))
    elif x[i] >= 0 and x[i+K-1] >= 0:
        lst.append(x[i+K-1])
    else:
        d1 = abs(x[i]) + x[i+K-1] - x[i]
        d2 = x[i+K-1] + x[i+K-1] - x[i]
        lst.append(min(d1, d2))
print(min(lst))


Measured memory_bytes: 14660
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define REPL1(i, n) for (long i = 1; i < n; i++)

using namespace std;

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

    vector<long> vec;

    REPL1(x, sqrt(n) + 1)
    {
        if (n % x == 0)
        {
            long y = n / x;
            long ij = x - 1 + y - 1;
            vec.push_back(ij);
        }
    }

    sort(vec.begin(), vec.end());
    cout << vec.front() << endl;
}

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

int main(void) {

	int s[6], a, b, i, j, x, count=0;

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

	for (i = a; i <= b; i++) {
		x = i;

		for (j = 0; j <= 4; j++) {
			s[j] = x % 10;
			x /= 10;
		}
		if (s[0] == s[4] && s[1] == s[3]) {
			count++;
		}
	}

	printf("%d", count);

	return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vector<P> p(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(all(p));

    ll ans = 0;
    ll cnt = 0;
    rep(i, n) {
        ll a = p[i].first;
        ll b = p[i].second;
        if(cnt + b > m) {
            ans += a*(m - cnt);
            break;
        }
        else {
            ans += a*b;
            cnt += b;
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            int[] countRoads = new int[n];

            foreach (var currentRoad in Enumerable.Range(0, m))
            {
                var ab = Console.ReadLine().Split(' ');
                countRoads[int.Parse(ab[0]) - 1]++;
                countRoads[int.Parse(ab[1]) - 1]++;
            }
            foreach(var currentCount in countRoads)
            {
                Console.WriteLine(currentCount);
            }

        }
    }
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

int main() {
    string s; cin >> s;
    string ans;
    if (s == "Sunny") {
        ans = "Cloudy";
    } else if (s == "Cloudy") {
        ans = "Rainy";
    } else {
        ans = "Sunny";
    }
    cout << ans << endl;
    return 0;
}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int n;
int* c;
ll* s;
int* f;
ll sol=0;
void solve(){
	FOR(i,n-1){
		sol=0;
		for(int j=i;j < n-1;j++){
			if(j==i) sol+=s[j];
			else{
				ll r= sol%f[j];
				if(sol <= s[j]) sol=s[j];
				else if(r==0) ;
				else sol+=f[j]-r;
			}
			sol+=c[j];
		}
		cout << sol << "\n";
	}
	cout << 0;
}

int main(){
	startTime=clock();
	cin >> n;
	c=new int[n-1];
	s=new ll[n-1];
	f=new int[n-1];
	FOR(i,n-1){
		cin >> c[i] >> s[i] >> f[i];
	}
	solve();

	return 0;
}

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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = 0; i < k; i++){
    if (i % 2 == 0) {
    if (a & 1) a--;
    b += a / 2;
    a /= 2;
    } else {
    if (b & 1) b--;
    a += b / 2;
    b /= 2;
    }
  }
  cout << a << " " << b << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int n;
pair <int, int> get(string& s)
{
	stack <char> st;
	pair <int, int> ans;
	ans.first = 0;
	for (int i = 0; i < (int)s.size(); i++)
	{
		if (s[i] == '(')
			st.push('(');
		else
		{
			if (!st.empty())
				st.pop();
			else
				ans.first++;
		}
	}
	ans.second = (int)st.size();
	return ans;
}
bool balanced(string &s)
{
	int x = 0, y = 0;
	for (int i = 0; i < (int)s.size(); i++)
	{
		if (s[i] == '(')
			x++;
		else
			y++;
		if (x < y)
			return false;
	}
	if (x == y)
		return true;
	else
		return false;
}
int32_t main() {
	fast_io();
	cin >> n;
	vector < pair <int, int>> v1;
	vector < pair <int, int>> v2;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		pair <int, int> p = get(s);
		if (p.first == 0 && p.second == 0)
			continue;
		else
		{
			if (p.second - p.first >= 0)
				v1.pb(p);
			else
				v2.pb({p.second, p.first});
		}
	}
	sort(v1.begin(), v1.end());
	sort(v2.rbegin(), v2.rend());
	string res;
	for (auto x : v1)
	{
		for (int i = 0; i < x.first; i++)
			res += ')';
		for (int i = 0; i < x.second; i++)
			res += '(';
	}
	for (auto x : v2)
	{
		for (int i = 0; i < x.second; i++)
			res += ')';
		for (int i = 0; i < x.first; i++)
			res += '(';
	}
	if (balanced(res))
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 21608
#include <iostream>
#include <string>
#include <algorithm> 
using namespace std;
int main(){
    int n,ans=0;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(a[i]!=a[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n, l = map(int, input().split())

min_apple = 10**10
ans = 0
index = 0
for i in range(1, n+1):
    ans += l+i-1
    min_apple = min(abs(l+i-1), min_apple)
    index = i
    if min_apple > abs(l+i-1):
        min_apple = min(abs(l+i-1), min_apple)
        index = i
print(ans - min_apple if l+index-1>0 else ans + min_apple)

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string L;
    cin >> L;
    ll k=L.size();
    vl dp0(k),dp1(k);//dp1はその桁まで見た時にそれ未満となることが保証されている組である
    dp0[0]=2;
    dp1[0]=1;
    rep(i,k-1){
        if(L[i+1]=='0'){
            dp0[i+1]=dp0[i]%MOD;
            dp1[i+1]=3*dp1[i]%MOD;
        }
        else{
            dp0[i+1]=2*dp0[i]%MOD;
            dp1[i+1]=(dp0[i]+3*dp1[i])%MOD;
        }
    }
    cout << (dp0[k-1]+dp1[k-1])%MOD << endl;
}


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

int main()

{
    int a, b, c, ar, s ;

    scanf("%d %d %d", &a, &b, &c) ;
    s=(a+b+c)/2 ;
    ar=sqrt(s*(s-a)*(s-b)*(s-c)) ;

    printf("%d\n", ar) ;

    return 0;
}

Measured memory_bytes: 2132
#include<iostream>
using namespace std;
int main()
{
	long long sum=100,x;
	cin>>x;
	int tot=0;
	for(long long i=1;i<=x;i++)
	{
		sum*=1.01;
		tot++;
		if(sum>=x)
		{
			cout<<tot;
			break;
		}
	}
}

Measured memory_bytes: 3632
def solve():
  ar = raw_input().split(' ')
  N = int(ar[0])
  T = int(ar[1])
  ar = raw_input().split(' ')
  end = 0
  count = 0
  for i in range(N):
    ti = int(ar[i])
    if(ti < end) : count -= (end-ti)
    end = ti + T
    count += T
  return count

if __name__ == '__main__' :
  print solve()

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, M; cin >> N >> M;
    vec v(N, 0);
    rep(i, M){
        int a, b; cin >> a >> b;
        a--; b--;
        v[a]++;
        v[b]++;
    }
    rep(i, N){
        if(v[i]%2){
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4736
use proconio::input;
fn main() {
    input!(n: usize);
    let mut n = n;
    let mut v = Vec::new();
    while n > 0 {
        let now = n % 26;
        if now == 0 {
            v.push(25);
            n -= 26;
        } else {
            v.push(now - 1);
        }
        n /= 26;
    }
    v.reverse();
    let alpha = b"abcdefghijklmnopqrstuvwxyz";
    let mut ans = vec![];
    for &e in &v {
        if e > 26 {
            println!("{}", e);
        }
        ans.push(alpha[e] as char);
    }

    let ans: String = ans.iter().collect();
    println!("{}", ans);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
pl P[MAX_N]; //r and l

void solve() {
	cin >> N;
	rep(i, 0, N) {
		ll x, l; cin >> x >> l;
		P[i] = pl(x + l, x - l);
	}
	sort(P, P + N);
	ll pre = -linf;
	int cnt = 0;
	rep(i, 0, N) {
		// debug(P[i]);
		if(pre <= P[i].sec) {
			pre = P[i].fst;
			cnt++;
		}
	}
	cout << cnt << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  if(t.size()!=s.size()+1) { cout<<"No"<<endl; return 0;}

  bool f=true;
  rep(i, s.size()){
    if(s[i]!=t[i])f=false;
  }

  if(f)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3620
import collections

h, w, n = map(int, input().split())
squares = collections.defaultdict(lambda: collections.defaultdict(int))
for index in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(-2, 1):
        for j in range(-2, 1):
            y = a + i
            x = b + j
            if 0 <= x < w - 2 and 0 <= y < h - 2:
                squares[y][x] += 1
counter = collections.Counter()
for y, xs in squares.items():
    for x, count in xs.items():
        counter[count] += 1
print((h - 2) * (w - 2) - sum(counter.values()))
for i in range(1, 10):
    print(counter[i])

Measured memory_bytes: 155524
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        for (int i = 0; i < 4; i++) {
            if (s.charAt(i) == '+') {
                ans++;
            } else {
                ans--;
            }
        }
        System.out.println(ans);
    }    
}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main()
{
	int a1, b1;
	cin >> a1>>b1;
	int c1, c2, c3,c4;
	c1 = a1 + b1;
	c2 = a1 - b1;
	c3 = a1 * b1;
	c4 = max(c1, c2);
	c4 = max(c4, c3);
	cout << c4 << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, d, x int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d %d", &d, &x)

	cnt := 0
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)

		for c := 1; c <= d; c += a {
			cnt += 1
		}
	}

	fmt.Println(cnt + x)
}


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

long long calc(long long a, long long b) {
    return (b - ((a + b) / 2));
}

int main() {
    long long n, a, b, res;
    cin >> n >> a >> b;
    if ((b - a - 1) % 2 == 1) res = b - ((a + b) / 2);
    else {
        // cout << calc(1, 5) << endl;
        res = min(a + calc(1, b - a), n - b + 1 + calc(a + n - b + 1, n));
    }
    cout << res << "\n";
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    // Your code here!
    var n = readLine()!!.toInt()
    var list:MutableList<Pair<Int,Int>> = mutableListOf()
    var preans = 0.0
    var ans = 0.0

    for(i in 1..n){
        var (x,y) = readLine()!!.split(" ").map{it.toInt()}
        list.add(x to y)
    }
    
    for(i in 0..n-1){
        for(j in i+1..n-1){
            var dis = (list[i].first - list[j].first) * (list[i].first - list[j].first) + 
            (list[i].second - list[j].second) * (list[i].second - list[j].second)
            preans += Math.sqrt(dis.toDouble())
        }
    }
    
    ans = (2*preans)/n
    println(ans)
}


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

using namespace std;
const int MAXN=110; const int MAXK=110000; const long long int MOD = 1e9+7;
int A[MAXN],N,K;
long long int sol[MAXN][MAXK];
void dp(){
	for(int index=N;index>=0;index--)
		for(int remaining=K;remaining>=0;remaining--)
		{
			if(index>=N && remaining!=0)
				sol[index][remaining]=0;
			else if(remaining==0)
				sol[index][remaining]=(sol[index][remaining+1]+1)%MOD;
			else 
				sol[index][remaining]=(sol[index][remaining+1]+(sol[index+1][max(0,remaining-A[index])]+MOD-sol[index+1][remaining+1])%MOD)%MOD;	
		}
}
int main(){
	cin>>N>>K;
	for(int i=0;i<N;i++)
		cin>>A[i];
	for(int i=0;i<=N;i++)
		sol[i][K+1]=0;
	dp();
	cout<<sol[0][K];
}

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

int main(){
    long long a,b,c,k,ans;
    cin >> a >> b >> c >> k;

    if(a >= k) ans=k;
    else if(a+b >= k) ans=a;
    else ans=a-(k-a-b);

    cout << ans << endl;
}

Measured memory_bytes: 3636
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

class SegmentTree:
	def __init__(self,N,S):
		self.N = N
		self.tree = [0]*(2*N-1)
		for i,s in enumerate(S):
			self.update(i,s)
	def update(self,i, x):
		i += self.N-1
		self.tree[i] = 1<<int(ord(x)-97)
		while (i > 0):
			i = (i-1) // 2
			self.tree[i] = self.tree[i*2+1] | self.tree[i*2+2]
	def query(self,a,b,k,l,r):
		if(r<=a or b<=l): return 0
		if (a<=l and r<=b) : return self.tree[k]
		else:
			c1 = self.query( a, b, 2 * k + 1, l, (l+r) // 2)
			c2 = self.query( a, b, 2 * k + 2, (l+r) // 2, r)
			return c1 | c2

def count_one_by_shift(num):
	num = (num & 0x55555555) + ((num & 0xAAAAAAAA) >> 1) 
	num = (num & 0x33333333) + ((num & 0xCCCCCCCC) >> 2)
	num = (num & 0x0F0F0F0F) + ((num & 0xF0F0F0F0) >> 4)
	num = (num & 0x00FF00FF) + ((num & 0xFF00FF00) >> 8)
	num = (num & 0x0000FFFF) + ((num & 0xFFFF0000) >> 16)
	return num

def main():
	n = II()
	S = IS()
	N = 1
	while N < n: N*=2
	st = SegmentTree(N,S)
	Q = II()
	ans = []
	for _ in range(Q):
		op, x, y = sys.stdin.readline().split()
		op = int(op)
		if op==1:
			x=int1(x);
			st.update(x,y)
		else:
			x,y=int1(x),int1(y)
			ans.append(count_one_by_shift(st.query(x,y+1,0,0,N)))
	printV(ans)


if __name__ == '__main__':
	main()

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
    int N,M,A,B;
    cin>>N>>M>>A>>B;
    vint D(N);rep(i,N)cin>>D[i];

    int cur=0;
    while(cur<N&&D[cur]>=A)cur++;
    if(N-cur<M)while(cur>0&&D[cur-1]<=B)cur--;
    cout<<cur<<endl;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define all(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  int ans=1;
  int a,b;
  cin>>a>>b;
  if(b==1)
  {
    cout<<0<<endl;
    exit(0);
  }
  int temp=a;
  while(a<b)
  {
    ans++;
    a=(temp-1) +a;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main(){
    int C[9], a1, a2, a3, b1, b2, b3;
    for(int i=0;i<9;i++){
        cin >> C[i];
    }
    string ans = "No";
    for(int i=0;i<=100;i++){
        a1 = i;
        b1 = C[0]-a1;
        a2 = C[1]-b1;
        a3 = C[2]-b1;
        b2 = C[3]-a1;
        b3 = C[6]-a1;
        if(C[4]==a2+b2 && C[5]==a3+b2 && C[7]==a2+b3 && C[8]==a3+b3){
            ans = "Yes";
            break;
        }

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


Measured memory_bytes: 256
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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

int main() {

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
       double a,b,h,m;
       cin>>a>>b>>h>>m;
       cout<<fixed<<showpoint;
       cout<<setprecision(9);
       cout<<sqrt(a*a+b*b-cos((pi*abs((h*30.0)+(m*.5)-(6.0*m)))/180.0)*2.0*a*b);
    }
    return 0;
}



Measured memory_bytes: 4204
#include<stdio.h>
#include<stdlib.h>
    
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef node* Node;
#define NIL NULL
   
node array[500000];
int size=0;
   
Node root = NIL;
    
Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}
    
Node treeSearch(Node u, int k){
  Node i=u;
  while(i!=NIL){
    if(i->key==k)return i;
    else if(i->key<k)i=i->right;
    else i=i->left;     
  }
  return NIL;
}
    
Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
    
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
      
  if(y->left!=NIL)x=y->left;
  else x=y->right;
    
  if(x!=NIL)x->parent=y->parent;
      
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;
    
  if(y!=z)z->key=y->key;
      
  //free(y);
}
    
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
    
  z = &array[size++];
  z->key = k;
  z->left = NIL;
  z->right = NIL;
    
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;   
}
   
   
void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
   
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
   
   
int main(){
  int n,x;
  char str[20];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s", str);
    if(str[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if (t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }
   
  return 0;
}


Measured memory_bytes: 15052
#白だけ返す、黒だけ返すとは限らない
#左は白、右は黒、にすることもある
n = int(input())
s = input()
b = 0
w = 0
bl = []
wl = []
for i in range(n):
    if s[i]==".":
        w += 1
        if b:
            bl.append(b)
            b = 0
    else:
        b += 1
        if w:
            wl.append(w)
            w = 0
if b:
    bl.append(b)
if w:
    wl.append(w)

if s[-1] == "#":
    bl.pop()


if s[0] == ".":
    wl.pop(0)
ans_b = 0
ans_w = sum(wl)
ans = ans_w + ans_b

for i in range(len(bl)):
    ans_b += bl[i]
    ans_w -= wl[i]
    ans = min(ans,ans_b +ans_w )

print(ans)

Measured memory_bytes: 52064