akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
  int n,m,t,l,e,d;
  vector<int> v;
  vector<int> vv;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>d;
    v.push_back(d);
  }
  sort(v.begin(),v.begin()+n);
  cin>>m;
  for(int j=0;j<m;j++){
    cin>>t;
    vv.push_back(t);
  }
  sort(vv.begin(),vv.begin()+m);
  l=0;e=0;
  if(m>n){cout<<"NO"<<endl;return 0;}
  while(l<m){
    if(vv[l]==v[e]){
      l++;e++;
    }else if(vv[l]<v[e]){
      cout<<"NO"<<endl;return 0;
    }else{
      e++;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 2548
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;
llong a[100005];

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

    sort(a, a + n);

    auto f = [&](llong s) {
        llong i;
        llong sum = 0;
        for (i = 0; i <= s; i++) {
            sum += a[i];
        }

        for (i = s + 1; i < n; i++) {
            if (sum * 2 >= a[i]) sum += a[i];
            else break;
        }

        if (i == n) return true;
        else return false;
    };

    llong valid, invalid;
    llong mid;
    valid = n - 1;
    invalid = -1;

    while (valid - invalid > 1) {
        mid = (valid + invalid) / 2;

        if (f(mid)) {
            valid = mid;
        }
        else {
            invalid = mid;
        }
    }

    cout << n - valid << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N;
l_l a[105];

l_l f(string s) {
    ll delta = 0;
    ll minimum = 0;
    for(auto c : s) {
        if(c == '(') delta++;
        else delta--;
        chmin(minimum, delta);
    }
    return {delta, minimum};
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    vector<l_l> one, two;
    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        l_l now = f(s);
        if(now.first >= 0) {
            one.push_back({-now.second, now.first});
        } else {
            two.push_back({now.second - now.first, now.first});
        }
    }
    sort(one.begin(), one.end());
    sort(two.begin(), two.end());
    ll now = 0;
    bool ok = true;
    for(auto tmp : one) {
        //cerr << -tmp.first << " " << tmp.second << endl;
        if(now < tmp.first) ok = false;
        now += tmp.second;
    }
    for(auto tmp : two) {
        //cerr << tmp.first << " " << tmp.second << endl;
        if(now < -tmp.first - tmp.second) ok = false;
        now += tmp.second;
    }
    if(now != 0) ok = false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 19020
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;
const ll INF = 1e10;

int n;
ll a[MAXN];

void solve() {
  int cntMinus = 0;
  ll minimum = INF;
  ll sum = 0;
  for (int i=0;i<n;i++) {
    if (a[i] < 0) {
      cntMinus++;
    }
    sum += abs(a[i]);
    minimum = min(abs(a[i]), minimum);
  }
  if (cntMinus & 1) {
    sum -= minimum * 2;
  }
  cout << sum << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i];
  }
  solve();
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    //--<for debugging>
    #define whatis(x) cout << #x << " is " << x<<" ";
    #define whatisl(x) cout << #x << " is " << x<<"\n";
    #define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
    #define lline cout<<"\n";
    #define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
    #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
        
    void err(istream_iterator<string> it) {}
    template<typename T, typename... Args>
    void err(istream_iterator<string> it, T a, Args... args) {
        cout << *it << " = " << a <<" , ";
        err(++it, args...);
    }
    //--</for debugging> 
    #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
    #define testcase ll tt; cin >> tt; while(tt--)
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
    #define pb push_back 
    #define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
    #define vll vector<ll>
    #define pll pair<ll,ll>
    #define sll set<ll>
    #define pint pair<int,int>
    const ll INF=1e9+7;
    const ll MOD=1e9+7;
    int main()
    {
        boost vars
        string str,temp;;
        cin>>str;
        reverse(str.begin(),str.end());
        n=str.length();
        for(i=0;i<n;i++)
        {
            temp=str.substr(i,5);
            reverse(temp.begin(),temp.end());
            //error(temp);
            if(temp=="dream"||temp=="erase"){i=i+4;continue;}
            temp=str.substr(i,6);
            reverse(temp.begin(),temp.end());
            //error(temp);
            if(temp=="eraser"){i=i+5;continue;}
            temp=str.substr(i,7);
            reverse(temp.begin(),temp.end());
            //errorl(temp);
            if(temp=="dreamer"){i=i+6;continue;}
            break;
        }
        if(i>=n)cout<<"YES";
        else cout<<"NO";
    }

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int oo = 1e9;
int main()
{
    int no_of_stones, no_of_steps;
    cin >> no_of_stones >> no_of_steps;
    vector <int> height(no_of_stones + 1, 0);
    for(int i = 1; i <= no_of_stones; i++)
    {
        cin >> height[i];
    }
    vector<int>minimum_cost(no_of_stones + 1, oo);
    minimum_cost[1] = 0;
    for(int i=2;i<=no_of_stones;i++)
    {
        for(int j=i-1;j>=max(1,i-no_of_steps);j--)
        {
            minimum_cost[i] = min(minimum_cost[i], minimum_cost[j] + abs(height[i] - height[j]));
        }
    }
    cout << minimum_cost[no_of_stones];
    return 0;
}


Measured memory_bytes: 4064
#include<iostream>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<typeinfo>
using namespace std;

int main(){
    int N, A;
    cin >> N;
    vector<int> AList(100000, 0);
    for(int i=0;i<N;i++){
        cin >> A;
        AList[A-1] += 1;
    }

    int S = 0;
    for (int i=0;i<100000;i++){
        if(AList[i] > 1) S += (AList[i] -1);
    }
    if(S % 2 == 0) cout << N - S << endl;
    if(S % 2 == 1) cout << N - S - 1 << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="Good";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int L=sc.nextInt();

        int l[]=new int[N];
        int key=0;
        for (int i=0;i<N;i++)
        {
            l[i]=L+i;
            if (Math.abs(l[i]) < min)
            {
                min=Math.abs(l[i]);
                key=i;
            }
//            System.err.println("aji "+l[i]);
        }
//        System.err.println(min);
//        System.err.println(key);
        for (int i=0;i<N;i++)
        {
            if (i!=key)
            {
//                System.err.println("aji "+l[i]);
                answer+=l[i];
            }
        }

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    long long ans = 0;
    int w = -1;
    bool flag = false;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'W') {
            w++;
            if (flag) {
                ans += i - w;
            }
        } else {
            flag = true;
        }
    }
    cout << ans;
}

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

