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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

struct edge {
  int from, to, cost;
};

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

  int n, m;         // vは頂点数,Eは辺数
  vector<edge> es;  //辺
  cin >> n >> m;
  bool cycle = false;
  int d[n];  //最短距離
  fill(d, d + n + 1, -LINF);
  d[1] = 0;

  rep(i, 0, m) {
    edge add;
    cin >> add.from;       //出発点
    cin >> add.to;         //到着点
    cin >> add.cost;       //コスト
    es.emplace_back(add);  //有向
                           /*****:無向:*****/
                           /*
                           swap(add.from,add.to);
                           es.emplace_back(add);
                           */
  }

  rep(i, 0, n) {
    rep(j, 0, es.size()) {
      edge e = es[j];
      if (d[e.from] != INF) {
        if (chmax(d[e.to], d[e.from] + e.cost)) {  //最短経路更新
          if (i == n - 1 && e.to == n) {           //閉路があるとき
            cout << "inf\n";
            return 0;
          }
        }
      }
    }
  }

  // rep(i, 1, n + 1) { cout << d[i] << ' '; }
  cout << d[n] << '\n';
  return 0;
}

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

using namespace std;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	LL N, M, K;
	cin >> N >> M >> K;

	vector<LL> A(N), B(M);
	REP(i, N) cin >> A[i];
	REP(i, M) cin >> B[i];

	LL a = 0, b = 0;
	REP(j, M) b += B[j];
	LL j = M;
	LL ret = 0;
	REP(i, N + 1)
	{
		if(0 < i) a += A[i - 1];
		while(0 < j && K < a + b){
			b -= B[j - 1];
			j--;
		}
		if(a + b <= K) ret = max(i + j, ret);
	}

	cout << ret << endl;


	return 0;
}


Measured memory_bytes: 6052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n>>s;
    int sum=0;
    for(int i=1;i<n;i++)if(s[i]=='E')sum++;
    int ans=sum;
    for(int i=1;i<n;i++){
        if(s[i]=='E')sum--;
        if(s[i-1]=='W')sum++;
        if(ans>sum)ans=sum;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 720
# Disjoint Set: Union Find Tree
class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 最初は全てが根であるとして初期化        
        self.parent = [-1] * N  # idxが各ノードのid, 値がそのノードの親ノードのid

    def find(self, x):  # ノードのidを受け取って一番上の親ノードのidを帰す
        if (self.parent[x] < 0):
            return x
        self.parent[x] = self.find(self.parent[x])  # 経由したノードすべての親を上書き（経路圧縮）
        return self.parent[x]

    def unite(self, x, y): # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        rx = self.find(x) # xの根をrx
        ry = self.find(y) # yの根をry
        if (rx == ry): # xとyの根が同じ(=同じ木にある)時はそのまま
            return False

        if self.parent[rx] > self.parent[ry]:
            rx, ry = ry, rx
 
        self.parent[rx] += self.parent[ry]
        self.parent[ry] = rx

        return True
    
    def size(self, x):
        return -self.parent[self.find(x)]
      
    def same(self, x, y):
        return self.find(x) == self.find(y)
      
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parent) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
N, M, K = map(int, input().split())
ds = UnionFind(N+1)
num = [0]*(N+1)
G = [[] for i in range(N+1)]
for _ in range(M):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)
    ds.unite(x, y)
for _ in range(K):
    x, y = map(int, input().split())
    if ds.same(x,y) == True:
        G[x].append(y)
        G[y].append(x)
for i in range(1,N+1):
    print(ds.size(i) - len(G[i])-1,end=" ")


Measured memory_bytes: 115104
N, D = map(int, input().split())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())


c = 0
for j in range(N):
    if x[j]**2 + y[j]**2 <= D**2:
        c += 1

print(c)

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


using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


