akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class Wifi {
public:
  int x;
  int y;
  int region;
  Wifi(int x,int y,int region) :
    x(x), y(y), region(region) {}
};

bool comp_x(const Wifi& s,const Wifi& t){
  return s.x < t.x;
}

bool comp_y(const Wifi& s,const Wifi& t){
  return s.y < t.y;
}

int main(){
  int N,W,H;

  while(~scanf("%d %d %d",&N,&W,&H)){
    vector<Wifi> points;
    for(int i = 0; i < N; i++){
      int x,y,region;
      scanf("%d %d %d",&x,&y,&region);
      points.push_back(Wifi(x,y,region));
    }
    
    sort(points.begin(),points.end(),comp_x);
    int max_x = 0;
    for(int i = 0; i < points.size(); i++){
      if(points[i].x - points[i].region <= max_x){
        max_x = max(points[i].x + points[i].region,max_x);
      }
    }
    
    sort(points.begin(),points.end(),comp_y);
    int max_y = 0;
    for(int i = 0; i < points.size(); i++){
      if(points[i].y - points[i].region <= max_y){
        max_y = max(points[i].y + points[i].region,max_y);
      }
    }
    
    printf("%s\n",(max_x >= W || max_y >= H) ? "Yes" : "No");
  }
}

Measured memory_bytes: 2700
#include<iostream>
#include<string>
using namespace std;
string s1,s2,s3;
int main(){
    cin>>s1>>s2>>s3;
    int l1=s1.length();
    int l2=s2.length();
    int l3=s3.length();
    bool ans=true;
    if (s1[l1-1]!=s2[0]) ans=false;
    if (s2[l2-1]!=s3[0]) ans=false;
    if (ans) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

int main() {
    int a,b,c;
    c = 0;
    cin >> a;
    for(int i = 0;i<a;i++){
        cin >> b;
        if(i%2 == 0 && b % 2 == 1){
            c++;
        }
    }
    cout << c << endl;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll a[n];
    ll sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    int m;cin>>m;
    ll p[m],x[m];
    for(int j=1;j<=m;j++){
        cin>>p[j]>>x[j];
        cout<<sum-a[p[j]]+x[j]<<"\n";
    }
    
    
    return 0;
}

Measured memory_bytes: 256
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if (a > b)
    {
        printf("a > b\n");
    }
    else if ( a == b)
    {
        printf("a == b\n");
    }
    else
    {
        printf("a < b\n");
    }
    return 0;
}


Measured memory_bytes: 2052
#include <stdio.h>
#include <stdlib.h>
#define N 2000000
#define Ai 10000

int main(){
  int *A,*B,C[Ai+1];
  int n,i,j;

  scanf("%d",&n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);
  for(i=0;i<=Ai;i++)
    C[i]=0;
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    C[A[i]]++;
  }

  for(i=1;i<=Ai;i++)
    C[i]=C[i]+C[i-1];


  for(j=0;j<n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<n;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n]);


  return 0;
}

Measured memory_bytes: 16272
/* ABC119 */
/* A */
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;

int main(void) {

    string ymd;
    // ymd = "2017/04/20";
    cin >> ymd;

    // "/"を削除する
    // find_first_of("/")で"/"のpositionを取得し、それをループのスタート地点にする
    // 文字列の最後はnposになる？ので、その手前（=文字列の最後）までループする
    // ループに入る変数は"/"のindex(iterator)
    for(size_t c = ymd.find_first_of("/"); c != string::npos; c = ymd.find_first_of("/")){
        ymd.erase(c,1);
    };

    int y;
    y = stoi(ymd);

    if (y<=20190430)
        cout << "Heisei" << endl;
    else 
        cout << "TBD" << endl;
}

Measured memory_bytes: 256
by = {"JPY" : 1.0, "BTC" : 380000.0}

N = int(input())
lst = [input().split() for i in range(N)]
lst = [[float(lst[i][0]), lst[i][1] ] for i in range(N)]
s = sum([lst[i][0] * by[lst[i][1]] for i in range(N)])
print(s)

Measured memory_bytes: 3316
# https://atcoder.jp/contests/abc120/tasks/abc120_d

