akhauriyash/Code-Regression huggingface dataset:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

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

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

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

	def members(self,x): # much time
		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.parents) 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()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1


n,k = readInts()
a = readInts()

now = [1]
check = [0]*n
check[0] = 1
l = 1

while check[l-1]<2:
	l = a[l-1]
	check[l-1]+=1
	now.append(l)

zen = now.index(now[-1])
kou = len(now)-zen

if k<zen:
	print(now[k])
else:
	x = (k-zen)%(kou-1)
	print(now[zen:][x])

Measured memory_bytes: 32160
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t A, B, N;
  cin >> A >> B >> N;
  int64_t x = 0;
  if (N < B) {
    x = N;
  } else {
    x = B - 1;
  }
  int64_t answer = (A * x) / B;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int res = 0;
  int n; cin >>n;
  string s; cin >>s;
  rep(i, n){
    if (s[i] == 'R') res++;
    else res--;
  }
  cout <<(res>0 ? "Yes" : "No") <<endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  vector<int> v(n);
  rep(i, n) v[i] = i+1;
  map<vector<int>, int> m;
  int count = 1;
  do {
    m[v] = count;
    count++;
  } while (next_permutation(v.begin(), v.end()));
  cout << abs(m[p] - m[q]) << endl;
  return 0;
}

Measured memory_bytes: 8668
N = int(input())
A, B = [int(_) for _ in input().split()]
P = [int(_) for _ in input().split()]

a = b = c = 0
for pi in P:
    if pi <= A:
        a += 1
    if A < pi <= B:
        b += 1
    if B < pi:
        c += 1

print(min(a, b, c))


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

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 dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  double ans = 0;
  rep(i,n){
    double x;
    string u;
    cin >> x >> u;
    if(u[0] == 'J') ans += x;
    else ans += x * 380000.0;
  }
  printf("%10f", ans);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.math.BigInteger;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
//	    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
           Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
           
           int [] arr = new int[5];
           for(int i = 0;i < 5;++i)
               arr[i] = input.nextInt();
           int k = input.nextInt();
           boolean flag = false;
           for(int i = 0;i < 5;++i) {
               for(int j = i+1;j < 5;++j){
                   if(arr[j]-arr[i] > k){
                       flag =true;
                       break;
                   }
               }
           }
           if(flag)
               System.out.println(":(");
           else
               System.out.println("Yay!");
	}
}     



Measured memory_bytes: 24404
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> vi;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

ll a[20][20];
int n,m;
bool cal(int x,int y){
	ll sum=0;
	for(int i=1;i<=m;i++){
		sum+=(a[x][i]-a[y][i])*(a[x][i]-a[y][i]);
	}
	ll temp=sqrt(sum);
	return sum==temp*temp;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			ans+=cal(i,j);
		}
	}
	cout<<ans<<endl;
	return 0;
}



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

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol(const vector<int>& v1, 
               const vector<int>& v2){ 
 return v1[0] < v2[0]; } 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{
	ll n;
	cin>>n;
	vll a(n),fr(10000000,0),done(10000000,0);
	for(ll i=0;i<n;i++)
		cin>>a[i],fr[a[i]]++;
	for(ll i=0;i<10000000;i++)
	{
		
		if(fr[i]>0 && done[i]==0)
		{
			for(ll j=i*2;j<=10000000;j+=i)
				done[j]=1;
			if(fr[i]>=2)
				done[i]=1;
		}
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		if(done[a[i]]==0)
		{
			ans++;
		}
	}
	cout<<ans;
	return;
}

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

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

int modadd(int a, int b, int m)
{
    int da = m - a;
    if ( da <= b )
    {
        return b - da;
    }
    else
    {
        return a + b;
    }   
}

int modmul(int n, int b, int m)
{
    long long int tmp = (long long int) b;
    tmp *= n;
    return tmp % m;
    int ans = 0;
    for( int i = 0; i < n; i++)
    {
        ans = modadd(ans, b, m);
    }
    return ans;
}

