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

int main(){
  int N; cin >>N;
  int A[N], front[N], back[N];
  for(int i=0;i<N;i++){
    cin >>A[i];
    if(i==0) front[i] = A[i]; // front[i]はA[0]からA[i]までのmax
    else front[i] = max(front[i-1], A[i]);
  }
  for(int i=N-1;i>=0;i--){
    if(i==N-1) back[i] = A[i];
    else back[i] = max(back[i+1], A[i]); // back[i]はA[N-1]からA[i]までのmax
  }

  cout << back[1] << endl;
  for(int i=1; i<N-1; i++) cout << max(front[i-1], back[i+1]) << endl;
  cout << front[N-2] << endl;
  return 0;
}


Measured memory_bytes: 3968
#include <iostream>

using namespace std;

int main() {
	long long a, b, c; cin >> a >> b >> c;
	if (a + b < c && 4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}
//a+2sqrt(ab)+b<c
//2sqrt(ab)<c-a-b
//4ab<(c-a-b)^2

Measured memory_bytes: 256
#include<stdio.h>


inline int max( int a ,int b )
{
	return a > b ? a : b ;
}

inline int min( int a ,int b )
{
	return a > b ? b : a ;
}


int main( void )
{
	int ans = 0 ;

	int sx ,sy ;

	int W ,H ,N ;
	scanf( "%d %d %d" ,&W ,&H ,&N ) ;

	scanf( "%d %d" ,&sx ,&sy ) ;

	int i ;
	for( i = 1 ; i < N ; ++i )
	{
		int gx ,gy ;
		scanf( "%d %d" ,&gx ,&gy ) ;

		if( ( gx < sx && gy < sy ) || ( gx > sx && gy > sy ) )
		{
			ans += max( max( sx ,gx ) - min( sx ,gx ) ,max( sy ,gy ) - min( sy ,gy ) ) ;
		}

		else
		{
			ans += ( max( gx ,sx ) - min( gx ,sx ) ) + ( max( gy ,sy ) - min( gy ,sy ) ) ;
		}

		sx = gx ; sy = gy ;
	}

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


	return 0 ;
}

Measured memory_bytes: 1784
#include <iostream>
#include <iomanip> //setprecision
#include <cstdlib>
#include <vector>
#include <cmath>
const int MAX = 100000000;

double ans(double x, double y) {
    double dis;
    dis = x - y;
    if (dis < 0) {
        dis = dis * (-1.0);
    }
    return dis;
}

double calc(std::vector<double> x, std::vector<double> y, int data_num, int p) {
    double dis;
    double total = 0;
    double temp;
    for (int i = 0; i < data_num; i++) {
        temp = 1.0;
        dis = ans(x[i], y[i]);
        for (int j = 0; j < p; j++) {
            temp *= dis; 
        }
        total += temp;
    }
    return pow(total, 1.0 / p);
}

int main(void) {
    int data_num;
    std::cin >> data_num;
    std::vector<double> x(100);
    std::vector<double> y(100);
    for (int i = 0; i < data_num; i++) {
        std::cin >> x[i]; 
    }
    for (int i = 0; i < data_num; i++) {
        std::cin >> y[i]; 
    }
    std::cout << std::fixed << std::setprecision(12);
    std::cout << calc(x, y, data_num, 1) << std::endl;
    std::cout << calc(x, y, data_num, 2) << std::endl;
    std::cout << calc(x, y, data_num, 3) << std::endl;
    double dis_Max = 0;
    double dis;
    for (int loop = 0; loop < data_num; loop++) {
        dis = ans(x[loop], y[loop]);
        if (dis > dis_Max) {
            dis_Max = dis;
        }
    }
    std::cout << dis_Max << std::endl;

    return EXIT_SUCCESS;
}

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

#define nl printf("\n")
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

///Output
template<class T>
void out(T y)
{
    if(typeid(y) == typeid(int))printf("%d ",y);
    else if(typeid(y) == typeid(long long))printf("%lld ",y);
    else if(typeid(y) == typeid(long double))printf("%LF ",y);
    else if(typeid(y) == typeid(float))printf("%f ",y);
    else if(typeid(y) == typeid(char))printf("%c ",y);
}

///Input
template<class T>
void read(T &y)
{
    if(typeid(y) == typeid(int))scanf("%d",&y);
    else if(typeid(y) == typeid(long long))scanf("%lld",&y);
    else if(typeid(y) == typeid(long double))scanf("%LF",&y);
    else if(typeid(y) == typeid(float))scanf("%f",&y);
}

int main()
{
    long long n;
    read(n);
    if(n==1){out(0);nl;return 0;}
    vector<pair<long long,int> >vp;
        for(long long i=2;i*i<=n;i++)
        {
            int c=0;
            while(n%i==0)
            {
                n/=i;
                c++;
            }
            vp.push_back({i,c});
        }
        if(n!=1)vp.push_back({n,1});
        int ans=0;
        for(auto x:vp)
        {
           int c=x.second,d=1;
           while(d<=c)
           {
               ans++;
               c-=d;
               d++;
           }

        }
        cout<<ans<<endl;
}


Measured memory_bytes: 19784
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



ll H, W;

int main () {
  cin >> H >> W;

  if (H % 3 == 0 || W % 3 == 0) {
    cout << 0 << "\n";
    return 0;
  }

  ll ans = LINF;

  rep(j, W) {
    ll s_min;
    ll s_max;
    ll s_rest;

    if (H % 2 == 0) {
      s_min = (W - j) * (H/2);
      s_max = (W - j) * (H/2);
    } else {
      s_min = (W - j) * ((H-1)/2);
      s_max = (W - j) * ((H+1)/2);
    }

    s_rest = H * j;

    //cout << s_max << s_min << s_rest << "\n";

    if (s_rest >= s_max) {
      ans = min(ans, s_rest-s_min);
    } else if (s_rest <= s_min) {
      ans = min(ans, s_max-s_rest);
    } else {
      ans = min(ans, s_max-s_min);
    }

    //cout << ans << "\n";
  }

  rep(i, H) {
    ll s_min;
    ll s_max;
    ll s_rest;

    if (W % 2 == 0) {
      s_min = (H - i) * (W/2);
      s_max = (H - i) * (W/2);
    } else {
      s_min = (H - i) * ((W-1)/2);
      s_max = (H - i) * ((W+1)/2);
    }

    s_rest = W * i;

    //cout << s_max << s_min << s_rest << "\n";

    if (s_rest >= s_max) {
      ans = min(ans, s_rest-s_min);
    } else if (s_rest <= s_min) {
      ans = min(ans, s_max-s_rest);
    } else {
      ans = min(ans, s_max-s_min);
    }

    //cout << ans << "\n";
  }
  
  ans = min(ans, H);
  ans = min(ans, W);

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  int r=0;
  cin >> N;
  for(int i=1;i<N;i++){
    r+=(N-1)/i;
  }

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>

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

using namespace std;

int main(){
	int n,a[100000];
	scanf("%d",&n);
	rep(i,n) scanf("%d",a+i);

	map<int,int> f1,f2;
	rep(i,n/2){
			f1[a[2*i  ]]++;
			f2[a[2*i+1]]++;
	}

	vector<pair<int,int>> b1,b2;
	for(auto it=f1.begin();it!=f1.end();++it) b1.emplace_back(-(it->second),it->first);
	for(auto it=f2.begin();it!=f2.end();++it) b2.emplace_back(-(it->second),it->first);
	b1.emplace_back(0,0);
	b2.emplace_back(0,0);

	sort(b1.begin(),b1.end());
	sort(b2.begin(),b2.end());

	int ans=n;
	rep(i,2) rep(j,2) if(b1[i].second!=b2[j].second) ans=min(ans,n/2+b1[i].first+n/2+b2[j].first);
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 6520
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repb(i, n) for(int i = n;i >= 0;i--)
#define reps(i, m, n) for(int i = m;i < n;i++)
#define repsb(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
 
int main(){
	int n;
	cin>>n;
	if(n>=1000){
		printf("ABD\n");
	}
	else{
		printf("ABC\n");
 
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  string S;
  cin>>S;

  bool f=true;
  for(int i=0;i<S.length()-1;i++){
    if(S[i]==S[i+1]) f=false;
  }
  cout<<((f)?"Good":"Bad")<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int r0, w0, c, r; cin >> r0 >> w0 >> c >> r;
    if(c == 0) break;
    int cnt = 0;
    while((r0 + cnt * r) / w0 < c) cnt++;
    cout << cnt << endl;
  }
}



Measured memory_bytes: 3116
#include<iostream>
using namespace std;
#define RENT 100000
int main(){
    int n;
    while(cin>>n){
        int ans=0;
        for(int a=0;a<10;a++){
            for(int b=0;b<10;b++){
                for(int c=0;c<10;c++){
                    for(int d=0;d<10;d++){
                        if(a+b+c+d==n)ans++;
                    }
                }
            }
        }
         
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7,p=998244353; bool fl[N];
int n,m,l,f1[N],f2[N],f3[N],g1[N],g2[N],g3[N]; long long g[N]; vector<int>v1[N],v2[N],v3[N];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num*10)+g-48,g=getchar(); return num;
}
inline void fwt(int *s){
	for(int d=1;d<l;d=d<<1)
		for(int i=0,r=d<<1;i<l;i+=r)
			for(int j=0;j<d;j++){
				int a=s[i+j],b=s[i+j+d];
				s[i+j]=(a+b)%p,s[i+j+d]=(a-b+p)%p;
			}
}
inline void twf(int *s){
	for(int d=1;d<l;d=d<<1)
		for(int i=0,r=d<<1;i<l;i+=r)
			for(int j=0;j<d;j++){
				int a=s[i+j],b=s[i+j+d];
				s[i+j]=1ll*(a+b)%p*((p+1)/2)%p,s[i+j+d]=1ll*(a-b+p)%p*((p+1)/2)%p;
			}
}
int main(){
	g[0]=1,g[1]=716070898,cin>>n; int u,t;
	for(int i=2;i<=n;i++) g[i]=g[i-1]*g[1]%p;
	m=read();
	for(int i=1;i<=m;i++){
		u=read(),t=read(); if(u>t) swap(u,t); v1[u].push_back(t);
	}
	m=read();
	for(int i=1;i<=m;i++){
		u=read(),t=read(); if(u>t) swap(u,t); v2[u].push_back(t);
	}
	m=read();
	for(int i=1;i<=m;i++){
		u=read(),t=read(); if(u>t) swap(u,t); v3[u].push_back(t);
	}
	for(int i=n-1;i>=1;i--){
		for(int x=0;x<v1[i].size();x++){
			int u=v1[i][x]; fl[f1[u]]=1;
		}
		while(fl[f1[i]]) f1[i]++;
		for(int x=0;x<v1[i].size();x++){
			int u=v1[i][x]; fl[f1[u]]=0;
		}
	}
	for(int i=n-1;i>=1;i--){
		for(int x=0;x<v2[i].size();x++){
			int u=v2[i][x]; fl[f2[u]]=1;
		}
		while(fl[f2[i]]) f2[i]++;
		for(int x=0;x<v2[i].size();x++){
			int u=v2[i][x]; fl[f2[u]]=0;
		}
	}
	for(int i=n-1;i>=1;i--){
		for(int x=0;x<v3[i].size();x++){
			int u=v3[i][x]; fl[f3[u]]=1;
		}
		while(fl[f3[i]]) f3[i]++;
		for(int x=0;x<v3[i].size();x++){
			int u=v3[i][x]; fl[f3[u]]=0;
		}
	}
	l=1; while(l<=n) l=l*2;
	
	for(int i=1;i<=n;i++) g1[f1[i]]=(g1[f1[i]]+g[i])%p,g2[f2[i]]=(g2[f2[i]]+g[i])%p,g3[f3[i]]=(g3[f3[i]]+g[i])%p;
	fwt(g1),fwt(g2),fwt(g3);
	for(int i=0;i<l;i++) g1[i]=1ll*g1[i]*g2[i]%p*g3[i]%p; twf(g1);
	cout<<g1[0]<<endl;
	return 0;
}

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

from copy import deepcopy

B = deepcopy(A)

for i in range(N):
    A[i] += i+1
    B[i] = (i+1)-B[i]

from collections import Counter

C = Counter(A)
D = Counter(B)

E = list(C.keys())

ans = 0
for i in E:
    ans += C[i]*D[i]

print(ans)

Measured memory_bytes: 55736
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

inline vector<int> get_d(int n) {return vector<int>(n, INF);}
inline vector<ll> get_d(ll n) {return vector<ll>(n, LINF);}
inline vector<ld> get_d(ld n) {return vector<ld>(n, LINF);}
template<typename T> vector<T> dijkstra(int s, vector<vector<pair<int, T>>>& g) {
    T n = sz(g);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
    vector<T> d = get_d(n);
    d[s] = 0;
    q.emplace(0, s);

    while (!q.empty()) {
        pair<T, int> p = q.top();
        q.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (auto x : g[v]) {
            if (d[x.first] > d[v] + x.second) {
                d[x.first] = d[v] + x.second;
                q.emplace(d[x.first], x.first);
            }
        }
    }
    return d;
}

ld dist(ld x1, ld y1, ld x2, ld y2) {
    return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}

void solve() {
    ld sx, sy, tx, ty;
    int n;
    cin >> sx >> sy >> tx >> ty >> n;
    vector<ld> x(n + 2);
    vector<ld> y(n + 2);
    vector<ld> r(n + 2);
    REP(i, n) cin >> x[i] >> y[i] >> r[i];
    x[n] = sx;
    x[n + 1] = tx;
    y[n] = sy;
    y[n + 1] = ty;
    r[n] = 0.0L;
    r[n + 1] = 0.0L;

    vector<vector<pair<int, ld>>> g(n + 2, vector<pair<int, ld>>());
    REP(i, n + 2) REP(j, n + 2) {
        if (i == j) continue;
        // cout << i << ":" << j << "| " << dist(x[i], y[i], x[j], y[j]) - (r[i] + r[j]) << endl;
        g[i].emplace_back(j, max(0.0L, dist(x[i], y[i], x[j], y[j]) - (r[i] + r[j])));
        g[j].emplace_back(i, max(0.0L, dist(x[i], y[i], x[j], y[j]) - (r[i] + r[j])));
    }
    auto ans = dijkstra(n, g);
    cout << ans[n + 1] << endl;
}



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

int main()
{
	int n;
	while (cin >> n && n != 0)
	{
		int ans = 0;
		for (int i = 1; i * i <= n; i++)
		{
			int sumI = i * i;
			if (sumI == n)ans++;
			for (int j = i; j * j <= n; j++)
			{
				int sumJ = sumI + j * j;
				if (sumJ == n)ans++;
				for (int k = j; k * k <= n; k++)
				{
					int sumK = sumJ + k * k;
					if (sumK == n)ans++;
					for (int l = k; l * l <= n; l++)
					{
						int sumL = sumK + l * l;
						if (sumL == n)
						{
							ans++;
						}
					}
				}
			}
		}

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

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
using namespace std;

int main(){
	double v;
	while(cin >> v){
		int n = 0;
		while(5 * n - 5 < v * v / 19.6)n++;
		cout << n << endl;
	}
}


Measured memory_bytes: 3128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n];
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        boolean flag = true;
        if (t[0] < x[0] + y[0]) {
            flag = false;
        }
        if (t[0] % 2 != (x[0] + y[0]) % 2) {
            flag = false;
        }
        if (n >= 2) {
            for (int i = 0; i < n - 1; i++) {
                int deltaT = t[i + 1] - t[i];
                int deltaX = Math.abs(x[i + 1] - x[i]);
                int deltaY = Math.abs(y[i + 1] - y[i]);
                int deltaPos = deltaX + deltaY;
                if (deltaT < deltaPos) {
                    flag = false;
                }
                if (deltaT % 2 != deltaPos % 2) {
                    flag = false;
                }
            }
        }
        System.out.println(flag ? "Yes" : "No");
    }
}

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

int main() {
  int N , K , sum = 0;
  cin >> N >> K;
  for (int i = 0;i < N;i++){
    int x;
    cin >> x;
    if (K - x < x){
      sum += (K -x) * 2;
    }
    else{
      sum += x * 2;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
s = input()
t = input()

cnt = 0

for i in range(len(s) - len(t)+1):
    tmp = 0
    for j in range(len(t)):
        if s[i+j] == t[j]:
            tmp += 1
    
    if cnt < tmp:
        cnt = tmp

print(len(t)-cnt)
    




Measured memory_bytes: 9064
M, D = map(int, input().split())

ans = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        d10, d1 = divmod(d, 10)
        if d10 >= 2 and d1 >= 2 and d10 * d1 == m:
            ans += 1
print(ans)

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

const double PI=3.14159265358979323846;

int main(){
    int a , b , h , m ;
    cin >> a >> b >> h >> m ;
    double theta_1 = (double) h * PI / 6 + (m*PI)/360 ;
    double theta_2 = (double) m * PI /30 ;
    double ans = (double) a * a + b * b - 2 * a * b * cos(abs(theta_1 - theta_2 )) ;
    ans = sqrt(ans) ;
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 4200
using System;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;


    void calc()
    {
        int X = cin.nextInt();
        int num = gcd(360, X);
        int ans = 360 / gcd(360, num);
        Console.WriteLine(ans);
    }

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

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 27548
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int n, q;

    cin >> n;
    vector<int> S(n);
    for(int i = 0; i < n; i++) cin >> S[i];
    
    cin >> q;
    vector<int> T(q);
    for(int i = 0; i < q; i++) cin >> T[i];

    sort(S.begin(), S.end());
    sort(T.begin(), T.end());

    int ret = 0;
    for(int i = 0; i < q; i++) {
        if( 0 != distance(lower_bound(S.begin(), S.end(), T[i]), lower_bound(S.begin(), S.end(), T[i]+1))) ret++;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3280
#morau dp
N=int(input())
dp=[float('inf') for i in range((10**5)*2)]
L6=[6**i for i in range(1,8)]#7ko
L9=[9**i for i in range(1,7)]#6ko
a=[1]
L=a+L6+L9
L.sort()#14ko
dp[0]=0
for i in range(N+1):
    for j in range(14):
        if i-L[j]>=0:
            dp[i]=min(dp[i],1+dp[i-L[j]])
print(dp[N])

Measured memory_bytes: 9368
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース


*/

//main.cpp----------------------------
#define MAX 100000

int a[5];
int k;

int main() {

  rep(i, 5) {
    cin >> a[i];
  }
  cin >> k;

  sort(a, a+5);

  if(a[4]-a[0]>k) {
    cout << ":(" << endl;
  }else {
    cout << "Yay!" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
sum = 0
sum_2 = 0

for i in range(n):
    sum += w[i]
half = sum/2

for i in range(n):
    sum_2 += w[i]
    if sum_2 >= half:
        ans = min(sum_2-half, half-ans)
        break
    else:
        ans = sum_2
print(int(ans*2))

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  B.at(0) = A.at(0);
  for (int i = 1; i < N; i++) B.at(i) = max(B.at(i - 1), A.at(i));
  long long int ans = 0;
  for (int i = 0; i < N; i++) ans += (B.at(i) - A.at(i));
  cout << ans << endl;
}

Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  for(int i=1;i<=9;i++){
  for(int j=1;j<=9;j++){
  if(N==i*j){
  cout<<"Yes"<<endl;
  return 0;
  }
    
   
      
    
  
  }
  }
   cout<<"No"<<endl;
  
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
struct SegmentTreeLazy //デフォルトは区間変更区間合計
{
    int n;
    const T ex = 1 << 30; //dat 初期値(合計なので)
    const T em = 1 << 30; //lazy 初期値(updateするので)
    //lazyで一括更新をもって、datでqueryに対応する。weightはそのnodeが担当する下のnodeの数
    //lazyは上から下に伝搬する。datは区間で探して下から上にもらう。
    vector<T> dat, lazy; //tree本体
    SegmentTreeLazy(vector<T> v){
        int x = 1;
        int i;
        n = v.size();
        while(x < n) x <<= 1;
        n = x; 
        dat.resize(2*n-1, ex); //tree本体
        lazy.resize(2*n-1, em); //遅延評価
        for(i = 0;i < v.size();++i){
            dat[i + n - 1] = v[i];
        }
        for(i = n-2;i >= 0;--i){
            dat[i] = fx(dat[2*i+1], dat[2*i+2]);
        }
    }
    
    T fx(T a, T b){ //dat上での計算
        return min(a, b);
    }
    
    void eval(int now){ //区間下は全て影響を受ける。(受ける時しか呼ばれない)
        if(lazy[now] == em) return;
        if(now < n - 1){ //区間変更なので値を代入する。
            lazy[2*now + 1] = min(lazy[2*now + 1], lazy[now]);
            lazy[2*now + 2] = min(lazy[2*now + 2], lazy[now]);
        }
        //**********************ここが大事
        dat[now] = min(dat[now], lazy[now]);
        //**********************
        lazy[now] = em;
    }
    
    void update(int a, int b, T x, int now, int l, int r){
        eval(now);
        if(a <= l && r<= b){ //区間内に全部いる。
            lazy[now] = x; //区間代入なので上から書き換える。
            eval(now);
        }else if(a < r && l < b){
            update(a, b, x, 2*now + 1, l, (l + r)/2);
            update(a, b, x, 2*now + 2, (l + r)/2, r);
            dat.at(now) = fx(dat[2*now + 1], dat[2*now + 2]);
        }
    }
    void update(int a, int b, T x){update(a, b, x, 0, 0, n);}
    
    T query(int a, int b){return query_sub(a, b, 0, 0, n);}
    T query_sub(int a, int b, int now, int l, int r){
        eval(now);
        if(r <= a || b <= l) return ex;
        else if(a <= l && r <= b) return dat.at(now);
        else{
            T vl = query_sub(a, b, 2*now + 1, l, (l + r)/2);
            T vr = query_sub(a, b, 2*now + 2, (l + r)/2, r);
            return fx(vl, vr);
        }
    }
    
    inline T operator[](int a) { return query(a, a + 1); }
    void print() {
        for (int i = 0; i < 2 * n - 1; ++i) {
            cout << (*this)[i];
            if (i != n) cout << ",";
        }
        cout << endl;
    }
};

int main()
{
    int i,j;
    int n,q;
    cin >> n >> q;
    vector<int> ini(n, n-1);
    SegmentTreeLazy<int> tate(ini);
    SegmentTreeLazy<int> yoko(ini);
    ll ans = (ll)(n-2)*(ll)(n-2);
    rep(i,q){
        int c,x;
        cin >> c >> x;
        --x;
        if(c == 1){
            int tmp = tate.query(x, x+1);
            ans -= tmp-1;
            yoko.update(0, tmp+1, x);
        }else if(c == 2){
            int tmp = yoko.query(x, x+1);
            ans -= tmp-1;
            tate.update(0, tmp+1, x);
        }
    }
    cout << ans << endl;

    return 0;
}

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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n;
string s;
unordered_map<string, int> mp;

int main() {
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        ++mp[s];
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return 0;
}


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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  int a,b;
  cin >> a >> b;
  cout << ((a % 2 == 0 or b % 2 == 0)?"No":"Yes") << endl;
}


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

int main() {
    vector<int> x(5);
    rep(i,0,5) cin >> x[i];
    rep(i,0,5) {
        if (x[i] == 0) {
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pr pair<int, int>
#define v1d vector<int>
#define mp make_pair
#define pb push_back
#define v1p vector<pr>
#define vb vector<bool>
#define v2d vector<vector<int>>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define S(v) sort(v.begin(), v.end())
#define RS(v) sort(v.rbegin(), v.rend())
#define eb emplace_back
#define endl "\n"
#define MOD 1000000007
#define pqx priority_queue <int>
#define pqn priority_queue <int, v1d, greater<int> >
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int INF = 1e18;

int32_t main() {
    fio
    int n; cin >> n;
  	v1d v(n);
  	bool ok = false;
  	for(auto &k : v) {
  	    cin >> k;
  	    if(k == 0) ok = true;
  	}
  	if(ok) {
  	    cout << 0; return 0;
  	}
  	int ans = 1;
  	for(int i=0; i < n; ++i) {
      int k = (INF / v[i]);
      if(k < ans) {
        cout << -1; return 0;
      }
      else ans *= v[i];
    }
    cout << ans;
}

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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;

int main()
{
	LL a, b, n;
	cin >> a >> b >> n;

	if (b <= n) {
		cout << (a*(b-1)/b) - a*((b-1)/b);
	}
	else {
		cout << (a*n/b) - a*(n/b) << "\n";

	}

}



Measured memory_bytes: 3636
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  int N, W, V;
  cin >> N >> W;

   V = 1000*N;

  vector<ll> ws(N + 1), vs(N + 1);
  vector<vector<ll> > dp(N + 1, vector<ll>(V + 1, LONG_LONG_MAX/2));

  for (int i = 1; i <= N; i++) {
    cin >> ws[i] >> vs[i];
  }


  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= V; j++) {
      dp[i][j] = dp[i - 1][j];
      if (vs[i] <= j) {
        dp[i][j] = min(dp[i][j], dp[i - 1][j - vs[i]] + ws[i]);
      } 
      if (vs[i] >= j) {
        dp[i][j] = min(dp[i][j], ws[i]);
      }

      if (dp[i][j] <= W) ans = max(ans, (ll)j);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 80256
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) (*find_by_order(i))
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 998244353
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0ll)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1ll);

/*======================================================================*/

void solve(){
    int n, k;
    cin >> n >> k;
    vi vv(n+5, 0);
    rep(j, 0,k){
        vi v(n+5, 0);
        rep(i, 0, n){
            int x;
            if(j == 0)cin >> x;
            else x = vv[i+1];
            v[max(1LL, i+1-x)]++;
            v[min(n+1, i+1+x+1)]--;
        }
        rep(i, 2, n+1)v[i] += v[i-1];
        if(vv == v)break;
        else vv = v;
    }
    rep(i, 1, n+1)cout << vv[i] << " ";
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 6368
N=int(input())
A=[int(i) for i in input().split()]
A.sort(key=lambda x:-x)
S=[0]
for i in range(N):
  S.append(S[i]+A[i])
ans=1
for i in range(1,N):
  if A[i-1]<=2*(S[N]-S[i]):
    ans+=1
  else:
    break
print(ans)



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

const long long mod = 1e9 + 7;

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

  long long ans = 0;
  for ( int d = 0; d < 60; d++ ) {
    long long n0 = 0, n1 = 0;
    for ( int i = 0; i < n; i++ ) {
      if ( (a[i] >> d) & 1 ) { n1++; } else { n0++; }
    }
    long long num = n0 * n1 % mod;
    long long pow_2_d = (1ll << d) % mod;
    long long sum_d = num * pow_2_d % mod;
    ans += sum_d;
    ans %= mod;
  }

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


Measured memory_bytes: 5928
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	h := getNextInt(scanner)
	w := getNextInt(scanner)
	ss := make([]string, h)
	path := make([][2]int, h)
	for i := 0; i < h; i++ {
		ss[i] = getNextString(scanner)
		path[i][0] = w
		for j := 0; j < w; j++ {
			if ss[i][j] == '#' {
				path[i][1] = j
			}
			if ss[i][w-1-j] == '#' {
				path[i][0] = w - 1 - j
			}
		}
		if i == 0 {
			continue
		}
		if path[i][0] < path[i-1][1] {
			fmt.Println("Impossible")
			return
		}
	}
	fmt.Println("Possible")
	writer.Flush()
}


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

#define MAX 100

int top=0, s_array[1000];

void push( int num)
{
  top++;
  s_array[top] = num;
}

int pop( void)
{
  top--;
  return s_array[top+1];
}

int main()
{
  int i=0, j=1, number, num1, num2;
  char array[MAX], one_num[9];

  while(1){
    if( scanf("%s", &array) == EOF )break;

    if( array[0] == '+' || array[0] == '-' || array[0] == '*'){
      num1 = pop();
      num2 = pop();
      if( array[0] == '+')push(num2 + num1);
      else if( array[0] == '*')push(num2 * num1);
      else push(num2 - num1);
    }
    else push(atoi(array));
    
  }      
  
  printf("%d\n", pop()); 
  
  return 0;
}

Measured memory_bytes: 548
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long int li;

li combin(int n,int r){
  if(n<r or r<0) return 0;
  int a=1;li s=1;
  rep(i,r){
    s*=n-a+1;
    s/=a;
    a++;
  }
  return s;
}
li pow9(int k){
  li s=1;
  rep(i,k){
    s*=9;
  }
  return s;
}

li f(int n,int k){
  return combin(n,k)*pow9(k);
}
int p(string st,int k){
  int s=0;
  for(auto x:st){
    if(x!='0') s++;
  }
  return s==k;
}

int main(){
  if(df) printf("*debug mode*\n");
  string st; cin >>st;
  int n=st.size();
  int k; cin>>k;
  li ans=0;  
  int i=0;
  if(df){
    rep(i,n){
      rep(j,3){
	printf("%ld ",f(i,j));
      }
      printf("\n");
    }
  }
  
  if(p(st,k))ans++;
  rep(i,n){
    if(k<0){break;}
    if(st.at(i)=='0') continue;
    ans+=f(n-i-1,k);
    ans+=f(n-i-1,k-1)*(st.at(i)-'0'-1);
    k--;
  }
  printf("%ld",ans);
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	for(int i=1;i<=10000;i++){
		cin>>a>>b;
		if(a == 0 && b == 0) break;
		else if(a<b){
			cout<<a<<" "<<b<<endl;
		}else{
			cout<<b<<" "<<a<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  if (S[K - 1] == 'A') {
    S[K - 1] = 'a';
  } else if (S[K - 1] == 'B'){
    S[K - 1] = 'b';
  } else if (S[K - 1] == 'C') {
    S[K - 1] = 'c';
  }
  cout << S;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int slove(int x,int y,int n);
    int main(void)
    {
        int N,Q;
        scanf("%d %d",&N,&Q);
        while(Q)
        {
            Q--;
            int x,y;
            scanf("%d %d",&x,&y);
            if(N==1)
                cout<<min(x,y)<<endl;
            else
            cout<<slove(x,y,N)<<endl;
        }
        return 0;
    }
    int slove(int x,int y,int n)
    {
        while(x!=y)
        {
            if(x > y)
                x = (x+n-2)/n;
            else if(y > x)
                y = (y+n-2)/n;
        }
        return x;
    }

Measured memory_bytes: 1280
#include <iostream>

using namespace std;
int calc(int a,int b,char op);

int main(){
    int a,b,answer;
    char op;
    cin >> a >> op >> b;
    answer = calc(a,b,op);
    cout << answer << endl;
}

int calc(int a,int b,char op){
    if(op == '+'){
        return a+b;
    }else{
        return a-b;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#define MAX 500000
#define BUF 200000 
bool reverse = false;
int main(){
    char S[MAX];
    scanf("%s",S);
    int Q;
    int length=strlen(S);
    int back = 1;
    for(int i=0;i<length;i++){
        S[i+BUF]=S[i];
        S[i]='\0';
    }
    scanf("%d",&Q);
    for(int i=0;i<Q;i++){
        int q;
        scanf("%d",&q);
        if(q==1){
            if(reverse)
                reverse = false;
            else
                reverse = true;
        }
        else if(q==2){
            int F;
            char C;
            scanf("%d %c",&F,&C);
            if((F==1 && !reverse) || (F==2 && reverse)){
                S[BUF-back]=C;
                back++;
            }
            else{
                S[BUF+length] = C;
                length++;
            }   
        }
    }
    if(!reverse){
        for(int i=BUF-back+1;i<BUF+length;i++)
         printf("%c",S[i]);
    }
    else{
        for(int i=BUF+length-1;i>BUF-back;i--)
            printf("%c",S[i]);
    }
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] l = new int[n];
        int d = 0;
        for(int i = 0; i < n; i++){
            l[i] = scanner.nextInt();
        }

        int i = 0;
        while(d <= x && i < n){
            d = d + l[i];
            i++;
        }
        if(i ==  n && d <= x ) {
            System.out.println(i + 1);
        } else {
            System.out.println(i);
        }

    }
}


Measured memory_bytes: 22228
#include <stdio.h>

int	main(void)
{
	int	num[3];
	scanf("%d %d %d", &num[0], &num[1], &num[2]);

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2 - i; j++)
		{
			if (num[j] > num[j + 1])
			{
				int tmp;
				tmp = num[j];
				num[j] = num[j + 1];
				num[j + 1] = tmp;
			}
		}
	}
	printf("%d %d %d\n", num[0], num[1], num[2]);
	return (0);
}



Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n=0;
	char rem[5];
	scanf("%s",rem);
	for (int i=0;i<4;i++){
		if (rem[i]=='+'){
			n++;
		}
		else n--;
	}
	printf ("%d\n",n);
}

Measured memory_bytes: 256
L, R = map(int, input().split())
mod = 2019
ans = 10**9 + 7
for i in range(L, min(L + mod, R)):
  for j in range(i + 1, min(i + mod + 1, R + 1)):
    ans = min((i * j) % mod, ans)
print(ans)


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

int main(){
	int N; cin >> N;
        vector<double> pHead(N + 1, 0.0);
        pHead[0] = 1;
        for(int curToss = 0; curToss < N; ++curToss){
            double headP; cin >> headP;
            for(int headC = curToss + 1; headC >= 0; --headC){
                pHead[headC] = (1 - headP) * pHead[headC]
                	    + (headP) * (headC > 0 ? pHead[headC - 1] : 0.0); 
            }
        }
        double totalP = 0.0;
        for(int headC = N / 2 + 1; headC <= N; ++headC) totalP += pHead[headC];
        cout << setprecision(10) << totalP << endl;
    	return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int sum=1;
  for(int i=0;i<N-1;i++){
    if(vec.at(i)!=vec.at(i+1)){
      sum++;
    }else{
      continue;
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
void solve(){
  int cnt =0;
  string s;
  cin>>s;
  for(auto it:s){
	   if(it=='+')cnt++;
	   else cnt--; 
	 }	
  cout<<cnt<<endl;
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}

Measured memory_bytes: 256
def is_like2017(X):
  res = 1
  for x in [X,(X+1)/2]:
    y = int(x**0.5)
    for i in range(2,y+1):
      if x%i==0:
        res=0
        break
    if res==0:
      break
  return res

prime_accumulation = []
for i in range(10**5+2):
  if i<2:
    prime_accumulation.append(0)
  elif i%2==0:
    prime_accumulation.append(prime_accumulation[i-1])
  else:
    if is_like2017(i)==1:
      prime_accumulation.append(prime_accumulation[i-1]+1)
    else:
      prime_accumulation.append(prime_accumulation[i-1])

#input
Q = int(input())
ans = []
for i in range(Q):
  l,r = map(int,input().split())
  print(prime_accumulation[r]-prime_accumulation[l-1])

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

namespace ABC085C_Otoshidama
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int n = input[0];
            int y = input[1];

            for(int i = 0; i <= n; i++)
            {
                for (int j = 0; j <= n - i; j++)
                {
                    int total = 10000 * i + 5000 * j + 1000 * (n - i - j);
                    if (total == y)
                    {
                        Console.WriteLine("{0} {1} {2}", i, j, n - i - j);
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	int n;cin >> n;
	vector<ll> a(n);REP(i, n)cin >> a[i];
	vector<ll> b(n);REP(i, n)cin >> b[i];
	ll ans = 0;
	REP(i, n)ans += max(0LL, a[i] - b[i]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ans,l,r,k,n;
const int mod=1e9+7;
int main()
{
	ans=0;
cin>>n>>k;
for(ll i=k;i<=n+1;i++)
{
	l=(0+i-1)*i/2;
	r=(n+n-i+1)*i/2;
	ans=(ans+r-l+1)%mod;
}
cout<<ans;
return 0;

}

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

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();

    int ans = 1e9;
    for (int i = 0; i <= n-m; ++i) {
        int cnt = 0;
        for (int j = 0; j < m; ++j) {
            if(s[i+j] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3592