akhauriyash/Code-Regression huggingface dataset:
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn to_vec(s: String, offset: u64) -> Vec<u64> {
    s.split_whitespace()
        .map(|s| s.parse::<u64>().unwrap() - offset)
        .collect()
}

fn evaluate(ws: &Vec<u64>, i: usize) -> u64 {
    let a: u64 = ws[..i].iter().sum();
    let b: u64 = ws[i..].iter().sum();
    if a < b { b - a } else { a - b }
}

fn main() {
    let n: usize = read_line().parse().unwrap();
    let ws = to_vec(read_line(), 0);

    let min = (0..n).map(|i| evaluate(&ws, i)).min().unwrap();

    println!("{}", min);
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

    vector<int> a;
    vector<int> b;
    int t1,t2;

    for (int i = 0; i < n; i++) {
        cin >> t1 >> t2;
        a.push_back(t1);
        b.push_back(t2);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if (n % 2) {//奇数
        cout << b[n / 2] - a[n / 2] + 1;
    } else {
        cout << (b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1]) + 1;
    }




    return 0;
}


Measured memory_bytes: 5100
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        scan.close();
        System.out.println(a * b * (a + b) % 3 == 0 ? "Possible" : "Impossible");
    }
}


Measured memory_bytes: 22736
#include <stdio.h>

int main() {
	int child, candy = 0;
	scanf("%d", &child);
	
	for(int i = 0; i < child; i++) {
		for(int j = 0; j < i; j++) {
			candy += 1;			
		}
		candy++;
	}
	printf("%d", candy);
	
	return 0;
}

Measured memory_bytes: 1728
function main(input){
    let numArray = [];
    numArray = input.split(' ').map(Number);
    W = numArray[0];
    H = numArray[1];
    x = numArray[2];
    y = numArray[3];
    r = numArray[4];
    function is_circle_inside(bottom,left,right,top,center_x,center_y,radius){
        if(left <= center_x - radius && bottom <= center_y - radius && right >= center_x + radius && top >= center_y + radius ){
            return "Yes";
        } else {
            return "No";
        }
    }
    let ans = is_circle_inside(0,0,W,H,x,y,r);
    console.log(ans);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15116
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        int N;
        N = int.Parse(Console.ReadLine());
        var W = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int sum_right = W.Sum();
        int sum_left = 0;
        int output_difference = sum_right;
        for (int i = 0; i < W.Length; i++)
        {
            sum_left += W[i];
            sum_right -= W[i];
            int temp_diff = Math.Abs(sum_right - sum_left);
            if (output_difference > temp_diff) output_difference = temp_diff;
        }
        Console.WriteLine(output_difference);


    }
    
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define S second
#define F first
const int  MOD = 1e9 + 7;
const int  N = 1e5 + 7;
int dp[N];