void go(){
	string n;cin>>n;
	int a=n[0]-'0',b=n[1]-'0',c=n[2]-'0',d=n[3]-'0';
	if(a+b+c+d==7) cout << n[0]<<'+'<<n[1]<<'+'<<n[2]<<'+'<<n[3]<<"=7";
	else if(a-b+c+d==7) cout << n[0] <<'-'<<n[1]<<'+'<<n[2]<<'+'<<n[3]<<"=7";
	else if(a+b-c+d==7) cout << n[0]<<'+'<<n[1]<<'-'<<n[2]<<'+'<<n[3]<<"=7";
	else if(a+b+c-d==7) cout << n[0]<<'+'<<n[1]<<'+'<<n[2]<<'-'<<n[3]<<"=7";
	else if(a-b-c+d==7) cout << n[0]<<'-'<<n[1]<<'-'<<n[2]<<'+'<<n[3]<<"=7";
	else if(a-b-c-d==7) cout << n[0]<<'-'<<n[1]<<'-'<<n[2]<<'-'<<n[3]<<"=7";
	else if(a-b+c-d==7) cout << n[0]<<'-'<<n[1]<<'+'<<n[2]<<'-'<<n[3]<<"=7";
	else if(a+b-c-d==7) cout << n[0]<<'+'<<n[1]<<'-'<<n[2]<<'-'<<n[3]<<"=7";
}
int main(){
   
   fastio();
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"
 
void solve(){
    ll n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0)ans+=i;
    }
    cout<<ans;
}
 
int main()
{
 
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
for i in range(200):
    if x-i not in p:
        print(x-i)
        break
    elif x+i not in p:
        print(x+i)
        break


Measured memory_bytes: 9172
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x;
		int a, b;
		double c;
		x = br.readLine();
		String[] ary = x.split(" ");
		a = Integer.parseInt(ary[0]);
		b = Integer.parseInt(ary[1]);
		
		
		System.out.print(a / b + " ");
		System.out.print(a % b + " ");
		c = (double)a / b;
		System.out.printf("%.5f", c);

	}
}

Measured memory_bytes: 24848
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 998244353
 
    N = II()
    D = LMIIS()
    num_D = [0]*N
    for d in D:
        num_D[d] += 1
    if D[0] != 0 or num_D[0] != 1:
        print(0)
        return
    ans = 1
    prev = 1
    dbg(num_D)
    for i,v in enumerate(num_D):
        if v == 0:
            if N-i != num_D.count(0):
                print(0)
                return
            break
        ans *= pow(prev,v,MOD)
        ans %= MOD
        prev = v
    print(ans)


    

    

if __name__ == '__main__':
    main()

Measured memory_bytes: 79144
N, Q = map(int, input().split())
S = input()
quiz = [list(map(int, input().split())) for _ in range(Q)]

t = [0] * (N+1)
for i in range(N):
  t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

for q in quiz:
  l = q[0]
  r = q[1]
  print(t[r-1] - t[l-1])

Measured memory_bytes: 92644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <fstream>

using namespace std;


int d[1001];
// eÌgpóµ
map<int,int> nums;
int mlen;
int n,m;
set<vector<int> > res;
int seq[1001];

