akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<cctype>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
using namespace std;
const int N=300005;
int n,L,ans=1,cnt,ok;
int x[N],t[N],l[N],r[N];
int main(){
	n=read();L=read()<<1;
	for(int i=1;i<=n;i++)x[i]=read();
	for(int i=1;i<=n;i++)t[i]=read();
	for(int i=1;i<=n;i++){
		int v=t[i]%L;
		ans+=t[i]/L+(t[i]%L!=0);
		l[i]=(0<v&&v<=2*x[i]);
		r[i]=(0<v&&v<=L-2*x[i]);
	}
	for(int i=1;i<n;i++)
		if(cnt&&r[i]){if(l[i])++ok;--ans;--cnt;}
		else if(l[i]) cnt++;
		else if(r[i]&&ok) ok--,cnt++;
	if(r[n])ans--;
	printf("%lld\n",1ll*ans*L);
	return 0;
}


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

int main() {
	
	ll d, g; cin >> d >> g;
	vector<ll> p(d), c(d);	
	for (ll i = 0; i < d; i++) {
		cin >> p[i] >> c[i];
	}
	ll ans = 9223372036854775807LL;
	for (int bit = 0; bit < (1 << d); ++bit) {
		ll tmpAns = 0;
		ll tmpPointSum = 0;
		vector<bool> used(d, false);
		for (ll i = 0; i < d; ++i) {
			if (bit & (1 << i)) {
				used[i] = true;
				tmpAns += p[i];
				tmpPointSum += (i + 1) * 100 * p[i];
				tmpPointSum += c[i];
			}
		}
		if (g <= tmpPointSum) {
			ans = min(ans, tmpAns);
			continue;
		}
		for (ll i = d - 1; i >= 0; i--) {
			if (used[i]) continue;
			ll p_cnt = p[i];
			while (p_cnt--) {					
				if (g <= tmpPointSum) {
					ans = min(ans, tmpAns);
					break;
				}
				tmpPointSum += (i + 1) * 100;
				tmpAns++;
			}
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3548
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,k,n) for(int (i)=(k);(i)<(n);(i)++)
using namespace std;
typedef long long int ll;

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i+1;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}



int main() {
    double H,W;
    cin >> H >> W;
    ll result = ceil(H*W/2);
    if(H==1||W==1){
        cout << 1<< endl;
    }else{
        cout << result << endl;
    }


}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int small[3][3] = {{0,1,0},{1,1,1},{0,1,0}};
int medium[3][3] ={{1,1,1},{1,1,1},{1,1,1}};
int big [5][5] = {{0,0,1,0,0},{0,1,1,1,0},{1,1,1,1,1},{0,1,1,1,0},{0,0,1,0,0}};

int main(){
    int paper[10][10] = {0};
    int x, y, size;
    int pivot_x, pivot_y;
    while(~scanf("%d,%d,%d", &x, &y, &size)){
        if(size == 1 || size == 2){
            pivot_x = x-1;
            pivot_y = y-1;
            for(int i=0; i<3; i++){
                for(int j=0; j<3; j++){
                    if((pivot_x+j >= 0)&&(pivot_x+j <= 9)&&(pivot_y+i >= 0)&&(pivot_y+i <= 9)){
                        if(size == 1){
                            paper[pivot_y+i][pivot_x+j] += small[j][i];
                        }else{
                            paper[pivot_y+i][pivot_x+j] += medium[j][i];
                        }
                    }
                }
            }
        }else{
            pivot_x = x-2;
            pivot_y = y-2;
            for(int i=0; i<5; i++){
                for(int j=0; j<5; j++){
                    if((pivot_x+j >= 0)&&(pivot_x+j <= 9)&&(pivot_y+i >= 0)&&(pivot_y+i <= 9)){
                        paper[pivot_y+i][pivot_x+j] += big[j][i];
                    }
                }
            }

        }
    }
    int max = 0;
    int cnt = 0;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            if(max < paper[i][j]){
                max = paper[i][j];
            }
            if(paper[i][j] == 0){
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    cout << max << endl;
    return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int N, T, A;
    cin >> N >> T >> A;
    vector<double> H(N);
    double h;
    REP(i, N){
        cin >> h;
        H[i] = fabs(T - h * 0.006 - A);
    }
    PRINT(min_element(ALL(H)) - H.begin() + 1);
    return 0;
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
//typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void printvi(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printvil(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}
void printvvi(vector<vector<int>> v){
    rep(i,0,v.size()){
        rep(j,0,v[i].size()){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
void printvstr(vector<string> v){
    rep(i,0,v.size()){
        cout<<v[i]<<endl;
    }
}

signed main (){
    rep(i,0,7){
        int a,b;
        cin>>a>>b;
        cout<<a-b<<endl;
    

    }

    
}
/*
*/



Measured memory_bytes: 3100
#include <stdio.h>

int f(int N, int one) {
	if (one) return (N - 1) / 2 * 2 + 1;
	return N / 2 * 2;
}

int main() {
	int T; for (scanf("%d", &T); T--; ) {
		int N, D; scanf("%d%d", &N, &D);
		int ans = 0;
		for (int bit = 0; bit < 7; bit++) {
			int x = ((1 << bit) & D) > 0;
			ans += f(N, x) * (1 << bit);
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long s[365][26]; 
int main() {
  int Date;
  cin >>Date;
  //int d=365;
  vector<int>c(26);
  vector<int>last(26,0);
  //vector<int>hinichi(26,0);
  long long wa=0;
  for(int i=0;i<26;i++){
    cin>>c[i];
    wa+=c[i];
  }
  for(int i=0;i<Date;i++){
    for(int j=0;j<26;j++){
      cin>>s[i][j];
    }
  }
  vector<int>t(Date);
  for(int i=0;i<Date;i++){
    cin>>t[i];
    t[i]--;
  }
  /*long long kotae=0;
  int hinichi=0;
  long long hikukazu=0;
  for(int i=0;i<Date;i++){
    long long atai=0;
    atai=s[i][t[i]];
    hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
    last[t[i]]=i;
    kotae+=atai-hikukazu;
    cout<<kotae<<endl;
  }*/
  int m;
  cin>>m;
  for(int j=0;j<m;j++){
    for(int k=0;k<26;k++)last[k]=0;
    int d,q;
    cin>>d>>q;
    d--;q--;
    int old=t[d];
    t[d]=q;
    //cout<<old<<" "<<q<<endl;
    long long kotae=0;
    int hinichi=0;
    long long hikukazu=0;
    for(int i=0;i<Date;i++){
      long long atai=0;
      atai=s[i][t[i]];
      //cout<<"last"<<last[t[i]];" ";
      hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
      last[t[i]]=i+1;
      kotae+=atai-hikukazu;
    //cout<<wa<<" "<<c[t[i]]<<" "<<hikukazu<<" "<<s[i][t[i]]<<" "<<last[t[i]]<<" "<<i<<" "<<kotae<<endl;
    }
    cout<<kotae<<endl;
  }
  return 0;
}

Measured memory_bytes: 3680
def main():
    d,g = (int(x) for x in input().split())
    g //= 100
    pc = []
    for _ in range(d):
        p,c = (int(x) for x in input().split())
        pc.append((p,c // 100))

    ans = 10**10
    for i in range(1 << d):
        cnt, total = 0, 0
        max = -1
        for j in range(d):
            if (i >> j) & 1:
                p,c = pc[j]
                cnt += p
                total += c + p * (j + 1)
            else:
                max = j + 1

        if  total < g:
            rem = (g - total + max - 1) // max
            if rem >= pc[max - 1][0]:
                continue
            cnt += rem

        ans = min(ans, cnt)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<cstdio>
#include<cstdlib>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int dx[]={-2,-2,-2,-1,0,1,-1,0,1,2,2,2};
int dy[]={-1,0,1,2,2,2,-2,-2,-2,-1,0,1};
typedef pair<int,int>P;
int F(P l,P r)
{
	if(l.first<0||l.second<0||l.first>=10||l.second>=10)return 0;
	return abs(l.first-r.first)<=1&&abs(l.second-r.second)<=1;
}
int main()
{
	int x,y,n,i,j,k,s;
	P p[10];
	while(scanf("%d%d",&x,&y),x&&y)
	{
		scanf("%d",&n);
		for(i=0;i<n;++i)scanf("%d%d",&p[i].first,&p[i].second);
		vector<P>v[2];
		v[0].push_back(P(x,y));
		for(s=i=0;i<n;++i)
		{
			sort(v[s].begin(),v[s].end());
			v[s].erase(unique(v[s].begin(),v[s].end()),v[s].end());
			v[!s].clear();
			for(j=0;j<v[s].size();++j)
			{
				for(k=0;k<12;++k)
				{
					P q(v[s][j].first+dx[k],v[s][j].second+dy[k]);
					if(F(q,p[i]))v[!s].push_back(q);
				}
			}
			s=!s;
		}
		puts(v[s].size()?"OK":"NA");
	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#define llint long long
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int a, b;

int main() {
    cin >> a >> b;
    if (a <= 8 && b <= 8) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int get() { int r; cin >> r; return r; }
double dis(double p, double q, double r, double s) { return sqrt((p - r) * (p - r) + (q - s) * (q - s)); }
signed main() {
	int n; cin >> n;
	while (n--) {
		double x1, y1, x2, y2, x3, y3;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double p = ((x3 - x2) * (x3 - x1) + (y3 - y2) * (y3 - y1)) / ((x3 - x2) * (y2 - y1) + (y3 - y2) * (x1 - x2)) / 2;
		double x4 = (x1 + x2) / 2 + p * (y2 - y1);
		double y4 = (y1 + y2) / 2 + p * (x1 - x2);
		double r = dis(x1, y1, x4, y4);
		printf("%.3f %.3f %.3f\n", x4, y4, r);
	}
}


Measured memory_bytes: 3132
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int num;
	scanf("%d", &num);
	vector<ll>va, vb;
	for (int i = 0; i < num; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		va.push_back(za);
		vb.push_back(zb);
	}
	ll now = 0;
	for (int i = num - 1; i >= 0; i--)
	{
		ll t = now + va[i];
		t = ((t + vb[i] - 1) / vb[i])*vb[i];
		now = t - va[i];
	}
	printf("%lld\n", now);
}

Measured memory_bytes: 2036
function main()
  
  (N,K) = map(x -> parse(Int,x), split(readline()))
  
  h = zeros(Int,N)
  
  for i in 1:N
    h[i] = parse(Int,readline())
  end
  
  sort!(h,rev=true)
  
  ans = 10^9
  
  for i in 1:N-K+1
    ans = min(h[i]-h[i+K-1],ans)
  end
  
  println(ans)
  
end

main()

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

typedef long long ll;
using namespace std;

//Doubly Linked-List
struct DLL{
	int prev,next;
	bool flag;
};

int n,m,q;
vector<int> a;
DLL l[200000];



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

	cin >> n >> m >> q;

	for (int i = 0;i < m;i++){
		int in; cin >> in;
		a.push_back(in);
	}

	for (int i = 0;i < n;i++){
		l[i].flag = true;
	   	l[i].prev = (i-1+n)%n;
		l[i].next = (i+1)%n;		
	}

	int now = 0;

	for (int i = 0;i < m;i++){
		if(a[i]%2 == 0){
			for (int j = 0;j < a[i];j++){
				now = l[now].next;
			}
		}else{
			for (int j = 0;j < a[i];j++){
				now = l[now].prev;
			}
		}
		l[now].flag = false;
		l[l[now].prev].next = l[now].next;
		l[l[now].next].prev = l[now].prev;
		now = l[now].next;
	}

	for (int i = 0;i < q;i++){
		int b; cin >> b;
		cout << (l[b].flag?1:0) << endl;
	}

	return 0;

}



Measured memory_bytes: 5932
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll res = 0;
    rep(i, n){
        ll x; cin >> x;
        res += x-1;
    }
    cout << res;
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
x = [0] * N
for i in range(N):
  x[0] += A[i] * (-1) ** i
for i in range(1,N):
  x[i] = x[i-1] * (-1) + 2 * A[i-1]
x = list(map(str,x))
print(" ".join(x))

Measured memory_bytes: 18504
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	ll N;
	cin >> N;
	vector<ll> vec(N);
	rep(i, N) cin >> vec[i];
	string ans = "YES";

	sort(vec.begin(), vec.end());
	rep(i, N - 1)
	{
		if (vec[i] == vec[i + 1])
		{
			ans = "NO";
			break ;
		}
	}


	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1792
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int v[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, a, b;
	cin >> n >> a >> b;
	int o = a - b;
	for (int i = 1; i <= n; i++) cin >> v[i];
	int l = 1, r = INF;
	int ans = 0;
	while (l <= r)
	{
		int mid = (l + r) / 2;
		LL tot = 0;
		for (int i = 1; i <= n; i++)
		{
			LL rest = max(0LL, v[i] - 1LL*mid * b);
			tot += (rest + o - 1) / o;
		}
		if (tot > mid) l = mid + 1;
		else ans = mid, r = mid - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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 long long INF = 1LL << 60;
#define PI 3.14159265359 
long long MOD = 1000000007;


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

long long dp[200100];

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

    vector<pair<int,int>>keiro(N);
    rep(i,N){
        int c, t;
        cin >> c >> t;

        keiro[i]=make_pair(c,t);
    }

    int ans = 9999;
    rep(i,N){
        if(keiro[i].second <=T)ans =min(ans,keiro[i].first);
    }

    if(9999 == ans)cout << "TLE" << endl;
    else cout << ans << endl;
}



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

int main() {
  int n; cin >> n;
  vector<int> v(n);
  int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    total += v[i];
  }
  int diff = 10001;
  int acc = 0;
  for (int i = 0; i < n; i++) {
    acc += v[i];
    diff = min(abs(total - acc - acc), diff);
  }
  cout << diff;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i, n+1) cin >> a[i];

    vector<ll> b(n);
    rep(i, n) cin >> b[i];
    
    ll sum = 0;
    rep(i, n) {
        int v1 = min(a[i], b[i]);
        a[i] -= v1;
        b[i] -= v1;
        int v2 = min(a[i+1], b[i]);
        a[i + 1] -= v2;
        b[i] -= v2;
        sum += v1 + v2;
    }

    put(sum);

    return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t a;
  std::string s;
  std::cin >> a >> s;
  if (3200 <= a) {
    std::cout << s << std::endl;
  } else {
    std::cout << "red" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


int main() {
  ll K,S;
  cin>>K>>S;
  ll count=0;
rep(i,K+1){
  rep(j,K+1)
  if(S-i-j>=0&&S-i-j<=K){
    count++;
  }
}
cout<<count<<endl;
}


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

using namespace std;

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

    string s;
    cin >> s;

    int n = s.size();
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == '+')
            ans++;
        else
            ans--;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.*;


public class Main {


    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n = in.nextInt();
        int arr[][] = new int[n][3];
        for(int i=0;i<n;i++){
            arr[i][0] = in.nextInt();
            arr[i][1] = in.nextInt();
            arr[i][2] = in.nextInt();
        }
        int dp1[] = new int[n];
        int dp2[] = new int[n];
        int dp3[] = new int[n];
        dp1[0] = arr[0][0];
        dp2[0] = arr[0][1];
        dp3[0] = arr[0][2];
        for(int i=1;i<n;i++){
            dp1[i] = Math.max(dp3[i-1],dp2[i-1]) + arr[i][0];
            dp2[i] = Math.max(dp1[i-1],dp3[i-1]) + arr[i][1];
            dp3[i] = Math.max(dp1[i-1],dp2[i-1]) + arr[i][2];
        }
        System.out.println(Math.max(dp1[n-1],Math.max(dp2[n-1],dp3[n-1])));


    }



    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}



Measured memory_bytes: 46184
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.mini = [i for i in range(n+1)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        mini = min(self.mini[x],self.mini[y])
        self.mini[x]=mini
        self.mini[y]=mini
    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

def main():
    N ,M = ints_raw()
    uft = UnionFind(N)
    ABs = [ints_raw() for _ in range(M)]
    for ab in ABs:
        a,b = ab
        uft.union(a-1,b-1)
    pars = [0]*N
    for n in range(N):
        pars[uft.find(n)]+=1
    print(max(pars))
    
main()


Measured memory_bytes: 111160
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}

signed main()
{   
    int N,M; cin>>N>>M;
    string s,t; cin>>s>>t;

    int g=gcd(N,M);
    for(int i=0,j=0;i<N;i+=N/g,j+=M/g){
        if(s[i]!=t[j]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<lcm(N,M)<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int N, a[10000] = {},ans=0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		if (a[i]%2==0)
		{
			while (a[i]%2==0)
			{
				a[i] /= 2;
				ans++;
			}
		}
	}
	cout << ans;
}


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

int main(){
	string s;
	cin >> s;
	if(s[0] != s[1] && s[1] != s[2] && s[2] != s[3]) cout << "Good" << endl;
	else cout << "Bad" << endl;
}

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 3612
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.function.Function;

class Main {
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long n;
        n = sc.nextLong();
        long[] v = new long[(int)(n)];
        for(int i = 0 ; i < n ; i++){
                v[i] = sc.nextLong();
        }
        solve(n, v);
    }

    static void solve(long n, long[] v){
        List<Long> even = new ArrayList<Long>();
        List<Long> odd = new ArrayList<Long>();
        for(int i = 0 ; i < n/2 ; i++ ){
            even.add(v[i*2]);
            odd.add(v[i*2+1]);
        }
        Map result_even = Sort(even);
        Map result_odd = Sort(odd);
        List<Long> E_value = new ArrayList<>(result_even.keySet());
        List<Integer> E_count = new ArrayList<>(result_even.values());
        List<Long> O_value = new ArrayList<>(result_odd.keySet());
        List<Integer> O_count = new ArrayList<>(result_odd.values());
        if (E_value.get(0).equals(O_value.get(0))) {
            E_count.add(0);
            O_count.add(0);
            System.out.println( Math.min(n-E_count.get(0)-O_count.get(1) , n-E_count.get(1)-O_count.get(0) ) );
        }else{
            System.out.println(n-E_count.get(0)-O_count.get(0));
        }
    }

    static Map<Long, Integer> Sort(final List<Long> list){
        Map<Long,Integer> map = list.stream().collect(
            Collectors.groupingBy( Function.identity(),Collectors.summingInt(s->1)) );
        Map<Long, Integer> result = map.entrySet().stream()
                .sorted(Map.Entry.<Long, Integer>comparingByValue().reversed()
                        .thenComparing(Map.Entry.comparingByKey()))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
        return result;
    } 

}


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


public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var ary2 = new int[n];
            string[] line = Console.ReadLine().Trim().Split(' ');
            var ary1 = Array.ConvertAll(line, int.Parse);
            var count = -1;
            var flag = 1;
            while (flag == 1)
            {
                flag = 0;
                for (int i = 0; i < n; i++)
                {
                    ary2[i] = ary1.Count(x => x == ary1[i]);
                    if (ary2[i] != ary1[i]) flag = 1;
                }
                for (int i = 0; i < n; i++) ary1[i] = ary2[i];
                count++;
            }
            Console.WriteLine(count);
            for (int i = 0; i < n; i++)
            {
                Console.Write(ary1[i]);
                if (i == n - 1) Console.WriteLine();
                else Console.Write(" ");
            }
        }
    }
}

Measured memory_bytes: 9612
N, M = map(int, input().split())
l = []
r = []
for _ in range(M):
  s, t = map(int, input().split())
  l.append(s)
  r.append(t)
  
lm = max(l)
rm = min(r)
print(max([rm - lm + 1, 0]))

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


int main() {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}
}

Measured memory_bytes: 1116
#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 repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-10;

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

int d[1010][1010];
int J[1010][1010], O[1010][1010], I[1010][1010];

int main(){
	int h, w, k;
	cin>>h>>w>>k;
	vector<string> s(h);
	rep(i, h) cin>>s[i];
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			J[i+1][j+1] += J[i+1][j];
			O[i+1][j+1] += O[i+1][j];
			I[i+1][j+1] += I[i+1][j];
			if(s[i][j] == 'J') J[i+1][j+1]++;
			else if(s[i][j] == 'O') O[i+1][j+1]++;
			else if(s[i][j] == 'I') I[i+1][j+1]++;
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			J[i+1][j+1] += J[i][j+1];
			O[i+1][j+1] += O[i][j+1];
			I[i+1][j+1] += I[i][j+1];
		}
	}
	rep(i, k){
		int a, b, c, d;
		cin>>a>>b>>c>>d;
		a--; b--;
		int x = J[c][d]-J[a][d]-J[c][b]+J[a][b];
		int y = O[c][d]-O[a][d]-O[c][b]+O[a][b];
		int z = I[c][d]-I[a][d]-I[c][b]+I[a][b];
		cout<<x<<" "<<y<<" "<<z<<endl;
	}
}

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

using namespace std;
typedef long long ll;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);
    for(int i = 0; i < n; i++)    cin >> a[i];
    
    for(int kk = 0 ;kk < min(k, 50); kk++)
    {
      	vector<int> fre(n, 0);
        for(int j = 0; j < n; j++)
        {
            int l = max(0, j - a[j]);
            int r = min(n-1, j + a[j]);
            fre[l]++;
            if(r+1 < n) fre[r+1]--;
}
for(int j = 0; j < n; j++)
{
    if(j != 0) fre[j] += fre[j-1];
}
a = fre;
}    

for(int i = 0; i < n; i++) cout << a[i] << " ";
        
}


Measured memory_bytes: 4816
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class b {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int n;
        cin >> n;

        string s, t;
        cin >> s >> t;

        string res;
        REP(i, n) {
            res += s[i];
            res += t[i];
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    b solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (x, a, b) = scan!(i64, i64, i64);
    if (x - a).abs() < (x - b).abs() {
        println!("A")
    } else {
        println!("B")
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846264338327950288
#define mt make_tuple


void love() {
	int n; cin>>n;
	int arr[n];
	for(int i = 0; i<n; i++) cin>>arr[i];

	int ans = 0;
	for(int i = 0; i<n; i++) {
		for(int j = i+1; j<n; j++) {
			ans += arr[i] * arr[j];
		}
	}
	cout<<ans<<endl;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	love();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
int main(){
    int N;
    int s;
    int smax,smin;
    int sum;
    while(1){
        cin >> N;
        if(N==0) return 0;
        smax = 0; smin = INF; sum = 0;
        for(int i=0;i<N;i++){
            cin >> s;
            smax = max(smax,s);
            smin = min(smin,s);
            sum += s;
        }
        sum = sum - smax - smin;
        int ans = sum/(N-2);
        cout << ans << endl;
    }
}


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

typedef long long int ll;

int main()
{
    vector<string> c(3);
    for(ll i = 0;i < 3;i++){
        cin >> c[i];
    }

    cout << c[0][0] << c[1][1] << c[2][2];

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
//vector<vector<int>> vec(縦,vector<int>(横));
/*deque<型> 配列の先頭にも用がある時はvectorの代わりに。
入力はstringでもらってから for( char d : s)push_back()*/

int main(){
  deque<char> deq;
  string s;
  char c;
  int Q,T,F;
  int turn=0;
  cin>>s;
  cin>>Q;
  for( char d : s){
    deq.push_back(d);
  }
  //turnが%2==0なら反転なし、%2==1なら最後に反転
  for(int i=0;i<Q;i++){
    cin>>T;
    if(T==1){
      turn++;
    }
    if(T==2){
      cin>>F>>c;
      
      if(turn%2==0){
        if(F==1) deq.push_front(c);
        else deq.push_back(c);
      }
      else{
        if(F==1) deq.push_back(c);
        else deq.push_front(c);
      }
    }
  }
  if(turn%2==0) {
    for(int i=0;i<deq.size();i++) cout<<deq[i];
  }
  else{
    reverse (deq.begin(),deq.end());
    for(int i=0;i<deq.size();i++) cout<<deq[i];
  }
}

Measured memory_bytes: 896
#include<stdio.h>

int lcm(int a, int b, int p)
{

    return a / p * b;
}

int gcm(int a, int b)
{

    int temp, x, k = 1;

    if(a < b) {
        temp = a;
        a = b;
        b = temp;
    }

    while(k) {
        x = a % b;
        if(x == 0)
            return b;

        a = b % x;
        if(a == 0)
            return x;

        b = x % a;
        if(b == 0)
            return a;
    }

}

int main(void)
{

    int n, a, b, c, i, p;

    while(scanf("%d %d", &a, &b) != EOF) {
        p = gcm(a, b);
        printf("%d %d\n", p, lcm(a, b, p));
    }

    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
using namespace std;
int main()
{
	ll h1,h2,m1,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	h1=h1*60+m1;
	h2=h2*60+m2;
	cout<<h2-h1-k<<endl;
}

Measured memory_bytes: 3624
from bisect import*
n,d,a,*t=map(int,open(0).read().split())
c=[0]*-~n
z=sorted(zip(*[iter(t)]*2))
y=[x for x,_ in z]
s=0
for i,(x,h)in enumerate(z):
    c[i]+=c[i-1]
    h-=c[i]
    t=0--max(0,h)//a
    c[i]+=t*a
    c[bisect(y,x+d+d)]-=t*a
    s+=t
print(s)

Measured memory_bytes: 48852
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
		freopen("in3.txt", "r", stdin);
//		freopen("ou1.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	ll ans = 0;
	for (ll i=1; i<n; i++) {
		ll x, y;
		cin >> x >> y;
		if (x > y) swap(x, y);
		ans += i*(n-i+1);
		ans -= x*(n-y+1);
	}
	ans += n;
	cout << ans;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 n,k;
    cin >> n >> k;
    n = n % k;
    ANS(min(n, k - n));
    return 0;
}

Measured memory_bytes: 256
n = int(input())
lst = [0] + list(map(int, input().split())) + [0]
d_all = sum(abs(lst[i] - lst[i+1]) for i in range(n+1))


for i in range(1, n+1):
    ans = d_all - abs(lst[i-1] - lst[i]) - abs(lst[i] - lst[i+1]) + abs(lst[i-1] - lst[i+1])
    print(ans)

Measured memory_bytes: 65772
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N;
    cin >> N ;
    double a = 0,ans = 0;
    for(int i = 1;i < N+1;i++){
        if(i % 2 == 1)a++;
    }
    cout << fixed << setprecision(10);
    cout << a/N << endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
counter = Counter(A)
total = 0
for k,v in counter.items():
  total += k*v
Q = int(input())

for _ in range(Q):
  b,c = map(int,input().split())
  if b in counter:
    total -= b*counter[b]
    item = counter[b]
    del counter[b]
    if c in counter:
      counter[c] += item
      total += c*item
    else:
      counter[c] = item
      total += c*counter[c]
  
  print(total)


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

int main()
{
	int A, B, C, tr;
	cin>>A>>B>>C>>tr;
	int count=0;
	for(int a=0;a<=A;a++)
	{
		for(int b=0;b<=B;b++)
		{
			for(int c=0;c<=C;c++)
			{
				int h=(a*500)+(b*100)+(c*50);
				if(h==tr)
				{
					count++;
				}
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define soja(i,a,n) for(ll i=a;i<=n;i++)
#define ulta(i,n,a) for(ll i=n;i>=a;i--)
ll n,m,k,sum;
int main()
{
cin>>n;
cout<<n+(n*n)+(n*n*n)<<endl;
}


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

int dfs(int depth, int cur, int accm, int n, int s)
{
  if (depth > n)
    return 0;

  if (depth == n && accm == s)
    return 1;

  if (accm > s)
    return 0;
  else {
    int count = 0;
    for (int i = cur + 1; i < 10; i++) {
      count += dfs(depth+1, i, accm+i, n, s);
    }
    return count;
  }
}


int main(int argc, char **argv)
{
  int n, s;
  for (;;) {
    cin >> n >> s;
    if (n==0 && s==0)
      break;

    int total = 0;
    for (int i = 0; i < 10; i++) {
      total += dfs(1, i, i, n, s);
    }

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

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
int main(){
  int i,s_len,result_w=0,result_b=0;
  char s[100000];
  
  scanf("%s",s);
  s_len=strlen(s);

  //check blackstart
  for(i=0;i<s_len;i++){
    if(i%2==0){
      if(s[i]!='1')result_b++;
    } else {
      if(s[i]!='0')result_b++;
    }
  }
  
  //check whitestart
  for(i=0;i<s_len;i++){
    if(i%2==0){
      if(s[i]!='0')result_w++;
    } else {
      if(s[i]!='1')result_w++;
    }
  }
  
  if(result_w<result_b){
    printf("%d",result_w);
  } else {
    printf("%d",result_b);
  }
}

Measured memory_bytes: 256
from collections import defaultdict, deque

N, M = map(int, input().split())
X = defaultdict(list)
for i in range(M):
    Ai, Bi = map(lambda s: int(s) - 1, input().split())
    X[Ai].append(Bi)
    X[Bi].append(Ai)

V = [False] * N
P = [0] * N
A = [0] * N
Q = deque([0])
V[0] = True
while len(Q) > 0:
    r = Q.popleft()
    for nr in X[r]:
        if V[nr] == True:
            continue
        V[nr] = True
        P[nr] = P[r] + 1
        A[nr] = r + 1
        Q.append(nr)

print('Yes')
for i in range(1, N):
    print(A[i])


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

#define dcm(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
    //clock_t start = clock();
    ios::sync_with_stdio(false); cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s; cin >> s;
    int arr[30];
    for (int i=0; i<30; ++i) arr[i] = 0;
    for (int i=0; i<s.size(); ++i) {
        arr[s[i]-97]++;
    }
    for (int i=0; i<26; ++i) {
        if (arr[i]%2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    //clock_t stop = clock();
    //cout << (double)(stop-start)/CLOCKS_PER_SEC << " (s)" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt(),i=0;
        int[]a=new int[n];
        for(;i<n;){
            a[i++]=sc.nextInt();
        }
        Arrays.sort(a);
        int s=1000000000;
        for(i=0;i+m-1<n;i++){
            s=Math.min(s,a[i+m-1]-a[i]);
        }
        System.out.print(s);
    }
}


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

int x,n;

int main()
{

    int a[104]={0};
    scanf("%d%d",&x,&n);
    if(n==0){
        printf("%d",x);
        return 0;
    }
    else{
        int i;
        for(i=1;i<=n;i++){
            int n1;
            scanf("%d",&n1);
            a[i]=n1;
        }

        int j,k,f=0;
        for(i=1;i<=n;i++){
            if(a[i]==x)
                f=1;
        }
        if(f==0){
            printf("%d\n",x);
            return 0;
        }
        for(i=2,j=x,k=x;;){
            j--;
            k++;
            int m,f1=0,f2=0;
            for(m=1;m<=n;m++){
                if(a[m]==j)
                    f1=1;
            }
            if(f1==0)
            {
                printf("%d\n",j);
                return 0;
            }
            for(m=1;m<=n;m++){
                if(a[m]==k)
                    f2=1;
            }
            if(f2==0)
            {
                printf("%d\n",k);
                return 0;
            }

        }

    }

    return 0;
}


Measured memory_bytes: 3688