//  a d f j k  l  ;
int main(){
    ios::sync_with_stdio(0);  cin.tie(0);
    int n , k;
    cin>>n>>k;
    vector<int> v(n);
    scanVec(v , n);
    for(int i = 0 ; i < n ; i++){
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    for(int i = 0 ; i < n ; i++){
        for(int j = 1; i - j >= 0 && j <= k ; j++){
            dp[i] = min(dp[i] , dp[i-j] + abs(v[i] - v[i-j]));
        }
    }
    cout<<dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 1024
from bisect import bisect_left
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

ba_cnt = [bisect_left(a, e) for e in b]
ba_acm = [0] + list(accumulate(ba_cnt))

ans = 0
for e in c:
    i = bisect_left(b, e)
    ans += ba_acm[i]

print(ans)


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

int main() {
  int n; cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  const ll M = 1e9+7;
  ll all = 1, a = 1, b = 1;
  rep(i,n) {
    a = a * 9 % M;
    b = b * 8 % M;
    all = all * 10 % M;
  }
  ll ans = (all - (a * 2 - b)) % M;
  if (ans < 0) ans += M;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define bgn begin()
#define sz size()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second

int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}

signed main(){
  string s;
  cin >> s;
  if(s.size() == 1){
    cout << s << endl;
    return 0;
  }
  int a = s[0] - '0';
  string k = "";
  fo(i,s.size()-1){
    k.pb('9');
  }
  if(s.substr(1) != k){
    cout << (s.size()-1)*9 + a - 1 << endl;
  }
  else
    cout << (s.size() -1) * 9 + a << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_H 110
#define MAX_W 10

ll dp[MAX_H][MAX_W] = {};
ll H, W, K;
vector<ll> all_pat;

// 現在 i 行 j 列にいるときのパターン数
ll dfs(ll i = 0, ll j = 0) {
    if(i >= H) {
        if(j == K) { return 1; }
        return 0;
    }

    ll& ret = dp[i][j];
    if(~ret) { return ret; }
    ret = 0;

    for(auto& pat : all_pat) {
        if(j > 0 && ((pat >> (j-1)) & 1) ) {
            // 左に移動するパターン
            ret += dfs(i+1, j-1);
            ret %= MOD;
        } else if(j < W-1 && ((pat >> (j)) & 1) ) {
            // 右に移動するパターン
            ret += dfs(i+1, j+1);
            ret %= MOD;
        } else {
            ret += dfs(i+1, j);
            ret %= MOD;
        }
    }

    return ret;
}

signed main()
{
    cin >> H >> W >> K;
    MINUS(dp);
    K--;

    // all_pat の作成
    for(int pat = 0; pat < (1 << (W-1)); ++pat) {
        // 隣り合うビットが 1 のものはダメ
        bool isOk = true;
        for(int i = 0; i < W-2; ++i) {
            if( ((pat >> i) & 1) && ((pat >> (i+1)) & 1) ) {
                isOk = false;
                break;
            }
        }
        if(isOk) { all_pat.push_back(pat); }
    }

    printf("%lld\n", dfs());
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,sum=0;
    cin>>n>>k;
    int p[n];
    for(i=0;i<n;i++){

    cin>>p[i];

}
sort(p,p+n);
for(i=0;i<k;i++){
sum+=p[i];
}
cout<<sum<<endl;
return 0;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,T,m=100000;
	cin>>N>>T;
	for(int i=0;i<N;i++)
	{
		int c,t;
		cin>>c>>t;
		if(T>=t)	m=min(m,c);
	} 
	if(m==100000)	cout<<"TLE"<<endl;
	else	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())
X = [int(x) for x in input().split()]

ret = sys.maxsize

for i in range(min(X) , max(X) + 1):
    pow = 0
    for x in X:
        pow += (x - i) ** 2
    if pow < ret:
        ret = pow

print(ret)

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

int main() {
    ll n;
    cin >> n;

    ll a=1, b=1, c=1;
    while(n > 0) {
        a *=10;
        b*= 9;
        c*= 8;
        a %= LARGE;
        b %= LARGE;
        c %= LARGE;
        n--;
    }
    b = (b*2);
    b %= LARGE;
    ll ans = a - b + c;
    if (ans < 0) ans += LARGE;

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
//#include<iostream>
#define pb push_back
#define pf push_front

using namespace std;	
typedef long long int lli;

lli n,k,l,m,t,a,b,r,c,temp1,temp2,x,y,temp,q,d,mod=1e9+7,w,p;

lli grid[3002][3002];
lli dp[3002][3002][4];

lli rec(lli x,lli y,lli k)
{
	if(dp[x][y][k]!=-1)return dp[x][y][k];
	
	if(k>0)
	{
		if(y<c)
		dp[x][y][k]=max(rec(x,y+1,k-1)+grid[x][y],rec(x,y+1,k));
		if(x<r)
		dp[x][y][k]=max(dp[x][y][k],max(rec(x+1,y,3)+grid[x][y],rec(x+1,y,3)));
	}
	else
	{
		lli mx=0;
		if(x<r)
		mx=max(mx,rec(x+1,y,3));
		if(y<c)
		mx=max(mx,rec(x,y+1,k));
		
		dp[x][y][k]=mx;
	}
	return dp[x][y][k];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	cin>>r>>c>>k;
	
	for(int i=0;i<k;i++)
	{
		cin>>a>>b>>d;
		grid[a][b]=d;
	}
	
	for(int i=1;i<=r;i++)
	{
		for(int j=1;j<=c;j++)
		for(int k=0;k<=3;k++)
		dp[i][j][k]=-1;
	}
	
	dp[r][c][3]=grid[r][c];
	dp[r][c][2]=grid[r][c];
	dp[r][c][1]=grid[r][c];
	dp[r][c][0]=0;
	
	
	cout<<rec(1,1,3)<<endl;
	
}


Measured memory_bytes: 355632
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <bitset>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int M, N;
bitset<128> question[11];
int memo[1<<11][1<<11];
int dfs(int used, int mask){
  int& res = memo[used][mask];
  if(res != -1) return res;
  bitset<128> cur;
  REP(i, N) cur.set(i, true);
  REP(i, M) if(used & (1<<i)){
    if(mask & (1<<i)){
      cur &= question[i];
    }else{
      cur &= (~question[i]);
    }
  }
  if(cur.count() <= 1){
    res = 0;
  }else{
    res = INF;
    REP(i, M) if(!(used & (1<<i))){
      res = min(res, 1 + max(dfs(used | (1<<i), mask), dfs(used | (1<<i), mask | (1<<i))));
    }
  }
  //printf("dfs(%d, %d) return %d\n", used, mask, res);
  assert(res < INF);
  return res;
}
int main(){
  while(cin>>M>>N && M){
    memset(memo, -1, sizeof(memo));
    REP(i, M) question[i] = bitset<128>();
    REP(i, N){
      string s; cin>>s;
      REP(j, M)if(s[j] == '1'){
        question[j].set(i, true);
      }
    }
    cout<<dfs(0, 0)<<endl;
  }
  return 0;
}

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

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


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int A[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int K;
  cin>>K;

  cout<<A[K-1]<<endl;

  return 0;
}


Measured memory_bytes: 892
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var abx = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Func<double, double, double, double> calcDifferenceVolume = (a, b, theta) =>
            {
                if (a * Math.Tan(theta) <= b)
                    return a * a * b - a * a * a * Math.Tan(theta) / 2.0;
                return b * b / Math.Tan(theta) * a / 2.0;
            };
            var valid = Math.PI / 2.0;
            var invalid = 0.0;
            for (var i = 1; i < 100000; i++)
            {
                var mid = (valid + invalid) / 2.0;
                if (calcDifferenceVolume(abx[0], abx[1], mid) < abx[2]) valid = mid;
                else invalid = mid;
            }
            Console.WriteLine(valid / Math.PI * 180);
        }
    }
}


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

int main() {
  int n,m;
  ll ans = 0;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  vector<pair<int,int>> c(m);
  rep(i,m) {
    int b;
    cin >> c[i].second >> b;
    c[i].first = -b;
  }
  sort(c.begin(),c.end());
  rep(i,n) {
    if(a[i] < -c[0].first) {
      if(c[c.size()-1].second <= 0) break;
      a[i] = -c[0].first;
      c[0].second--;
      if(c[0].second == 0) {
        c.erase(c.begin());
      }
    }
  }
  rep(i,n) ans += a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
char line[80];
/* int index; */

int strsumdigit(char *str) {
  char *a_ptr;
  char *b_ptr;
  int sum;
  int digit;
  str[strlen(str)-1] = '\0';
  a_ptr = str;
  b_ptr = strchr(str, (int) ' ');
  ++b_ptr;
  /* printf("%s\n", b_ptr); */
  /* printf("%d\n", atoi(b_ptr)); */
  sum = atoi(a_ptr) + atoi(b_ptr);
  digit = (int)log10(sum) + 1;
  return digit;
}

int main(){
  while(fgets(line, sizeof(line), stdin) != NULL){
    printf("%d\n", strsumdigit(line));
  }
}

Measured memory_bytes: 584
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	s := ""
	answer := 0

	for {
		s = subseq(s)
		m, _ := strconv.Atoi(s)
		if m > n {
			break
		}
		if strings.ContainsRune(s, '3') && strings.ContainsRune(s, '5') && strings.ContainsRune(s, '7') {
			answer++
		}
	}

	fmt.Println(answer)
}

func subseq(s string) string {
	l := len(s)
	if l == 0 {
		return "3"
	} else if s[l-1] == '7' {
		return subseq(s[0:l-1]) + "3"
	} else if s[l-1] == '5' {
		return s[0:l-1] + "7"
	} else if s[l-1] == '3' {
		return s[0:l-1] + "5"
	} else {
		return "3"
	}
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    rep(i,n){
        cout<<s[i]<<t[i];
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int a;
    string s;
    cin >>a>>s;
    if(a>=3200){
        cout <<s<<endl;
    }
    else{
        cout<<"red"<<endl;
    }
}

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

int partition(int A[],int p,int r){
  int x=A[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

int main(){
  int n; cin>>n;
  int A[100005];
  for(int i=0;i<n;i++) cin>>A[i];

  int k=partition(A,0,n-1);
  
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    if(i==k) cout<<"["<<A[i]<<"]";
    else cout<<A[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3468
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] x = new int[m];
		for (int i = 0; i < m; i++) {
			x[i] = Integer.parseInt(sc.next());
		}

		Arrays.sort(x);

		int[] xd = new int[m - 1];
		for (int i = 0; i < m - 1; i++) {
			xd[i] = x[i + 1] - x[i];
		}
		Arrays.sort(xd);
		int ans = x[m - 1] - x[0];

		if (n < m) {

			for (int i = 1; i < n; i++) {
				ans -= xd[m - i - 1];
			}
		} else {
			ans = 0;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 46748
<?php
$str = "0".trim(fgets(STDIN));
$l = strlen($str);
$dp0 = array_fill(0, $l+1, 0);//超えてないやつ
$dp1 = array_fill(0, $l+1, 0);//超えたやつ
for($i = 0; $i < $l; ++$i){
  $s = $str[$i];
  $dp0[$i+1] = min($dp0[$i]+$s, $dp1[$i] + 10 - $s);
  $dp1[$i+1] = min($dp0[$i]+$s+1, $dp1[$i] + 9 -  $s);
}
echo $dp0[$i],"\n";


Measured memory_bytes: 72184
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n+1);
    a[0] = 0;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    a.push_back(0);
    int all = 0;
    for (int i = 1; i <= n+1; ++i) all += abs(a[i-1]-a[i]);
    for (int i = 1; i <= n; ++i) {
        int ans = all-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1]);
        //printf("all: %d, minus: %d, plus: %d, ans: %d \n", all, (abs(a[i-1]-a[i])+abs(a[i]-a[i+1])), abs(a[i-1]-a[i+1]), ans);
        cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x=0,f=0; char s; cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(f==2&&s=='C'){
      f=0; x++;
    }else if(f==1&&s=='B'){
      f=2;
    }else if(s=='A'){
      f=1;
    }else{
      f=0;
    }
  }
  cout<<x<<endl;
}
    

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int k;
    cin >> k;
    int a,b;
    cin >> a >> b;
    
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout << "OK";
            return 0;
            
        }
    }
    cout << "NG";
    return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