// ÔÉèÄé
void rec(int lpos,int rpos,int lcnt,int rcnt){
	if(abs(lcnt-rcnt)==1){
		vector<int> v;
		for(int i=1;i<n;i++){
			v.push_back(seq[i]-seq[i-1]);
		}
		res.insert(v);
		return;
	}
	// cèÌvfÌÅAÅàå«¢àÌð©Â¯é
	map<int,int>::iterator iit=nums.end();
	while(1){
		iit--;
		if(iit->second!=0)break;
	}
	map<int,int> having;
	// ¶¤ÉèÄé©E¤ÉèÄé©Åêª¯
	// left
	if(lpos<iit->first){
		bool ok=true;
		// S_Ô£ªðminus
		for(int i=0;i<=lcnt;i++){
			int len=abs(seq[i]-iit->first);
			if(len>0){
				if(nums.find(len)!=nums.end()&&nums[len]>0){
					having[len]++;
					nums[len]--;
				}
				else ok=false;
			}
			else ok=false;
		}
		// S_Ô£ªðminus
		for(int i=n-1;i>=rcnt;i--){
			int len=abs(seq[i]-iit->first);
			if(len>0){
				if(nums.find(len)!=nums.end()&&nums[len]>0){
					having[len]++;
					nums[len]--;
				}
				else ok=false;
			}
			else ok=false;
		}
		if(ok){
			seq[rcnt-1]=iit->first;
			rec(lpos,iit->first,lcnt,rcnt-1);
		}
		for(map<int,int>::iterator it=having.begin();it!=having.end();it++)
			nums[it->first]+=it->second;
	}
	having.clear();
	// right
	if(rpos>(mlen-iit->first)){
		bool ok=true;
		// S_Ô£ªðminus
		for(int i=0;i<=lcnt;i++){
			int len=abs(seq[i]-(mlen-iit->first));
			if(len>0){
				if(nums.find(len)!=nums.end()&&nums[len]>0){
					having[len]++;
					nums[len]--;
				}
				else ok=false;
			}
			else ok=false;
		}
		// S_Ô£ªðminus
		for(int i=n-1;i>=rcnt;i--){
			int len=abs(seq[i]-(mlen-iit->first));
			if(len>0){
				if(nums.find(len)!=nums.end()&&nums[len]>0){
					having[len]++;
					nums[len]--;
				}
				else ok=false;
			}
			else ok=false;
		}
		if(ok){
			seq[lcnt+1]=(mlen-iit->first);
			rec(seq[lcnt+1],rpos,lcnt+1,rcnt);
		}
		for(map<int,int>::iterator it=having.begin();it!=having.end();it++)
			nums[it->first]+=it->second;
	}
}

int main(){
	while(cin>>n&&n!=0){
		cin>>mlen;
		m=n*(n-1)/2;
		for(int i=1;i<m;i++){
			cin>>d[i-1];
			nums[d[i-1]]++;
		}
		if(n==2)cout<<mlen<<endl;
		else{
			seq[0]=0;
			seq[n-1]=mlen;
			rec(0,mlen,0,n-1);
			for(set<vector<int> >::iterator it=res.begin();it!=res.end();it++){
				for(int i=0;i<(int)it->size();i++){
					cout<<(*it)[i];
					if(i==(int)it->size()-1)cout<<endl;
					else cout<<" ";
				}
			}
		}
		cout<<"-----"<<endl;
		res.clear();
		nums.clear();
	}
	return 0;
}

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

minus = 0
for i in range(N):
    if A[i] < 0:
        minus += 1
        A[i] *= -1

if minus%2 == 0:
    print(sum(A))
else:
    print(sum(A)-2*min(A))

Measured memory_bytes: 64880
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

int main(){
	int n;
	scanf("%d", &n);
	int yak[1001];
	for(int i=0; i<1001; i++){
		yak[i] = 1;
	}

	int temp;
	for(int i=2; i<=n; i++){
		temp = i;
		for(int j=2; temp != 1; j++){
			if(temp%j == 0){
				while(temp%j == 0){
					yak[j]++;
					temp = temp/j;
				}
			}
		}
	}
	long int answer=1;
	for(int i=0; i<1001; i++){
		answer =(long int) answer*yak[i];
		answer = answer%MOD;
	}
	printf("%ld\n", answer);

	return 0;
}

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

