akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Graph vector<vector<int>>
constexpr int INF = 2000000;

int main() {
	int h, w;
	cin >> h >> w;
	Graph field(h);
	rep(i, h) {
		field[i].resize(w);
	}
	char c;
	int n = 0, m = 0;
	rep(i, h) {
		rep(j, w) {
			cin >> c;
			if (c == '.') {
				field[i][j] = n;
				++n;
			}
			else {
				field[i][j] = -1;
				++m;
			}
		}
	}
	//rep(i, h) {
	//	rep(j, w) {
	//		if (field[i][j] == -1)cout << "#\t";
	//		else cout << field[i][j] << "\t";
	//	}
	//	cout << endl;
	//}
	Graph M(n);
	rep(i, h) {
		rep(j, w) {
			if (field[i][j] > -1) {
				if (i > 0) {
					if (field[i - 1][j] >= 0) {
						M[field[i][j]].push_back(field[i - 1][j]);
					}
				}
				if (j > 0) {
					if (field[i][j - 1] >= 0) {
						M[field[i][j]].push_back(field[i][j - 1]);
					}
				}
				if (i < h - 1) {
					if (field[i + 1][j] >= 0) {
						M[field[i][j]].push_back(field[i + 1][j]);
					}
				}
				if (j < w - 1) {
					if (field[i][j + 1] >= 0) {
						M[field[i][j]].push_back(field[i][j + 1]);
					}
				}
			}
		}
	}
	//rep(i, n) {
	//	cout << i << "\t\t";
	//	for (int x : M[i]) {
	//		cout << x << "\t";
	//	}
	//	cout << endl;
	//}
	vector<int> d(n, INF);
	d[0] = 0;
	queue<int> q;
	//bfs start
	q.push(0);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int v : M[u]) {
			if (d[v] != INF)continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	//bfs end
	//rep(i, h) {
	//	rep(j, w) {
	//		if (field[i][j] == -1)cout << "#\t";
	//		else cout << d[field[i][j]] << "\t";
	//	}
	//	cout << endl;
	//}
	if (d[field[h - 1][w - 1]] != INF) {
		cout << (h* w) - (d[field[h - 1][w - 1]] + 1) - m << endl;
	}
	else cout << "-1" << endl;
}



Measured memory_bytes: 384
import sys

N=int(input())
lo,hi = 0,N-1
print(lo,"\n")
sys.stdout.flush()
val_lo = input()
if val_lo == 'Vacant':exit()
print(hi,"\n")
sys.stdout.flush()
val_hi = input()
if val_hi == 'Vacant':exit()

while True:
  m = (lo+hi)//2
  print(m,"\n")
  sys.stdout.flush()
  val_m = input()
  if val_m == 'Vacant':exit()
  if ((m-lo) % 2 == 0 and val_lo != val_m) or ((m-lo) % 2 and val_lo == val_m):
    hi = m
    val_hi = val_m
  else:
    lo = m
    val_lo = val_m

Measured memory_bytes: 9180
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

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

	return gcd(b, a % b);
}

int main(void) {
	int n;
	cin >> n;
	ll p=0;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int l = 1; l <= n; l++) {

			int a =gcd(i, j);
			int b =gcd(a, l);
			p += b;
			}
		}
	}

	cout << p;
	return 0;
}

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