typedef long long int llint;
using namespace std;
int main() {
	int s;
	cin >> s;
	int a;
	for (int i = 1;;i++) {
		if (i == 1) {
			a = s;
		}
		else if (a % 2 == 0) {
			a = a / 2;
		}
		else {
			a = a * 3 + 1;
		}
		if (a == 4 || a == 2 || a == 1) {
			cout << i + 3 << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, m, a[MAX_N], imos[MAX_N*2]{}, sum[MAX_N]{};
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n-1;i++){
        ll dif = (a[i+1]-a[i]+m) % m;
        // xにしたとき回数が減るような区間の個数をimosで数える
        if(dif > 1){
            imos[a[i]+2]++;
            imos[a[i]+dif+1]--;
        }
        sum[a[i+1]+1] += dif-1;  // a[i+1]+1にしたときの増加分
        sum[1] += min(dif, a[i+1]);  // 1のとき
    }
    for(int i=0;i<m*2;i++){
        imos[i+1] += imos[i];
    }
    for(int i=2;i<=m;i++){
        sum[i] += sum[i-1] - (imos[i]+imos[i+m]);
    }

    ll ans = LLINF;
    for(int i=1;i<=m;i++){
        ans = min(ans, sum[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
program DDCC2020B
    implicit none
    integer(8)::N,i
    integer(8)::sum_half=0
    integer(8)::sum_A
    integer(8),allocatable,dimension(:)::A,A_diff

    read(5,*)N
    allocate(A(N))
    allocate(A_diff(N))
    read(5,*)(A(i),i=1,N)

    sum_A=sum(A)

    do i=1,N
       sum_half=sum_half+A(i)
       A_diff(i)=abs(2*sum_half-sum_A)
    end do
    
    print'(i0)',minval(A_diff)

end program DDCC2020B

Measured memory_bytes: 3968
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    S = input().rstrip()
    S = [conv(c) for c in S]
    segtree = SegmentTree(initial_values=S, f=lambda x,y:x|y)

    Q = int(input())
    for _ in range(Q):
        t, a, b = input().rstrip().split()
        if t == '1':
            a = int(a) - 1
            segtree.set_val(a, conv(b))
        else:
            a, b = int(a) - 1, int(b)
            q = segtree.query(a, b)
            print(popcount(q))

def conv(c): return 1 << (ord(c) - ord('a'))
def popcount(x):
    x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555)
    x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333)
    x = x + (x >> 4) & 0x0f0f0f0f0f0f0f0f
    x += x >> 8
    x += x >> 16
    x += x >> 32
    return x & 0x7f

class SegmentTree:
    def __init__(self, n=None, f=max, identity_factory=int, initial_values=None):
        assert(n or initial_values)
        size = n if n else len(initial_values)
        d = [identity_factory() for _ in range(2 * size + 1)]
        self.__n, self.__d, self.__f, self.__e = size, d, f, identity_factory
        if initial_values:
            for i, v in enumerate(initial_values): d[size + i] = v
            for i in range(size - 1, 0, -1): d[i] = f(d[i<<1], d[i<<1|1])

    def get_val(self, index):
        return self.__d[index + self.__n]

    def set_val(self, index, value):
        i, d, f = index + self.__n, self.__d, self.__f
        if d[i] == value: return
        d[i] = value
        while i:
            i = i >> 1
            d[i] = f(d[i<<1], d[i<<1|1])

    def modify(self, index, value):
        self.set_val(index, self.__f(self.__d[index + self.__n], value))

    def query(self, from_inclusive, to_exclusive):
        ans = self.__e()
        if to_exclusive <= from_inclusive: return ans
        l, r, d, f = from_inclusive + self.__n, to_exclusive + self.__n, self.__d, self.__f
        while l < r:
            if l & 1: ans, l = f(ans, d[l]), l+1
            if r & 1: ans, r = f(d[r-1], ans), r-1
            l, r = l >> 1, r >> 1
        return ans

    def bisect_left(self, func):
        '''func()がFalseになるもっとも左のindexを探す
        '''
        i, n, f, d, v = 1, self.__n, self.__f, self.__d, self.__e()
        while i < n:
            if func(f(v, d[i<<1])): v, i = f(v, d[i<<1]), i<<1|1
            else: i = i<<1
        return i - n


if __name__ == '__main__':
    main()

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

namespace _166A
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            if (S == "ABC") {
                Console.WriteLine("ARC");
            }else{
                Console.WriteLine("ABC");
            }
              
        }
    }
}


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

