akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
    ll x, y;
    cin >> x >> y;
    cout << (x % y == 0 ? -1 : x) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [1] * n
ans = 1

for i in range(1,n+1):
    b = 2
    
    while i != 1:
        if i % b == 0:
            i //= b
            a[b-1] += 1
        else:
            b += 1
            
for i in a:
    if 1 < i:
        ans *= i
        ans %= 10**9 + 7
            
print(ans)

Measured memory_bytes: 8992
h, n = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
inf = 1 << 30
dp = [inf] * (h + 1)
dp[h] = 0

for i in range(n):
    for j in range(h, 0, -1):
        nx = max(0, j - ab[i][0])
        dp[nx] = min(dp[nx], dp[j] + ab[i][1])
print(dp[0])

Measured memory_bytes: 74120
#include<bits/stdc++.h>
#define MAXN 105
using namespace std;
int N;
int A[3][MAXN];
int dp[MAXN][2];
int main()
{
    scanf("%d",&N);
    for(int i=1;i<=2;i++)
        for(int j=1;j<=N;j++)
            scanf("%d",&A[i][j]);
    for(int i=1;i<=N;i++)
    {
        dp[i][1]=A[1][i]+dp[i-1][1];
        dp[i][2]=A[2][i]+max(dp[i][1],dp[i-1][2]);
    }
    printf("%d\n",dp[N][2]);
    return 0;
}


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

public class Main{
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            while(true){
                int n = sc.nextInt();
                if(n==0) break;
                int[] s = new int[n];
                for(int i=0;i<s.length;i++){
                    s[i]=sc.nextInt();
                }
                Arrays.sort(s);
                int sum=0;
                for(int i=1;i<s.length-1;i++){
                    sum+=s[i];
                }
                int answer = sum/(n-2);
                System.out.println(answer);
            }
        }
    }
}


Measured memory_bytes: 29196
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    struct AB
    {
        public int A;
        public int B;
    }
    public void run()
    {
        int N = int.Parse(Console.ReadLine());
        int T = 0;
        bool flag = false;
        AB[] list = new AB[N];
        for(int i = 0; i < N; i++)
        {
            var input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            list[i].A = a;
            list[i].B = b;
        }
        IOrderedEnumerable<AB> sortList = list.OrderBy(rec => rec.B);
        foreach (AB ab in sortList)
        {
            T += ab.A;
            if(ab.B < T)
            {
                flag = true;
                break;
            }
        }
        if (flag)
        {
            Console.WriteLine("No");
        }
        else
        {
            Console.WriteLine("Yes");
        }
    }
    public static void Main()
    {
        var prog = new Prog();
        prog.run();
    }
    /*
    最小公倍数
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
    */
}

//Array.ConvertAll(int.Parse)
//str.IndexOf("Stage",System.StringComparison.CurrentCulture)


