akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...U>void _(const char*s,T h,U...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}//break continue pop_back
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...)
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

int32_t main(){

    int n,d;
    cin>>n>>d;
    int x=d+d+1;
    cout<<(n+x-1)/x<<'\n';
    return 0;
}


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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

long long N, M;
vector<long long> A;

bool isOK(long long mid) {
    long long cnt = 0;
    for (int i = 0; i < N; i++) {
        cnt += A.end() - lower_bound(A.begin(), A.end(), mid - A[i]);
    }
    if (cnt <= M) return true;
    else return false;    
}

void solve() {
    cin >> N >> M;
    A.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());

    long long ok = 10000000000;
    long long ng = 0;
 
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        if (isOK(mid)) ok = mid;
        else ng = mid;
    }

    vector<long long> cumsum(N+1);
    for (int i = 1; i <= N; i++) {
        cumsum[i] += cumsum[i-1] + A[i-1]; 
    }

    long long ans = 0, cnt = 0;
    for (int i = 0; i < N; i++) {
        int len = A.end() - lower_bound(A.begin(), A.end(), ok - A[i]);
        cnt += len;
        ans += A[i] * len + (cumsum[N] - cumsum[N-len]);
    }
    ans += (M - cnt) * ng;

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

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

    solve();

    return 0;
}


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    double ans=v[0];
    for(int i=1;i<n;i++){
        ans=(ans+v[i])/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100][2];
ll n;
int main(){
	cin>>n;
	ll x;
	for(ll i=1;i<=n;i++){
		cin>>x;
		ll t=1;
		for(ll j=1;j<=62;j++){
			if(x&t){
				a[j][1]++;
			}else{
				a[j][0]++;
			}
			t=(t<<1);
		}
	}
	ll ans=0,t=1;
	for(ll i=1;i<=62;i++){
		ans=ans+t*(a[i][0]*a[i][1]%1000000007);
		ans%=1000000007;
		t=(t<<1);
		t%=1000000007;
	}
	cout<<ans;
	return 0;
}


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

int main(void){
    string t;
    cin >> t;
    
    int a = 0,b = 0;
    for(int i = 0;i < t.size();i++){
        if(t[i] == '0')a++;
        else b++;
    }
    
    cout << min(a,b)*2 << endl;
}

Measured memory_bytes: 512
import scala.io.StdIn.readLine

object Main {
  def getTime(s:String) = {
    val t = s.split(" ").map(_.toInt)
    t(3)*3600 + t(4)*60 + t(5)- (t(0)*3600 + t(1)*60 + t(2))
  }

  def main(args:Array[String]) = {
    (1 to 3).foreach { _ =>
      val t = getTime(readLine)
      println((t/3600) + " " + ((t/60)%60) + " " + (t%60))
    }
  }
}