int main(void)
{
    int n, m;
    cin >> n;
    cin >> m;

    int* f = (int*) malloc(sizeof(int) * (3 * n + 1) * (n + 1) );
    for( int i = 0; i <= 3 * n; i++)
    {
        for( int j = 0; j <= n; j++)
        {
            if( i <= 1 )
            {
                f[i * (n + 1) + j] = 1;
            }
            else
            {
                if( n - j > ( 3 * n ) - i ) 
                {
                    f[ i * (n + 1) + j] = 0;
                }
                else
                {
                    int ans =  f[ (i - 1) * (n + 1) + j ];
                    if( i - 3 >= 0 && j > 0 ) ans = modadd( ans, modmul(( i - 1 ), modmul(( i - 2 ), f[ (i - 3) * (n + 1) + j - 1 ], m), m), m ); 
                    if( i - 2 >= 0 && j > 0 ) ans = modadd( ans, modmul(( i - 1 ), f[ (i - 2) * (n + 1) + j - 1 ], m), m);
                    f[ i * (n + 1) + j] = ans;
                }
            }
        }
    }

    cout << f[ 3 * n * (n + 1) + n];

}

Measured memory_bytes: 47104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
    ll n;cin >> n;
    vl v(n);
    rep(i,n)cin >> v[i];
    ll ans=v[0]-1;
    ll p=2;
    repl(i,1,n){
        ll res=(v[i]-1)/p;
        ans+=res;
        if(p==v[i])p++;
        //cout << p << " " << res <<endl;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
typedef unsigned int UINT;
using namespace std;

void insert(string & text, char ch)
{
    text += ch;
}
void backkey(string &text)
{
    if (text.length() == 0)
        return;
    text.pop_back();
}


void edit(string &text, char ch)
{
    if (ch == 'B')
        backkey(text);
    else
        insert(text, ch);
}

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

    for (auto s : S) {
        edit(ans, s);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
int main()
{
	std::string S;
	std::cin >> S;
	bool first = true;
	int max_count = 0;
	int count = 0;
	for (int i = 0; i < 3; ++i) {
		if (S[i] == 'R') {
			++count;
			if (count > max_count) {
				max_count = count;
			}
		}
		else {
			count = 0;
		}
	}
	std::cout << max_count << std::endl;
	return 0;
}

Measured memory_bytes: 3624
N = int(input())
h = list(map(int, input().split()))


def calc(arr):
    count = min(arr)
    l = 0
    new_arr = [arr[i] - count for i in range(len(arr))]
    for i, v in enumerate(new_arr):
        if v == 0:
            if l < i:
                count += calc(new_arr[l:i])
            l = i + 1
    if l < len(new_arr):
        count += calc(new_arr[l:len(new_arr)])

    return count


ans = calc(h)
print(ans)

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

int main()
{
    long long int n,i,a=0,b=0,c=0,d=0;
    string x;

    cin>>n;
    while(n--)
    {
        cin>>x;

        if(x=="AC")
            a++;

        else if(x=="WA")
            b++;

        else if(x=="TLE")
            c++;

        else if(x=="RE")
            d++;
    }

    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;

    return 0;
}


Measured memory_bytes: 3632
a,b,c,d=[int(i) for i in input().split()]
M=[4*a,2*b,c,d/2]
N=int(input())

if M[0]==min(M):
    print(N*M[0])
elif M[1]==min(M):
    print(N*M[1])
elif M[2]==min(M):
    print(N*M[2])
else:
    if N%2==0:
        print(int(N//2*int(M[3]*2)))
    else:
        if M[0]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[0])
        elif M[1]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[1])
        elif M[2]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[2])


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

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
// all_of

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

#if _DEBUG
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#endif

LL N, A, B;
LL X[100000];
int main() {
	cin >> N >> A >> B;
	REP(i, 0, N) {
		cin >> X[i];
	}
	LL sum = 0;
	REP(i, 0, N - 1) {
		sum += min((X[i + 1] - X[i]) * A, B);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int N;
vector<int> x(10);
vector<int> y(10);

double dist(int i,int j){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}
int main()
{
    cin >> N;
    double ans = 0.0;
    vector<int> v(N);
    for (int i = 0; i < N;i++)
    {
        v[i] = i + 1;
    }
    for (int i = 1; i <= N; i++)
    {
        cin >> x[i] >> y[i];
    }
    do{
        for (int i = 0; i < N - 1;i++)
        {
            ans = ans + dist(v[i],v[i+1]);
        }
    } while (next_permutation(v.begin(),v.end()));
    int fac = 1;
    for (int i = 2; i <= N;i++)
    {
        fac *= i;
    }
    ans /= fac;
    cout <<fixed<< ans <<setprecision(10)<< endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b,x;
    cin >> x;
    for(int a=1;a<=9;a++){
        for(int b=1;b<=9;b++){
            if(a*b==x){
                cout<<"Yes";
                return 0;
            }
            
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);

        //出力
        Console.WriteLine(nCm(N, 2) + nCm(M, 2));
    }

    static public int nCm(int n, int m)
    {
        if (m == 0) return 1;
        if (n == 0) return 0;
        return n * nCm(n - 1, m - 1) / m;
    }
}

Measured memory_bytes: 13140
# -*- coding: utf-8 -*-
"""
Created on Tue May  5 14:08:29 2020

@author: Sakai
"""


c = str(input())
if c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o':
    print('vowel')
else:
    print('consonant')

Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int cnt[30];
int main()
{
    string s;
    cin >>s;
    for(int i = 0 ; i < s.length() ; i ++)
    {
        cnt[s[i]-'a']++;
    }
    for(int i = 0 ; i < 26  ; i++)
    {
        if(cnt[i]%2!=0)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

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

int A, B, M;
vector<int> a, b;
int res = INT_MAX;
int mina, minb;


int main(void){
    cin >> A >> B >> M;
    rep(i, A){
        int ak;
        cin >> ak;
        a.push_back(ak);
    }
    rep(i, B){
        int bk;
        cin >> bk;
        b.push_back(bk);
    }
    rep(i, M){
        int x, y, c;
        cin >> x >> y >> c;
        res = min(res, a[x-1]+b[y-1]-c);
    }
    
    mina = *min_element(a.begin(), a.end());
    minb = *min_element(b.begin(), b.end());
    res = min(res, mina+minb);

    cout << res << endl;
    return 0;
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  set<int> s;
  while (k--) {
    int l, x;
    cin >> l;
    while (l--) {
      cin >> x;
      s.insert(x);
    }
  }
  cout << n - (int) s.size() << "\n";
  return 0;
}


Measured memory_bytes: 3648
import java.util.*;

class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int h = sc.nextInt();
      	int w = sc.nextInt();
      	int k = sc.nextInt();
      	
      	char[][] M = new char[h][w];
      	for (int i=0; i<h; i++) {
          	String s = sc.next();
        	for (int j=0; j<w; j++) {
            	M[i][j] = s.charAt(j);
            }
        }
      	
      	int c = 0, black_counter = 0;//counter
      	String r, l;
      	for (int i=0; i<(int)Math.pow(2, h); i++) {
        	for (int j=0; j<(int)Math.pow(2, w); j++) {
              	black_counter = 0;
            	r = Integer.toBinaryString(i);
              	l = Integer.toBinaryString(j);
              	int x = 0, y = 0;
              	while (r.length()<h) {r = '0' + r; x++;}
              	while (l.length()<w) {l = '0' + l; y++;}
              
              
              	for (int m=0; m<h; m++) {
                  	for (int n=0; n<w; n++) {
                    	if ((r.charAt(m)=='0')&&(l.charAt(n)=='1')&&(M[m][n]=='#')) {
                          	black_counter++;
                        }
                    }
                }
              	if (black_counter==k) {c++;}
            }
        }
      	System.out.println(c);
    }
}

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

int main() {
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);
    const string h = "Heisei";
    const string r = "TBD";
    string ans = h;
    if(y > 2019 || (y == 2019 && m > 4))
        ans = r;
    cout << ans << endl;
    return 0;
}


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

/* 
  idea : for each number, find the leftmost and rightmost point 
  which this number can be the minimum value in that range

  and add that l * r * number to our sum
*/

int main(){
  int n, arr[200005], left[200005], right[200005];
  cin >> n;
  for(int i=1; i<=n; i++){
    cin >> arr[i];
  }

  vector<int> stack;
  for(int i=1; i<=n; i++){
    while(!stack.empty() && arr[stack.back()] >= arr[i]) stack.pop_back();
    left[i] = (stack.empty() ? i : i - stack.back());
    stack.push_back(i);
  }

  stack.clear();
  for(int i=n; i>=1; i--){
    while(!stack.empty() && arr[stack.back()] >= arr[i]) stack.pop_back();
    right[i] = (stack.empty() ? (n-i+1) : stack.back()-i);
    stack.push_back(i);
  }

  long long ans = 0;
  for(int i=1; i<=n; i++) ans += 1ll * left[i] * right[i] * arr[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6584
// WeirdBugsButOkay

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

void solve()
{
    string s,t;
    cin >> s >> t;
    if(s.size() + 1 != t.size())
    {
        cout << "No" << endl;
        return;
    }
    for(ll i = 0; i < s.size(); i++)
    {
        if(s[i] != t[i])
        {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++)
    {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define ll long long
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  int a,b;
  cin>>a>>b;
  if(a+b>=10)cout<<"error"<<endl;
  else cout<<a+b<<endl;
  return 0;
}


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

int main(){

int A,B,K;
cin>>A>>B>>K;
int ans=0;

for(int i=A;ans<=K;--i){
if(A%i==0&&B%i==0){ans++;}

if(ans==K) {
  cout<<i<<endl;
  break;
}
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	string ans;
	if(a + b == c || a + c == b || b + c == a) ans = "Yes";
	else ans = "No";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
 
signed main(){
    int n;  cin >> n;
    vi a(n), b(n), c(n);
    rep(i, n)cin >> a[i];
    rep(i, n)cin >> b[i];
    rep(i, n)cin >> c[i];
 
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    
    vi b_sum(n + 1, 0);
    rep(i, n){
        auto c_st = upper_bound(all(c), b[i]);
        if(c_st == c.end())break;
        b_sum[i + 1] = distance(c_st ,c.end());
    }
 
    loop(i, 1, n + 1)
        b_sum[i] += b_sum[i - 1];
 
 
    vi a_sum(n + 1, 0);
    rep(i, n){
        auto b_st = upper_bound(all(b), a[i]);
        if(b_st == b.end())break;
        a_sum[i + 1] = b_sum[n] - b_sum[distance(b.begin(), b_st)];
    }
 
    loop(i, 1, n + 1)
        a_sum[i] += a_sum[i - 1];
    cout << a_sum[n] << endl;
}

Measured memory_bytes: 4224
var
  x,y:longint;
begin
  readln(x,y);
  if odd(x*4-y) then begin writeln('No');exit;end;
  if x*4-y<0 then begin writeln('No');exit;end;
  if odd(y-x*2) then begin writeln('No');exit;end;
  if y-x*2<0 then begin writeln('No');exit;end;
  writeln('Yes');
end.

Measured memory_bytes: 1376
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#define For(i, a, b) for (int i = a; i < b; ++i)
#define Out(i, a, b) for (int i = a - 1; i >= b; --i)
#define pb push_back
#define x first
#define y second
#define files(FileName) read(FileName); write(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
 
  
const string FileName = "input";
 
typedef long long base;
 
const int MAXN = 2e4;
 
bitset <5001> bag[5002][2];

int n, k;
int arr[5002];
 
int main() {
    ios::sync_with_stdio(0);
    //read(FileName);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i + 1];
    }
    bag[0][0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        bag[i][0] |= bag[i - 1][0];
        bag[i][0] |= bag[i - 1][0] << arr[i];
    }
    bag[n + 1][1][0] = 1;
    for (int i = n; i >= 1; --i) {
        bag[i][1] |= bag[i + 1][1];
        bag[i][1] |= bag[i + 1][1] << arr[i];
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        if (arr[i] > k) continue;
        int L = k, R = k - 1, sum = 0;
        bool OK = false;
        //cout << bag[i + 1][1][0] << endl;
        for (int j = 0; j < k; ++j) {

            if (bag[i - 1][0][j]) {
                while (j + L > k - arr[i]) {
                    --L;
                    if (L >= 0)
                        sum += bag[i + 1][1][L];
                }
                while (j + R > k - 1) {
                    if (R >= 0) 
                        sum -= bag[i + 1][1][R];
                    --R;
                }
                //cout << arr[i] << ' ' << j << ' ' << j + L << ' ' << j + R << ' ' << sum << endl;
                if (sum) {
                    OK = true;
                    break;
                }
            }
        }
        if (!OK) cnt++;
    }
    cout << cnt << endl;
}  
 
/*
2 AB 11
2!2
3 ABB 122
3!3
4 ABB 2222
4!3
5 ABBBB 12222
5!5
6 ABBB 121222
6!4
7 ABBBB 1212122
7!5
8 ABBB 12121212
8!4
9 ABBBBBBBB 122222222
9!9
10 ABBBBB 1212222222
10!6
11 ABBBBBBBB 12121222222
11!9
12 ABBBBB 121212122222
12!6
13 ABBBBBBBB 1212121212222
13!9
14 ABBBBB 12121212121222
14!6
15 ABBBBBBBB 121212121212122
15!9
16 ABBBBB 1212121212121212
16!6
17 ABBBBBBBBBBBBBBBB 12222222222222222
17!17
18 ABBBBBBBBB 121222222222222222
18!10
19 ABBBBBBBBBBBBBBBB 1212122222222222222
19!17
20 ABBBBBBBBB 12121212222222222222
20!10
[Finished in 3.1s]
*/

Measured memory_bytes: 6400
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int n, m;

struct Edge {
  int dst, cap;
  Edge *rev;
  Edge(): dst(0), cap(0), rev(nullptr){}
  Edge(int dst, int cap, Edge *rev): dst(dst), cap(cap), rev(rev){}
};

vector<Edge> g[300];

void addEdge(int src, int dst){
  g[src].emplace_back(dst, 1, nullptr);
  g[dst].emplace_back(src, 0, nullptr);
  g[src].back().rev = &g[dst].back();
  g[dst].back().rev = &g[src].back();

  g[dst].emplace_back(src, 1, nullptr);
  g[src].emplace_back(dst, 0, nullptr);
  g[dst].back().rev = &g[src].back();
  g[src].back().rev = &g[dst].back();
}

bool used[300];

int dfs(int v, int t, int f){
  if (v == t) return f;
  used[v] = true;
  each(e, g[v]){
    if (!used[e.dst] && e.cap > 0){
      int d = dfs(e.dst, t, min(f, e.cap));
      if (d > 0){
        e.cap -= d;
        e.rev->cap += d;
        return d;
      }
    }
  }
  return 0;
}

int maxFlow(int s, int t){
  int flow = 0;
  while (true){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, inf);
    if (f == 0) return flow;
    flow += f;
  }
}

Edge *tar[1000];

int main(){
  cin >> n >> m;
  rep(i, n) g[i].reserve(m * 2);
  rep(i, m){
    int s, t;
    cin >> s >> t, s--, t--;
    addEdge(s, t);
    tar[i] = &g[t].back();
  }
  int s, t;
  cin >> s >> t, s--, t--;
  cout << maxFlow(s, t) << endl;
  vector<int> res;
  rep(i, m){
    if (tar[i]->cap == 0){// 逆向きの辺が使われている
      res.push_back(i + 1);
    }
  }
  cout << res.size() << endl;
  each(x, res) cout << x << endl;
}

Measured memory_bytes: 4304
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    MOD = 10 ** 9 + 7
    
    sum_a = sum(A)
    sum_squares = sum([a * a for a in A])
    
    ans = (sum_a ** 2 - sum_squares) // 2
    ans %= MOD

    print(ans)
    
    
if __name__ == '__main__':
    main()  

Measured memory_bytes: 31564
N = gets.to_i
D,X = gets.split(" ").map { |item| item.to_i }
a = []
for i in 0..N-1 do
  ai = gets.to_i
  a << ai
end

count = []
for i in 0..N-1 do
  count[i] = 1 + (D-1)/a[i]
end

res = X
for i in 0..N-1 do
  res += count[i]
end

puts res


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    sort(a.begin(),a.end());
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(a[i] + a[j] <= a[k])break;
                else ans++;
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1, i##_end_ = (n); i <= i##_end_; ++i)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

int r, g, b, n;
int main() {
    scanf("%d%d%d%d", &r, &g, &b, &n);
    int ans = 0;
    for(int R = 0; R <= n; R += r) {
        for(int G = 0; R + G <= n; G += g) {
            if((n-R-G) % b == 0) ans++;
        }
    }
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
const main = x => {
    s = x[0];
    var i, ans=0, value;
    for(i=0; i<s.length-2; i++) {
        value = Math.abs(753-parseInt(s.slice(i,i+3)));
        ans = ans?Math.min(ans, value):value;
    }
    console.log(ans);
    
};
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 21192
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

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

int main() {
    
    int N;
    cin >> N;
    vector<ll> A(N);
    ll all = 0;
    REP(i, N) {
        cin >> A[i];
        all ^= A[i];
    }
    REP(i, N) {
        ll ans = all^A[i];
        cout << ans;
        if (i != N-1) cout << " ";
    }
    cout << endl;
    
    return 0;
}


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

int main(){
    string s; cin >> s;
    string t; cin >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
"""
A - Happy Birthday!
"""

a, b = map(int, input().split())

if a < b:
    temp = a
    a = b
    b = temp

piza = 16
for i in range(16):
    if (i % 2) == 0 and a != 0:
        piza -= 1
        a -= 1
    elif b != 0:
        piza -= 1
        b -= 1
    elif a == 0 and b == 0:
        break

if a != 0 or b != 0:
    print(":(")
else:
    print("Yay!")

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

struct Dice {
        int s[6];

        void roll (char c) {
                int b;
                if (c == 'E') {
                        b = s[0];
                        s[0] = s[3];
                        s[3] = s[5];
                        s[5] = s[2];
                        s[2] = b;
                }
                if (c == 'W') {
                        b = s[0];
                        s[0] = s[2];
                        s[2] = s[5];
                        s[5] = s[3];
                        s[3] = b;
                }
                if (c == 'N') {
                        b = s[0];
                        s[0] = s[1];
                        s[1] = s[5];
                        s[5] = s[4];
                        s[4] = b;
                }
                if (c == 'S') {
                        b = s[0];
                        s[0] = s[4];
                        s[4] = s[5];
                        s[5] = s[1];
                        s[1] = b;
                }
        }

        int top() {
                return s[0];
        }
};


int main()
{
        Dice d;
        for (int i = 0; i < 6; ++i) {
                cin >> d.s[i];
        }
        string op;
        cin >> op;
        for (int i = 0; i < op.length(); ++i) {
                d.roll(op[i]);
        }
        cout << d.top() << endl;
}



Measured memory_bytes: 3224
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int b1 = sc.nextInt();
		int b2 = sc.nextInt();
		int b3 = sc.nextInt();
		
		if(b1 == 1)
			if(b2 == 1)
				System.out.println("Open");
			else
				System.out.println("Close");
		
		else
			if(b2 == 1)
				System.out.println("Close");
			else{
				if(b3 == 1)
					System.out.println("Open");
				else
					System.out.println("Close");
			}
		sc.close();
	}
}

Measured memory_bytes: 17160
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		int result = 0;
		if(s.equals("SSS")) result = 0;
		if(s.equals("SSR")) result = 1;
		if(s.equals("SRS")) result = 1;
		if(s.equals("SRR")) result = 2;
		if(s.equals("RSS")) result = 1;
		if(s.equals("RSR")) result = 1;
		if(s.equals("RRS")) result = 2;
		if(s.equals("RRR")) result = 3;
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 25344
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    vector<ll> dp1(N+1),dp2(N+1);
    dp2[0] = 1;
    reverse(all(S));
    rep(i,N) {
        int k = S[i] - '0';
        dp1[i+1] = min(dp1[i],dp2[i]+1) + k;
        dp2[i+1] = min(dp1[i]+10-k,dp2[i]+9-k);
    }

    cout << min(dp1[N],dp2[N]+1) << ln;
}

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

using namespace std;

int main(int r, int c) {
    cin >> r >> c;
    int a;
    int A[r+1][c+1] = {};
    for (int i = 0; i < r;  i++) {
        for (int j = 0; j < c; j++) {
            cin >> a;
            A[i][j] += a;
            A[r][j] += a;
            A[i][c] += a;
        }
    }
    for (int i = 0; i < r; i++) {
        A[r][c] += A[i][c];
    }
    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            if (j > 0) cout << " ";
            cout << A[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
int par(int i){
  return i / 2;
}
int lef(int i){
  return i * 2;
}
int rig(int i){
  return 2 * i + 1;
}

int A[2000000 + 10];
int h = 0;

void insert(int key){
  h++;
  A[h] = key;
  int i = h;
  while(i > 1 && A[par(i)] < A[i]){
    swap(A[i],A[par(i)]);
    i = par(i);
  }
}

void max_h(int *B,int i){
  int l = lef(i);
  int r = rig(i);
  int lar = i;
  if(l <= h && B[lar] < B[l]) lar = l;
  if(r <= h && B[lar] < B[r]) lar = r;

  if(i != lar){
    swap(B[i],B[lar]);
    max_h(B,lar);
  }
}

int extra(){
  int maxi = A[1];
  A[1] = A[h];
  h--;
  max_h(A,1);
  return maxi;
}
//-----------------------------------------

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


  string s;
  while(1){
    cin >> s;
    string t = s.substr(0,2);
    if(t == "en") break;
    if(t == "ex"){
      cout << extra() <<endl;
    }
    else{
      int a;
      cin >> a;
      insert(a);
    }
  }





  return 0;
}



Measured memory_bytes: 7116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e7+5;
vector<ll> V;
ll cnt[maxn];
int main() {
    for(int i=1;i<maxn;i++) 
    	for(int j=i;j<maxn;j+=i) cnt[j]++;
    int n;ll ans=0;cin>>n;
	for(int i=1;i<=n;i++) ans+=cnt[i]*i;
		cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 81732
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)

template <typename T> lint gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> lint lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c; cin >> c;
  cout << ++c << '\n';
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
#define inf 1e9+1
#define Inf 223372036854775807
#define maxn 1010000
#define eps 1e-8
const ll mod=998244353;

ll h, w, n;

int main()
{
    cin>>h>>w>>n;
    if (h<w) swap(h, w);
    cout<<(n+h-1)/h;
    return 0;
}


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

A = list(map(int,input().split()))
 
MAX = 10 ** 5 + 1
MOD = 10 ** 9 + 7
 
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
  
for i in range(MAX, 0, -1):
    finv[i - 1] = finv[i] * i % MOD
 
def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD

A.sort()
ans = 0
for i in range(N):
    if i >= K - 1:
        ans += comb(i, K - 1) * A[i]
    if i + K - 1 < N:
        ans -= comb(N - i - 1, K - 1) * A[i]
    ans %= MOD
print(ans)
 

Measured memory_bytes: 87932
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;

ll solve(void);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}


ll solve(void)
{
	map<string, string> m;
	m["Sunny"] = "Cloudy";
	m["Cloudy"] = "Rainy";
	m["Rainy"] = "Sunny";

	string s;
	cin >> s;

	cout << m[s] << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, K;
	vector<int> A;
	
	
	cin>>N>>K;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
	}
	
	for(int i = K; i < N; i++){
		if(A[i-K] < A[i]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4780
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main () {

	int N;
	cin >> N;

	vector<long> a(N);
	for(auto &x: a) cin >> x;

	vector<vector<long> > dp(N + 1, vector<long>(N + 1, 0));

	for(int i = N - 1; i >= 0; i--) {
		for(int j = 0; j <= i; j++) {
			if(i % 2 == 0) {
				dp[i - j][j] = max(dp[i - j + 1][j] + a[i - j], dp[i - j][j + 1] + a[N - j - 1]);
			} else {
				dp[i - j][j] = min(dp[i - j + 1][j] - a[i - j], dp[i - j][j + 1] - a[N - j - 1]);
			}
		}
	}

	cout << dp[0][0] << endl;
}


Measured memory_bytes: 70784