int main(int argc, char const *argv[]) {
    int a, b;
    cin >> a >> b;

    if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
        cout << a * b << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi A(N),B(N),C(N);
  rep(i,N) {
    cin >> A[i] >> B[i];
    C[i] = A[i] + B[i];
  }
  sort(rng(C));
  reverse(rng(C));
  ll ans = 0;
  rep(i,N) {
    if(i % 2 == 0) ans += (ll)C[i];
  }
  rep(i,N) {
    ans -= (ll)B[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  for(int i=0;i<n;i++) {
    cin >> x[i];
    y[i] = x[i];
  }

  sort(y.begin(), y.end());

  for(int i=0;i<n;i++) {
    if(x[i] >= y[n/2]) {
      cout << y[n/2-1] << endl;
    } else {
      cout << y[n/2] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 5376
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int n;
int k;

int rec(int v, int n) {
  if (n == 0) {
    return v;
  } else {
    return rec(min(2*v, v+k), n-1);
  }
}

int main() {

  cin >> n >> k ;
  cout << rec(1, n) << endl;
}


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

int main() {
  int a,b;cin>>a>>b;
  if (a==1) a=14;
  if (b==1) b=14;
  string ans = a>b?"Alice":(a<b?"Bob":"Draw");
  // cout << (ans?"H":"D") << endl;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int N;
string W[101];
int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> W[i];
  }
  for(int i = 0; i < N; i++){
    if( (i < N - 1) && (W[i][W[i].size() - 1] != W[i + 1][0]) ){
      cout << "No" << endl;
      return 0;
    }
    for(int j = i + 1; j < N; j++){
      if(W[i] == W[j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
#include <iostream>
#include<algorithm>
#include <stdio.h>

using namespace std;

int main() {
	int n,tmp,m=0,x=100;
	long long ans = 99999999;
	vector <int> v;
	long int sum = 0;
	long int s=99999999;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		v.push_back(tmp);
		m=min(m, tmp);
		x = max(x, tmp);
	}
	for (int i = m; i < x; i++) {
		sum = 0;
		for (auto& num : v) {
			sum += (num - i) * (num - i);
			
		}
		s = min(sum, s);
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256
# AGC033A - Darker and Darker
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.distance_transform_cdt.html
from scipy.ndimage import distance_transform_cdt as dist


def main():
    H, W, *A = open(0).read().split()
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    ans = D.max()
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
	int H, W; cin >> H >> W;
	string a;
	for(int i=0; i<H+2; ++i){
	    if(!i || i>H) for(int j=0; j<W+2; ++j) cout << '#';
	    else{
	        cin >> a;
	        cout << '#' << a << '#';
	    }
	    cout << endl;
	}
	return 0;
}


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

int main() {
	string s;
	while (cin >> s) {
		char ans = 'd';
		rep(i, 3)if (s[i] == s[i + 3] && s[i] == s[i + 6] && s[i] != 's')ans = s[i];
		for (int i = 0; i <= 6; i += 3)if (s[i] == s[i + 1] && s[i] == s[i + 2] && s[i] != 's')ans = s[i];
		if (s[0] == s[4] && s[0] == s[8] && s[0] != 's')ans = s[0];
		if (s[2] == s[4] && s[2] == s[6] && s[2] != 's')ans = s[2];
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

const ll M = 2019;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll L, R; cin >> L >> R;
    ll ans = M - 1;
    for(ll l=L;l<=min(R, L+M-1);l++){
        for(ll r=l+1;r<=min(R, L+M-1);r++){
            ans = min(ans, (l*r) % M);
        }
    }
    cout << ans << endl;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;
		int w, h;
		cin >> w >> h;
		VVB tbl(h + 1, VB (w + 1));
		rep (i, n) {
			int x, y;
			cin >> x >> y;
			tbl[y][x] = true;
		}
		int s, t;
		cin >> s >> t;
		int ans = -1;
		rep (i, h + 1) {
			rep (j, w + 1) {
				int cnt = 0;
				REP (k, i, min(i + t, h + 1)) {
					REP (l, j, min(j + s, w + 1)) {
						cnt += tbl[k][l];
					}
				}
				ans = max(ans, cnt);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	int h,w,n,i,j,*a,**c,k=0;
	scanf("%d%d",&h,&w);
	c=new int* [h];
	for(i=0;i<h;i++){
		c[i]=new int[w];
	}
	scanf("%d",&n);
	a=new int [n];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<h;i++){
		if(i%2==0){
			for(j=0;j<w;j++){
				c[i][j]=k+1;
				a[k]--;
				if(a[k]==0){
					k++;
				}
			}
		}
		else{
			for(j=w-1;j>=0;j--){
				c[i][j]=k+1;
				a[k]--;
				if(a[k]==0){
					k++;
				}
			}
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			printf("%d",c[i][j]);
			if(j!=w-1){
				printf(" ");
			}
		}
		if(i!=h-1){
			printf("\n");
		}
	}
	return 0;
	system("pause");
} 

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

int main() {
	long int A,B,K;
	cin >>A>>B>>K;
	if(A>=K){
		cout <<A-K<<" "<<B;
	}
	else if(A+B>=K){
		cout <<0<<" "<<A+B-K;
	}
	else{
		cout <<0<<" "<<0;
	}
}

Measured memory_bytes: 256
program permutation_oddness
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer :: n, k, i, j, l
  integer(8) :: dp(0:50,-1:51,0:2500) = 0_8
  read(*,*) n, k
  if (mod(k,2) == 1) then
    write(*,'(i0)') 0
    stop
  end if
  dp(0,0,0) = 1_8
  do i = 1, n
    do l = k, 0, -1
      do j = 0, min(l/2,n)
        dp(i,j,l) = dp(i-1,j,l-2*j)*int(2*j+1,8)+ &
        &           dp(i-1,j+1,l-2*j)*int(j*j+2*j+1,8)+ &
        &           dp(i-1,j-1,l-2*j)
        dp(i,j,l) = mod(dp(i,j,l),md)
      end do
    end do
  end do
  write(*,'(i0)') dp(n,0,k)
  stop
end program permutation_oddness

Measured memory_bytes: 52352
#include <bits/stdc++.h>
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 FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
  int N;
  int lower = 0;
  int ans = 0;
  cin >> N;
  long long before = 0;
  vector<long long> H(N);
  REP(i, N) {
    long long h;
    cin >> h;
    if (before >= h) {
      lower++;
    } else {
      lower = 0;
    }
    if (ans < lower) {
      ans = lower;
    }
    before = h;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# 配列から累積和を返す
def make_cumulative(A):
    C = [0] * (len(A) + 1)
    for i, a in enumerate(A):
        i += 1
        C[i] = C[i - 1] + a
    return C


def main():
    N = NI()
    T = [0] + NLI()
    V = [0] + NLI() + [0]
    B = [[] for _ in range(N+1)]
    cum_T = make_cumulative(T)[1:]

    limits = [[] for _ in range(N)]
    for i, v in enumerate(V):
        for t in range(N):
            if t == i-1:
                limits[t].append([v, 0])
            elif t == i:
                limits[t].append([v, 1])
            elif t < i-1:
                limits[t].append([v + (cum_T[i-1] - cum_T[t]), -1])
            else:
                limits[t].append([v + (cum_T[t] - cum_T[i]), 1])
    limits = [sorted(l) for l in limits]


    ans = 0
    for li, limit in enumerate(limits):
        if limit[0][1] == -1:
            ans += limit[0][0] * T[li+1] - T[li+1]**2 / 2
            continue

        if limit[0][1] == 0:
            next_l = limit[1]
            for j in range(1, len(limit)):
                if limit[j][1] == -1:
                    next_l = limit[j]
                    break
            if next_l[1] == -1 and next_l[0] < limit[0][0] + T[li+1]:
                ans += limit[0][0] * T[li+1] - (limit[0][0]-next_l[0]+T[li+1])**2 / 2
            else:
                ans += limit[0][0] * T[li+1]
            continue

        stay = [l for l in limit if l[1] == 0]
        down = [l for l in limit if l[1] == -1]
        if down == []:
            down_l = [10**5, -1]
        else:
            down_l = down[0]
        if stay == []:
            stay_l = [10**5, 0]
        else:
            stay_l = stay[0]

        if down_l[0] >= limit[0][0] + T[li+1]*2:
            ans += limit[0][0] * T[li + 1] + T[li + 1] ** 2 / 2
            if limit[0][0] < stay_l[0] < limit[0][0] + T[li+1]:
                ans -= (limit[0][0] + T[li+1] - stay_l[0])**2 / 2
        else:
            h = (down_l[0] - limit[0][0])/2
            if stay_l[0] >= limit[0][0] + h:
                ans += (limit[0][0]+h) * T[li+1] - h**2/2 - (T[li+1]-h)**2/2
                continue

            m, M = min(limit[0][0], down_l[0]-T[li+1]), max(limit[0][0], down_l[0]-T[li+1])
            if M < stay_l[0] < limit[0][0] + h:
                ans += (limit[0][0] + h) * T[li + 1] - h ** 2/2 - (T[li + 1] - h) ** 2/2
                ans -= (limit[0][0] + h - stay_l[0]) ** 2
                continue

            if stay_l[0] <= M:
                ans += stay_l[0] * T[li+1] - (stay_l[0]-limit[0][0])**2 / 2
                continue

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 10408
def main():
    N = int(input())
    ans = N*(N**2 + 3*N + 2)//6
    for _ in range(N-1):
        a, b = (int(i) for i in input().split())
        if a > b:
            a, b = b, a
        ans -= a*(N-b+1)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74344
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm> 
const int inf=0x3f3f3f3f;
#define ll long long
using namespace std;
int main()
{
	int n,x,t;
	;
	int a;
	
	while(~scanf("%d",&n))
	{
		a=0;
		t=inf;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		if(x<t)
		{
		a++;
		t=x;	
		}
		
	 } 
	 printf("%d\n",a);
}
	return 0;
}

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

int main() {
  int A, B, c = 0;
  cin >> A >> B;
  int N = B - A + 1;
  for (int i = 0; i < N; i++){
    if (A % 10 == A / 10000 && (A / 10) % 10 == (A /1000) % 10){
      c++;
    }
    A++;
  }
  cout << c << endl;
}


Measured memory_bytes: 3604
#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>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

ll powll(ll n,ll k){ ll ret=1; while(k){ if(k&1)ret=ret*n; n=n*n; k>>=1; } return ret; }

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];

  int m = 1<<n;
  vector<vector<int>> dp((1<<20), vector<int>(20,inf));
  rep(i,n){ dp[1<<i][i]=0; }
  rep(i,m){
    int c = __builtin_popcountll(i);
    int cnt = c;
    rep(j,n){
      if(bit(i,j)){
        cnt--;
        int pre = i^(1<<j); //hirou
        rep(k,n){
          if(bit(pre,k)){
            int cur = abs(c-1-k)%2 ? a[k]:b[k];
            int nxt = abs(c-j)  %2 ? a[j]:b[j];
            if(cur<=nxt){
              dp[i][j] = min(dp[i][j], dp[pre][k]+cnt);
            }
          }
        }
      }
    }
  }
  int ans = inf;
  rep(i,n){
    ans = min(ans, dp[m-1][i]);
  }
  if(ans==inf) ans = -1;
  cout << ans << endl;
  return 0;  
}

Measured memory_bytes: 123136
n = gets.to_i
a = gets.split.map(&:to_i)
ans = 0
total = a.inject(:+)
l = 1
a.each_with_index do |d, i|
    if d > l
        ans = -1
        break
    end
    total -= d
    ans += l
    l = [(l - d) * 2, total].min
end
puts ans

Measured memory_bytes: 20708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e13)
#define PI (acos(-1))
//const ll mod = 1000000007;

ll N, M;
ll load[205][205];
ll marine[205][205];
ll dist[1005][205];
bool chmin(ll &a, ll b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
int z[1005];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> N >> M;
        if(N == 0) break;
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                load[i][j] = INF;
                marine[i][j] = INF;
            }
            load[i][i] = 0;
            marine[i][i] = 0;
        }
        while(M--) {
            ll u, v, c;
            char s;
            cin >> u >> v >> c >> s;
            if(s == 'L') {
                chmin(load[u][v], c);
                chmin(load[v][u], c);
            } else {
                chmin(marine[u][v], c);
                chmin(marine[v][u], c);
            }
        }
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                for(int k = 1; k <= N; k++) {
                    chmin(load[j][k], load[j][i] + load[i][k]);
                    chmin(marine[j][k], marine[j][i] + marine[i][k]);
                }
            }
        }
        ll R;
        cin >> R;
        for(int i = 1; i <= R; i++) cin >> z[i];
        z[0] = 1;
        for(ll i = 1; i <= N; i++) {
            for(int j = 0; j <= R; j++) {
                dist[j][i] = INF;
            }
        }
        dist[1][z[1]] = 0;
        for(int query = 2; query <= R; query++) {
            for(int before = 1; before <= N; before++) {
                chmin(dist[query][before], dist[query-1][before] + load[z[query-1]][z[query]]);
                for(int after = 1; after <= N; after++) {
                    chmin(dist[query][after], dist[query-1][before] + load[z[query-1]][before] + marine[before][after] + load[after][z[query]]);
                }
            }
            for(int i = 1; i <= N; i++) {
                //cerr << query << " " << i << " " << dist[query][i] << endl;
            }
        }
        ll ans = INF;
        for(int i = 1; i <= N; i++) {
            chmin(ans, dist[R][i]);
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 5364
import sys
input = sys.stdin.buffer.readline
import bisect

def main():
    N = int(input())
    if N == 1:
        print(0)
        exit()
    
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])

        if temp!=1:
            arr.append([temp, 1])   

        if arr==[]:
            arr.append([n, 1])

        return arr
    
    c = factorization(N)
    
    can = []
    for i in range(1,50):
        can.append((i*(i+1))//2)

    ans = 0
    for _,cnt in c:
        ind = bisect.bisect_right(can,cnt)
        ans += ind
    
    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;

int main()
{
    string O;
    string E;
    string res;
    int num;
    cin >> O >> E;
    for(int i = 0; i < E.length(); i++)
    {
        cout << O[i] << E[i];
        num = i;
    }
    if(O.length() != E.length())
    {
        cout << O[num+1];
    }
    cout << endl;
}


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

const int INF = 1e+9;
int dp[41][401][401];

int main()
{
  int n, ma, mb;
  int a[40], b[40], c[40];

  cin >> n >> ma >> mb;
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i] >> c[i];
  }

  for(int i = 0; i < 41; i++)
    for(int j = 0; j < 401; j++)
      for(int k = 0; k < 401; k++)
        dp[i][j][k] = INF;

  dp[0][0][0] = 0;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 401; j++){
      for(int k = 0; k < 401; k++){
        if(dp[i][j][k] == INF) continue;
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
      }
    }
  }

  int ans = INF;
  for(int i = 1; i < 401; i++){
    for(int j = 1; j < 401; j++){
      if(ma * j == mb * i) ans = min(ans, dp[n][i][j]);
    }
  }

  if(ans == INF) ans = -1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 25984
import java.util.*

const val mInf = 1 shl 31
const val inf = mInf - 1
private val sc = Scanner(System.`in`)

fun readWord(): String = sc.next()
fun readLine(): String = sc.nextLine()
fun readInt(): Int = readLine().toInt()

fun readArray(): List<String> = readLine().split(" ").toList()
fun readStringList(size: Int): List<String> = (0 until size).map { readLine() }


fun readMultiRowToStringArray(size: Int, f: (String) -> Unit = {}): Array<String> =
    Array(size) { readLine().apply(f) }

fun readMultiRowToIntArray(size: Int, f: (Int) -> Unit = {}): IntArray =
    IntArray(size) { readLine().toInt().apply(f) }

fun readMultiRowToBooleanArray(size: Int, f: (String) -> Boolean): BooleanArray = BooleanArray(size) { f(readLine()) }

//
fun readRowSplitToStringArray(size: Int, f: (String) -> String = { it }): Array<String> =
    Array(size) { sc.next().apply { f } }

fun readRowSplitToIntArray(size: Int, f: (Int) -> Unit = { }): IntArray =
    IntArray(size) { sc.next().toInt().apply(f) }

fun readRowSplitToBooleanArray(size: Int, f: (String) -> Boolean): BooleanArray = BooleanArray(size) { f(sc.next()) }


fun main(args: Array<String>) {
    readRowSplitToIntArray(3).let {
        print("${it[2]} ${it[0]} ${it[1]}")
    }
}

Measured memory_bytes: 29464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        long n = nl();
        long s = nl();

        if (n < s) {
            out.println(-1);
            return;
        }

        if (n == s) {
            out.println(n + 1);
            return;
        }

        for (long i = 2; i * i <= n; i++) {
            if (f(i, n) == s) {
                out.println(i);
                return;
            }
        }

        for (long i = (long) Math.sqrt(n); i >= 1; i--) {
            if ((n - s) / i > 0 && f((n - s) / i + 1, n) == s) {
                out.println((n - s) / i + 1);
                return;
            }
        }

        out.println(-1);
    }

    long f(long b, long n) {
        if (n < b) return n;
        else return f(b, n / b) + (n % b);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 9044
n=int(input())
pn = list(map(int, input().split()))
cnt = 0

for i in range(1, n-1):
		if pn[i-1]<pn[i]<=pn[i+1] or pn[i+1]<pn[i]<=pn[i-1]:
			cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){

    int N = 0;//??\?????°(?????°)
	int D = 0;//??????
    int i = 0;//??????????????°
	int now_d = 0;//????????°
	int now_s = 0;//?????¨?????????
    int now_f = 0;//?????¨????????°(0????????????????????±???)
	int f_diff = 0;//f-now_f
	long long total_s = 0;//?????????????????????
    int s[101010] = {0};//??\????§???°
    int f[101010] = {0};//??\????????°
    
    scanf("%d %d",&N,&D);//??\?????°??¨????????\???
    for(i=0;i<N;i++){//??\???
        scanf("%d %d",&s[i],&f[i]);
        f[i] -= 1;//?????°???0????????????????????£
    }
    for(i=0;i<N;i++){
        f_diff = f[i] - now_f;//?????°??????
	    if(f_diff < 0) f_diff *= (-1);//?????°???????????¶?????????
        if((s[i] - now_s) >= (f[i] + now_f)){//????????????????£????????????????
            total_s += 1LL * now_f * now_d;//??????
			now_s = s[i];
			now_f = f[i];
			now_d = 1;
            continue;
		}
        if(((s[i] - now_s) >= f_diff)&&(now_d < D)){//???????????????????????????????????????????¶??????§????????????
            total_s += 1LL * (s[i] - now_s) * now_d;
			now_s = s[i];
			now_f = f[i];
			now_d++;
		}
        else{ 
            printf("-1\n");
            return 0;
        }
    }
    total_s += 1LL * now_f * now_d;//??????????????????????¨?
	printf("%lld\n",total_s);
    return 0;
}

Measured memory_bytes: 2648
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

string gr(string a, string b) {
    if (a.size() > b.size()) return a;
    else if (a.size() < b.size()) return b;
    else {
        assert(a.size() == b.size());
        vector<int> Q_a;
        vector<int> Q_b;
        rep(i, a.size()) {
            Q_a.pb(a[i]-'0');
            Q_b.pb(b[i]-'0');
        }
        sort(all(Q_a));
        sort(all(Q_b));
        reverse(all(Q_a));
        reverse(all(Q_b));
        rep(i, a.size()) {
            int a_top = Q_a[i];
            int b_top = Q_b[i];
            if (a_top > b_top) return a;
            else if (a_top < b_top) return b;
        }
    }
    return a;
}

string dp[10000 + 10];
vi A;
int match[10];

signed main(void) {
    int N, M; cin >> N >> M;
    REP(i, 0, N) dp[i] = "none";
    match[1] = 2;
    match[2] = 5;
    match[3] = 5;
    match[4] = 4;
    match[5] = 5;
    match[6] = 6;
    match[7] = 3;
    match[8] = 7;
    match[9] = 6;
    rep(i, M) {
        int a; cin >> a;
        A.pb(a);
    }

    REP(i, 0, N) { //i:マッチの本数
        string num = "none";
        rep(j, M) { //A[j]:調べる１桁目の数字
            if (match[A[j]] <= i) { //採用可能
                if (i-match[A[j]] == 0) { //１桁の数字が完成
                    if (num == "none") num = to_string(A[j]);
                    else num = gr(to_string(A[j]), num);
                } else if (dp[i-match[A[j]]] != "none"){ //複数桁の数字が完成
                    string cand = to_string(A[j])+dp[i-match[A[j]]];
                    if (num == "none") num = cand;
                    else num = gr(cand, num);
                }
            }
        }
        dp[i] = num;
    }
    
    // REP(i, 0, N) {
    //     cout << i << ":" << dp[i] << endl;
    // }

    string ans = dp[N];
    // cout << ans << endl;

    priority_queue<int> Q;

    rep(i, ans.size()) {
        Q.push(ans[i] - '0');
    }
    rep(i, ans.size()) {
        cout << Q.top();
        Q.pop();
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 29444
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    char[] n = br.readLine().toCharArray();
    
    for (int i=0; i<n.length; i++){
      if (n[i] != n[n.length-1-i]){
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 21332
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
	ll num,n;
	cin>>num>>n;
	ll sum=0,x;
	rep(i,0,n)
	{
		cin>>x;
		sum+=x;
	}
	cout<<(num-sum<0?-1:num-sum)<<endl;
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 3804
import os, sys, re, math

N = int(input())

a = list(map(int,input().split(' ')))

memo = [0 for _ in range(N+1)]

for i in range(N,0,-1):
    tmp_s = 0
    idx = i

    while idx <= N:
        tmp_s += memo[idx]
        idx += i

    memo[i] = (tmp_s % 2) ^ a[i-1]

ret = [i for i in range(1,N+1) if memo[i] == 1]
if len(ret) == 0:
    print(0)
else:
    print(len(ret))
    ret = list(map(str,ret))
    print(' '.join(ret))


Measured memory_bytes: 19636
#include <iostream>

using namespace std;
int frecv[1000001],n,x,v[200001],sol,ok;
int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> v[i];
        ++frecv[v[i]];
    }
    if(frecv[1] > 1) sol = 0;
    else if(frecv[1] == 1) sol = 1;
    else
    {
        for(int i = 1; i <= n; ++i)
        {
            ok = 1;
            if(frecv[v[i]] > 1) ok = 0;
            else
            {
                for(int j = 2; j*j <= v[i]; ++j)
                {
                    if(v[i] % j == 0 && frecv[j] >= 1)
                        ok = 0;
                    if(v[i] % (v[i]/j) == 0 && frecv[v[i]/j] >= 1)
                        ok = 0;
                }
            }
            sol += ok;
        }
    }
    cout << sol << " ";
    return 0;
}


Measured memory_bytes: 8212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int gcd(int a,int b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    int ans=a[0];
    rep(i,n){
        ans=gcd(ans,a[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  n,i,r=0,d=0;
   string s;
   cin>>n>>s;
   for(i=0;i<s.size();i++)
   {
         if(s[i]=='R')
         r++;
   }
   for(i=0;i<r;i++)
   {
     if(s[i]=='R')
     d++;
   }
cout<<r-d<<endl;
return 0;
}


Measured memory_bytes: 3724
function main()
	N=parse(Int,readline())
	A=[0]
	for a=map(x->parse(Int,x),split(readline()))
		push!(A,a)
	end
	push!(A,0)
	ans=0;
	for i=1:N+1
		ans+=abs(A[i+1]-A[i])
	end
	for i=2:N+1
		println(ans-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))
	end
end
main()


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

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

  if (s[0] == s[1]) cout << "Bad" << endl;
  else if (s[1] == s[2]) cout << "Bad" << endl;
  else if (s[2] == s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
return 0;
}

Measured memory_bytes: 256
import sys,heapq
input = sys.stdin.buffer.readline
 
R,C,k = map(int,input().split())
 
 
val = dict()
for _ in range(k):
    rr,cc,vv = map(int,input().split())
    rr -= 1
    cc -= 1
    val[rr*C + cc] = vv
 
dp = [[0,0,0,0] for i in range(C)]
dp2 = [[0,0,0,0] for i in range(C)]

for i in range(R):
    for j in range(C):
        idx  = j
        if i*C + j in val:
            v = val[i*C + j]
        else:
            v = 0
        if i%2 == 0:
            if i == 0:
                if j == 0:
                    dp[idx][1] = v
                else:
                    dp[idx][1] = max(dp[idx-1][1],v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
            else:
                if j == 0:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3])
                    dp[idx][1] = dp[idx][0] + v
                else:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0])
                    dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
        else:
            if i == 0:
                if j == 0:
                    dp2[idx][1] = v
                else:
                    dp2[idx][1] = max(dp2[idx-1][1],v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
            else:
                if j == 0:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3])
                    dp2[idx][1] = dp2[idx][0] + v
                else:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0])
                    dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
 