Measured memory_bytes: 43708
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int n,m;
    int a[101];
    cin >> n >> m;
    REP(i,m){
	cin >> a[i];
    }
    int ans[101] = {0};
    REP(i,m){
	int add = n;
	REP(j,n) {
	    int temp;
	    cin >> temp;
	    if(temp == a[i]) {
		ans[j]++;
		add--;
	    }
	}
	ans[a[i]-1] += add;
    }
    REP(i,n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>


using namespace std;


int main(void){
  
  int N,ans;
  
  cin >> N;

  if(N%2 ==0){
    ans = N/2;
  }else{
    ans = N/2 + 1;
  }
  
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	int n,m;
	cin>>n>>m;
	vector<int>num;
	rep(i,n){
		num.push_back(2);
	}
	rep(i,m){
		num.push_back(1);
	}
	int cnt=0;
	rep(i,n+m){
		FOR(j,i+1,n+m){
			if((num[i]+num[j])%2==0){
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 256
if __name__ == '__main__':
    n,k = list(map(int, input().split()))
    n2 = n
    count = 1
    kakuritu = 0

    while(n2 != 0):

        ktop = int(n2 - k + 1)
        if(ktop > 0):
            kakuritu += ktop / n * 1 / count
            n2 -= ktop

        k /= 2
        count *= 2
        
    print(kakuritu)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
/////////////////////////



//Answer


int main() {
long count=0;
long N;
cin>>N;
vector<long> a(N);
for(long i=0;i<N;i++){
    cin>>a.at(i);
    if(i%2==0&&a.at(i)%2==1){
        count++;
}
}
cout<<count<<endl;


}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
signed main(){
	int n,t[50],ans;
  	string s,x;
  	vector<string> str;
  	cin>>n;
  	for(int i=1;i<=n;i++){
	  	cin>>s>>t[i];
      	str.push_back(s);
      	t[i]+=t[i-1];
    }
  	cin>>x;
  	for(int i=0;i<n;i++){
      if(str[i] == x)
        cout<<t[n]-t[i+1]<<endl;
    }
  return(0);
    }

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

using namespace std;

bool val[10];

int toInt(string s) {
	int res = 0;
	for (int i = 0; i < s.size(); i++) {
		res = (res * 10) + (s[i] - '0');
	}
	return res;
}

int main() {
	string n;
	int k;
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int a;
		cin >> a;
		val[a] = true;
	}
	int men = 0;
	for (int i = 1; i < 10; i++) {
		if (!val[i]){
			men = i;
			break;
		}
	}
	int indi = n.size() - 1;
	string aux = n;
	string res = n;
	while (indi >= 0) {
		int l = n[indi] - '0';
		if (val[l]) {
			bool cam = false;
			for(int i = l + 1; i < 10; i++) {
				if (!val[i]){
					l = i;
					cam = true;
					break;
				}
			}
			if(!cam) {
				for(int i = 0; i <= l; i++) {
					if (!val[i]){
						l = i;
						cam = true;
						break;
					}
				}
			}else {
				if (!val[0]) {
					for (int i = indi + 1; i < n.size(); i++) {
						res[i] = '0';
					}
				}else {	
					for (int i = indi + 1; i < n.size(); i++) {
						res[i] = (char)(men + '0');
					}
				}
			}
		}
		res[indi] = (char)(l + '0');
		indi--;
	}
	int a = toInt(res);
	int b = toInt(aux);
	if (a < b) {
		res = (char)(men + '0') + res;
		if (!val[0]) {
			for (int i = 1; i < res.size(); i++) {
				res[i] = '0';
			}
		}else {	
			for (int i = 1; i < res.size(); i++) {
				res[i] = (char)(men + '0');
			}
		}
	} 
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int V[150][150],d[150],f[150],color[150];
int time, n;

void DFSVisit(int u){
  int v;

  color[u] = 1;
  time++;
  d[u] = time;

  for(v = 1; v <= n; v++){
    if(V[u][v] == 1 && color[v] == 0){
      DFSVisit(v);
    }
  }
  color[u] = 2;
  time++;
  f[u] = time;
}

void DFS(){
  int u;

  time = 0;
  for(u = 1; u <= n; u++){
    if(color[u] == 0){
      DFSVisit(u);
    }
  }
}

int main(){
  int i,j,v,m,k;

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    scanf("%d%d",&v,&m);
    for(j = 1; j <= m; j++){
      scanf("%d",&k);
      V[v][k] = 1;
    }
  }

  DFS();

  for(i = 1; i <= n; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }

  return 0;
}

Measured memory_bytes: 660
#include <bits/stdc++.h>
using namespace std;
#define endl       "\n"
#define ll         long long
#define pb         push_back
#define FIO        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define NUM        1000000007
#define MOD        998244353
#define F          first
#define S          second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a-1;i>=b;i--)
#define vi         vector<ll>
#define pii        pair<ll,ll>
#define vpi        vector<pii>
#define mi         map<ll,ll>
#define mpi        map<pii,ll>
#define all(v)     (v).begin(),(v).end()
#define rall(v)    (v).rbegin(),(v).rend()
#define fac(a)     tgamma(a+1)

bool compare(const pair<ll,ll> &a,const pair<ll,ll> &b)
{ 
    return (a.second < b.second);      // compare function for sorting modification
}

vector<ll> primes;
vector<bool> PRIME(1000005,true);       // prime no.s less than 10^6
void sieve(ll n)                        // PRIME[i]=true => i=prime no.
{  PRIME[0]=false;PRIME[1]=false;
    for (ll p=2; p*p<=n; p++) { 
        if (PRIME[p] == true) { 
            for (ll i=p*p; i<=n; i += p){PRIME[i]=false;} 
        } 
    } rep(i,2,n+1){if(PRIME[i]){primes.pb(i);}}
}  

ll nCr[1001][1001];
void combination(ll n)                  // nCr values
{
    rep(i,0,n+1){
        rep(j,0,i+1){
            if(j==0 or j==i)nCr[i][j]=1;
            else nCr[i][j]=(nCr[i-1][j-1]+nCr[i-1][j])%NUM;
        }
    }
}

#define N  1000005

ll a,b,c,d,e,i,j,k,l,m,n,q,p,r,u,v,w,x,y,z,mn,mx;
ll arr[N];
//ll dp[2005][2005];

int main() 
{
    FIO;
    ll t=1;
    //cin >> t;
    while(t--)
    {
        mn=LONG_LONG_MAX;
        mx=LONG_LONG_MIN;
        cin>>n;
        ll dp[n][3];
        cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
        rep(i,1,n)
        {
            cin>>dp[i][0]>>dp[i][1]>>dp[i][2];
            dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]+=max(dp[i-1][1],dp[i-1][0]);
        }
        
        cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
        
        
        
        
        
        
        
        
        
        
        
        h:;
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 6032
n = gets.to_i
edges = []
(n - 1).times { edges << gets.split.map(&:to_i) }
graph = Array.new(n + 1) { Array.new }
edges.each do |from, to|
  graph[from] << to
  graph[to] << from
end
nums = gets.split.map(&:to_i).sort
sum = nums.inject(:+) - nums.last
ans = Array.new(n + 1)
queue = [1]
until queue.empty?
  current = queue.shift
  unless ans[current]
    ans[current] = nums.pop
    graph[current].each do |to|
      queue << to
    end
  end
end
ans.shift
puts sum
puts ans.join(" ")


Measured memory_bytes: 6136
#include <iostream>
#include<string>
using namespace std;
#define ll long long int


int main ()
{
     long long int  n,t,i,k,sum=0,flag=0,z,cnt=0,m,b,a1,a2,k1,k2,neg=0,pos=0,j;
     string s;
     cin>>s;
     if(s=="Sunny")
     {
         cout<<"Cloudy";
     }
     else if(s=="Cloudy")
     {
         cout<<"Rainy";
     }
     else
     {
         cout<<"Sunny";
     }





return 0;
}


Measured memory_bytes: 760
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 300100;

int n;
long long a[N], s[N], sum = 0;

int main() {

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		sum += a[i];
	}

	s[0] = 0;

	for (int i = 0; i < n; i++) {
		s[i + 1] = s[i] + a[i];
	}

	long long res = (long long) 2e18;

	for (int i = 0; i <= n; i++) {
		long long x = s[i];
		long long y = sum - x;
		res = min(res, llabs(x - y));
	}

	printf("%lld\n", res);

	return 0;

}

Measured memory_bytes: 6916
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int num,line[105],line1[105],i;
 
double d(int p)
{
    int i;
    double D;
    for(D=0.0,i=0;i<num;i++)
    {
        if(p==4)D=D>abs(line[i]-line1[i])?D:abs(line[i]-line1[i]);
        else D+=pow(abs(line[i]-line1[i]),p);
    }
    return p==4?D:pow((double)D,1.0/p);
}
 
int main(void)
{
    scanf("%d",&num);
    for(i=0;i<num;i++)
        scanf("%d",&line[i]);
    for(i=0;i<num;i++)
        scanf("%d",&line1[i]);
    for(i=1;i<5;i++)
        printf("%lf\n",d(i));
    return 0;
}

Measured memory_bytes: 696
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > M[MAX];

void dijkstra(void);

int main()
{
  int i, j;
  int u, k, v, c;

  cin >> n;

  for( i = 0 ; i < n ; i++ ){
    cin >> u >> k;
    for( j = 0 ; j < k ; j++ ){
      cin >> v >> c;
      M[u].push_back(make_pair(v, c));
    }
  }

  dijkstra();

  return 0;
}

void dijkstra()
{
  priority_queue<pair<int, int> > p;
  pair<int, int> tmp;
  int i, j, u, v;
  int color[MAX], d[MAX];
  
  for( i = 0 ; i < n ; i++ ){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  p.push(make_pair(0, 0));
  color[0] = GRAY;

  while( !p.empty() ){
    tmp = p.top();
    p.pop();
    u = tmp.second;
    color[u] = BLACK;

    if( d[u] < tmp.first * (-1) ) continue;

    for( j = 0 ; j < M[u].size() ; j++ ){
      v = M[u][j].first;
      if( color[v] == BLACK ) continue;
      if( d[v] > d[u] + M[u][j].second ){
	d[v] = d[u] + M[u][j].second;
	p.push(make_pair(d[v] * (-1), v));
	color[v] = GRAY;
      }
    }
  }

  for( i = 0 ; i < n ; i++ ) cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;

}

Measured memory_bytes: 6304
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, N, B):
    C = [[False] * 3 for _ in range(3)]
    D = {}
    for i, r in enumerate(A):
        for j, c in enumerate(r):
            D[c] = (i, j)

    for b in B:
        if b in D:
            i, j = D[b]
            C[i][j] = True

    for i in range(3):
        t = True
        for j in range(3):
            t = t and C[i][j]
        if t:
            return 'Yes'

    for i in range(3):
        t = True
        for j in range(3):
            t = t and C[j][i]
        if t:
            return 'Yes'

    t = True
    for i in range(3):
        t = t and C[i][i]
    if t:
            return 'Yes'

    t = True
    for i in range(3):
        t = t and C[2-i][i]
    if t:
            return 'Yes'
    return 'No'


def main():
    A = [read_int_n() for _ in range(3)]
    N = read_int()
    B = [read_int() for _ in range(N)]

    print(slv(A, N, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6728
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	int n;
	cin>>n;
	vector<int> cnt(5);
	rep(i,n){
		int x;
		cin>>x; x=__gcd(x,4);
		++cnt[x];
	}
	if(cnt[2]){
		cout<<(cnt[1]>cnt[4]?"No":"Yes")<<endl;
	}else{
		cout<<(cnt[1]>cnt[4]+1?"No":"Yes")<<endl;
	}
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int d, g;
  cin >> d >> g;
  vi p(d), c(d);
  rep(i,d) cin >> p[i] >> c[i];

  int ans = INF;
  rep(b,1<<d) {
    int score = 0;
    int num = 0;
    rep(i,d) {
      if (b&(1<<i)) {
        score += 100*(i+1)*p[i] + c[i];
        num += p[i];
        if (score >= g) {
          ans = min(ans, num);
          break;
        }
      }
    }
    for (int i = d-1; i >= 0; --i) {
      if (!(b&(1<<i))) {
        rep(_,p[i]-1) {
          score += 100*(i+1);
          num++;
          if (score >= g) {
            ans = min(ans, num);
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
inputs = []
while True:
    try:
        inputs.append(int(input()))
    except(EOFError):
        break

inputs.pop(0)

minv = inputs[0]
maxv = inputs[1] - inputs[0]

for i in range(1, len(inputs)):
    maxv = max([maxv, inputs[i] - minv])
    minv = min([minv, inputs[i]])

print(maxv)





Measured memory_bytes: 13612
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

struct Vertex
{
	std::vector<int> connectEdge;
};

struct Edge
{
	int from;
	int to;
	long long w;
};

Vertex v[2510];
int n;
Edge edge[5010];
int m;

int p;
long long dis[2510];	//到点i的最短路径 

long long ans;

const long long INF = 0x3f3f3f3f3f3f3f3f;

bool bellman_ford()
{
//    memset(dis,INF,sizeof(dis));
    for (int i = 1 ; i <= n ; i++)
    	dis[i] = 1000000000000000000L;
    dis[1] = 0;
//    int sum = m + k;
    bool flag;
    for(int i = 1 ; i <= n - 1 ; i++)
    {
        flag = true;
        for(int j = 1 ; j <= m ; j++)
        {
            int u = edge[j].from;
			int v = edge[j].to;
			long long val = edge[j].w;
            if(dis[v] > dis[u] + val)
            {
                dis[v] = dis[u] + val;
                flag = false;
            }
        }
        if(flag) break;
    }
	for(int i = 1 ; i <= n - 1 ; i++)
	{
	    for(int j = 1 ; j <= m ; j++)
	    {
			int u = edge[j].from;
			int v = edge[j].to;
			long long val = edge[j].w;
			if ((dis[v] > dis[u] + val))
			{
				if (v == n)
					return true;
				dis[v] = dis[u] + val;
			}
	    }
	}
   
    ans = dis[n];

    return false;
}

//bellman_ford算法，对权重进行调整后所得 
int main()
{
	scanf("%d%d%d", &n, &m, &p);

	int a, b, weight;
	for (int i = 1 ; i <= m ; i++)
	{
		scanf("%d%d%d", &a, &b, &weight);
		v[a].connectEdge.push_back(i);
		edge[i].from = a;
		edge[i].to = b;
		edge[i].w = -weight + p;
	}
	
	bool isCycle = bellman_ford();
	
	if (isCycle)
		printf("-1\n");
	else
	{
		ans = -ans;
		if (ans < 0)
			ans = 0;
		printf("%lld\n", ans);		
	}

	
		
	return 0;
}


Measured memory_bytes: 512
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
answer = 0
for i in range(N):
    # print(A1[:i+1])
    # print(A2[i:])
    if answer <= sum(A1[:i+1] + A2[i:]):
        answer = sum(A1[:i+1] + A2[i:])

print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59



int main(){
  ll i,j;
  ll w,h,x,y;
  cin>>w>>h>>x>>y;
  cout<<double(w*h)/2<<" ";
  if(x*2==w&&y*2==h) cout<<1<<endl;
  else cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<int,int> pint;
const int inf   = 1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


ll sum(ll m,ll k){
  ll mod=(k+1)%m;
  ll num=(k+1)/m;
  ll ret=num*(num-1)*m/2;
  ret+=mod*num;
  return ret;
  }

int main(){
  ll n,k;
  cin>>n>>k;
  if(k==0){cout<<n*n<<endl; return 0;}
  ll ans=0;
  for(ll i=k+1;i<=n;i++){
    ans+=sum(i,n+i-k)-sum(i,n);
    }
  cout<<ans<<endl;    
  return 0;
  }

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

int main()
{
    int ans = 0;
    char ch;
    for(int i = 1;i <= 4;i++)
    {
        scanf("%c",&ch);
        if(ch == '+') ans++;
        if(ch == '-') ans--;
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int h = sc.nextInt();
		int w = sc.nextInt();

		char[][] s = new char[h][];
		for (int i = 0; i < h; i++) {
			s[i] = sc.next().toCharArray();
		}

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

		for (int i = 0; i < h; i++) {
			out:
			for (int j = 0; j < w; j++) {
				if (s[i][j] == '#') {
					for (int k = 0; k < 4; k++) {
						int nx = j + dx[k];
						int ny = i + dy[k];

						if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
							continue;
						}

						if (s[ny][nx] == '#') {
							continue out;
						}
					}

					pr.println("No");
					return;
				}
			}
		}

		pr.println("Yes");
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

int main(){
    int n; cin >> n;
    int c[n+1],s[n+1],f[n+1];
    for(int i = 0; i < n-1; i++){
        cin >> c[i] >> s[i] >> f[i];
    }

    c[n-1] = s[n-1] = 0;
    f[n-1] = 1;

    for(int i = 0; i < n; i++){
        int now = s[i] + c[i];
        for(int j = i+1; j < n; j++){
            if(now < s[j]) now += (s[j]-now);
            else if((now-s[j]) % f[j] != 0) now += f[j] - (now%f[j]);

            now += c[j];
        }
        cout << now << endl;

    }

    return 0;
}

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

function main()
	s = chomp(readline())
	flg = 0
	for i in 0:7
		t = s[1:i]*s[length(s)-6+i:length(s)]
		if t=="keyence"
			flg = 1
			break
		end
	end
	if flg == 1
		println("YES")
	else
		println("NO")
	end
end

main()


Measured memory_bytes: 130976
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl;
#define wa() cout<<"No"<<endl;
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//
const int maxm=3e3+5;
const int mod=998244353;


signed main(){
    int n=re,a=re,b=re;
    int ans=0;
    ans+=n/(a+b)*a;
    n-=n/(a+b)*(a+b);
    if(n>=a)ans+=a;
    else ans+=n;
    pr(ans);
    return 0;
}



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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;

int n, m, x;
int c[13], a[13][13];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> x;
    int minCost = INF;
    for(int i=0; i<n; i++)
    {
        cin >> c[i];
        for(int j=0; j<m; j++)
        {
            cin >> a[i][j];
        }
    }
    for(int i=0; i<(1<<n); i++)
    {
        int cost = 0;
        int u[m];
        memset(u, 0, sizeof(u));
        for(int j=0; j<n; j++)
        {
            if(1<<j & i)
            {
                cost += c[j];
                for(int k=0; k<m; k++)
                {
                    u[k] += a[j][k];
                }
            }
        }
        bool is = true;
        for(int i=0; i<m; i++)
        {
            if(u[i] < x)
                is = false;
        }
        if(is)
        {
            minCost = min(minCost, cost);
        }
    }
    if(minCost == INF)
    {
        cout << -1;
    }
    else
    {
        cout << minCost;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll unsigned long long

const ll MOD = 1000000000000000000;

int main() {
	//入力
	int k;
	string s;
	cin >> k >> s;

	//処理
	string ans = s;
	if (s.size() > k) {
		ans = s.substr(0, k) + "...";
	}

	//出力
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


new_A = [0]
pre = 0
for a in A:
    if a > K:
        break
    pre += a
    if pre > K:
        break
    new_A.append(pre)

new_B = [0]
pre = 0
for b in B:
    if b > K:
        break
    pre += b
    if pre > K:
        break
    new_B.append(pre)

ans = 0
j = len(new_B) - 1

for i, a in enumerate(new_A):
    while new_B[j] > K - a:
        j -= 1
    ans = max(ans, i+j)

print(ans)


Measured memory_bytes: 122988
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(ll &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666;
ll n,x,v[N],qz[N];ll res=6e18;
int main() {
	read(n);read(x);rep(i,1,n)read(v[i]),qz[i]=qz[i-1]+v[i];
	per(a,n,1){
		ll tmp=(n+a)*x+2*(qz[n]-qz[n-a]);ll xs=1;
		for(int p=n;p>=1;p-=a){
			xs+=2;if(tmp+1.0*xs*(qz[p]-(p-a>=0?qz[p-a]:0))>res+100){tmp=res+233;break;}
			tmp+=xs*(qz[p]-(p-a>=0?qz[p-a]:0));
		}
		res=min(res,tmp);
	}
	cout<<res;return 0;
}

Measured memory_bytes: 5888
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *NOIP 2019 RP++                                      *
 ***********************************************************/
#pragma GCC optimize(3)
#define ADD_STACK int size = 512 << 20;\
    char *p = (char*)malloc(size) + size;  \
    __asm__("movl %0, %%esp\n" :: "r"(p))
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) ((x>y)?x:y)
#define Min(x,y) ((x<y)?x:y)
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (int)(1<<30)
#define mod (int)(19260817)
#define FOR(a,b,c) for (register int a=b;a<=c;a++)
#define FORD(a,b,c) for (register int a=b;a>=c;a--)
using namespace std;
//char buf[1<<20],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline int read(){
    int x=0,f=1;char c;
    for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());return x*f;
}
template<typename T>
inline void write(T a){
    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}
inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//
int n,m,a[12][12],p[12],k[12],b[12],ans,kk,x;
inline void dfs(int d){
	if(d>n){
		FOR(i,1,m)if(b[i]!=p[i])return;
		++ans;return;
	}
	dfs(d+1);
	FOR(i,1,k[d])b[a[d][i]]^=1;
	dfs(d+1);
	FOR(i,1,k[d])b[a[d][i]]^=1;
}
signed main(){
    n=read(),m=read();
    FOR(i,1,m){
    	kk=read();
    	FOR(j,1,kk)x=read(),a[x][++k[x]]=i;
    }
    FOR(i,1,m)p[i]=read();
    dfs(1);
    writeln(ans);
    return 0;
}


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

int main(){
  int N,M,i;
  cin >> N >> M;
  vector<vector<int>> c(N+1);
  vector<int> p(N+1,-1);
  vector<int> d(N+1,-1);
  int a,b;
  for(int i=0;i<M;i++){
    cin >> a >> b;
    c[a].push_back(b);
    c[b].push_back(a);
  }
  p[1] = 1;
  queue<int> que;
  que.push(1);
  //cout << "q:" << que.front() << endl;
  
  while(!que.empty()){
    i = que.front();
    que.pop();
    for(auto n:c[i])
      if (p[n] == -1){
        que.push(n);
        //cout << "n:" << n << endl;
        p[n] = p[i]+1;
        d[n] = i;
      }
  }
  for(i=2;i<=N;i++)
    if(d[i] == -1){
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
  for(i=2;i<=N;i++)
    cout << d[i] << endl;

  return 0;
}

Measured memory_bytes: 10720
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;
const int INF = -2e9;

int n, m, p;
int dist[N], cnt[N];
bool inqueue[N];
vector<pair<int, int> > g[N];
vector<int> rg[N];
bool vis[N];

void dfs(int u)
{
	if(vis[u])
		return;
	vis[u] = 1;
	for(auto &it:rg[u])
		dfs(it);
}
// For refernce : https://cp-algorithms.com/graph/bellman_ford.html
bool negativeCycle() //Returns true if there is a negative cycle
{
	queue<int> q;

	for(int i = 1; i <= 1; i++)
	{
		dist[i] = cnt[i] = 0;
		q.push(i), inqueue[i]=true;
	}

	for(int i = 2; i <= n; i++)
		dist[i] = -INF;

	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		inqueue[v]=false;

		for(auto &edge:g[v])
		{
			int to=edge.first;
			int w=edge.second;

			if(dist[v] + w < dist[to])
			{
				dist[to] = dist[v] + w;
				dist[to] = max(dist[to], INF);
				if(!inqueue[to])
				{
					q.push(to);
					inqueue[to]=true;
					cnt[to]++;
					if(cnt[to]>n)
						return true;
				}
			}
		}
	}
	return false;
}

int32_t main()
{
	IOS;
	cin >> n >> m >> p;
	for(int i = 1; i <= m; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		g[u].push_back({v, p - w});
		rg[v].push_back(u);
	}
	dfs(n);
	for(int i = 1; i <= n; i++)
	{
		vector<pair<int, int> > v;
		for(auto &it:g[i])
			if(vis[it.first])
				v.push_back(it);
		g[i].clear();
		g[i] = v;
	}
	int check = negativeCycle();
	if(check)
	{
		cout << "-1";
		return 0;
	}
	cout << max(0LL, -dist[n]);
	return 0;
}


Measured memory_bytes: 6656
n = int(input())
a = [int(_) for _ in input().split()]
a.sort()

for i in range(0, n-n%2-1, 2):
    if a[i] + a[i+1] < 0:
        a[i] = -a[i]
        a[i+1] = -a[i+1]
    else:
        break
print(sum(a))


Measured memory_bytes: 14412
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        if ((a > 0 && b < 0) || (a < 0 && b > 0)) {
            System.out.println("Zero");
        } else if (b < 0) {
            long ans = (b - a) + 1;
            if (ans % 2 == 0) {
                System.out.println("Positive");
            } else {
                System.out.println("Negative");
            }
        } else {
            System.out.println("Positive");
        }
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long


int32_t main()
{
	
	IOS
	int a,b,c;cin>>a>>b>>c;
	cout<<(c/a)*b<<endl;
	
	
			
	
		
			
	
		
	
	
}			
	
	
	
	
	

	

	

	
		


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

int main() {
    int H, W;
    cin >> H >> W;
    string s[H];
    for(int i = 0; i < H; i++){
        cin >> s[i];
    }
    int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
    int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i].at(j) == '#'){
                continue;
            }
            int num = 0;
            for(int k = 0; k < 8; k++){
                int ni = i + dy[k];
                int nj = j + dx[k];
                if(ni < 0 || H <= ni){
                    continue;
                }
                if(nj < 0 || W <= nj){
                    continue;
                }
                if(s[ni].at(nj) == '#'){
                    num++;
                }
            }
            s[i].at(j) = char(num + '0');
        }
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 3648
# coding: utf-8


def solve(*args: str) -> str:
    N = list(map(int, args[0]))

    a, b = 0, 1
    for n in N:
        a, b = min(b+(10-n), a+n), min(b+(9-n), a+n+1)
    return str(a)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 13516
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1000000007;

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

    int cnt = 0;
    for (int i = 0; i < S.length() / 2; i++) {
        if (S[i] != S[S.length() - i - 1]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n,k;
  cin>>n>>k;
  int h[n];
  rep(i,n) cin>>h[i];
  int mi = MOD;
  sort(h, h + n);
  
  for(int i = k-1; i < n; i++)
  {
    mi = min(mi, h[i] - h[i - (k-1)]);
  }
  cout << mi << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

///////////////////////////////////////////////////////////////////////////

int main(){
	int h,w;
	
	cin >> h >> w;

	rep(i,0,w+2)cout << "#";
	cout << endl;

	rep(i,0,h){
		cout << "#";
		string s;
		cin >> s;
		cout << s << "#" <<endl;
	}
	
	rep(i,0,w+2)cout << "#";
	cout << endl;

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

ll calc(ll n, ll div, ll a, ll d) {
  ll dec = n / div * (div - 1);
  if (dec > mod) {
    return a;
  }
  return min(dec * d, a);
}

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

  ll t;
  cin >> t;

  rep(i, t) {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    ll ans = -1;

    priority_queue<P, std::vector<P>, greater<P>> que;
    que.emplace(0, n);

    map<ll, ll> mn;

    while (!que.empty()) {
      auto p = que.top();
      que.pop();

      ll co = p.first;
      ll v = p.second;
      if (v == 1) {
        ans = co + d;
        break;
      }

      if (mn.find(v) != mn.end()) {
        continue;
      }
      mn[v] = co;

      if (v % 5 == 0) {
        que.emplace(co + calc(v, 5, c, d), v / 5);
      } else {
        ll tmp = v % 5;
        if (tmp >= 3) {
          que.emplace(co + (5 - tmp) * d + calc(v + tmp, 5, c, d), (v + tmp) / 5);
        } else {
          que.emplace(co + tmp * d + calc(v + tmp, 5, c, d), (v + tmp) / 5);
        }
      }

      if (v % 3 == 0) {
        que.emplace(co + calc(v, 3, b, d), v / 3);
      } else {
        ll tmp = v % 3;
        if (tmp >= 2) {
          que.emplace(co + (3 - tmp) * d + calc(v + tmp, 3, b, d), (v + tmp) / 3);
        } else {
          que.emplace(co + tmp * d + calc(v + tmp, 3, b, d), (v + tmp) / 3);
        }
      }

      if (v % 2 == 0) {
        que.emplace(co + calc(v, 2, a, d), v / 2);
      } else {
        ll tmp = v % 2;
        que.emplace(co + (2 - tmp) * d + calc(v + tmp, 2, a, d), (v + tmp) / 2);
        que.emplace(co + tmp * d + calc(v + tmp, 2, a, d), (v + tmp) / 2);
      }

      // que.emplace(co + d, v + 1);
      // que.emplace(co + d, v - 1);
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e4 + 10;
int a[maxn], b[maxn];
int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    while(cin >> n) {
        srand(time(0));
        for(int i = 0; i < n; ++i)
            cin >> a[i];
        ll aa = 0, bb = 0;
        for(int i = 0; i < n; ++i) {
            cin >> b[i];
            int ans = b[i] - a[i];
            if(ans > 0) aa += ((ans + 1) >> 1), bb += (ans & 1);
            else if(ans < 0) bb += -ans;
        }
        cout << (aa >= bb ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;
const LL mod = 1e9+7;
const int Max_Num = 1e5;

LL F[Max_Num];
LL Finv[Max_Num];

LL modpow(LL x, LL n){
	LL r=1;
	while(n){
		if(n&1) r=r*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return r;
}

LL modinv(LL x){
	LL m=mod, u=1, v=0;
	while(m){
		LL t=x/m;
		x-=t*m; swap(x,m);
		u-=t*v; swap(u,v);
	}
	u%=mod;
	if(u<0) u+=mod;
	return u;
}

void fact(){
	F[0]=1;
	rep(i,Max_Num-1){
		F[i+1]=F[i]*(i+1);
		F[i+1]%=mod;
	}
	rep(i,Max_Num) Finv[i]=modinv(F[i]);
}

int main(){
	fact();
	LL S;
	cin >> S;
	LL M=S/3;
	LL ans=0;
	for(int i=1; i<=M; i++){
		LL res=S-3*i;
		LL num=F[res+i-1]*Finv[res]%mod*Finv[i-1]%mod;
		ans+=num;
		ans%=mod;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector <int> pos(N);

    long double tmp = 0;
    rep(i,N){
        cin >> pos.at(i);
        tmp += pos.at(i);
    }
    tmp = round(tmp/N);


    long int result =0;
    rep(i,N){
        result += (pos.at(i) - tmp) * (pos.at(i) - tmp);
    }

    cout << result << endl;
}

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

int main(){
	int a;
	int b;
	int n;
	int x;
	int y;
	int k;
	while(true) {
		cin >> a >> b;
		if ( a == 0 ) break;
		cin >> n;
		int joi[17][17] = {0};
		for ( int i = 0; i < n; i++ ) {
			cin >> x >> y;
			joi[x][y] = -1;
		}
		for ( int i = 1; i <= a; i++ ) {
			for ( int j = 1; j <= b; j++ ) {
				if ( i == 1 && j == 1 ) {
					joi[i][j] = 1;
				}else {
					if ( joi[i][j] == -1 ) {
						joi[i][j] = 0;
					}else {
						joi[i][j] = joi[i-1][j] + joi[i][j-1];
					}
				}
			}
		}
		cout << joi[a][b] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
h = [int(i) for i in input().split()]
c,h = 0,h+[0]
while sum(h):
	f = 0
	for i in range(n+1):
		if f and h[i]==0:
			m,f = min(h[l:i]),0
			for j in range(l,i): h[j]-=m
			c+=m
		elif 1-f and h[i]: f,l = 1,i
print(c)

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

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M);
    for (int i=0; i<M; i++){
        cin >> A[i];
    }
    int ans;
    sort(begin(A), end(A));
    for (int i=0; i<M; i++){
        if (A[i] < X) continue;
        ans = min(i, M-i);
        break;
    }
    cout << ans << endl;
}

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

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

    int n;
    cin >> n;

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

    for(int i = 1; i < n; i++){
        A[i] += A[i - 1];
    }

    long long ans = 1e18;
    for(int i = 0; i < n - 1; i++){
        ans = min(ans, abs(A[n - 1] - 2 * A[i]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792