void solve(){
	int a;
	cin>>a;
	vector<int64_t>v(a);
    for(int i=0;i<a;i++)
		cin>>v[i];
	sort(v.begin(),v.end());
	if(v[0]==0){
		printf("0");
	}
	else{
		long double res=1;
		for(int i=0;i<a;i++){
			res*=v[i];
			if(res>1e18){
				printf("-1");
			    return ;
			}
		}
		cout<<(long long )(res);
	}
}

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


Measured memory_bytes: 3992
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

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

const int mod = 1e9 + 7;

int a[300023];
int ind[300023];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, x;
	cin >> n >> x;

	if(x == 1 or x == 2 * n - 1){
		cout << "No\n";
		return 0;
	}

	int m = 2 * n - 1;
	for (int i = 0 ; i < n - 1; i++)
		a[i] = m - i;
	a[n - 1] = 2;
	a[n]	 = 1;

	int val = 3;
	for (int i = 2 * n - 2; i > n; i--)
		a[i] = val++;

	for(int i = 0 ; i < m; i++)
		ind[a[i]] = i;

	
	for(int i = 2; i < min(x, n); i++){
		int val = i + 1;
		a[n - 1] = val;
		a[ind[i - 1]] = val - 1;
		a[ind[val]] = val - 2;

		int temp = ind[val];
		ind[val] = n - 1;
		ind[val - 1] = ind[val - 2];
		ind[val - 2] = temp;
	}

	for(int i = min(x, n); i < x; i++){
		int val = i + 1;
		a[n - 1] = val;
		a[ind[val + 1]] = val - 1;
		a[ind[val]] = val + 1;

		int temp = ind[val];
		ind[val] = n - 1;
		ind[val - 1] = ind[val + 1];
		ind[val + 1] = temp; 
	}

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