Measured memory_bytes: 22068
#include<bits/stdc++.h>
using namespace std;
int i,n;
double a[50];
int main(){
  for(cin>>n;i<n;i++)cin>>a[i];
  while(n>1){
    sort(a,a+n);
    a[0]=(a[0]+a[1])/2;
    for(i=1;i<n-1;i++)a[i]=a[i+1];
    n--;
  }
  cout<<a[0];
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

const long long maxn = 310;
const long long mod = 998244353;
long long n , m;
long long a[maxn][maxn];
long long s[maxn][maxn];
long long r;
long long pow ( long long x ) {
	long long s = 1 , f = 2;
	while ( x ) {
		if ( x % 2 ) s = ( s * f ) % mod;
		f = ( f * f ) % mod; x = x / 2;
	}
	return s;
}
void work () {
	long long i , j , k;
	scanf ( "%lld%lld" , &n , &m );
	for ( i = 1 ; i <= n ; i++ )
		for ( j = 1 ; j <= m ; j++ )
			scanf ( "%lld" , &a[i][j] );
	for ( i = 1 ; i <= n ; i++ ) {
		for ( j = 1 ; j <= m ; j++ ) {
			if ( s[j][j] == 0 && a[i][j] == 1 ) {
				for ( k = 1 ; k <= m ; k++ ) {
					s[j][k] = a[i][k];
				}
				r++;
				break;
			}
			if ( a[i][j] == 1 )
				for ( k = 1 ; k <= m ; k++ ) {
					a[i][k] ^= s[j][k];
				}
		}
	}
	printf ( "%lld\n" , ( pow ( n + m - 1 ) - pow ( n + m - r - 1 ) + mod ) % mod );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
 
import sys
import math

s = input()
t = input()

dist_list = []

for i in range(len(s) - len(t) + 1):
    #tと同じ文字数をsから切り出す
    sd = s[i:i+len(t)]

    #ハミング距離を求める
    dist = 0
    for j in range(len(t)):
        if sd[j] != t[j]:
            dist += 1
    
    dist_list.append(dist)

print(min(dist_list))


Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define INF 1e18

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,w,sum_v,a[101],b[101];
long long d[100001];

void nhap()
{
    scanf("%d %d",&n,&w);
    for (int i=1;i<=n;++i)
    {
        scanf("%d %d",&a[i],&b[i]);
        sum_v+=b[i];
    }
    for (int i=1;i<=sum_v;++i)
        d[i]=INF;
}

void process()
{
    for (int i=1;i<=n;++i)
    {
        for (int j=sum_v-b[i];j>=0;--j)
        {
            d[j+b[i]]=min(d[j+b[i]],d[j]+a[i]);
        }
    }
    int ma=0;
    for (int i=1;i<=sum_v;++i)
    {
        if (d[i]<=w) ma=max(ma,i);
    }
    cout<<ma;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if((b - a) == (c - b)) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
'use strict';

const receive = require('fs')
  .readFileSync('/dev/stdin', 'utf8')
  .split(/\s/);

const main = input => {
  const N = Number(input[0]);
  var arr = [...Array(N).keys()].map(x => ++x); // 連番の配列を作成
  var counter = 0; // 2で割った回数

  while (arr.length > 1) { // 残った数字が1つになった時点で終了
    var arr = arr.filter(x => x % 2 === 0).map(x => x / 2);
    counter++;
  }

  const ans = arr[0] * Math.pow(2, counter);
  console.log(ans);
};

main(receive);


Measured memory_bytes: 7372
class in{struct myIterator{int it;const bool rev;explicit constexpr myIterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(myIterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const myIterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const myIterator& begin(){return i;}const myIterator& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

int dp[2001][2001]; //I
int dp2[2001][2001]; //OI
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    int ans = 0;
    for(int i : in(n + 1)) for(int j : in(m + 1)) {
        ans = max(ans, dp[i][j]);
        if(i < n) {
            if(s[i] == 'I')
              dp[i + 1][j] = max(dp[i + 1][j], dp2[i][j] + 1);
            else if(dp[i][j] > 0)
              dp2[i + 1][j] = max(dp2[i + 1][j], dp[i][j] + 1);
        }
        if(j < m) {
            if(t[j] == 'I')
              dp[i][j + 1] = max(dp[i][j + 1], dp2[i][j] + 1);
            else if(dp[i][j] > 0)
              dp2[i][j + 1] = max(dp2[i][j + 1], dp[i][j] + 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34508
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	private static final char A = 'A';
	private static final char B = 'B';
	private static final char C = 'C';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] count = new int['Z'];
			count[A] = scanner.nextInt();
			count[B] = scanner.nextInt();
			count[C] = scanner.nextInt();
			char[][] s = new char[n][];
			IntStream.range(0, n).forEach(i -> s[i] = scanner.next().toCharArray());
			List<String> answer = new ArrayList<>();
			boolean result = true;
			for (int i = 0; i < n; i++) {
				if (0 == count[s[i][0]] + count[s[i][1]]) {
					result = false;
					break;
				}
				if (count[s[i][0]] > count[s[i][1]]) {
					count[s[i][0]]--;
					count[s[i][1]]++;
					answer.add(String.valueOf(s[i][1]));
				} else if (count[s[i][0]] < count[s[i][1]]) {
					count[s[i][0]]++;
					count[s[i][1]]--;
					answer.add(String.valueOf(s[i][0]));
				} else if (count[s[i][0]] == count[s[i][1]]) {
					if (i < n - 1) {
						// 次のパターンで判定する
						if ((s[i][0] == s[i + 1][0]) && (s[i][1] == s[i + 1][1])) {
							// 次のパターンが同じとき
							count[s[i][0]]++;
							count[s[i][1]]--;
							answer.add(String.valueOf(s[i][0]));
						} else if ((s[i][0] == s[i + 1][0]) || (s[i][0] == s[i + 1][1])) {
							// 次のパターンと同じ文字のものを+1とする
							count[s[i][0]]++;
							count[s[i][1]]--;
							answer.add(String.valueOf(s[i][0]));
						} else {
							count[s[i][0]]--;
							count[s[i][1]]++;
							answer.add(String.valueOf(s[i][1]));
						}
					} else {
						count[s[i][0]]++;
						count[s[i][1]]--;
						answer.add(String.valueOf(s[i][0]));
					}
				}
			}
			System.out.println(result ? "Yes" : "No");
			if (result) {
				answer.forEach(System.out::println);
			}
		}
	}
}


Measured memory_bytes: 67804
#include<iostream>
#include<string>
using namespace std;
#define MIN_NUM 0;
#define MAX_NUM 200000;

int main() {
  string s; cin >> s;
  int min_pos_a = MAX_NUM;
  int max_pos_z = MIN_NUM;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'A' && i <= min_pos_a) min_pos_a = i;
    if(s[i] == 'Z' && max_pos_z <= i) max_pos_z = i;
  }
  cout << max_pos_z - min_pos_a + 1 << endl;

  return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[101];
int m,ans=0;
int main()
{
	int n;
	cin>>n;
	scanf("%s",s+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='I')m++;
		else m--;
		ans=max(ans,m);
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 256
N,M = map(int,input().split())
L = list(map(int,input().split()))
if N >= M :
    ans = 0
else :
    A = []
    L = sorted(L)
    for i in range(M-1) :
        A.append(L[i+1] - L[i])
    A = sorted(A)
    ans = sum(A[:M-N])

print(ans)


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

int main(int argc, const char * argv[]) {
    // insert code here...
    int r, g, b;
    cin >> r >> g >> b;
    int total = 100 * r + 10 * g + b;
    if (total % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(X: int, Y: int):
    print(X+Y//2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n = int(input())

result = 0
for i in range(n):
    num = i*2
    if num > n:
        break
    hasndivisors = 0
    for divisor in range(n):
        # print(num+1, divisor+1)
        if (num+1)/(divisor+1) == (num+1)//(divisor+1):
            hasndivisors += 1
    # print(num+1, 'has', hasndivisors, 'divisors')
    if hasndivisors == 8:
        result += 1

print(result)

Measured memory_bytes: 9100
#include<iostream>
using namespace std;
int main(){
  char b;
  cin >> b;
  char ans;
  if(b == 'A') ans = 'T';
  else if(b == 'T') ans = 'A';
  else if(b == 'G') ans = 'C';
  else ans = 'G';
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

n, t = list(map(int, input().split()))

ct = [list(map(int, input().split())) for _ in range(n)]

ct = sorted(ct, key=lambda x: x[0])

# print(n, t)
# print(ct)
for i in ct:
    if i[1] <= t:
        print(i[0])
        exit()

print("TLE")


Measured memory_bytes: 8984
n = int(input())
h = list(map(int, input().split()))

l = -1
r = -1
ans = 0
while sum(h) > 0:
    for i in range(n):
        if l == -1 and h[i] > 0:
            l = i
            
        if l != -1 and h[i] == 0:
            r = i-1
        elif  l != -1 and i == n-1:
            r = i
        
        if l != -1 and r != -1:
            ans += 1
            for j in range(l, r+1):
                h[j] -= 1
            else:
                l = -1
                r = -1

print(ans)

Measured memory_bytes: 9224
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,x; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <long long int> >& v) {
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
vector<ll> vi(200010);
ll a, b, c, d; bool flg = true; bool af = false; bool bf = false;
bool dfs(ll x,ll y) {
	if (x == c) { af = true; }
	if (y == d) { bf = true; }
	if (a>c||b>d) return false;
	else if (af&&bf) return true;
	for (int i = 1; i <= 2; i++) {
		if (flg) {
			if (vi[x + i] == 0) {
				x += i;
				vi[x] = 2;
				dfs(x, y);
			}
			else if (vi[x + i] == 2) {
				vi[x] = 2;
				flg = false;
				dfs(x, y);
			}
		}
		else if (!flg) {
			if (vi[y + i] == 0) {
				y += i;
				vi[y] = 2;
				dfs(x, y);
			}
			else if (vi[y + i] == 2) {
				vi[y] = 2;
				flg = true;
				dfs(x, y);
			}
		}
		else return false;
	}
}

int main() {
	cin >> n; ll res = INF;
	for(ll i=0;i<=n;i++) {
		ll cc = 0;
		ll t = i;
		while (t > 0) {
			cc += t % 6;
			t /= 6;
		}
		t = n - i;
		while (t > 0) {
			cc += t % 9;
			t /= 9;
		}
		if (res > cc) res = cc;
	}
	cout << res << endl;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

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

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define LINF		((ll)1 << 63 -1)
#define INF 		2000000007
#define MINF		-2000000007
#define MAX 		100005

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

int N;
vector<vector<int>> edge(MAX);
int used[20];

int dfs(int n,int cnt){
	if(cnt == N && used[n]==0)return 1;
	used[n] = cnt;
	int c = 0;
	for(int itr : edge[n]){
		if(used[itr]!=0)continue;
		c += dfs(itr,cnt+1);
	}
	used[n]=0;
	return c;
}

//
int main(){
	int M;cin>>N>>M;
	
	REP(i,M){
		int a,b;
		cin>>a>>b;
		edge[--a].push_back(--b);
		edge[b].push_back(a);
	}

	cout << dfs(0,1) << endl;


	return 0;
}




Measured memory_bytes: 2560
import java.io.PrintWriter;
import java.util.*;

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

		char[] S = sc.next().toCharArray();
		int N = S.length;
		char[] T = sc.next().toCharArray();
		int M = T.length;
		
		int[] scnt = new int[N+1];
		for(int i=0; i<N; i++) {
			scnt[i+1] = (scnt[i] + (S[i]=='A' ? 1 : 2))%3;
		}
		int[] tcnt = new int[M+1];
		for(int i=0; i<M; i++) {
			tcnt[i+1] = (tcnt[i] + (T[i]=='A' ? 1 : 2))%3;
		}
		
		int Q = sc.nextInt();
		for(int i=0; i<Q; i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt();
			int c = sc.nextInt()-1;
			int d = sc.nextInt();
			pw.println((scnt[b]-scnt[a]-tcnt[d]+tcnt[c]+6)%3==0 ? "YES" : "NO");
		}
		
		sc.close();
		pw.close();
	}
}


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

void solve(){
  ll a,b;
  scanf("%lld",&a);
  b=360;
  while(b%a != 0)
    b+=360;
  printf("%lld",b/a);

}
int main()
{
    
     int t=1; 
     // cin >> t;
     while (t--) solve();
 
     return 0;
}


Measured memory_bytes: 3828
#include <stdio.h>

int main(void){
  long long n,k,s;
  scanf("%lld%lld%lld",&n,&k,&s);
  if(s<1000000000){
  for(int i=0;i<n;i++){
  if(i<k) printf("%lld ",s);
  else{
    printf("%lld ",s+1);
  }
  }
  }
  if(s==1000000000){
    for(int i=0;i<n;i++){
      if(i<k) printf("%lld ",s);
    else{
      printf("1 ");
    }
    }
  }

  return 0;
}


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

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  int g[12] = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if (g[x - 1] == g[y - 1]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N= 1e7+5;
int n,t,m;
int a,b,c,k;
string s1,s2;

int32_t main()
{
	IOS;
	cin>>a>>b>>c>>k;
	if(k<=a)
		cout<<k<<endl;
	else if(k<=(a+b))
		cout<<a<<endl;
	else{
		cout<<a-(k-(a+b))<<endl;
	}
}
	 


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

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

int main() {
    cin >> n;
    vl a(n + 10), b(n + 10);
    IPT(a, n + 1)
    IPT(b, n)

    ans = 0;
    NREP() {
        ll attack = min(a[i], b[i]);
        a[i] -= attack;
        b[i] -= attack;
        ans += attack;

        attack = min(a[i+1], b[i]);
        a[i+1] -= attack;
        b[i] -= attack;
        ans += attack;
    }
    MSG(ans)
}


Measured memory_bytes: 4812
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

// Union Find用
class DisjointSet {
private:
  vector<int> p;
  
public:
  DisjointSet(int size) : p(size, -1) {}

  bool unite_set(int x, int y) {
    x = root(x);
    y = root(y);
    
    if (x != y) {
      if (x > y) { swap(x, y); }
      p[x] += p[y];
      p[y] = x;
    }   

    return x != y;
  }

private:
  int root(int x) {
    return p[x] < 0 ? x : p[x] = root(p[x]);
  }
};

// 通路
struct corridor {
  int a, b;     // 繋がっているcell
  double len;   // 通路の長さ
  corridor(int a, int b, double len) : a(a), b(b), len(len) {}

  // ソート用
  bool operator <(const corridor& rhs) const {
    if (len != rhs.len) { return len < rhs.len; }
    if (a != rhs.a) { return a < rhs.a; }
    return b < rhs.b;
  }
};

double dist(double x1, double y1, double z1, double x2, double y2, double z2) {
  return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}

int main(int argc, char const* argv[]) {
  int n;
  while (cin >> n && n) {
    double x[100], y[100], z[100], r[100];
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i] >> z[i] >> r[i];
    }

    // 全ての通路を長さでソートする
    vector<corridor> cor;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < i; j++) {
        cor.push_back(corridor(i, j, max(0.0, dist(x[i], y[i], z[i], x[j], y[j], z[j]) - r[i] - r[j])));
      }
    }
    sort(cor.begin(), cor.end());

    DisjointSet ds(n);
    double ans = 0;   // 通路の長さの総和
    int count = 0;    // 選んだ通路の数

    for (vector<corridor>::iterator itr = cor.begin(); count < n - 1; itr++) {
      // aとbが別々の集合に属しているならばその通路を採用する
      if (ds.unite_set(itr->a, itr->b)) {
        ans += itr->len;
        count++;
      }
    }

    printf("%.3f\n", ans);
  }
  return 0;
}


Measured memory_bytes: 3256
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define	n	1000005
#define P	1000000007

int		N, M, K, T, Ans, L[n], R[n], H[n];

int		Pow(int a,int b){
		int ret=1;
		for (;b;b>>=1,a=1ll*a*a%P)
			if  (b&1)	ret=1ll*ret*a%P;
		return	ret;
}

int		C(int a, int b){
		return	1ll*L[a]*R[b]%P*R[a-b]%P;
}

int		main(int argc, char* argv[]){
		N= IN()-1;
		M= IN();
		K= IN();
		T= N+M+K;
	
		L[0]= 1;
		For(i, 1, T)	L[i]= 1ll*L[i-1]*i%P;
		
		R[T]= Pow(L[T], P-2);
		Rep(i, T, 1)	R[i-1]= 1ll*R[i]*i%P;
		
		H[0]= 1;
		For(i, 1, T)	H[i]= 1ll*H[i-1]*3%P;
		
		int sum= 1;
		For(t, 0, M+K)	{
			Ans= (1ll*C(N+t, N)*H[M+K-t]%P*sum + Ans)%P;
			sum= (sum + sum)%P;
			
			if	(t >= M)	sum= (sum - C(t, M) + P)%P;
			if	(t >= K)	sum= (sum - C(t, K) + P)%P;
		}
		printf("%d\n", Ans);
		
		return	0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char c[4];
	int i,co=0;
	scanf("%s",c);
	for(i=0;i<3;i++)
	{
		if(c[i]=='o')
			co++;
	}
	printf("%d",700+co*100);
	return 0;
}


Measured memory_bytes: 256
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, c = inintm()

if a == b == c == 1:
    print(0)
    exit()

if a == b == c:
    print(-1)
    exit()

ans = 0

while a % 2 == b % 2 == c % 2 == 0:
    d = a
    e = b
    f = c
    a = e/2 + f/2
    b = d/2 + f/2
    c = d/2 + e/2
    ans += 1

print(ans)

Measured memory_bytes: 61924
#include<stdio.h>
#include<math.h>

int main(void){
	int a,b,h,m;
	scanf("%d %d %d %d",&a,&b,&h,&m);
	long double kaku,ans;
	kaku=fabs((h*60+m)*0.5-m*6);
	if(kaku>180){
		kaku=360-kaku;
	}
	
	ans=a*a+b*b-2*a*b*(long double)cos(kaku*3.14159265358979323846/180);
	
	printf("%.10Lf",sqrtl(ans));
	
	return 0;
}

Measured memory_bytes: 2600
import numpy as np

N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = np.zeros((N,M), dtype=int)
for n in range(N):
    A[n,:] = list(map(int, input().split()))

cnt = 0
for i in range(N):
    calc = C
    for m in range(M):
        calc += (A[i,m] * B[m])
    if calc > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 12468
#include<stdio.h>
signed main(){
    int sum, ans;
    sum = 0;
    int i=0;
    int X[10];
    for(i=0; i < 5; i++){
    scanf("%d",&X[i]); 
    }
    for(i=0; i<5; i++){
        sum = sum + X[i];
    }
    ans = 15 - sum;
    printf("%d\n",ans);
}

Measured memory_bytes: 1684
N, K = map(int, input().split())

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

area.sort()
d = [0] * N
a = [0] * N


def func(pos):
    for l, r in area:
        if pos + l - 1 < N:
            a[pos + l-1] += d[pos]
        if pos + r < N:
            a[pos + r] -= d[pos]
    d[pos+1] = (d[pos] + a[pos]) % 998244353


d[0] = 1
a[0] = -1
for i in range(0, N-1):
    func(i)

print(d[N-1] % 998244353)


Measured memory_bytes: 76880
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
 double a,b,c,d,e,f;
 while(cin>>a>>b>>c>>d>>e>>f){
  double x = (c*e-f*b)/(a*e-b*d);
  double y = (a*f-d*c)/(a*e-d*b);
  if(x == 0) x = 0.0;
  if(y == 0) y = 0.0;
  printf("%.3lf %.3lf\n",x,y);
 }
 return 0;
}  


Measured memory_bytes: 3116
#include <stdio.h>





int main(){
  int i,j,n,r,l,c,d,k;
  int G[150][150];
  
  scanf("%d",&n);
  

  for(i = 0;i < n; i++){
    
    
    scanf("%d%d",&r,&j);
    for(k = 0;k < j; k++){

      
      
      scanf("%d",&l);
      
      
      G[r-1][l-1] = 1;
      

    }
  }
  
  
  for(c = 0;c < n; c++){
    for(d = 0;d < n-1; d++){
      
      
      printf("%d ",G[c][d]);
      
    }
    printf("%d",G[c][d]);
    
    printf("\n");
  }
 
  
  return 0;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,b,c,d;

main() {
    cin >> a >> b >> c >> d;
    ct(max(a*b,c*d))
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,r;
    cin>>n>>r;
    if(n>=10)
    {
        cout<<r<<endl;
    }
    else
    {
        cout<<r+(100*(10-n))<<endl;
    }
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   string s,t;
   s = "AKIHABARA";
   cin >> t;
   int i=0,j=0;
   
   for(i,j;i<s.size();i++)
   {
      if(s[i]==t[j])
      {
         j++;
      }
      else if(s[i]=='A')
      {
         
      }
      else
      {
         cout<<"NO"<<endl;
         return 0;
      }
   }

   if(j==t.size())cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
   return 0;
}

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

int main()
{
    int n,k;
    cin>>n>>k;
    int *dist=new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>dist[i];
    }
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<n)
            {
                dp[j]=min(dp[j],dp[i]+abs(dist[i]-dist[j]));
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 4036
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> oset;

// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

const int mod = 1e9 + 7;
const int inf = 9e18;
const int N = 1e5 + 5;

int i,n,u,v,d1[N],d2[N];
vi g[N];

void dfs1(int v,int par){
    for(int u:g[v]){
        if(u!=par){
            d1[u]=d1[v]+1;
            dfs1(u,v);
        }
    }
}

void dfs2(int v,int par){
    for(int u:g[v]){
        if(u!=par){
            d2[u]=d2[v]+1;
            dfs2(u,v);
        }
    }
}

void solve(){
    cin>>n>>u>>v;
    for(i=0;i<n-1;++i){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    if(sz(g[u])==1 && v==g[u][0]){
        cout<<0;
        return;
    }
    d1[u]=d2[v]=0;
    dfs1(u,0);
    dfs2(v,0);
    int ans=0;
    for(i=1;i<=n;++i){
        if(d1[i]<d2[i]){
            ans=max(ans,d2[i]-1);
        }
    }
    cout<<ans;
}

signed main(){
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	for(int i = 0; i < n; i++)
		if(a[i] == a[i+1])
		{
			cout << "NO";
			return 0;
		}
	cout << "YES";
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=3005;
int a[N],n,x,y;
vi e[N];
ll f[N];

void dfs(int u,int fa){
	f[u]=1e18;
	for(auto v:e[u]){
		if(v==fa) continue;
		dfs(v,u);
		if(a[v]<f[v]) f[u]=min(f[u],(ll)a[v]+1);
	}
	f[u]=max(f[u],1ll);
}

int main(){
	read(n);
	rep(i,1,n) read(a[i]);
	rep(i,1,n-1){
		read(x),read(y);
		e[x].pb(y),e[y].pb(x);
	}
	rep(i,1,n){
		dfs(i,0);
		if(a[i]>=f[i]) printf("%d ",i);
	}
	return 0;
}

Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    string s,t;
    cin>>s>>t;
    set<char> st;
    int n=t.size(),m=s.size();
    rep(i,m) st.insert(s[i]);
    int k=m-1;
    bool ok=0;
    int cnt=0;
    while(k>=0){
        if(s[k]=='?') cnt++;
        else cnt=0;
        if(cnt==n){
            ok=1;
            for(int i=k;i<k+n;i++){
                s[i]=t[i-k];
            }
            break;
        }
        if(st.count(s[k])){
            set<int> ss;
            rep(i,n){
                if(t[i]==s[k]) ss.insert(i);
            }
            set<int> sss;
            for(auto v:ss){
                bool ok1=1;
                int h=k-v;
                rep(j,n){
                    if(k-v<0||k+(n-v)>m){
                        ok1=0;
                        break;
                    }
                    if(s[k-v+j]!='?'&&s[k-v+j]!=t[j]){
                        ok1=0;
                        break;
                    }
                }
                if(ok1) sss.insert(v);
            }
            if(!sss.empty()){
                ok=1;
                int u=*begin(sss);
                for(int i=k-u;i<k+(n-u);i++) s[i]=t[-k+u+i];
                break;
            }
        }
        k--;
    }
    if(ok){
        rep(i,m){
            if(s[i]=='?') s[i]='a';
        }
        cout<<s<<endl;
    }else{
        cout<<"UNRESTORABLE"<<endl;
    }
}

Measured memory_bytes: 256
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<int>());
#define ALL(X) (X).begin(),(X).end()
#define INF 99999999
#define M_PI 3.14159265358979323846
#define MOD 1000000007

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

// ナップサック問題なんだけど
// ふつうのナップサックと異なる。

string N;

void input(){
  #ifdef __LOCAL
      fs::path p = __FILE__;
      fs::path input,output;
      input = output = p.parent_path();
      input += string("/input/") + string(p.stem()) + string(".txt");
      output += string("/output/") + string(p.stem()) + string(".txt");
      freopen(input.c_str(), "r", stdin);
      freopen(output.c_str(), "w", stdout);
  #endif

  fast_io();
  cin >> N;
}


int solve(){
  input();
  string M="0"+N;
  ll ans=0;
  DBG(M)
  for(int i=N.size();i>=1;i--){
    if(M[i]<='4') continue;
    if((M[i]=='5')&&(M[i-1]<'5')) continue;
    else {
      ans += 10-(M[i]-'0');
      M[i] = '0';
      M[i-1] = M[i-1] + 1;
      DBG(ans)
      DBG(M) 
      }
  }
  DBG(M)
  DBG(ans)
  REP(i,M.size()) ans+=(M[i]-'0');
  cout << ans << endl;  
  return 0;
}

int sample_solve(string n){
  N = n;
  DBG(n)
  // solve(n);
  return 0;
}

int main()
{
  solve();
  // sample_solve("987654321");
  return 0;
}


Measured memory_bytes: 2332
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
int n,ans,ri=-INF;
P a[100010];
signed main(){
    cin>>n;
    rep(i,n){
        int l,r;
        cin>>l>>r;
        a[i]={l+r,l-r};
    }
    sort(a,a+n);
    rep(i,n){
        if(ri<=a[i].se){
            ri=(a[i].fi);
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << "No"; return;}

void solve() {
    int n; cin >> n;
    vector <int> a(n);
    int ans = 0, cur = 0;
    loop(i, n) {
        cin >> a[i];
        if (i && a[i] > a[i - 1]) {
            ans = max(ans, cur); cur = 0;
        }
        ++cur;
    }
    ans = max(ans, cur);
    cout << ans - 1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3688
def gcd(a,b):
 while b!=0:
   a,b=b,a%b
 return a

n,x = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
tmp = abs(l[0]-x)

for i in range(1,n):
    tmp =  gcd(tmp,abs(l[i]-x))

print(tmp)

Measured memory_bytes: 85668
#include <iostream>
#include <stdio.h>

int main()
{
    char number[1000];
    while(1) {
        scanf("%s", number);
        if(number[0] == '0') {
            break;
        }
        
        int sum = 0;
        for(int i = 0; number[i] != '\0'; i++) {
            sum += number[i] - '0';
        }
        
        printf("%d\n", sum);
    }
}


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

using namespace std;

#define ll long long

ll gcd(ll a, ll b){
    if (a < b) return gcd(b, a);
    ll r;
    while (r = a % b){
        a = b;
        b = r;
    }
    return b;
}

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return (a / g) * (b / g) * g;
}

signed main(){
    int n; cin >> n;
    vector<ll> t(n);
    for (int i = 0; i < n; ++i)
        cin >> t.at(i);
    ll ans = 1;
    for (int i = 0; i < n; ++i)
        ans = lcm(ans, t[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define M1 100001
#define M2 10001

int bs (int [], int, int);

int compar (const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}


int main(void)
{
  int d, n, m, s[M1], k[M2];
  int i, temp, sum, pr, pl;
  
  while(scanf("%d",&d))
    {
      if(d==0)
	break;
      else
	{  
	  scanf("%d",&n);
	  scanf("%d",&m);
	  s[0]=0;
	  s[n]=d;
	  for(i=1;i<=n-1;i++)
	    {
	      scanf("%d",&s[i]);
	    }
	  for(i=0;i<m;i++)
	    {
	      scanf("%d",&k[i]);
	    }
	  qsort(s,n,sizeof(int),compar);
	  
	  sum = 0;
	  for(i=0;i<m;i++)
	    {
	      temp = bs(s,n,k[i]);
	      //printf("bs = %d\n",temp);
	      if(s[temp]<k[i])
		{
		  pr = k[i] - s[temp];
		  pl = s[temp+1] - k[i];
		  if(pr>pl)
		    sum+=pl;
		  else
		    sum+=pr;
		}
	      else if(s[temp]>k[i])
		{
		  pr = s[temp] - k[i];
		  pl = k[i] - s[temp-1];
		  if(pr>pl)
		    sum+=pl;
		  else
		    sum+=pr;
		}
	    }
	  printf("%d\n",sum);
	}
    }
  return 0;
}

int bs (int s[], int n, int d) {
  // D: ??????, n: ???????????????, d: ??¢?´¢????????????
  int c=0, head=0, tail=n-1, p=-1, t=0;
  while (head <= tail) {
    int mid = (head+tail)/2;
    c++;
    //printf(" ???%2d: [%d, %d] D[%d]=%d\n", c, head, tail, mid, s[mid]); // ??????????????¨???
    t = mid;
    if (d==s[mid]) { // d ??? D[mid] ?????????
      p = mid;
      break;
    } else if (d<s[mid]) {
      tail = mid-1;
    } else {
      head = mid+1;
    }
  }
  //printf("  ???????????°:%d\n", c);  // ???????????°?????¨???: ????¨???¨
  return t;                     // ?????¨ => ??????, ?????¨????????? => -1
}

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

using namespace std;
string a,b;
int dp[3009][3009];

int solve(int idx1,int idx2){
	if(idx1>=a.length()||idx2>=b.length())return 0;

	if(dp[idx1][idx2]!=-1)return dp[idx1][idx2];

	if(a[idx1]==b[idx2]){
		dp[idx1][idx2]=solve(idx1+1,idx2+1)+1;
	}
	else{
		dp[idx1][idx2]=max(solve(idx1+1,idx2),solve(idx1,idx2+1));
	}
	return dp[idx1][idx2];
}
void build(int idx1,int idx2){
	if(idx1>=a.length()||idx2>=b.length())return ;
	if(a[idx1]==b[idx2]){
		cout<<a[idx1];
		idx1++;idx2++;
	}
	else if(dp[idx1][idx2]==solve(idx1+1,idx2)){
		idx1++;
	}
	else if(dp[idx1][idx2]==solve(idx1,idx2+1)){
		idx2++;
	}
	build(idx1,idx2);
	return;

}


int main(){

	memset(dp,-1,sizeof(dp));
	cin>>a>>b;
	solve(0,0);
	build(0,0);
}


Measured memory_bytes: 35968
#include <stdio.h>
#define SUM(a,b) a+b

int main(void){
    int n,m,i,j,re=0;
    scanf("%d %d",&n,&m);
    int ary[n][m], m_ary[m], a_ary[n];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&ary[i][j]);
        }
    }
    for(j=0;j<m;j++) scanf("%d",&m_ary[j]);
    for(i=0;i<n;i++,re=0){
        for(j=0;j<m;j++){re=SUM(re,ary[i][j]*m_ary[j]);}
        a_ary[i]=re;
    }
    for(i=0;i<n;i++) printf("%d\n",a_ary[i]);
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char a[100005][15];
char *p[100005] ;
int cmp(char c,char b){
	return c<b;
}
int cmp1(char *c,char *b){
	if(strcmp(c,b)<0) 
		return 1;
	else return 0;
}
long long s=0;
int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
		int len=strlen(a[i]) ;
		sort(a[i],a[i]+len,cmp) ;
		p[i]=a[i] ;
	}
	sort(p,p+n,cmp1) ;
	long long m=1;
	string c;
	c=p[0] ;
	for(int i=1;i<n;i++) {
		if(c==p[i]) m++;
		else {
			s+=(m-1)*m/2;
			m=1;
			c=p[i] ;
		}
	}
	s+=(m-1)*m/2;
	cout << s<<endl;	
	return 0;
}

Measured memory_bytes: 2432