######### Union Find ########
class UnionFind(object):
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def count(self, x):
        return -self.root[self.find(x)]


if __name__ == '__main__':
    n, m = map(int, input().split())
    ab = []
    for _ in range(m):
        ai, bi = map(int, input().split())
        ab.append((ai - 1, bi - 1))
    all_n = n * (n - 1) // 2
    ans = [all_n]
    uf = UnionFind(n)

    # 後ろから
    for i in range(m - 1):
        ai, bi = ab[-1 - i]
        # print(ai, bi)

        if not uf.is_same(ai, bi):
            all_n -= uf.count(ai) * uf.count(bi)
        uf.unite(ai, bi)
        ans.append(all_n)

    for v in ans[::-1]:
        print(v)


Measured memory_bytes: 110808
import java.util.*

class Task(a: Int, b: Int) {
    val a = a
    val b = b
}

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val tasks: MutableList<Task> = mutableListOf()
    for (i in 0..n-1) {
        tasks.add(Task(cin.nextInt(), cin.nextInt()))
    }
    val tasks_s = tasks.sortedBy{ it.b }
    var now: Long = 0
    var ok = true
    for (t in tasks_s) {
        now += t.a.toLong()
        if (now > t.b.toLong()) {
            ok = false
            break
        }
    }
    if (ok) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 126124
#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>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n, m, k;
int a[3005][3005];

void solve() {
    cin>>n>>m>>k;
    vector< vector<int> > old_dp(m + 2, vector<int>(4, 0));
    vector< vector<int> > new_dp(m + 2, vector<int>(4, 0));
    f(i, k) {
        int x, y, v;
        cin>>x>>y>>v;
        x--, y--;
        a[x][y] = v;
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            int pMax = max({old_dp[j + 1][0], old_dp[j + 1][1], old_dp[j + 1][2], old_dp[j + 1][3]});
            new_dp[j + 1][0] = max(pMax, new_dp[j][0]);
            new_dp[j + 1][1] = max(pMax + a[i][j], max(new_dp[j][1], new_dp[j][0] + a[i][j]));

            new_dp[j + 1][2] = max(new_dp[j][1] + a[i][j], new_dp[j][2]);

            new_dp[j + 1][3] = max(new_dp[j][2] + a[i][j], new_dp[j][3]);
        }
        old_dp = new_dp;
        f(kk, m + 2) f(jj, 4) new_dp[kk][jj] = 0;
    }
    cout<<max({old_dp[m][0], old_dp[m][1], old_dp[m][2], old_dp[m][3]});
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 74352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using P = pair<int,int>;

const int INF = 1e9;
const int N = 1010;

char board[N][N];
int dist[N][N];

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

int h,w;

bool isSafe(int x, int y) {
  if(1 <= x && x <= h && 1 <= y && y <= w && board[x][y] == '.') {
    return true;
  } else {
    return false;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> h >> w;
  int ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> board[i][j];
    }
  }

  rep(i,N) rep(j,N) dist[i][j] = INF;

  deque<P> que;
  que.emplace_front(ch, cw);
  dist[ch][cw] = 0;

  while(!que.empty()) {
    int curx = que.front().first;
    int cury = que.front().second;
    que.pop_front();

    for (int i = 0; i < 4; i++) {
      int nx = curx + dx[i];
      int ny = cury + dy[i];
      if(!isSafe(nx, ny)) continue;
      if(dist[nx][ny] <= dist[curx][cury]) continue;

      dist[nx][ny] = dist[curx][cury];
      que.emplace_front(nx, ny);
    }

    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        int nx = curx + i;
        int ny = cury + j;
        if(!isSafe(nx, ny)) continue;
        if(dist[nx][ny] <= dist[curx][cury] + 1) continue;
        dist[nx][ny] = dist[curx][cury] + 1;
        que.emplace_back(nx, ny);
      }
    }
  }
  int ans = dist[dh][dw];
  if(ans == INF) ans = -1;

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