Measured memory_bytes: 3072
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.IOException;
import java.io.Reader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Denis Nedelyaev
 */
public class Main {
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtA solver = new AtA(in, out);
        solver.solve(1);
        out.close();
    }

    static class AtA {
        private final FastScanner in;
        private final PrintWriter out;

        public AtA(FastScanner in, PrintWriter out) {
            this.in = in;
            this.out = out;
        }

        public void solve(int testNumber) throws IOException {
            int a = in.nextInt();
            int b = in.nextInt();

            if (a <= 0 && b >= 0) {
                out.println("Zero");
            } else if (a > 0) {
                out.println("Positive");
            } else if (Math.abs(a - b) % 2 == 1) {
                out.println("Positive");
            } else {
                out.println("Negative");
            }
        }

    }

    static class FastScanner {
        private final BufferedReader br;
        private String line;
        private int pos;

        public FastScanner(String s) throws IOException {
            this(new StringReader(s));
        }

        public FastScanner(InputStream is) throws IOException {
            this(new InputStreamReader(is, "UTF-8"));
        }

        public FastScanner(Reader reader) throws IOException {
            this(new BufferedReader(reader));
        }

        public FastScanner(BufferedReader reader) throws IOException {
            br = reader;
            line = br.readLine();
            pos = 0;
        }

        public String next() throws IOException {
            if (!skipWhitespace()) {
                return null;
            }

            int start = pos;

            while (pos < line.length()) {
                char c = line.charAt(pos);

                if (c == ' ' || c == '\t') {
                    break;
                }

                pos++;
            }

            return line.substring(start, pos);
        }

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

        private boolean skipWhitespace() throws IOException {
            while (line != null) {
                while (pos < line.length()) {
                    char c = line.charAt(pos);

                    if (c != ' ' && c != '\t') {
                        return true;
                    }

                    pos++;
                }

                line = br.readLine();
                pos = 0;
            }

            return false;
        }

    }
}