int main(){
  double x1, x2, y1, y2;
  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  printf("%lf\n", sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
  return 0;
}


Measured memory_bytes: 2100
#include <cstdio>
#include <algorithm>

const int MAXN = 55;
const int MOD = 1000000007;

struct Matrix {
    int n, m;
    long long a[MAXN][MAXN];

    Matrix() {}
    Matrix(int n, int m, bool eye = false) : n(n), m(m) {
        for (int i = 0; i < n; i++) std::fill(a[i], a[i] + m, 0);
        if (eye) for (int i = 0; i < n; i++) a[i][i] = 1;
    }

    long long *operator[](int i) {
        return a[i];
    }
    const long long *operator[](int i) const {
        return a[i];
    }

    Matrix operator*(const Matrix &rhs) const {
        Matrix res(n, rhs.m);
        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (a[i][j]) {
            for (int k = 0; k < rhs.m; k++) {
                res[i][k] += a[i][j] * rhs[j][k] % MOD;
                res[i][k] >= MOD ? res[i][k] -= MOD : 0;
            }
        }
        return res;
    }
} A;

Matrix qpow(Matrix &a, long long n) {
    Matrix res(a.n, a.m, true);
    for (; n; n >>= 1, a = a * a) if (n & 1) res = res * a;
    return res;
}

int main() {
    int n;
    long long K;
    scanf("%d %lld", &n, &K);
    A.n = A.m = n;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%lld", &A[i][j]);

    A = qpow(A, K);
    long long ans = 0;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
        ans += A[i][j];
        ans >= MOD ? ans -= MOD : 0;
    }
    printf("%lld\n", ans);
    
    return 0;
}

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

int main(){

  int s = 0;
  int a[1000000] = {};
  bool loop = true;

  cin >> s;

  int j = 0;
  // initial term //
  a[j] = s;
  while(loop){
    j++;
    
    if(a[j-1] % 2 == 0 ){
      a[j] = a[j-1]/2;
    };
    
    if(a[j-1] % 2 == 1 ){
      a[j] = 3 * a[j-1] + 1;
    };
    
    for(int i = 0 ; i < j ; i++ ){
      // cout << a[j] << "\t" << a[i] << endl;
      if( a[j] == a[i] ) {
        loop = false;
        break;
      }
    }
  }
  cout << j+1 << endl;
}

Measured memory_bytes: 4096
//
//  main.cpp
//  usaco
//
//  Created by 김현수 on 2020/08/30.
//  Copyright © 2020 김현수. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
    int a;
    scanf("%d", &a);
    if(a%2==0)
    {
        printf("%d", a);
    }
    else if(a%2!=0)
    {
        printf("%d", a*2);
    }
}


Measured memory_bytes: 3656
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func call(n int) {
	for i := 1; i <= n; i++ {
		x := i
		if x%3 == 0 {
			fmt.Printf(" %d", i)
		} else {
			for x > 0 {
				if x%10 == 3 {
					fmt.Printf(" %d", i)
					break
				}
				x /= 10
			}
		}
	}
	fmt.Println()
}

func main() {
	rd := bufio.NewReader(os.Stdin)
	for {
		s, err := rd.ReadString('\n')
		if err == io.EOF {
			return
		}
		arr := strings.Split(strings.TrimSpace(s), " ")
		x, _ := strconv.Atoi(arr[0])
		call(x)
	}
}