Measured memory_bytes: 8616
n,W=map(int,input().split())
vw=[list(map(int,input().split())) for _ in [0]*n]
memo=[0]*(W+1)
for i in range(n):
    v,w=vw[i]
    for j,k in enumerate(memo[W-w::-1]):
        memo[W-j]=max(v+k,memo[W-j])
print(max(memo))


Measured memory_bytes: 6256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

struct mat
{
    vvl v;
    mat(int n){
        v.resize(n,vl(n,0));
    }
};

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

mat mul(const mat& m1,const mat& m2)
{
    int MAX_N = len(m1.v);
    mat res(MAX_N);
    rep(i,MAX_N){
        rep(j,MAX_N){
            res.v[0][i] = add(res.v[0][i],mul(m1.v[0][j],m2.v[j][i]));
        }
    }
    srep(i,1,MAX_N){
        rep(j,MAX_N){
            res.v[i][j] = res.v[0][(j+MAX_N-i)%MAX_N];
        }
    }
    return res;
}

mat mod_pow(const mat& m1,ll b)
{
    int n = len(m1.v);
    mat res(n);
    rep(i,n){
        res.v[i][i] = 1;
    }
    mat nw(n);
    nw = m1;
    while(b){
        if(b & 1){
            res = mul(res,nw);
        }
        nw = mul(nw,nw);
        b >>= 1;
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,K;
    cin >> n >> m >> K;
    mat a(n);
    rep(i,n){
        a.v[i][i]++;
    }
    rep(i,m){
        int b;
        cin >> b;
        rep(j,n){
            a.v[j][(j+b)%n]++;
        }
    }
    mat res(n);
    res = mod_pow(a,K);
    rep(i,n){
        cout << res.v[0][i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 27992
#include <cstdio>
#include <map>
#include <set>
#include <vector>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)

typedef long long i64;

typedef vector<int> Vi;
typedef pair<i64, i64> pii;

const int NR = 1e5 + 10;

set<pii> xs, ys;
map<pii, int> px, py;
i64 ans, X[NR], Y[NR], D;
int A, B, n;
pii q[NR];

#define fi first
#define se second


pii rev(const pii &a) { return pii(a.se, a.fi); }
int h, t;
int delx(i64 x, i64 yl, i64 yr) {
	for (auto it = xs.lower_bound(pii(x, yl)); it != xs.end() && it->fi == x && it->se <= yr;) {
		pii tmp = *it;
		q[++t] = tmp;
		++it;
		xs.erase(tmp);
		ys.erase(rev(tmp));
	}

	auto it = px.lower_bound(pii(x, yl));
	if (it == px.end() || it->fi.fi != x) return 0;
	auto jt = px.upper_bound(pii(x, yr));

	return (jt == px.end() ? n + 1 : jt->se) - it->se;
}

int dely(i64 y, i64 xl, i64 xr) {
	for (auto it = ys.lower_bound(pii(y, xl)); it != ys.end() && it->fi == y && it->se <= xr;) {
		pii tmp = rev(*it);
		q[++t] = tmp;
		++it;
		xs.erase(tmp);
		ys.erase(rev(tmp));
	}

	auto it = py.lower_bound(pii(y, xl));
	if (it == py.end() || it->fi.fi != y) return 0;
	auto jt = py.upper_bound(pii(y, xr));

	return (jt == py.end() ? n + 1 : jt->se) - it->se;
}

int main() {
	//freopen("65E.in", "r", stdin);
	scanf("%d%d%d", &n, &A, &B);
	iter(i, n) {
		int x, y;
		scanf("%d%d", &x, &y);
		X[i] = x + y; Y[i] = x - y;

		if (i != A && i != B) {
			xs.insert(pii(X[i], Y[i]));
			ys.insert(pii(Y[i], X[i]));
		}

		px[pii(X[i], Y[i])] = 0;
		py[pii(Y[i], X[i])] = 0;
	}

	int xz = 0, yz = 0;
	for (auto it = px.begin(); it != px.end(); ++it) it->se = ++xz;
	for (auto it = py.begin(); it != py.end(); ++it) it->se = ++yz;

	D = max(abs(X[A] - X[B]), abs(Y[A] - Y[B]));

	q[h = 1] = pii(X[A], Y[A]);
	q[t = 2] = pii(X[B], Y[B]);
	
	while (h <= t) {
		pii p = q[h++];
		i64 x = p.fi, y = p.se;

		

		ans += -(px.find(pii(x - D, y - D)) != px.end()) - (px.find(pii(x - D, y + D)) != px.end())
			   -(px.find(pii(x + D, y - D)) != px.end()) - (px.find(pii(x + D, y + D)) != px.end()) +
			delx(x - D, y - D, y + D) +
			delx(x + D, y - D, y + D) +
			dely(y - D, x - D, x + D) +
			dely(y + D, x - D, x + D);

			//printf("[%lld %lld]\n", x, y);
	}


	printf("%lld\n", ans / 2);
	return 0;
}


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

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

int main() {
	int N, K;
	cin >> N >> K;
	double odd, j, ans;
	ans = 0;
	odd = 1 / (double) N;
	rep(i, N) {
		j = i + 1;
		while (j < K) {
			j *= 2;
			odd /= 2;
		}
		ans += odd;
		odd = 1 / (double) N;
	}
	cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
using System;
using static System.Console;

class Program {
  static void Main() {
    int a = int.Parse(ReadLine());
    int b = int.Parse(ReadLine()); ;
    int c = int.Parse(ReadLine()); ;
    int d = int.Parse(ReadLine()); ;
    WriteLine(Math.Min(a, b) + Math.Min(c, d));
  }
}

Measured memory_bytes: 11092
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,k = readline() |> split |> parseMap
	d = readline() |> split |> parseMap
	v = zeros(Int,10)
	for i in 1:k
		v[d[i]+1] = 1
	end
	while 1==1
		m = n
		f = 0
		while m>0
			if v[m%10+1]==1
				f = 1
				break
			end
			m=div(m,10)
		end
		if f==0
			println(n)
			break
		end
		n+=1
	end
end

main()

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n);
  for(int i=0;i<m;i++) {
    int a, b;
    cin >> a >> b;

    ans[a-1]++;
    ans[b-1]++;
  }

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

Measured memory_bytes: 256
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m
let i = scan  "%s" id

let () =
  Printf.printf "%s\n" (if i = "ABC" then "ARC" else "ABC")


Measured memory_bytes: 5300
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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

string s;
vs t,d;
int n,q;

int f(int ind){
    rep(i,q)if(t[i][0] == s[ind]){
        if(d[i] == "R")ind++;
        else ind--;
        if(ind == n || ind < 0)break;
    }
    return ind;
}

signed main(void) {
    cin >> n >> q;
    cin >> s;
    t = d = vs(q);
    rep(i,q)cin >> t[i] >> d[i];
    int ans = n;
    {
        int ok = -1, ng = n;
        while(ng - ok > 1){
            int mid = (ok+ng)/2;
            if(f(mid) == -1)ok = mid;
            else ng = mid;
        }
        ans -= ok - -1;
    }
    {
        int ok = n, ng = -1;
        while(ok - ng > 1){
            int mid = (ok+ng)/2;
            if(f(mid) == n)ok = mid;
            else ng = mid;
        }
        ans -= n - ok;
    }
    cout << ans << endl;
}


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

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
  int i, j, k, l;
  int L;
  double edge;
  std::cin >> L;
  edge = L / 3.0;
  printf("%lf\n", edge * edge * edge);
  return 0;
}


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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  int max = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (i != j && max < abs(A.at(i) - A.at(j))){
        max = abs(A.at(i) - A.at(j));
      }
    }
    
  }

  cout << max << endl;
  
  
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

typedef long double fack;

const int MAXN = 53;
const fack EPS = 1e-8;
LL v[MAXN];
LL a, b;
map<LL, LL> cnt;

LL ncr[MAXN][MAXN];
void pre() {
  ncr[1][0] = 1; ncr[1][1] = 1;
  for(LL i = 2; i < MAXN; i++) {
    ncr[i][0] = 1;
    for(LL r = 1; r <= i; r++) {
      ncr[i][r] = ncr[i-1][r] + ncr[i-1][r-1];
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  LL n;
  cin >> n >> a >> b;
  assert(a > 0 && a <= b && b <= n);
  for(int i = 1; i <= n; i++) {
    cin >> v[i];
    cnt[v[i]]++;
  }
  pre();
  sort(v + 1, v + n + 1);
  fack maxim = 0;
  for(int s = a; s <= b; s++) {
    LL total = 0;
    for(int i = n, cnt = 0; i > 0 && cnt < s; cnt++, i--) {
      total += v[i];
    }
    maxim = max(maxim, total/(fack)s);
  }
  cout << setprecision(9) << fixed << maxim << '\n';
  LL res = 0;
  for(int s = a; s <= b; s++) {
    LL total = 0;
    map<LL, LL> taken;
    LL last;
    for(int i = n, cnt = 0; i > 0 && cnt < s; cnt++, i--) {
      total += v[i];
      taken[v[i]]++;
      last = v[i];
    }
    fack temp = total/(fack)s;
    if(fabs(temp - maxim) < EPS) {
      res += ncr[cnt[last]][taken[last]];
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc116/tasks/abc116_c

#[allow(unused)]
use std::cmp::{max, min, Ordering};
#[allow(unused)]
use std::collections::{HashSet, VecDeque};
use std::io;
use std::io::{BufRead, Read, Write};
use std::str::FromStr;

#[allow(unused, non_snake_case)]
pub fn solve<R: BufRead, W: Write>(mut io: Io<R, W>) {
    let N: usize = io.next();
    let mut hs: Vec<usize> = io.nexts(N);

    let mut res = 0;

    loop {
        let mutating_count: usize = hs
            .iter()
            .scan(0, |prev, curr| {
                let was_zero = *prev == 0;
                *prev = *curr;

                if was_zero && *curr > 0 {
                    Some(1)
                } else {
                    Some(0)
                }
            })
            .sum();

        hs = hs.iter().map(|h| if *h > 0 { *h - 1 } else { 0 }).vec();

        if mutating_count > 0 {
            res += mutating_count
        } else {
            break;
        }
    }

    io.println(res);
}

#[allow(dead_code)]
fn main() {
    let stdin = io::stdin();
    let stdin_lock = stdin.lock();
    let stdout = io::stdout();
    let stdout_lock = stdout.lock();

    let io = Io {
        reader: stdin_lock,
        writer: stdout_lock,
    };

    solve(io);
}

/* IO helpers */

pub struct Io<R, W>
where
    R: BufRead,
    W: Write,
{
    pub reader: R,
    pub writer: W,
}

#[allow(dead_code)]
impl<R, W> Io<R, W>
where
    R: BufRead,
    W: Write,
{
    fn println<T: std::fmt::Debug>(&mut self, value: T) {
        writeln!(&mut self.writer, "{:?}", value).expect("Unable to write");
    }

    fn print<T: std::fmt::Debug>(&mut self, value: T) {
        write!(&mut self.writer, "{:?}", value).expect("Unable to write");
    }

    fn next<T: FromStr>(&mut self) -> T {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok().expect("Unable to parse")
    }

    fn nexts<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next::<T>()).collect::<Vec<T>>()
    }
}

/* Structure helpers */

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}


Measured memory_bytes: 4352
#include <stdio.h>
#define swap(a, b) a^=b^=a^=b

int gcd(int,int);

int main(){
  int n,m,divisor;

  scanf("%d %d",&n,&m);
  divisor = gcd(n, m);
  printf("%d\n", divisor);
  
  return 0;
}

int gcd(int x,int y){
  int r;
  
  if(x<y) swap(x,y);
    while(y>0){
      r=x%y;
      x=y;
      y=r;
    }
    return x;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }


int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    vector<pair<int, int>> v;
    for (int i = 1; i <= 12; ++i) {
      v.push_back(make_pair(i, i));
    }
    int cnt = 0;
    each (i, v) cnt += i <= make_pair(a, b);
    cout << cnt << endl;
  }

  return 0;
}


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

ll power(ll x,ll y)
{
    ll res = 1;
    while(y>0){
        if(y&1)
            res *= x;
        y>>=1;
        x*=x;
    }
    return res;
}

int b[110];

int main()
{
    int n;
    cin>>n;
    //vector<pair<int,int>> a(n-1);
    //vector<int> b;
    for(int i=0;i<n-1;i++){
        cin>>b[i];
    }
    int a[110]={0};
    a[0] = b[0];
    a[1] = b[0];
    for(int i=1;i<n-1;i++){
        if(b[i]<a[i]){a[i]=b[i];}
        a[i+1] = b[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=a[i];
    }
    cout<<ans<<'\n';

}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#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;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<ll> dqll;

#define MOD 1000000007

int main() {
  ll H, W, D;
  cin >> H >> W >> D;

  vector<vector<pair<ll, P> > > lst(D);
  vector<unordered_map<ll, ll> > db(D);
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      ll v;
      cin >> v;
      lst[v % D].push_back(make_pair(v / D, P(i, j)));
    }  // j
  }  // i

  for (int i = 0; i < D; i++) {
    sort(lst[i].begin(), lst[i].end());
    db[i][lst[i][0].first] = 0;
    for (size_t j = 1; j < lst[i].size(); j++) {
      ll x, y, px, py;
      py = lst[i][j - 1].second.first;
      px = lst[i][j - 1].second.second;
      y  = lst[i][j].second.first;
      x  = lst[i][j].second.second;
      db[i][lst[i][j].first] = abs(py - y) + abs(px - x) + db[i][lst[i][j-1].first];
    }  // j
  } // i

  ll Q;
  cin >> Q;
  vll res(Q, 0);
  for (int i = 0; i < Q; i++) {
    ll L, R;
    cin >> L >> R;
    res[i] = db[L%D][R/D] - db[L%D][L/D];
  }  // i

  for (int i = 0; i < Q; i++) {
    cout << res[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 16640
import numpy as np
import math
import itertools

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
yakusu = make_divisors(N)
min_tasi = 10**15

for i in range(len(yakusu)):
  other = N / yakusu[i]
  tasi = yakusu[i] + other
  
  if tasi < min_tasi:
    min_tasi = tasi

print(int(min_tasi) - 2)

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

#define INF INT_MAX

using Weight = long long;
using Weights = vector<Weight>;
using Matrix = vector<Weights>;

bool WF(const Matrix &g, Matrix &dist, vector<vector<int>> &prev) {
	int V = g.size();
	dist = g;
	prev.assign(V, vector<int>(V, -1));
	for (int k = 0; k < V; ++k) {
		for (int i = 0; i < V; ++i) {
			for (int j = 0; j < V; ++j) {
				if (dist[i][k] == INF || dist[k][j] == INF) continue;
				if (dist[i][j] > dist[i][k] + dist[k][j]) {
					dist[i][j] = dist[i][k] + dist[k][j];
					prev[i][j] = k;
				}
			}
		}
	}
	for (int i = 0; i < V; ++i) if (dist[i][i] < 0) return true;
	return false;
}

void buildPath(const vector< vector<int> > &prev,
	int s, int t, vector<int> &path) {
	int u = prev[s][t];
	if (u < 0) path.push_back(s);
	else buildPath(prev, s, u, path), buildPath(prev, u, s, path);
}
vector<int> buildPath(
	const vector< vector<int> > &prev, int s, int t) {
	vector<int> path;
	buildPath(prev, s, t, path);
	path.push_back(t);
	return path;
}

int main(void) {
	int V, E;
	cin >> V >> E;
	Matrix g(V, vector<Weight>(V, INF));
	for (int i = 0; i < V; ++i) g[i][i] = 0;
	for (int i = 0; i < E; ++i) {
		long long s, t, w;
		cin >> s >> t >> w;
		g[s][t] = w;
	}

	Matrix dist;
	vector<vector<int>> prev;
	bool nc = WF(g, dist, prev);
	if (nc) {
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}
	for (int i = 0; i < V; ++i) {
		for (int j = 0; j < V; ++j) {
			if (i == j) cout << "0";
			else if (dist[i][j] == INF) cout << "INF";
			else cout << dist[i][j];
			if (j != V - 1)cout << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3288
#include<string>
#include<iostream>
#include<set>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<61);
const int mod=1000000007;
inline int gcd(int a,int b) { return b ? gcd(b, a % b) : a; }


int main(void){
	string a,b;
	cin>>a>>b;
	if(a.size()>b.size()){cout<<"GREATER";}
	else if(a.size()<b.size()){cout<<"LESS";}
	else if(a>b){cout<<"GREATER";}
	else if(a<b){cout<<"LESS";}
	else {cout<<"EQUAL";}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<strings.h>
using namespace std;
int main(){
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H')cout<<"H"<<endl;
	else if(a=='D'&&b=='H')cout<<"D"<<endl;
	else if(a=='D'&&b=='D')cout<<"H"<<endl;
	else cout<<"D"<<endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    ll N;
    cin>>N;
    ll K=1;
    bool exist=false;
    for(K=1;K<=N;K++){
        if(K*(K+1)/2==N){
            exist=true;
            break;
        }
    }

    if(!exist){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    cout<<K+1<<endl;
    vector<vector<ll>> res(K+1,vector<ll>());
    ll sum=1;
    for(int k=K;k>=1;k--){
        for(int i=0;i<k;i++){
            res[K-k].push_back(sum+i);
            res[K-k+i+1].push_back(sum+i);
        }
        sum+=k;
    }

    for(int i=0;i<K+1;i++){
        cout<<res[i].size();
        for(int j=0;j<res[i].size();j++) cout<<" "<<res[i][j];
        cout<<endl;
    }

}

Measured memory_bytes: 3200
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = readline().decode('utf8').strip()
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])

if A + B + C + D == 7:
    print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A + B + C - D == 7:
    print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A + B - C + D == 7:
    print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A - B + C + D == 7:
    print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A + B - C - D == 7:
    print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A - B + C - D == 7:
    print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A - B - C + D == 7:
    print('{}-{}-{}+{}=7'.format(A, B, C, D))
else:
    print('{}-{}-{}-{}=7'.format(A, B, C, D))


Measured memory_bytes: 12468
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    int j=min(n,m);
    int cd=0;
    while(1){
        if(n%j==0 && m%j==0){
            cd++;
            //cout<<"j="<<j<<endl;
        }
        if(cd==k){
            break;
        }
        j--;
    }
    cout<<j<<endl;

}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int N,x;
    cin >> N >> x;
    vector<int> a(N);
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    ll cnt = 0;
    if (a[0] > x){
        cnt += a[0]-x;
        a[0] = x;
    }
    for (int i = 0; i < N-1; i++){
        if (a[i]+a[i+1] > x){
            cnt += a[i+1]-(x-a[i]);
            a[i+1] = x-a[i];
        }
    }
    cout << cnt << endl;


        


    return 0;
}


Measured memory_bytes: 640
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var n = Number(lines[0]);
 var mid = n / 2 - 1;
 var diff = lines[1].split(' ').sort((a, b)=> a - b);
 var ans = diff[mid+1] - diff[mid];
 console.log(ans);
});

Measured memory_bytes: 21052
s = input()
x, y = map(int, input().split())
x += 8500
y += 8500

dpx = [0 for i in range(17000)]
dpy = [0 for i in range(17000)]

dpx[8500] = 1
dpy[8500] = 1

f = s.split("T")

fx = []
fy = []

for i, fi in enumerate(f):
    if i % 2:
        fy.append(len(fi))
    else:
        fx.append(len(fi))

for i, fxi in enumerate(fx):
    nex = [0] * 17000
    for j in range(17000):
        if dpx[j]:
            if fxi + j < 17000:
                nex[fxi + j] = 1
            if i > 0 and j - fxi >= 0:
                nex[j - fxi] = 1
    dpx = nex
        
for fyi in fy:
    nex = [0] * 17000
    for j in range(17000):
        if dpy[j]:
            if fyi + j < 17000:
                nex[fyi + j] = 1
            if j - fyi >= 0:
                nex[j - fyi] = 1
    dpy = nex

if dpx[x] and dpy[y]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 220084
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
string s;
ll ans,a[1000005],len;
int main()
{
    //IOS;
    cin>>s;
    len=s.length();
    for(int i=len-1;i>=0;i--)
    {
        a[len-i]=(s[i]-'0');
    }
    for(int i=1;i<=len+1;i++)
    {
        if(a[i]==5)
        {
            ans+=a[i];
            if(a[i+1]>=5)
            {
                a[i+1]++;
            }
        }
        else if(a[i]<5)
        {
            ans+=a[i];
        }
        else
        {
            ans+=(10-a[i]);
            a[i+1]++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 9220
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int x;
// main solution goes here:
void execute(int test_number)
{
    cin>>x;
    for (int i=-1500; i<=1500; i++) {
        for (int j=-1500; j<=1500; j++) {
            if (i*i*i*i*i-j*j*j*j*j == x) {
                cout<<i<<" "<<j;
                return;
            } 
        }
    }
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

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

int main(){
  char c;
  cin>>c;
  if(c=='a')
    cout<<"vowel"<<endl;
  else if(c=='e')
    cout<<"vowel"<<endl;
  else if(c=='i')
    cout<<"vowel"<<endl;
  else if(c=='o')
    cout<<"vowel"<<endl;
  else if(c=='u')
    cout<<"vowel"<<endl;
  else
    cout<<"consonant"<<endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,t,ans=0;
cin >> a>>b>>c;
while(1){
t=c;
t%=a;
if(t==0) {ans++;};
if (b==a) break;
a++;
}	
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1'000'000'007;
// const ll MOD = 998244353;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S, T;
    cin >> S >> T;
    int N = S.size();
    int M = T.size();
    ll ans = INFLL;
    for(int i = 0; i < N; i++){
        if(i + M > N)continue;
        string tmp = S.substr(i, M);
        // dump(tmp);
        ll cnt = 0;
        rep(j,M)cnt += T[j] != tmp[j];
        chmin(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int main(){
	int n;
	ll bs = 0;
	cin >> n;
	ll mi = INF;
	bool f = true;
	REP(i, n){
		ll a, b;
		cin >> a >> b;
		bs += b;
		if(a > b) mi = min(b, mi);
		if(a != b) f = false;
	}
	if(f) cout << 0 << endl;
	else cout << bs - mi << endl;
}

/*
1 1
0 0
0 0
0 0
*/

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:isize,
    b:isize,
    c:isize,
    }
    println!("{}",(a+b)*c/2)
}

Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int n, k;
    cin >> n >> k;
    ll x[n];
    for (int i = 0; i < n; i++) cin >> x[i];
    sort(x, x+n);
    ll sec, left = x[0], right = x[k - 1];
    if (abs(left) < abs(right)) {
        sec = abs(0 - left);
        sec += abs(left - right);
    } else {
        sec = abs(0 - right);
        sec += abs(right - left);
    }
    ll ans = sec;
    for (int i = 1; i < n - k + 1; i++) {
        left = x[i];
        right = x[i + k - 1];
        if (abs(left) < abs(right)) {
            sec = abs(0 - left);
            sec += abs(left - right);
        } else {
            sec = abs(0 - right);
            sec += abs(right - left);
        }
        ans = min(ans, sec);
    }
    cout << ans << endl;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  string s; cin >> s;
  ll ans = 0;
  rep(i, 1LL<<n) {
    string t1 = "", t2 = "";
    rep(j, n) {
      if (i>>j & 1) t1 += s[j];
      else t2 += s[j];
    }
    reverse(all(t1));
    reverse(all(t2));
    if (t1.size() > t2.size()) swap(t1, t2);
    ll m1 = t1.size(), m2 = t2.size();
    vector<vector<ll>> dp(n+1, vector<ll>(m1+1, 0));
    dp[0][0] = 1;
    rep(a, n) rep(l1, m1+1) {
      if (dp[a][l1] == 0) continue;
      ll l2 = a - l1;
      if (l2 < 0 || l2 > m2) continue;
      if (l1 < m1 && s[n+a] == t1[l1]) {
        dp[a+1][l1+1] += dp[a][l1];
      }
      if (l2 < m2 && s[n+a] == t2[l2]) {
        dp[a+1][l1] += dp[a][l1];
      }
    }
    ans += dp[n][m1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256