Measured memory_bytes: 8148
INF=10**6
f=lambda:map(int,input().split())
h,w=f()
ch,cw=f()
dh,dw=f()
ch-=1
cw-=1
dh-=1
dw-=1
g=[input() for _ in range(h)]
from collections import *
d=[[INF]*w for _ in range(h)]
q=deque([(0,ch,cw)])
while q:
  td,tx,ty=q.popleft()
  if d[tx][ty]<=td: continue
  d[tx][ty]=td
  for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
    nx,ny=tx+dx,ty+dy
    if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.':
      q.appendleft((td,nx,ny))
  for dx in range(-2,3):
    for dy in range(-2,3):
      nx,ny=tx+dx,ty+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.':
        q.append((td+1,nx,ny))
a=d[dh][dw]
print([-1,a][a<INF])

Measured memory_bytes: 259804
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main() 
{
	int i,n;
	long long s=0;
	scanf("%d",&n);
	a[0]=a[n+1]=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		s+=abs(a[i]-a[i-1]);
	}
	s+=abs(a[n]);
	for(i=1;i<=n;i++)
	{
		printf("%lld\n",s-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
	}
	return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
 <url:https://arc085.contest.atcoder.jp/tasks/arc085_b>
 問題文============================================================
 N 枚のカードからなる山札があります。カードにはそれぞれ数が書かれており，
 上から i 枚目には ai が書かれています。
 
 この山札を使い，X さんと Y さんが 2 人でゲームをします。
 X, Y さんは最初，Z,W が書かれたカードを持っています。 そして X さんから交互に以下を行います。
 
 山札から何枚かカードを引く。そして今持っているカードを捨て，最後に引いたカードを代わりに持つ。
 ただし，必ず 1 枚は引かなくてはならない。
 山札がなくなるとゲームは終了で，2 人の持っているカードに書かれた数の差の絶対値がこのゲームのスコアになります。
 
 X さんはスコアを最大化するように，Y さんはスコアを最小化するようにゲームをプレイした時，
 スコアはいくつになるでしょうか？
 
 =================================================================
 
 解説=============================================================
 
 よくよく考えると 最適にするには X君は a_N or a_N-1 のカードをとらなければ行けないことがわかる
 よって O(1)
 
 
 ちなみに min-max法 + αβ法　を使えば　ゴリ押せる
 
 ================================================================
 */

// ===================================== //
// O(1)
void solve1(){
    ll N,Z,W; cin >> N >> Z >> W;
    vector<ll> a(N);
    for(auto &in:a) cin >> in;
    if(N != 1){
        cout << max({abs(a[N-1] - W),abs(a[N-2] - a[N-1])}) << endl;
    }else{
        cout << abs(a[N-1]-W) << endl;
    }
}

// ===================================== //
// minmax + αβ
ll N, Z, W;
ll dp[2001][2001];
vector<ll> a;
ll rec(ll i,ll j, ll k,ll alpha, ll beta) {
    ll& res = dp[i][j];
    if (res != -LINF)return res;
    if (i == N || j == N) {
        ll X = (i == 0) ? Z : a[i];
        ll Y = (j == 0) ? W : a[j];
        res = abs(X - Y);
        return res;
    }
    if (k == 1) {
        res = LINF;
        for (int y = i + 1; y <= N;y++) {
            res = min(res, rec(i, y, 0, alpha, res));
            if (alpha >= res) {
                return alpha;
            }
        }
    }
    else {
        for (int x = j + 1; x <= N;x++) {
            res = max(res, rec(x, j, 1, res, beta));
            if (res >= beta) {
                return beta;
            }
        }
    }
    return res;
}
void solve_minmax(){
    cin >> N >> Z >> W;
    a.resize(N + 1);
    for (int i = 1; i <= N;i++) cin >> a[i];
    for (int i = 0; i <= N;i++) {
        for (int j = 0; j <= N;j++) {
            dp[i][j] = -LINF;
        }
    }
    cout << rec(0, 0, 0, -LINF, LINF) << endl;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
//    solve1();
    solve_minmax();
    return 0;
}


Measured memory_bytes: 31616
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
    string rightc = "yuiophjklnm";

    while (1) {
        string s;
        cin >> s;

        if (s == "#") break;

        
        bool pright = count(rightc.begin(), rightc.end(), s[0]);

        int ans = 0;
        for (int i = 1; i < s.size(); ++i) {
            bool right = count(rightc.begin(), rightc.end(), s[i]);
            if (pright != right) {
                ans++;
                pright = right;
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3164
import math
N = int(input())
prime=[]
count=[]
ans = 1
place = 0
t=10**9
t+=7
for k in range(1,N+1):
    for i in range(2,k+1):
        while k % i == 0:
            k //= i
            if(i in prime):
                count[prime.index(i)] += 1
            else:
                prime.append(i)
                count.append(1)
                place += 1
for j in range(0,place):
    ans *= (count[j]+1)
print(ans%t)

Measured memory_bytes: 40304
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let S: Vec<char> = sc.chars();
    let T: Vec<char> = sc.chars();
    let N = S.len();
    let mut ans = 0;
    for i in 0..N {
        if S[i] != T[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 3888
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
ll N, K; vector<ll> Ap, Am, Az;
ll getCount(ll x) {
  ll cnt = 0;
  for(ll m = 0, p = Ap.size()-1; m < Am.size(); ++m) {
    while(p >= 0 && x >= -Am[m]*Ap[p]) --p;
    cnt += Ap.size()-p-1;
  }
  if(x < 0) return cnt;
  for(ll z = 1; z <= Az.size(); ++z) {
    cnt += N-z;
  }
  if(x <= 0) return cnt;
  for(ll l = 0, r = Ap.size()-1; l < r; ++l) {
    while(l <= r && x < Ap[l]*Ap[r]) --r;
    if(l < r) cnt += r-l;
  }
  for(ll l = 0, r = Am.size()-1; l < r; ++l) {
    while(l <= r && x < Am[l]*Am[r]) --r;
    if(l < r) cnt += r-l;
  }
  return cnt;
}
int main() {
  scanf("%ld %ld", &N, &K);
  for(ll i = 1, A; i <= N; ++i) {
    scanf("%ld", &A);
    if(A > 0) Ap.push_back(A);
    else if(A < 0) Am.push_back(-A);
    else Az.push_back(A);
  }
  sort(Ap.begin(), Ap.end());
  sort(Am.begin(), Am.end());
  ll l = -1e18, r = 1e18;
  while(r-l > 1) {
    ll m = (l+r)/2;
    if(getCount(m) >= K) r = m;
    else l = m;
  }
  printf("%ld\n", r);
}

Measured memory_bytes: 2548
#問題の理解に少し時間を要した。理解できるとコードを書くのが楽しいアルゴリズム

s = int(input())

def func(x):
    if x % 2 == 0:
        return int(x / 2)
    else:
        return int(3 * x + 1)

a = [s]

i = 2
while True:
    b = func(a[i-1-1])
    if b in a:
        break
    a.append(b)
    i += 1
    
print(i)


Measured memory_bytes: 2940
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int x = 40000000;
	int y = 0;
	for(int i = 0; i < n; i++) {
		a[i] = sc.nextInt();
	}
	for(int i = -100; i < 101; i++) {
		for(int j = 0; j < n; j++) {
			y += Math.pow((i - a[j]), 2);
		}
		if(x > y) {
			x = y;
		}
		y = 0;
	}
	System.out.println(x);
}
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

int main()
{
    int n;
    std::cin >> n;

    int building[4][3][10] = {};

    int b, f, r, v;
    for (int i = 0; i < n; ++i) {
        std::cin >> b >> f >> r >> v;

        building[b-1][f-1][r-1] += v;
    }

    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 10; ++k) {
                std::cout << " " << building[i][j][k];
            }
            std::cout << std::endl;
        }
        if (i != 3) {
            std::cout << "####################" << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string.h>
#include<set>
#define inf 0x3f3f3f3f
using namespace std;
map<string,int>mp;
map<string,int>::iterator it;
int main()
{
    int n,l;
    cin>>n>>l;
    for(int i=0; i<n; i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    for(it=mp.begin(); it!=mp.end(); )
    {
        cout<<it->first;
        it->second--;
        if(it->second==0)
            it++;
    }
    puts("");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string>
#define int long long
#define P pair<int,int>
#define V vector<int>
#define rep(i,n) for(int i=0;i<n;++i)
#define vsort(vec) sort(vec.begin(),vec.end())
#define end system("PAUSE");return 0
using namespace std;
signed main() {
	int n, a[100], cnt = 1, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i&&a[i] == a[i - 1])cnt++;
		else if (i) {
			ans += cnt / 2;
			cnt = 1;
		}
	}
	ans += cnt / 2;
	cout << ans << endl;
	end;
}


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

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

string s;

bool check(ll l){
    if(l%2 == 1){
        return s[l/2] == '1';
    }
    return s[l/2] == '1' && s[l/2-1] == '1';
}

void rev(ll l){
    for(int i=0;i<l;i++){
        if(s[i] == '0') s[i] = '1';
        else s[i] = '0';
    }
}

int main(){
    cin >> s;
    ll L = s.size();
    ll K = 1e8;
    if(check(L)) rev(L);
    bool f = true;
    for(int i=0;i<L;i++) f &= (s[i] == '0');
    if(f){
        cout << L << endl;
        return 0;
    }
    for(int i=0;i<L;i++){
        if(s[i] == '0') continue;
        K = min(K, max((ll)i, (ll)L-i-1));
    }
    cout << K << endl;
    return 0;
}

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

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AChristmasEveEveEve {
public:
	void solve(istream& in, ostream& out) {
        int d; in >> d;
        if(d == 22) out << "Christmas Eve Eve Eve" << endl;
        if(d == 23) out << "Christmas Eve Eve " << endl;
        if(d == 24) out << "Christmas Eve" << endl;
        if(d == 25) out << "Christmas" << endl;
	}
};

int main() {
	AChristmasEveEveEve solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

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

char dir[5] = "NESW";

int N, M, D, X, Y, A, i, j, k, C[20], R[20], P[21][21];

char c;

int main()
{
	while (true)
	{
		scanf("%d", &N);

		if (N == 0) { break; }

		memset(P, 0, sizeof(P));

		X = Y = 10; A = 0; P[X][Y] = 1;

		for (i = 0; i < N; i++) { scanf("%d%d", &C[i], &R[i]); }

		scanf("%d", &M);

		for (i = 0; i < M; i++)
		{
			std::cin >> c >> D;

			for (j = 0; j < 4; j++)
			{
				if (c == dir[j])
				{
					for (k = 0; k < D; k++) { X += dx[j]; Y += dy[j]; P[X][Y] = 1; }
				}
			}
		}

		for (i = 0; i < N; i++) { A += P[C[i]][R[i]]; }

		printf("%s\n", A == N ? "Yes" : "No");
	}

	return 0;
}

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

using namespace std;
const int N=2e5+5;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long ans=0;
    int n;cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            for(int k=1;k<=n;k++)
                ans+=__gcd(__gcd(i,j),k);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<ll, P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

ll n, k;
vector<ll> a, f;

bool check(ll x){
    ll cnt = 0;
    for(int i=0;i<n;i++){
        if(a[i]*f[i] > x)cnt += max(0LL, (a[i]*f[i]-x-1)/f[i]+1);
    }
    return cnt <= k;
}
 
int main(){
    cin >> n >> k;
    a.resize(n);
    f.resize(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> f[i];
    }
    SORT(a);
    SORTR(f);
    ll ok = LLINF/10, ng = -1;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        if(check(mid)){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}

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

const int inf = 1000000000;

int N,C;

int D[30][30], c[500][500];

int incom[30][3];

void sub_solve(int n){
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			incom[n][(i+j+2)%3] += D[c[i][j]][n];
		}
	}
}

int com_min(int i,int j,int k){
	int ans=inf;
	vector<int> v={i,j,k};
	sort(v.begin(),v.end());

	do{
		ans = min(ans, incom[v[0]][0]+incom[v[1]][1]+incom[v[2]][2]);
	}while( next_permutation(v.begin(), v.end()) );
	return ans;
}


void solve(){
	int ans = inf;
	for(int i=0;i<C;i++){
		sub_solve(i);
	}

	// for(int i=0;i<C;i++){
	// 	for(int j=0;j<3;j++){
	// 		cout << incom[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	for(int i=0;i<C;i++) for(int j=i+1;j<C-1;j++) for(int k=j+1;k<C;k++){
		ans = min(ans, com_min(i,j,k));
	}

	cout << ans << endl;


}


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

	for(int i=0;i<C;i++){
		for(int j=0;j<C;j++){
			cin >> D[i][j];
		}
	}

	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin >> c[i][j];
			c[i][j]--;
		}
	}
	solve();
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    int MAXN = 2010;
    bool g[MAXN][MAXN];
    forn(i, h) forn(j, w)
    {
        char tmp;
        cin >> tmp;
        g[i][j] = (tmp == '.');
    }

    int m[MAXN][MAXN];
    memset(m, 0, sizeof m);
    ll ans = 0;
    forn(i, h)
    {
        int cnt = 0, pos = 0;
        forn(j, w)
        {
            if (g[i][j])
                cnt++;
            else
            {
                fori(k, pos, j) m[i][k] = cnt;
                cnt = 0, pos = j + 1;
            }
        }
        fori(k, pos, w) m[i][k] = cnt;
    }
    // forn(i, h)
    // {
    //     forn(j, w) cout << m[i][j] << ' ';
    //     cout << endl;
    // }
    // cout << endl;
    forn(j, w)
    {
        int cnt = 0, pos = 0;
        forn(i, h)
        {
            if (g[i][j])
                cnt++;
            else
            {
                fori(k, pos, i) m[k][j] += cnt, ans = max(ans, (ll)m[k][j]);
                cnt = 0, pos = i + 1;
            }
        }
        fori(k, pos, h) m[k][j] += cnt, ans = max(ans, (ll)m[k][j]);
    }
    // forn(i, h)
    // {
    //     forn(j, w) cout << m[i][j] << ' ';
    //     cout << endl;
    // }
    // cout << endl;
    cout << (ans - 1);
    return 0;
}

Measured memory_bytes: 19968