Measured memory_bytes: 1140
//2019.7.7 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-12
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
//inline int read() {
//    res s=0,ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
inline int read() {
    res s=0,ch=gc(),w=1;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s*w;
}
inline LL Read() {
    RG LL s=0;
    res ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int kcz=1e9+7;
const int N=1e5+10;
namespace MAIN{
    int n,k;
    struct E{
        int next,to;
        E() {}
        E(res next,res to):next(next),to(to) {}
    }edge[N<<1];
    int head[N],cnt,du[N];
    inline void addedge(const res &u,const res &v){
        edge[++cnt]=E(head[u],v),head[u]=cnt,du[u]++;
        edge[++cnt]=E(head[v],u),head[v]=cnt,du[v]++;
    }
    inline int mul(const res &x,const res &y){
        return int(1LL*x*y%kcz);
    }
    int dp[N],fa[N],sz[N],ans=1;
    void dfs(res x,res fax){
        fa[x]=fax;
        for(res i=head[x];~i;i=edge[i].next){
            res tox=edge[i].to;
            if(tox==fax)continue;
            sz[x]++,dfs(tox,x);
        }
        res op=k;
        if(fa[fa[x]])op--;
        if(fa[x])op--;
        op-=sz[fa[x]];
        if(fa[x])op++;
//        printf("%d %d\n",op,x);
        if(op<=0){puts("0");exit(0);}
        ans=mul(ans,op);
    }
    inline void MAIN(){
        n=read(),k=read();
        for(res i=1;i<=n;i++)head[i]=-1;
        for(res i=1;i<n;i++){
            res u=read(),v=read();
            addedge(u,v);
        }
        dfs(1,0);
        printf("%d\n",ans);
    }
}
int main() {
//    srand((unsigned)time(NULL));
    // freopen("zao.in","r",stdin);
    // freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

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

    rep(i, 0, n + 1) rep(j, 0, n + 1) {
        int k = n - i - j;
        if (k < 0 || n < k) continue;
        int sum = i * 10000 + j * 5000 + k * 1000;
        if (sum == y) {
            cout << i << " " << j << " " << k << endl;
            return 0;
        }
    }
    
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    n,x=map(int,input().split())
    s=0
    if n==0 and x==0:
        break
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    s+=1
    print(s)


Measured memory_bytes: 5596
#include <stdio.h>

void Do(int S){
  int a, b, ma, mb;
  a = S / 100;
  b = S % 100;
  if(a > 0 && a <= 12) ma = 1;
  else ma = 0;
  if(b > 0 && b <= 12) mb = 1;
  else mb = 0;
  if(ma == 1 && mb == 1) printf("AMBIGUOUS\n");
  else if(ma == 1 && mb == 0) printf("MMYY\n");
  else if(ma == 0 && mb == 1) printf("YYMM\n");
  else printf("NA\n");
}

int main(void){
  int S;
  scanf("%d", &S);
  Do(S);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pcase printf("Case %d: ",c)
int c=1;
using namespace std;
int main(){
    string a ,b;
    cin>>a;
    cin>>b;
    int l = a.length();
    int s = 0;
    for(int i =0;i<l;i++){
    if(a[i]!= b[i]){s++;}

}
cout<<s<<endl;
}



Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
int s(int x,int y)
{
    if(x<=y)
		return y-x;
    else 
		return x-y+2;
}
int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    printf("%d\n",min(s(x,y),min(s(-x,y)+1,min(s(x,-y)+1,s(-x,-y)+2))));
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

def main():
	N = int(input())
	plan = []
	for _ in range(N):
		a, b, c = map(int, input().split(" "))
		plan.append((a, b, c))
		
	DP = [[-1 for _ in range(3)] for _ in range(N)]
	a, b, c = plan[0]
	DP[0][0] = a
	DP[0][1] = b
	DP[0][2] = c
	
	for i in range(1, len(plan)):
		a, b, c = plan[i]
		DP[i][0] = a + max(DP[i-1][1], DP[i-1][2])
		DP[i][1] = b + max(DP[i-1][0], DP[i-1][2])
		DP[i][2] = c + max(DP[i-1][0], DP[i-1][1])
		
	print(max(DP[-1][0], DP[-1][1], DP[-1][2]))
		
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 41760
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main()
{
    cin>>S;
    N = S.size();
    vec num(2019, 0);
    ++num[0];
    ll temp = 1, sum = 0, mod = 2019, ans = 0;
    Rrep(i,N)
    {
        (sum += temp * (S[i] - '0'))%=mod;
        ans += num[sum];
        ++num[sum];
        (temp *= 10)%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3724
N = int(input())
int2char = {i: chr(i + 96) for i in range(1, 11)}
ans = ['a']
for n in range(2, N+1):
    new_list = []
    for string in ans:
        str_set = set(string)
        for i in range(1, n+1):
            if len(str_set) + 1< i:
                continue 
            new_str = string + int2char[i]
            new_list.append(new_str)
    ans = new_list
ans = sorted(ans)
for a in ans:
    print(a)                



    



Measured memory_bytes: 57436
#include<iostream>

using namespace std;

int main(){
  int a,flag = 0;
  cin>>a;
  for(int i= 1;i<10;i++){
    for(int j= 1;j<10;j++){
      if (i*j ==a) flag=1;
    }
  }
  if(flag == 1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#define min(a, b) ((a) < (b) ? (a) : (b))

int right_start(int A, int B, int C);

int left_start(int A, int B, int C)
{
	if (!B && !C) return 0;

	if (A & 1){
		return left_start(A>>1, B>>1, C>>1);
	}
	if (B & 1){
		return right_start(A>>1, B>>1, C>>1 ) + 1 + left_start(0, 0, (A|B|C)>>1 );
	}
	if (C & 1){
		return left_start(A>>1,B>>1,C>>1) + 1 + right_start((A|B|C)>>1, 0, 0) + 1 + left_start(0, 0, (A|B|C)>>1);
	}
}

int right_start(int A, int B, int C)
{
	if (!A && !B) return 0;

	if (C & 1){
		return right_start(A>>1, B>>1, C>>1);
	}
	if (B & 1){
		return left_start(A>>1, B>>1, C>>1) + 1 + right_start((A|B|C)>>1, 0, 0);
	}
	if (A & 1 ){
		return right_start(A>>1, B>>1, C>>1) + 1 + left_start(0, 0, (A|B|C)>>1) + 1 + right_start((A|B|C)>>1, 0, 0);
	}
}

int main(void)
{
	int n,m;
	int c_max,c;
	int i,j;
	int a;
	int cup[3];

	while(scanf("%d%d", &n, &m) && n+m){
		for(i=0;i<3;i++){
			cup[i] = 0;
			scanf("%d", &c_max);
			for(j=0;j<c_max;j++){
				scanf("%d", &c);
				cup[i] |= 1 << (c-1);
			}
		}

		a=min(left_start(cup[0],cup[1],cup[2]), right_start(cup[0],cup[1],cup[2]));
		printf("%d\n",(a>m?-1:a));
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
int n;
void selectionSort(vector<char>A,vector<int>B){
  bool flag=false;
  map<int,int>c;
  for(int i=0;i<n;i++){
    c[B[i]]++;
    if(c[B[i]]==2){
      for(int j=i+1;j<n;j++){
        if(B[i]>B[j]){
          flag=true;
          break;
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    int min_id=i;
    for(int j=i+1;j<n;j++){
      if(B[j]<B[min_id]){
        min_id=j;
      }
    }
    swap(A[i],A[min_id]);
    swap(B[i],B[min_id]);
  }
  for(int i=0;i<n;i++)cout<<A[i]<<B[i]<<(i==n-1?'\n':' ');
  cout<<(flag?"Not stable":"Stable")<<endl;
}
void bubbleSort(vector<char>A,vector<int>B){
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(B[j]<B[j-1]){
        swap(B[j],B[j-1]);
        swap(A[j],A[j-1]);
      }
    }
  }
  for(int i=0;i<n;i++)cout<<A[i]<<B[i]<<(i==n-1?'\n':' ');
  cout<<"Stable"<<endl;
}
int main(void){
  cin>>n;
  vector<char>A(n);
  vector<int>B(n);
  char c;
  int t;
  for(int i=0;i<n;i++){
    cin>>c>>t;
    A[i]=c;
    B[i]=t;
  }
  bubbleSort(A,B);
  selectionSort(A,B);
  return 0;
}



Measured memory_bytes: 3160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int N, M;
int ans;

signed main() {
	cin >> N >> M;

	ans = (N - M) * 100 + M * 1900;

	ans *= (1 << M);


	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//実行部
void Main()
{
  ll n, m; cin >> n >> m;
  vll a(m); rep(i, m) cin >> a[i];
  ll S = 0;
  rep(i, m) S += a[i];
  if(S > n) fin(-1);
  fin(n - S);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 3724
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Measured memory_bytes: 4492
#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()
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, m;
    cin >> n >> m;
    int ans = n*(n-1) / 2;
    ans += m*(m-1) /2 ;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use std::cmp::{min,max};

const SZ:usize = 18;

type i64 = i128;

fn powm(x:i64,k:i64,m:i64) -> i64{
    let mut k = k;
    let mut x = x%m;
    let mut ans = 1;
    while k>0 {
        if k&1==1 {
            ans = ans*x%m;
        }
        x = x*x%m;
        k>>=1;
    }
    return ans;
}

fn f(x:i64,n:i64,m:i64) -> i64{
    // eprintln!("f{}",n);
    if n<=0 { 0 } 
    else if n<=1 { 1 }
    else { 
        let hn = n/2;
        let tmp = f(x,hn,m);
        let lhs = tmp*(1+powm(x,hn,m))%m;
        let rhs = if n%2==1 {powm(x,n-1,m)} else {0};
        (lhs+rhs)%m
    }
}

fn g(x:i64,n:i64,m:i64) -> i64{
    // eprintln!("g{}",n);
    if n<=1 { 0 } 
    else { 
        let hn = n/2;
        let tmp = g(x,hn,m);
        let vl = tmp*(1+powm(x,hn,m))%m;
        let vr = hn%m*f(x,hn,m)%m*powm(x,hn,m)%m;
        let lhs = (vl+vr)%m;
        let rhs = if n%2==1 {(n-1)%m*powm(x,n-1,m)%m} else {0};
        (lhs+rhs)%m
    }
}

fn main() {
    input! {
        l:i64,
        a:i64,
        b:i64,
        m:i64
    };
    let max_v = a+b*(l-1);

    let mut ans = 0 ;
    let mut keta_sum = 0;
    for k in (0..SZ).rev() {
        let k = k as i64;
        let mut v = 1 as i64;
        for _ in 0..k { v*=10 }
        let v = v;
        if max_v<v || 10*v<=a {continue;}
        let lb = min(max((v-a+b-1)/b,0),l);
        let ub = max(min((v*10-a+b-1)/b,l),0);
        let rate = powm(10,keta_sum,m);
        let x = powm(10,k+1,m);
        let w = ub-lb;
        let lhs = (a%m+b%m*(((ub-1)%m)))%m*f(x,w,m)%m;
        let rhs = -b%m*g(x,w,m)%m;
        let sum = rate*((lhs+rhs)%m);
        let sum = (sum+m)%m;
        // eprintln!("lbub {} {} {} {}",lb,ub,keta_sum,sum);
        ans = ((ans + sum)%m+m)%m;    
        keta_sum += w*(k+1);
        
    }
    println!("{}",ans);
}




Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll x;
    cin  >> x;
    ll now = 100;
    ll cnt = 0;
    while (1) {
        cnt++;
        now *= 1.01;
        now = floor(now);
        if (now >= x) {
            cout << cnt << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            HashSet<int> hs = new HashSet<int>();

            for (int i = 0;; i++)
            {
                if (!hs.Add(N))
                {
                    Console.WriteLine(i + 1);
                    return;
                }

                if (0 == N % 2)
                {
                    N /= 2;
                }
                else
                {
                    N = 3 * N + 1;
                }
            }
        }
    }
}



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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

pair<int,int> v[105];
ll dp[105][100005];
int n, w;
bool mark[105][100005];

ll f(int i, int j) {
	if(i == n) return 0;
	if(mark[i][j]) return dp[i][j];
	mark[i][j] = true;

	ll ret = f(i+1, j);
	if(j >= v[i].ff)
		ret = max(ret, f(i+1, j-v[i].ff) + v[i].ss);

	return dp[i][j] = ret;
}

int main() {
	scanf("%d%d", &n, &w);

	for(int i = 0; i < n; i++)
		scanf("%d%d", &v[i].ff, &v[i].ss);

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

Measured memory_bytes: 89984
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>
#include <string.h>

using std::endl;
using std::string;

#define ll long long int
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std

int a = 0;

int main()
{
	string s;
	IN >> s;


	if (s[0] == 'o') a++;
	if (s[1] == 'o') a++;
	if (s[2] == 'o') a++;

	OUT << (700 + (100 * a)) << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
from operator import mul
from functools import reduce
heads = ["M","A","R","C","H"]

N = int(input())
S = [0,0,0,0,0]

for i in range(N):
  s = input()[0]
  if s in heads:
    n = heads.index(s)
    S[n] += 1

S = [i for i in S if i != 0]

nums = list(itertools.combinations(S,3))

total = 0

for list in nums:
  total += reduce(mul,list)

print(total)

Measured memory_bytes: 3540
#include <stdio.h>
/*
p==1 毒
p==0 健康
a 解毒剤入まずいクッキーの枚数
b 解毒剤入美味しいクッキーの枚数
c 毒入り美味しいクッキーの枚数
*/
int main(void){
    int a, b, c, cnt=0, p=0;

    scanf("%d %d %d", &a, &b, &c);

    while(1){
        if(p==0 && c>0){
            c=c-1;
            cnt++;
            p=1;
        }
        else if(c<=0)
            break;
        else  if(p==1 && b>0){
            b=b-1;
            cnt++;
            p=0;
        }
        else if(p==1 && a>0){
            a=a-1;
            p=0;
        }
        else
            break;
    }
    
    cnt=cnt+b;

    printf("%d\n", cnt);
    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
  long long H, N = 1,cnt = 0;
  cin >> H;
  while (H > 1){
    H = floor(H/2);
    cnt += N;
    N *= 2;
  }
  cout << cnt+N << endl;
}

Measured memory_bytes: 256
var
 n,i,x,max:longint;
 a:array[0..1000000] of longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   read(x);
   inc(a[x-1]);inc(a[x+1]);inc(a[x]);
  end;
 for i:=1 to 100000 do if a[i]>max then max:=a[i];
 writeln(max);
end.

Measured memory_bytes: 512
import sys
 
N=int(input())
#print(N)
A=input().split()
A_int = [int(s) for s in A]
#print(A_int)
if 0 in A_int:
  print(0)
  sys.exit()


ans=1
for i in range(N):
  ans=ans*A_int[i]
  if(ans>10**18):
    ans=-1
    break

print(ans)

Measured memory_bytes: 21592
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

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

	public Main() {
		while(sc.hasNext()){
			new aoj0095().doIt();
		}
	}
	class aoj0095 {	
		void doIt() {
			int n = sc.nextInt();
			int asum[] = new int [n+1];
			for(int i = 0;i < n;i++){
				int a = sc.nextInt();
				int v = sc.nextInt();
				asum[a] = asum[a] + v;
			}
			int maxa = 1;
			int maxv = 0;
			for(int i = 1;i <= n;i++){
				if(maxv < asum[i]){
					maxa = i;
					maxv = asum[i];
				}
			}
			System.out.println(maxa+" "+maxv);
		}
	}
}

Measured memory_bytes: 17376
#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007LL
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	if(exponent<0) exponent+=MOD-1;
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
bool visited[MAX];
int ans[MAX];
bool flag=true;
vector<pii> v[MAX];
int lefti[MAX];
void DFS(int n)
{
	visited[n]=true;
	for(auto i:v[n])
	{
		if(i.SS!=0)
		lefti[i.FF]--;
		if((!visited[i.FF]))
		{
			ans[i.FF]=ans[n]+i.SS;
			DFS(i.FF);
		}
		else if(ans[i.FF]!=ans[n]+i.SS)
		{
			flag=false;
		}
		//cout<<n<<" "<<i.FF<<" "<<ans[i.FF]<<" "<<ans[n]<<" "<<i.SS<<endl;

	}

}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int l,r,d;
		cin>>l>>r>>d;
		v[l].pb(mp(r,d));
		if(d!=0)
		lefti[r]++;
	}
	for(int i=0;i<n;i++)
	{
		if((!visited[i])&&lefti[i]==0)
		{
			DFS(i);
		}
	}
	for(int i=0;i<n;i++)
		if(ans[i]>1e9||lefti[i]!=0)
		{
			flag=false;
			//cout<<lefti[i]<<endl;
		}
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

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

using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector <string> str(N);
  for(int i = 0; i < N; i++) {
    cin >> str[i];
  }

  string prev = str[0];
  set <string> s;
  s.insert(prev);
  for(int i = 1; i < N; i++) {
    string next = str[i];
    if((prev[prev.length() - 1] == next[0]) && s.insert(next).second) {
      prev = next;
    }
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
    string s;
    cin>>s;
    cout<<(s=="ARC"?"ABC":"ARC");
}

Measured memory_bytes: 3612
use std::io::{stdin, Read};

fn main() {
    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();

    let mut a = String::new();
    stdin().read_to_string(&mut a).unwrap();
    let mut a: Vec<_> = a.trim().split_whitespace().zip(0..).map(|(s, i)|s.parse::<i64>().unwrap() - i).collect();
    a.sort();

    println!("{}", a.iter().map(|&s| (s - a[n / 2]).abs()).sum::<i64>());
}


Measured memory_bytes: 10492
#include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define repm(i, m, n) for (int i = (m); i < (n); i++)
#define rep_rev(i, n) for (int i = int (n); i >= 0; i--)
typedef long long ll;
using namespace std;

int main() {
	string s;
	ll k;
	cin >> s >> k;
	
	bool flag = true;
	rep(i, s.size() - 1)if (s[i] != s[i + 1]) { flag = false; break; }
	if (flag) {
		cout << (ll)(s.size() * k) / 2 << endl;
		return 0;
	}

	ll cnt = 0;
	flag = false;
	rep(i, s.size() - 1) {
		if (s[i] == s[i + 1] && !flag) {
			cnt++;
			flag = true;
		}
		else if (s[i] == s[i + 1] && flag) {
			flag = false;
		}
		else {
			flag = false;
		}
	}

	ll startNum = 1, endNum = 1;
	char start = s[0];
	char end = s[s.size() - 1];

	flag = false;
	rep1(i, s.size() - 1) {
		if (start == s[i])startNum++;
		else break;
	}
	for (int i = s.size() - 2; i > 0; i--) {
		if (end == s[i])endNum++;
		else break;
	}
	ll sum = cnt * k;
	if (startNum % 2 == 1 && endNum % 2 == 1 && start == end)sum += k - 1;
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
from subprocess import*
call(('python3','-c','from scipy.optimize import*;_,*s=open(0).read().split();f=lambda x:max((x[0]-i)**2+(x[1]-j)**2for i,j in zip(*[map(int,s)]*2));print(f(fmin(f,(9,9),disp=0))**.5)'))

Measured memory_bytes: 74996
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
for i in range(1, N+1):
    A[i] += A[i-1]

i = N
total = 0
ans = 0
for j in range(M+1):
    total += B[j]
    while i >= 0 and A[i]+total > K:
        i -= 1
    if A[i]+total <= K:
        ans = max(ans, i+j)

print(ans)

Measured memory_bytes: 39988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  ll x = (a + d - 1) / d, y = (b + c - 1) / b;
  
  if(x >= y) cout << "Yes" << endl;
  else cout << "No" << endl;
} 

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

int main() {

  int n,k;
  cin >> n >> k;
  
  vector<int> t(n);
  rep(i,n) cin >> t[i];
  
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  int ans = 0;
  rep(i,k) ans += t[i];
  
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll c = 0, ans = 0, h, w, n;std::cin >> h >> w >> n;
  ll H_ = w, W_ = h;
  while(c<n){
    if(H_<W_) c+=W_, H_--;
    else c+=H_, W_--;
    ans++;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
int getCost(int height[],int cost[],int k)
{
	if(k==1)
	return 0;
	if(k==2)
	return abs(height[k] - height[k-1]);
	
	if(cost[k] >= 0)
	return cost[k];
	
	int i,j,val;
	i = abs(height[k] - height[k-2]) + getCost(height,cost,k-2);
	j = abs(height[k] - height[k-1]) + getCost(height,cost,k-1);
	val = min(i,j);
	cost[k] = val;
	return val;
}
main()
{
	int i,n;
	cin>>n;
	int height[n+1];
	int cost[n+1];
	for(i=1;i<=n;i++)
	{
		cost[i] = -1;
	}
	for(i=1;i<=n;i++)
	{
		cin>>height[i];
	}
	i = getCost(height,cost,n);
	cout<<i;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int edge_num=-1;
struct edge
{
	int to,p,nxt;
}e[1000001];
int head[1000001];
void add_edge(int u,int v)
{
	e[++edge_num].to=v;
	e[edge_num].nxt=head[u];
	head[u]=edge_num;
}
int cnt;
int dfn[1000001];
int out[1000001];
void dfs(int u,int fa)
{
	dfn[u]=++cnt;
	for(int i=head[u];i!=-1;i=e[i].nxt)
	{
		int to=e[i].to;
		if(dfn[to]==0)
		{
			dfs(to,u);
			if(out[to]%2==0)
				e[i].p=1,e[i^1].p=-1,out[u]++;
			else
				e[i^1].p=1,e[i].p=-1,out[to]++;
		}
		else if(dfn[to]>dfn[u])
		{
			e[i].p=1;
			e[i^1].p=-1;
			out[u]++;
		}
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n,m;
	scanf("%d%d",&n,&m);
	if(m%2==1)
	{
		printf("-1");
		return 0;
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		for(int j=head[i];j!=-1;j=e[j].nxt)
			if(e[j].p==1)
				printf("%d %d\n",i,e[j].to);
    return 0;
}
/*
5 6
1 2
2 3
3 4
4 5
1 3
1 4
*/

Measured memory_bytes: 20352
s = input().rstrip()
s = s[::-1]
n = len(s)
dp = [[0]*2 for _ in range(n+1)]
for i in range(1,n+1):
  if i == 1:
    dp[1][0] = int(s[0])
    dp[1][1] = 10-int(s[0])
  else:
    dp[i][0] = min(dp[i-1][0]+int(s[i-1]),dp[i-1][1]+int(s[i-1])+1)
    dp[i][1] = min(dp[i-1][0]+10-int(s[i-1]),dp[i-1][1]+9-int(s[i-1]))
print(min(dp[n][0],dp[n][1]+1))

Measured memory_bytes: 139568
N,T=map(int,input().split())
A=[int(i) for i in input().split()]
l=T
A+=[10**19]
ans=0
for i in range(1,N+1):
    if l>=A[i]:
        ans+=A[i]-A[i-1]
        l=A[i]+T
        #print(ans,l)
    else:
        ans+=T
        l=l=A[i]+T
        #print(ans,l)
print(ans)

Measured memory_bytes: 91984
INF = 10**12
MAXV = 1100 * 100
N, W = gets.split.map(&:to_i)
lists = []
N.times do
  lists << gets.split.map(&:to_i)
end
# p lists
dp = Array.new(MAXV, INF)
dp[0] = 0
N.times do |i|
  (MAXV - 1).downto(lists[i][1]) do |j|
    # dp[j] = [dp[j], dp[j - lists[i][1]] + lists[i][0]].min
    dp[j] = dp[j - lists[i][1]] + lists[i][0] if dp[j] > dp[j - lists[i][1]] + lists[i][0]
  end
end
# binding.pry
(MAXV - 1).downto(0) do |i|
  if dp[i] <= W
    puts i
    exit
  end
end

Measured memory_bytes: 2684
N = int(input())
kouho = [1]
for i in range(1, 100):
    t = 6 ** i
    if t <= 10 ** 5:
        kouho.append(t)
    else:
        break
for i in range(1, 100):
    t = 9 ** i
    if t <= 10 ** 5:
        kouho.append(t)
    else:
        break
# print(kouho)

kouho.sort(reverse=True)
kouho_cnt = len(kouho)
INF = 10 ** 9
dp = [INF] * ((10 ** 5) + 1)
dp[0] = 0
for i in range(1, N + 1):
    for k in kouho:
        if i - k >= 0:
            dp[i] = min(dp[i], dp[i - k] + 1)
#print(dp)
print(dp[N])
# cur = 0
# ans = 0
# while N > 0:
#     if N >= kouho[cur]:
#         N -= kouho[cur]
#         ans += 1
#     else:
#         cur += 1
# print(ans)


Measured memory_bytes: 9612
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, a, b = map(int, input().split())
if a > b:
    print(0)
    sys.exit(0)
if n == 1 and a != b:
    print(0)
    sys.exit(0)
print((a + b * (n - 1)) - (b + a * (n - 1)) + 1)


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

public class Main {

    public static void main(String args[]) throws Exception {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int L = sc.nextInt();
        String[] S = new String[N];

        for (int i = 0; i < N; i++) {
            S[i] = sc.next();
        }

        Arrays.sort(S);

        String result = "";
        for (int i=0; i < S.length; i++) {
            result = result + S[i];
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 25300
n, k = gets.split(" ").map(&:to_i)
ary = gets.split(" ").map(&:to_i)
ary_rate = []

ary.each do |x|
  ary_rate << (x + 1) / 2.0
end

sum = ary_rate[0..(k-1)].inject(:+)
max = sum

(n - k).times do |i|
  sum = sum - ary_rate[i] + ary_rate[i+k]
  if sum > max
    max = sum
  end
end

puts max

Measured memory_bytes: 17340
#include <iostream>
using namespace std;
typedef long long ll;
ll d, g, p[20], c[20], res;
const ll INF = 1000000000000000000;

void func(ll x, ll y, ll sum, ll num){
    if (x == 0) {
        if (y == 0) {
            res = min(res, num);
        } else {
            for (ll i = 0; i < p[y]; i++) {
                if (g <= sum + y * 100 * i) res = min(res, num + i);
            }
        }
    } else {
        func(x - 1, y, sum, num);
        if (x == y) {
            func(x - 1, y - 1, sum + x * 100 * p[x] + c[x], num + p[x]);
        } else {
            func(x - 1, y, sum + x * 100 * p[x] + c[x], num + p[x]);
        }
    }
}

int main(void){
    // Your code here!
    res = INF;
    cin >> d >> g;
    for (ll i = 1; i <= d; i++) {
        cin >> p[i] >> c[i];
    }
    func(d, d, 0, 0);
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>

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

 int* A=new int[N];
 for(int i=0;i<N;i++){
  std::cin>>A[i];
 }

 int sum=0;
 for(int i=0;i<N;i++){
  sum=sum^A[i];
 }

 for(int i=0;i<N;i++){
  std::cout<< (int)(sum^A[i]) <<" ";
 }
 std::cout<<std::endl;

 return 0;
}

Measured memory_bytes: 4380
if __name__ == "__main__":
    n = int(input())
    taro, hanako = 0, 0
    for _ in range(n):
        tw, hw = input().split()
        if tw > hw:
            taro += 3
        elif tw < hw:
            hanako += 3
        else:
            taro += 1
            hanako += 1
    print(taro, hanako)

Measured memory_bytes: 7676
#include <iostream>
#include <list>
using namespace std;

int main()
{
    int n;
    cin >> n;
    list<int> v;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        if(i&1) 
            v.push_back(t);
        else
            v.push_front(t);
    }
    
    if(n%2)
        for(auto itr = v.begin(); itr!= v.end(); itr++) cout << *itr << " ";
    else
        for(auto itr = v.rbegin(); itr != v.rend(); itr++) cout << *itr << " ";

    return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

template<class In>
void print_array(In begin, In end) {
  cout << (*begin);
  begin++;
  for (; begin != end; begin++)
  {
    cout << " " << (*begin);
  }
  cout << endl;
}
template<typename T>
T gcd(T a, T b) {
  if (a > b) {
    T tmp = b;
    b = a;
    a = tmp;
  }
  while (a > 0){
    T tmp = b % a;
    b = a;
    a = tmp;
  }
  return b;
}

template<typename T>
T lcm(T a, T b) {
  return a / gcd<T>(a, b) * b;
}


int main()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll num_divc = (b / c) - ((a-1) / c);
  ll num_divd = (b / d) - ((a-1) / d);
  ll cd = lcm(c, d);
  ll num_divcd = (b / cd) - ((a-1) / cd);
  // cout << "num_divc=" << num_divc << endl;
  // cout << "num_divd=" << num_divd << endl;
  // cout << "num_divcd=" << num_divcd << endl;
  ll res = b - a + 1 - (num_divc + num_divd) + num_divcd;

  cout << res << endl;

  return 0;
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a==b and b==c){
    cout << "No" << endl;
  }
  else if (a!=b and b!=c and c!=a){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define ji -
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define fe(x) for(int i=be[x];i;i=e[i].ne)
using namespace std;
int n,na[110000],et,be[110000],t;
struct nod{
	int x,y;
};
nod a[110000];
struct edg{
	int y,z,ne;
};
edg e[510000];
inline bool cmpx(int c,int d){
	return a[c].x<a[d].x;
}
inline bool cmpy(int c,int d){
	return a[c].y<a[d].y;
}
inline void add_edge(int x,int y,int z){
	e[++et].y=y;
	e[et].z=z;
	e[et].ne=be[x];
	be[x]=et;
}
long long ans;
struct nod2{
	int x,v;
	bool operator <(const nod2 &a)const{
		return v>a.v;
	}
};
priority_queue<nod2> q; 
bool p[110000];
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d%d",&a[i].x,&a[i].y);
	fo(i,1,n) na[i]=i;
	sort(na+1,na+n+1,cmpx);
	fo(i,2,n){
		add_edge(na[i-1],na[i],a[na[i]].x-a[na[i-1]].x);
		add_edge(na[i],na[i-1],a[na[i]].x-a[na[i-1]].x);
	}
	sort(na+1,na+n+1,cmpy);
	fo(i,2,n){
		add_edge(na[i-1],na[i],a[na[i]].y-a[na[i-1]].y);
		add_edge(na[i],na[i-1],a[na[i]].y-a[na[i-1]].y);
	}	
	p[1]=1;
	fe(1) if(!p[e[i].y]) q.push((nod2){e[i].y,e[i].z});
	t=1;
	while (t<n){
		nod2 te=q.top();q.pop();
		if (p[te.x]) continue;
		p[te.x]=1;ans+=te.v;
		fe(te.x) q.push((nod2){e[i].y,e[i].z});
		t++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10100