int main(){
  ll N = 0,x = 0;
  cin >> N;
  rep(i,10000000){
    if(pow(2,i) > N){
      x = pow(2,i) - 1;
      cout << x;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

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

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

ll mp[2019];
ll kake[222222];

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

	string str;cin >> str;
	ll ans = 0;
	ll now = 0;
	mp[0]++;

	kake[222222 - 1] = 1;
	REV(i, 222222 - 1)kake[i] = kake[i+1] * 10 % 2019;

	REP(i, str.size()){
		now *= 10;
		now += str[i] - '0';
		now %= 2019;

		ans += mp[now * kake[i] % 2019];
		mp[now * kake[i] % 2019]++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4996
#include<stdio.h>
int main(void){
        int x,y;
	while(1){
         scanf("%d %d",&x,&y);
         if(x==0 && y==0){
          break;
         }
         if(x<=y){
          printf("%d %d\n",x,y);
         }
         else if(x>y){
          printf("%d %d\n",y,x);
         }

        }
	return 0;
}

Measured memory_bytes: 1740
#include<stdio.h>
#include<math.h>
 
 
int main(){
 
  double x1,x2,x3,y1,y2,y3,xp,yp,A,B,C;
  double s,t;
  
 while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp) != EOF){
   A=(x2-x1)*(y3-y1) - (x3-x1)*(y2-y1);
   B=(xp-x1)*(y3-y1) - (x3-x1)*(yp-y1);
   C=(x2-x1)*(yp-y1) - (xp-x1)*(y2-y1);
 
   s=B/A;
   t=C/A;
 
   if(s>0 && t>0 && 0<s+t && s+t<1){printf("YES\n");}
   else{printf("NO\n");}
    
  }
  return 0;
}

Measured memory_bytes: 608
N, L = input().split()
'''
sum = 0
for i in range(1,int(N)+1):
    sum+=int(L)+i-1
if int(L) <= 0:
    if int(N) > -int(L):
        print(sum)
    else:
        print(sum-int(L)-int(N))
else:
    print(sum-int(L))
#print(sum)
'''
N, L = int(N), int(L)
min_pos = 9999999
min_neg = -9999999
sum = 0
for i in range(1,N+1):
    sum+=int(L)+i-1
for i in range(N):
    t = L + i
    #print(t, min_pos, min_neg)
    if t >= 0:
        if min_pos > t:
            min_pos = t
    elif min_neg < t:
        min_neg = t
if min_pos > abs(min_neg):
    print(sum-min_neg)
else:
    print(sum - min_pos)

#print(sum,min_pos,min_neg)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


vector<int> v[100000];
vector<bool> u(100000,false);

int main(){
  int r;
  cin >> r;
  cout << 3*r*r << endl;
  return 0;
}

Measured memory_bytes: 2560
//NEVER GIVE UP I AM GOING TO IMPROVE ONE DAY.
//PRACTICE,PRACTICE,PRACTICE!!!
#include<bits/stdc++.h>
#define int long long int
// #define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e18
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const int M=1000000007;
const double pi = acos(-1.0);
using namespace std;
// cout<<"Case #"<<test-t<<":"<<" "<<ans<<endl;
int32_t main(){
    fast;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        int l,r,d,ans=0;
        cin>>l>>r>>d;
        for(int i=l;i<=r;i++){
            if(i%d==0){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3616
n = int(input())
p = list(map(int,input().split()))

large_small = 2
ans = 0
for i in range(n-1):
    if p[i] > p[i+1]:
        if large_small == 1:
            ans += 1
        large_small = 1
    elif p[i] < p[i+1]:
        if large_small == -1:
            ans += 1
        large_small = -1
    else:
        large_small = 0

print(ans)


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    h_list = LI()

    mn = 10**10
    for h in reversed(h_list):
        if h >= mn + 2:
            print('No')
            return
        if h < mn:
            mn = h

    print('Yes')
solve()

Measured memory_bytes: 14684
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    string s[H];
    for(int i = 0; i < H; i++) cin >> s[i];

    bool exist[W];
    fill(exist, exist + W, false);
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#') exist[j] = true;
        }
    }

    int ans[H][W];
    fill(ans[0], ans[H], -1);

    int ind = 0;
    for(int j = 0; j < W; j++){
        if(!exist[j]) continue;
        bool found = false;
        ind++;
        for(int i = 0; i < H; i++){
            if(!found && s[i][j] == '.'){
                ans[i][j] = ind;
            }
            else if(!found && s[i][j] == '#'){
                found = true;
                ans[i][j] = ind;
            }
            else if(found && s[i][j] == '.'){
                ans[i][j] = ind;
            }
            else if(found && s[i][j] == '#'){
                ind++;
                ans[i][j] = ind;
            }
        }
    }

    //一番左の存在する列
    int jj = 0;
    while(!exist[jj]) jj++;

    //cout << jj << endl;

    //jjより左の列をヌル
    for(int j = jj - 1; j >= 0; j--){
        for(int i = 0; i < H; i++){
            ans[i][j] = ans[i][j + 1];
        }
    }

    //
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(ans[i][j] == -1) ans[i][j] = ans[i][j - 1];
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int N;
	cin>>N;
	vector<int> a(N);
	double sum=0;
	for(int i=0; i<N; i++)
	{
		cin>>a[i];
		sum += (double)1/a[i];
	}
	cout<<1/sum<<endl;
}

Measured memory_bytes: 256
K, N = map(int, input().split(" "))
A = [int(a) for a in input().split(" ")]

A.sort()
seg = []
for i in range(N - 1):
  seg.append(A[i + 1] - A[i])
seg.append(K - A[N - 1] + A[0])

print(sum(seg) - max(seg))

Measured memory_bytes: 26436
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll N,K,sum = 0;
vector<ll> A;
vector<ll> B;

bool F(ll x){
    B = vector<ll>();
    ll SUM = 0,NOW = 0,NOW2 = 0;
    rep(i,N){
        B.push_back(A[i] % x);
        SUM += x - B[i];
    }
    sort(ALL(B));
    ll res = INF;
    rep(i,N){
        NOW += B[i];
        NOW2 += x - B[i];
        ll A = NOW,B = SUM - NOW2;
        res = min(res,max(A,B));
    }
    return res <= K;
}

int main(){
    cin >> N >> K;
    rep(i,N){
        ll a;cin >> a;
        A.push_back(a);
        sum += a;
    }
    ll ans = 0;
    for(ll i = 1;i * i <= sum;i++){
        if(sum % i == 0){
            if(F(i)) ans = max(ans,i);
            if(F(sum / i)) ans = max(ans,sum / i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
dishes = [input() for _ in range(5)]


def tanuki(dishes):
    if all([i[-1] == '0' for i in dishes]):
        return sum([int(i) for i in dishes])

    sum_dishes = 0
    last_dish = 0
    last_tmp = 0
    for idx, dish in enumerate(dishes):
        tmp = 10 - int(dish[-1])
        dish = int(dish)
        if tmp == 10:
            sum_dishes += dish
        elif tmp > last_tmp:
            sum_dishes += last_dish + last_tmp
            last_dish = dish
            last_tmp = tmp
            last_idx = idx
        else:
            sum_dishes += dish + tmp
    return sum_dishes + int(dishes[last_idx])


print(tanuki(dishes))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
    //freopen("file.in", "r", stdin);
    int a;string s;
    cin>>a>>s;
    if(a>=3200)
    	cout<<s<<endl;
    else
		cout<<"red"<<endl;	
	return 0;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll A[10100], B[10100], C[10100];

int main(){
	for(ll n, m; cin >> n >> m, n;){
		vector<P>path[105];
		rep(i, m){
			cin >> A[i] >> B[i] >> C[i];
			path[A[i]].push_back(P(C[i], B[i]));
			path[B[i]].push_back(P(C[i], A[i]));
		}
		ll ans = INF;
		rep(i, m){
			vector<ll>flg(n + 1, INF);
			priority_queue<P>Q;
			Q.push(P(C[i], B[i]));
			while(!Q.empty()){
				ll w = Q.top().first;
				ll idx = Q.top().second;
				Q.pop();
				if(flg[idx] != INF)continue;
				flg[idx] = w;
				rep(j, path[idx].size()){
					ll to = path[idx][j].second;
					if(flg[to] != INF)continue;
					if(path[idx][j].first > C[i])continue;
					Q.push(path[idx][j]);
				}
			}
			ll tmp = INF;
			rep1(j, n){
				if(flg[j] == INF)tmp = -1;
				chmin(tmp, flg[j]);
			}
			if(tmp > 0)chmin(ans, C[i] - tmp);
		}
		if(ans == INF)cout << -1 << endl;
		else cout << ans << endl;
	}

    return 0;
}


Measured memory_bytes: 3392
#include<stdio.h>
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
#define MAX(a,b) (((a)>(b)) ? (a) : (b))

int GCD(int a,int b)
{
  if(a==0||b==0) return MAX(a,b);
  else return GCD(MAX(a,b)%MIN(a,b),MIN(a,b));
}

int LCM(int a,int b)
{
  int c;
  c=GCD(a,b);
  return (a/c)*(b/c)*c;
}

int main(){
  int a,b;
  while(scanf("%d %d",&a,&b)!=EOF)
    {
      printf("%d %d\n",GCD(a,b),LCM(a,b));
    }
  return 0;
}

Measured memory_bytes: 596
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);
parse_tuple!(A, B, C, D);
parse_tuple!(A, B, C, D, E);

// ===

fn main() {
    let (n, _z, w): (usize, i32, i32) = read();
    let a: Vec<i32> = readnc();
    let mut ans = (w-a[n-1]).abs();
    if n >= 2 {
        ans = max(ans, (a[n-2]-a[n-1]).abs());
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto A = RDA;

	long ans = 1000;
	foreach (i; 0..N-1)
	{
		if (A[i] < A[i+1])
		{
			auto cnt = ans / A[i];
			ans = ans % A[i];
			ans += A[i+1] * cnt;
		}
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}


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

typedef long long ll;

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

    int k,a,b;
    cin >> k >> a >> b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3652
w = input()
q = int(input())
for _ in range(q):
    S = input().split()
    s = S[0]
    a, b = map(int, S[1: 3])
    if s == "print":
        print(w[a: b + 1])
    elif s == "reverse":
        w = w[:a] + w[a: b + 1][::-1] + w[b + 1:]
    else:
        w = w[:a] + S[3] + w[b + 1:]


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

using namespace std;

namespace {
    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> A[i];
        }
    }

    typedef long long ll;

    void solve() {
        auto acc = vector<ll>(N + 1, 0);
        for (auto i = 0; i < N; i++) {
            acc[i + 1] = acc[i] + A[i];
        }
        auto ans = LLONG_MAX;
        for (auto i = 1; i < N; i++) {
            auto x = acc[i];
            auto y = acc.back() - x;
            ans = min(ans, abs(x - y));
        }
        cout << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
// #include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
#include <iterator>
#include <queue>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for (int i=(a-1);i>=(b);--i)
#define rrep(i,n) rrepd(i,n,0)
typedef long long ll;
typedef pair<int, int> P;


int main(int argc, const char * argv[]) {
  // x1, x2を座標圧縮し、座標圧縮した際の幅を返す 
  int n;
  cin >> n;
  
  vector<int> x(n);
  vector<int> y(n);
  rep(i, n){
    cin >> x[i] >> y[i];
  }
  double sum_ = 0.0;
  rep(i, n){
    repd(j, i+1, n){
      sum_ += sqrt(pow((x[i] - x[j]), 2) + pow((y[i] - y[j]), 2)) *2.0;
    }
  }

  printf("%.10lf\n", sum_/n);

  return 0;
}

Measured memory_bytes: 888
# -*- coding: utf-8 -*-
n = int(input())

a = [int(input()) for _ in range(n)]

most = max(a)
most_idx = a.index(most)
second = max(a[:most_idx] + a[most_idx+1:])

for i in range(n):
    print(second if a[i] == most else most)


Measured memory_bytes: 20156
n = input()
An = list(map(int, input().split()))

def tako(An):
    stool = 0
    Anstool = [An[0]]
    for n in range(len(An)-1):
        pers = An[n+1]
        fr = Anstool[n]
        if fr > pers:
            stool += fr - pers
            pers = fr
        Anstool.append(pers)
    return stool

print(tako(An))

Measured memory_bytes: 32236
//*******************************************************************************
//       Exhaustive Search                 
//*******************************************************************************
//     < ???????????? >
//       Exhaustive Search ????????????????????¨??????????£??????????
//*******************************************************************************
#include <iostream>
#include <vector>
using namespace  std;

void fnInput(vector<int> &rvnElm,  vector<int> &rvnTrg )
{
  int nElmCnt, nTrgCnt;
  cin >> nElmCnt;

  rvnElm.resize(nElmCnt);
  for (int i = 0; i < nElmCnt; i++)
    cin >> rvnElm[i];

  cin >> nTrgCnt;

  rvnTrg.resize(nTrgCnt);
  for (int i = 0; i < nTrgCnt; i++)
    cin >> rvnTrg[i];
}

void fnDPtblMake(vector<vector<int>> &rvvnDP, const vector<int> &cnrvnElm, int nMaxTrg)
{
  rvvnDP[cnrvnElm.size()][0] = 1;
  for (int j = 1; j <= nMaxTrg; j++)
    rvvnDP[cnrvnElm.size()][j] = 0;

  for (int i = cnrvnElm.size() - 1; i >= 0; i--)
    for (int j = 0; j <= nMaxTrg; j++)
      if (cnrvnElm[i] <= j)
        rvvnDP[i][j] = rvvnDP[i + 1][j] || rvvnDP[i + 1][j - cnrvnElm[i]];
      else
        rvvnDP[i][j] = rvvnDP[i + 1][j];

}

void fnExhSch(const vector<int> &cnrvnElm, const vector<int> &cnrvnTrg)
{
  vector<vector<int>> vvnDP(21, vector<int>(2001, -1));

  int nMaxTrg = cnrvnTrg[0]; 
  for (int i = 1; i < cnrvnTrg.size(); i++)
    nMaxTrg = max(nMaxTrg, cnrvnTrg[i]);

  fnDPtblMake(vvnDP, cnrvnElm, nMaxTrg);

  for (int i = 0; i < cnrvnTrg.size(); i++)
    if (vvnDP[0][cnrvnTrg[i]])
      cout << "yes" << endl;
    else
      cout << "no" << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnElm, vnTrg;

  fnInput(vnElm, vnTrg);
  fnExhSch(vnElm, vnTrg);

  return 0;
}

Measured memory_bytes: 1340
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

const int MAX_V = 300;

int V;
bool G[MAX_V][MAX_V];
int match[MAX_V];
bool used[MAX_V];

bool dfs(int v) {
	used[v] = true;
	for(int i = 0; i < V; i++) {
		if(!G[v][i]) continue;
		int u = i, w = match[u];
		if(w < 0 || (!used[w] && dfs(w))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int bipartite_matching() {
	int res = 0;
	memset(match, -1, sizeof(match));
	for(int v = 0; v < V; v++) {
		if(match[v] < 0) {
			memset(used, 0, sizeof(used));
			if(dfs(v)) {
				res++;
			}
		}
	}
	return res;
}

int N, M;
int xa[100], ya[100], xb[100], yb[100], v[100];

bool check(double k) {
	memset(G, 0, sizeof G);
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < M; j++) {
			double d = sqrt((xa[i] - xb[j]) * (xa[i] - xb[j]) + (ya[i] - yb[j]) * (ya[i] - yb[j]));
			G[i][j + N] = G[j + N][i] = ((d / v[i]) <= k);
		}
	}

	return bipartite_matching() == M;
}

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

	while(cin >> N >> M, N) {
		V = N + M;
		for(int i = 0; i < N; i++) {
			cin >> xa[i] >> ya[i] >> v[i];
		}
		for(int i = 0; i < M; i++) {
			cin >> xb[i] >> yb[i];
		}

		double ng = 0, ok = 1e9;
		for(int loop = 0; loop < 100; loop++) {
			double mid = (ng + ok) / 2.0;
			if(check(mid)) ok = mid;
			else ng = mid;
		}
		cout << fixed << setprecision(10) << ok << endl;
	}
}

Measured memory_bytes: 3364
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1], C = ip[2], D = ip[3];
	if(A + B > C + D) writeln("Left");
	else if(A + B < C + D) writeln("Right");
	else writeln("Balanced");
 }

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
double num[105];
inline double cmp(double x,double y){
	return x>y;
}
priority_queue<double,vector<double>,greater<double> > qu; 
int main () {
	cin>>n;
	for(int i=1;i<=n;i++){
		double x;
		cin >> x;
		num[i]=x;
		qu.push(x);
	}
	sort(num+1,num+1+n,cmp);
	if(n==1){
		cout<<num[1]<<endl;
		return 0;
	}
	else if ( n == 2) {
		printf ( "%.5lf\n" , ( num[1] + num[2] ) / 2 );
		return 0;
	}
	double tmp=qu.top();
	qu.pop();
	while ( !qu.empty () ) {
		double los = qu.top ();
		qu.pop ();
		tmp=(tmp+los)/2;		
	}
	printf("%.5lf\n",tmp);
	return 0;
}

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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;

#ifndef LOCAL_H
    const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t clock_start = clock();
        solve();
        clock_t clock_end = clock();
        const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

/************************************************************************************************************************************************/

void solve(){
    string S;
    cin >> S;
    LL ans = 0;
    int flag = 0;
    for(int i = 0;i < S.size();i++){
        int num = S[i]-'0';
        if(num > 5){
            ans += 11-num;
            if(flag){
                ans -= 2;
            }
            flag = true;
        }
        else if(num == 5){
            if(flag){
                ans += 4;
                flag = true;
            }
            else{
                if(i != S.size()-1 && S[i+1]-'0' >= 5){
                    ans += 6;
                    flag = true;
                }
                else{
                    ans += 5;
                    flag = false;
                }
            }
        }
        else{
            ans += num;
            if(num == 4 && i != S.size()-1 && S[i+1]-'0' >= 5 && flag){
                ans++;
                flag = true;
            }
            
            else{
                flag = false;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int buttons(int A, int B) {
    if (A == B) {
        return A + B;
    } else if (A > B) {
        return 2 * A - 1;
    } else {
        return 2 * B - 1;
    }
}

int main() {
    int A, B; cin >> A >> B;
    
    int ans = buttons(A, B);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
B - AtCoder Beginner Contest 111
https://atcoder.jp/contests/abc111/tasks/abc111_b

"""
import sys


def solve(N):
    while True:
        if len(set(str(N))) == 1:
            break
        N += 1
    return N


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a + b < 10) cout << a + b << endl;
  else cout << "error" << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int m;
    cin >> m;
    int sum = accumulate(t.begin(), t.end(), 0);
    for(int i=0; i<m; ++i){
        int p, x;
        cin >> p >> x;
        int ans = sum - t[p-1] + x;
        cout << ans << endl;
    }

    return 0;
}


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

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

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

int main() {
  int a, b;
  top = 0;
  char s[100];

  while( scanf("%s", s) != EOF ) {
    if ( s[0] == '+' ) {
      a = pop();
      b = pop();
      push(a + b);
    } else if ( s[0] == '-' ) {
      a = pop();
      b = pop();
      push(b- a);
    } else if ( s[0] == '*' ) {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }

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

  return 0;
}

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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;


void solve(long long N, long long K, std::string S) {
	int cnt = 1;
	int res = 0;
	reps(i, 1, N) {
		if (S[i-1] == S[i]) {
			cnt++;
		} else {
			res += cnt - 1;
			cnt = 1;
		}
	}
	res += cnt - 1;
	cout << min(N-1, res + K * 2) << endl;
}

signed main() {
	long long N;
	scanf("%lld",&N);
	long long K;
	scanf("%lld",&K);
	std::string S;
	std::cin >> S;
	solve(N, K, S);
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, L;
  string a = "", s[200];
  cin >> N >> L;

  for (int i = 0; i < N; i++) cin >> s[i];

  sort(s, s + N);

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

  printf("%s\n", a.c_str());
}


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

int main() {
  int s;
  cin >> s;
  int c = 0;
  if (s % 2 == 1){
    c ++;
  }
  if ((s / 10) % 2 == 1){
    c ++;
  }
  if ((s / 100) % 2 == 1){
    c ++;
  }
  cout << c << endl;
}

Measured memory_bytes: 256