print(max(max(dp[-1]),max(dp2[-1])))

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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

int main(void) {
	while (1) {
		double r, w, c, R;

		cin >> r >> w >> c >> R;
		if (r == 0) {
			break;
		}
		FOR(i, 0, 1e10) {
			if (c <= (r + i * R) / w) {
				cout << i << endl;
				break;
			}
		}
	}
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll I, O, T, J, L, S, Z;
  cin >> I >> O >> T >> J >> L >> S >> Z;

  ll ans = 0;
  ans += O;

  ans += 2 * (I / 2);
  ans += 2 * (J / 2);
  ans += 2 * (L / 2);

  if(I % 2 == 1 && J % 2 == 1 && L % 2 == 1){
    ans += 3;
  }else if(I % 2 == 1 && J % 2 == 1 && L >= 2){
    ans += 1;
  }else if(I % 2 == 1 && J >= 2 && L % 2 == 1){
    ans += 1;
  }else if(I >= 2 && J % 2 == 1 && L % 2 == 1){
    ans += 1;
  }

  cout << ans << endl;


  return 0;
}


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

int main(){
int a,b,c[60],d[30];
cin >> a;cin >> b;
for(int i = 0;i <= (b - 1);i++){
	scanf("%d,%d",&c[2 * i],&c[2 * i + 1]);
}
for(int e = 1;e <= a;e++){
	d[e - 1] = e;
}
for(int f = 0;f <= b - 1;f++){
	swap(d[c[2 * f] - 1],d[c[2 * f + 1] - 1]);
}
for(int g = 0;g <= a - 1;g++){
	cout << d[g] << endl;
}
fflush(stdin);
getchar();


return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
const int INF = 1000000;
int main(){
    int n;cin >> n;
    vector<int> b(n);
    rep(i,n-1) cin >> b[i];
    b[n-1] = INF;
    ll sum = b[0];
    for(int i=1;i<n;++i){
        sum += min(b[i-1],b[i]);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
l,r=gets.chomp.split(" ").map{|s| s.to_i}
if r-l>3000
  puts 0
else
  ans=2019
  for i in l..r-1
    for j in i+1..r
      ans=[ans,(i*j)%2019].min
      break if ans==0
    end
  end
  puts ans
end


Measured memory_bytes: 1788
N = int(input())
W = list(map(int, input().split()))

S_left = []
S_right = []
l = r = 0
for i in range(N - 1):
    l += W[i]
    S_left.append(l)
    r += W[N - 1 - i]
    S_right.insert(0, r)

ans = 10 ** 6
for i in range(N - 1):
    ans = min(ans, abs(S_left[i] - S_right[i]))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    vector<pii > p;
    for(intl i = 1; i * i <= n; i++){
        if(!(n % i)){
            p.pb(mp(n / i,n / (n / i)));
        }
    }
    sort(all(p));
    cout << digit10(p[0].first) << endl;
    return 0;
}

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

typedef struct{
  int p,l,r,s;
}Node;

int depth(Node*,int,int);
int height(Node*,int,int,int);

int main(){
  int num,i,j,k,number;
  Node node[N]; 
  
  scanf("%d",&num);

  for(i=0; i<num; i++){
    node[i].p = -1;
  }  
  for(i=0; i<num; i++){
    scanf("%d",&number);
    scanf("%d",&node[number].l);
    scanf("%d",&node[number].r);
    node[node[number].l].p = number;
    node[node[number].r].p = number;
  }
  
  
  for(i=0; i<num; i++){
    printf("node %d: parent = %d, ",i,node[i].p);

    if(node[i].p == -1)printf("sibling = -1, ");
    else if(node[node[i].p].l == -1 && node[node[i].p].r == -1) printf("sibling = -1, ");
    else if(node[node[i].p].l == i) printf("sibling = %d, ",node[node[i].p].r);
    else  printf("sibling = %d, ",node[node[i].p].l);

    if(node[i].l == -1 && node[i].r == -1) printf("degree = 0, ");
    else if (node[i].l == -1 || node[i].r == -1) printf("degree = 1, ");
    else  printf("degree = 2, ");

    printf("depth = %d, height = %d, ",depth(node,i,0),height(node,i,0,0));
    
    if(node[i].p==-1) printf("root\n");
    else if(node[i].l==-1 && node[i].r==-1) printf("leaf\n");
    else printf("internal node\n");
  }
  
  return 0;
}


int depth(Node *node,int num,int count){
  if(node[num].p==-1)return count;
  count++;
  count = depth(node,node[num].p,count);
  return count;
}



int height(Node *node,int num,int count,int max){
  if(node[num].l == -1 && node[num].r == -1){
    if(max < count) max = count;
    return max;
  }
  count++;
  if(node[num].l!=-1) max = height(node,node[num].l,count,max);
  if(node[num].r!=-1) max = height(node,node[num].r,count,max);
  
  count--;
  return max;
}

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

#define eb emplace_back
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ull unsigned long long
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()

const int INF = (int)1e9 + 7;
const int N = (int)7070 + 7;
const int MAXN = (int)1e6 + 228;

using namespace std;
const int mod = 998244353;
int n, dp[MAXN], cnt[MAXN], w[MAXN];

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

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

#ifdef Local
  freopen(".in", "r", stdin);
#else
  // freopen("sum.in", "r", stdin);
  // freopen("sum.out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  for (int i = 1; i <= (int)1e6; ++i) {
    w[i] = (w[i] + binpow(i, mod - 2)) % mod;
    for (int j = i + i; j <= (int)1e6; j += i) {
      w[j] = (w[j] - w[i] + mod) % mod;
    }
  }

  long long ans = 0;

  for (int i = (int)1e6; i >= 1; --i) {
    int sum = 0, res = 0;
    for (int j = i; j <= (int)1e6; j += i) {
      for (int k = 0; k < cnt[j]; ++k) {
        res = (res + j * 1ll * sum % mod) % mod;
        sum = (sum + j) % mod;
      }
    }
    ans = (ans + w[i] * 1ll * res % mod) % mod;
  }
  cout << ans << endl;

  return 0;
}

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


int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin >>p[i];
  int ans =0;
	for(int i=0;i<n-2;i++){
     if((max({p[i],p[i+1],p[i+2]}) ==p[i] && min({p[i],p[i+1],p[i+2]}) ==p[i+2]) ||(max({p[i],p[i+1],p[i+2]}) ==p[i+2] && min({p[i],p[i+1],p[i+2]}) ==p[i])){
    ans++;
     }
     }
      cout <<ans <<endl;
 }

Measured memory_bytes: 256