akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


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



int main() {

	int a, b;
	cin >> a >> b;
	int c = b - a;
	int sum = 0;

	FOR(i, 1, c) {
		sum += i;
	}
	cout << sum - b << endl;


	return 0;
}



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input! {
        n: usize,
        w: usize,
        goods: [(usize, usize); n],
    }

    let mut dp = vec![vec![0; w+1]; n+1];

    for i in 1..n+1 {
        for j in 1..w+1 {
            if j >= goods[i-1].0 {
                dp[i][j] = cmp::max(dp[i-1][j], dp[i-1][j - goods[i-1].0] + goods[i-1].1);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    println!("{}", dp[n][w]);

}

Measured memory_bytes: 106748
import java.util.Scanner;

public class Main {
    static final String YES = "Yes";
    static final String NO = "No";
    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int X = scan.nextInt();
        int Y = scan.nextInt();

        scan.close();

        if (Y%2 != 0){
            System.out.println(NO);
            return;
        }

        int crane = 2*X - Y/2;
        int turtle = (Y-2*X)/2;

        if (crane < 0 ){
            System.out.println(NO);
            return;
        }

        if( turtle < 0){
            System.out.println(NO);
            return;
        }

        System.out.println(YES);
        
    }
}


Measured memory_bytes: 35736
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <deque>
#include <bitset>
#include <climits>
#include <cstdio>
#include <list>
#include <iomanip>
using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define si second
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define mod 1000000007

ll dp[ 22 ][ (1<<22) ];
ll n;
ll comp[ 22 ][ 22 ]= { 0 };

ll Solve(ll i, ll womens){
	if(i == n)
		return womens == 0;

	if(dp[i][womens] != -1)
		return dp[i][womens];
	ll ans = 0;
	for(ll w = 0 ; w < n ; w++){
		bool available = (1<<w)&womens;
		if(available and comp[i][w])
			ans = ( ans + Solve(i+1,womens^(1<<w) ))%mod;
	}
	return dp[i][womens] = ans;
}

int main(){
	fastIO
	cin>>n;
	NF(comp,n,n);
	
	memset(dp,-1,sizeof dp);

	cout<<Solve(0, ((1<<n)-1) )<<endl;
	


	return 0;
}

Measured memory_bytes: 721152
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define rall(a)		(a).rbegin(), (a).rend()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;

const int M = 100;
int main()
{
	int t, p, r;

	while (cin >> t >> p >> r && t){

		int pe[M]; clr(pe);
		int wr[M][M]; clr(wr);
		int w[M]; clr(w);


		rep(i, r){
			int tid, pid, time;
			string mes;
			cin >> tid >> pid >> time >> mes;
			if (mes == "CORRECT"){
				w[tid]++;
				pe[tid] += wr[tid][pid] * 1200 + time;
			}
			else{
				wr[tid][pid]++;
			}
		}

		for (int i = p; i >= 0; i--){
			bool f[M]; clr(f);
			For(j, 1, t + 1){
				if (w[j] == i)f[j] = 1;
			}
			vector<P> v;
			For(j, 1, t + 1){
				if (f[j]){
					v.push_back(P(pe[j], j));
				}
			}
			sort(all(v));

			rep(j, v.size()){
				cout << v[j].second << " " << i << " " << v[j].first << endl;

			}

		}


	}


	return 0;
}

Measured memory_bytes: 1264
K = int(input())
seq = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(seq[K-1])


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String w = br.readLine();
		String line;
		int count = 0;
		while(!(line = br.readLine()).equals("END_OF_TEXT")){
			line = line.toLowerCase();
			String[] words = line.split(" ");
			for(int i = 0;i < words.length;i++){
				if(words[i].equals(w)){
					count++;
				}
			}
		}
		System.out.println(count);
	}

}

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

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int N,W;	cin>>N>>W;
	pair<int,int> obj[N];
	for(int i=0;i<N;i++)
		cin>>obj[i].first>>obj[i].second; //value,weight
	
	int dp[N+1][W+1]; //max value when only first i objs can be taken and total weight<=j
	
	for(int i=0;i<=W;i++)
		dp[0][i]=0;
	
	for(int i=1;i<=N;i++){
		for(int j=0;j<=W;j++){
			if(j-obj[i-1].second<0)
				dp[i][j]=dp[i-1][j];
			else
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-obj[i-1].second]+obj[i-1].first);
		}
	}
	
	cout<<dp[N][W]<<"\n";
	return 0;
}



Measured memory_bytes: 7068
/*
 * ----------------------------------------------------------------------------
 *  (: Bismillahir Rahmanir Rahim :) 
 * File: /home/grimfirefly/Programming/Atcoder/Today/B_Go_to_Jail.cpp
 * Project: /home/grimfirefly/Programming/Atcoder/Today
 * Created Date: Saturday, September 19th 2020, 6:04:42 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sat Sep 19 2020
 * Modified By: Grim Firefly :)
 * -----
 *   ________        .__           ___________.__                  _____ .__          
 *  /  _____/_______ |__|  _____   \_   _____/|__|_______   ____ _/ ____\|  |  ___.__.
 * /   \  ___\_  __ \|  | /     \   |    __)  |  |\_  __ \_/ __ \\   __\ |  | <   |  |
 * \    \_\  \|  | \/|  ||  Y Y  \  |     \   |  | |  | \/\  ___/ |  |   |  |__\___  |
 *  \______  /|__|   |__||__|_|  /  \___  /   |__| |__|    \___  >|__|   |____// ____|
 *         \/                  \/       \/                     \/              \/     
 * 
 *           |\_|\
 *           | a_a\
 *           | | "]
 *       ____| '-\___
 *      /.----.___.-'\
 *     //        _    \
 *    //   .-. (GF)  /|
 *   |'|  /\:  .--  / \
 *  // |-/  \_/____/\/~|
 * |/  \ |  []_|_|_] \ |
 * | \  | \ |___   _\ ]_}
 * | |  '-' /   '.'  |
 * | |     /    /|:  | 
 * | |     |   / |:  /\
 * | |     /  /  |  /  \
 * | |    |  /  /  |    \
 * \ |    |/\/  |/|/\    \
 *  \|\ |\|  |  | / /\/\__\
 *   \ \| | /   | |__
 *        / |   |____)
 *        |_/
 * ----------------------------------------------------------------------------
 */

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

//constant
#define PI acos(-1.0)
#define SZ 10000
#define mod 1000000007
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef unsigned un;
typedef pair<int, int> pii;
typedef vector<int> vi;

//Debug Setting up
#define watch(x) cout << (#x) << "=" << x << endl
#define watch2(x, y) cout << (#x) << "=" << x << " & " << (#y) << "=" << y << endl;
#define watchara(wow)     \
    for (auto x : wow)    \
    {                     \
        cout << x << " "; \
    }                     \
    cout << "\n"

//defining fast_io
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

//defining something
#define F first
#define S second

//Main Function Start From Here
void solve()
{
    int n, x, y, cnt = 0;
    cin >> n;
    bool flag = true;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        if (x == y)
            cnt++;
        else
            cnt = 0;
        if (cnt >= 3 && flag)
        {
            cout << "Yes" << endl;
            flag = false;
        }
    }
    if (flag)
        cout << "No\n";
}

int main()
{
    fast_io;

    solve();

    return 0;
}

Measured memory_bytes: 3648
import math
S = int(input())
div = S // 3
mod = S % 3
sum = 0
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)

for i in range(div):
    sum = sum + C(div-1-i+mod+3*i,mod+3*i)
    sum = sum % (10**9+7)
print(sum)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	std::string S;
  	int num=0;
  	cin >> S;
  	if (S.at(2)==S.at(3) && S.at(4)==S.at(5))
    {
      cout<<"Yes"<<endl;
    }
  	else
    {
      cout<<"No"<<endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int a;
  //string a;
  cin >> a;
  vector<int> order(a);
  rep(i, a) cin >> order[i];
  vector<int> basic(a);
  rep(i, a) cin >> basic[i];
  vector<int> plus(a - 1);
  rep(i, a - 1) cin >> plus[i];
  
  int ans = 0;
  //string ans = "Yes";
  //string ans = "No";
  //string ans = "YES";
  //string ans = "NO";
  int cnt = 0;
  rep(i, a) ans += basic[i];
  rep(i, a - 1){
    if (order[i] + 1 == order[i + 1]) ans += plus[order[i] - 1];
  }
  
  cout << ans << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<int M>
class Modulo {
  using ll = long long;
  int n;
public:
  Modulo () : n(0) {;}
  Modulo (int m) : n(m) {
    if (n >= M) n %= M;
    else if (n < 0) n = (n % M + M) % M;
  }
  Modulo (ll m) {
    if (m >= M) m %= M;
    else if (m < 0) m = (m % M + M) % M;
    n = m;
  }
  explicit operator int() const { return n; }
  explicit operator ll() const { return n; }
  bool operator==(const Modulo &a) const { return n == a.n; }
  Modulo operator+=(const Modulo &a) { n += a.n; if (n >= M) n -= M; return *this; }
  Modulo operator-=(const Modulo &a) { n -= a.n; if (n < 0) n += M; return *this; }
  Modulo operator*=(const Modulo &a) { n = (ll(n) * a.n) % M; return *this; }
  Modulo operator+(const Modulo &a) const { Modulo res = *this; return res += a; }
  Modulo operator-(const Modulo &a) const { Modulo res = *this; return res -= a; }
  Modulo operator*(const Modulo &a) const { Modulo res = *this; return res *= a; }
};

const int mod = 1000000009;

using Mod = Modulo<mod>;
template <typename T> using Matrix = vector<vector<T>>;

template<typename T>
T dot(const vector<T> &a, const vector<T> &b) {
  return inner_product(begin(a), end(a), begin(b), T(0));
}

template<typename T>
Matrix<T> transpose(const Matrix<T> &A) {
  const int n = A[0].size(), m = A.size();
  Matrix<T> res(n, vector<T>(m, 0));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      res[i][j] = A[j][i];
  return res;
}

template<typename T>
Matrix<T> operator*(const Matrix<T> &a, Matrix<T> b) {
  b = transpose(b);
  const int n = a.size(), m = b.size();
  assert (a[0].size() == b[0].size());
  Matrix<T> res(n, vector<T>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      res[i][j] = dot(a[i], b[j]);
  return res;
}

template<typename T>
Matrix<T> powmat(const Matrix<T> &a, ll n) {
  if (n == 0) {
    const int n = a.size();
    Matrix<T> res(n, vector<T>(n, 0));
    REP(i,n) res[i][i] = Mod(1);
    return res;
  }
  else {
    if (n % 2) return powmat(a, n - 1) * a;
    return powmat(a * a, n / 2);
  }
}

int main() {
  ll W, H, N;
  for (int cas = 1; cin >> W >> H >> N, W; ++cas) {
    Matrix<Mod> next(W, vector<Mod>(W, 0));
    REP(i,W) REP(j,W) {
      if (abs(i - j) <= 1) next[i][j] = 1;
    }
    vector<pair<ll,ll>> obstacles;
    REP(i,N) {
      ll x, y;
      cin >> x >> y;
      obstacles.emplace_back(y - 1, x - 1);
    }
    sort(ALL(obstacles));
    Matrix<Mod> vec(W, vector<Mod>(1, 0));
    vec[0][0] = 1;
    ll prev = 0;
    for (auto p: obstacles) {
      ll y, x;
      tie(y, x) = p;
      vec = powmat(next, y - prev) * vec;
      vec[x][0] = 0;
      prev = y;
    }
    vec = powmat(next, H - 1 - prev) * vec;
    printf("Case %d: %d\n", cas, int(vec[W-1][0]));
  }
  return 0;
}

Measured memory_bytes: 7076
/**
 * Sum of Consecutive Integers
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) break;

			int[] nums = new int[n / 2 + 2];
			for (int i = 1; i < nums.length; i++) {
				nums[i] = nums[i - 1] + i;
			}

			int count = 0;
			for (int i = 1; i < nums.length - 1; i++) {
				for (int j = 2; j < nums.length; j++) {
					if (i < j) {
						if (nums[j] - nums[i - 1] == n) count++;
					}
				}
			}
			System.out.println(count);
		} //end while
	} //end main
}

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

int main()
{
    string n;
    cin >> n;
    n += '0';
    reverse(n.begin(), n.end());
    n += '0';
    int k = n.size();
    int ans = 0;
    for(int i = 1; i < k; i++){
        if(n[i] <= '4'){
            ans += n[i] - '0';
        }
        else if(n[i] >= '6'){
            ans += 10 - (n[i] - '0');
            n[i + 1]++;
        }
        else{
            if(n[i + 1] <= '4'){
                ans += n[i] - '0';
            }
            else{
                ans += 10 - (n[i] - '0');
                n[i + 1]++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1412
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
 
using namespace std;
 
int main(){
    int r, g, b, n;
    scanf("%d %d %d %d", &r, &g, &b, &n);

    int ans = 0;

    for(int i = 0; i <= n / r; ++i){
        for(int j = 0; j <= (n - r*i)/g; ++j){
            if((n - r*i - g*j) % b == 0){
                ans++;
            }
        }
    }

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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define allr(v)	     ((v).rbegin()), ((v).rend())
#define sz(v) ((int)(v).size())
#define clr(v, d)        memset(v, d, sizeof(v))
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
typedef long long ll;
const double PI = acos(-1.0);
int dx[] = { 1,-1,0,0 };
int dy[] = { 0,0,1,-1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);// freopen("out.txt", "w", stdout);  
#endif
}
bool check_prime(ll a)
{
	bool flag = true;
	if (a <= 1)
		return false;
	else
	{
		for (ll i = 2; i <= sqrt(a); i++)
		{
			if (a % i == 0)
			{
				flag = false;
				break;
			}
		}
	}
	if (flag)
		return true;
	else
	{
		return false;
	}
}

int main()
{
	//file();
	Fast;
	ll n, l;
	cin >> n >> l;
	vector<string>v(n);
	string b;
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
	{
		b += v[i];
	}
	cout << b;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;

int main(){

  string s;
  int n,m;

  while(true){
    cin >> s;
    if(s == "0") break;

    n = m = 0;

    for(int i=1;i<s.size();i++){
      if(s[i] == 'A') n++;
      else if(s[i] == 'B') m++;
    }

    if(n > m) cout << n+1 << " " << m << endl;
    else cout << n << " " << m+1 << endl;
  }
}

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

long long  l;
string s;

long long  solve();

int main(){
    cin >> l >> s;
    cout << solve() << endl;
    return 0;
}

long long  solve(){
    long long ans = 0;
    for(int i = 0;i < l;++i){
        if(s[i] != '.')continue;
        if(i != 0 && i != l-1 && s[i-1] == 'B' && s[i+1] == 'B')continue;
        long long now = 0,cnt = 0,id = i - 1,ch = 0;
        //check
        while(id >= 0 && s[id] == 'W')--id;
        if(id >= 0 && s[id] == 'B')++ch;
        id = i + 1;
        while(id < l && s[id] == 'W')++id;
        if(id < l && s[id] == 'B')++ch;
        if(ch == 2)continue;
        id = i - 1;
        while(id >= 0 && s[id] == 'B')++cnt,--id;
        if(id >= 0 && s[id] == 'W')now += cnt;
        cnt = 0;
        id = i + 1;
        while(id < l && s[id] == 'B')++cnt,++id;
        if(id < l && s[id] == 'W')now += cnt;
        ans = max(ans,now);
    }
    return ans;
}


Measured memory_bytes: 3208
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,a,b,c=map(int,input().split())
s=[input() for i in range(n)]
# print(s)
abc=[a,b,c]
dic={"A":0,"B":1,"C":2}

anslst=[]

for i in range(n-1):
    tmp=0
    v=dic[s[i][0]]
    w=dic[s[i][1]]
    x=dic[s[i+1][0]]
    y=dic[s[i+1][1]]
    # どっちも0は終了
    if abc[v]==abc[w]==0:
        print("No")
        quit()
    # 片方が0なのでもう片方から引く
    if abc[v]==0:
        anslst.append(s[i][0])
        abc[v]+=1
        abc[w]-=1
    elif abc[w]==0:
        anslst.append(s[i][1])
        abc[v]-=1
        abc[w]+=1
    # 今回と次が同じだから平均化
    elif s[i]==s[i+1]:
        if abc[v]>abc[w]:
            anslst.append(s[i][1])
            abc[v]-=1
            abc[w]+=1
        else:
            anslst.append(s[i][0])
            abc[v]+=1
            abc[w]-=1
    # 今回と次Aが出るからAに足す
    elif v==x:
        anslst.append(s[i][0])
        abc[v]+=1
        abc[w]-=1
    # 今回と次Cが出るからCに足す
    elif w==y:
        anslst.append(s[i][1])
        abc[v]-=1
        abc[w]+=1
    # 今回と次Bが出るからBに足す
    else:
        if v==y:
            anslst.append(s[i][0])
            abc[v]+=1
            abc[w]-=1
        else:
            anslst.append(s[i][1])
            abc[v]-=1
            abc[w]+=1
    # print(abc)

if abc[dic[s[-1][0]]]==abc[dic[s[-1][1]]]==0:
    print("No")
    quit()
else:
    if abc[dic[s[-1][0]]]>abc[dic[s[-1][1]]]:
        anslst.append(s[-1][1])
    else:
        anslst.append(s[-1][0])
    
print("Yes")
for i in range(n):
    print(anslst[i])

Measured memory_bytes: 81840
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if(s.equals("SAT")){
      System.out.println(1);
    }else if(s.equals("FRI")){
      System.out.println(2);
    }else if(s.equals("THU")){
      System.out.println(3);
    }else if(s.equals("WED")){
      System.out.println(4);
    }else if(s.equals("TUE")){
      System.out.println(5);
    }else if(s.equals("MON")){
      System.out.println(6);
    }else{
      System.out.println(7);
    }
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

int main()
{    
    int a,b,c;
    cin >> a >> b >> c;
    
    cout << max(0, c-(a-b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

int a, b, c, d, l, r;
int main(void) {
	scanf("%d%d%d%d", &a, &b, &c, &d);
	l = max(a, c);
	r = min(b, d);
	if (l <= r)
		printf("%d", r - l);
	else
		printf("%d", 0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
using namespace std;
map <int,int> mp;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;
static const int NMAX=100;
int N;
int main(){
    cin>>N;
    ll cunt=1;
    for(int i=1;i<=N;i++){
        cunt*=i;
        cunt%=(1000000000ll+7);
    }
    cout<<cunt<<"\n";

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int K=sc.nextInt();
        int A=sc.nextInt();
        int B=sc.nextInt();
        int temp=K;
        while(B>=temp){
            if(A<=temp){
                System.out.println("OK");
                System.exit(0);
            }else{
                temp+=K;
            }
        }
        System.out.println("NG");
    }
}

Measured memory_bytes: 35816
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){

    int n,i;
    double sum1=0,sum2=0,sum3,max=0,ans[4];
    
    scanf("%d",&n);
    double x[n],y[n];
    for(i=0;i<n;i++){
         scanf("%lf",&x[i]);
    }
    for(i=0;i<n;i++){
     scanf("%lf",&y[i]);
    }
    for(i=0;i<n;i++){
        sum1+=abs(x[i]-y[i]);
        if(abs(x[i]-y[i])>max){
            max=abs(x[i]-y[i]);
        }
    
        sum2+=pow(abs(x[i]-y[i]),2);
        sum3+=pow(abs(x[i]-y[i]),3);
    }
    
    printf("%lf\n%lf\n%lf\n%lf\n",sum1,sqrt(sum2),cbrt(sum3),max);
    

}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using i64 = int64_t;

std::vector<i64> g_ACC;

i64 range_sum(size_t begin, size_t end)
{
    return g_ACC[end] - g_ACC[begin];
}

i64 sumdiff(size_t begin, size_t div, size_t end)
{
    return std::abs(range_sum(begin, div) - range_sum(div, end));
}

size_t eqcut(size_t begin, size_t end, size_t hint, bool inc)
{
    size_t best_ix = hint;
    size_t best_diff = sumdiff(begin, hint, end);
    for (size_t ix = hint; inc ? ix < end : ix > begin; inc ? ix++ : ix--) {
        size_t diff = sumdiff(begin, ix, end);
        if (diff > best_diff) {
            break;
        } else {
            best_ix = ix;
            best_diff = diff;
        }
    }
    return best_ix;

}

int main()
{
    size_t n;
    std::cin >> n;
    g_ACC.push_back(0);
    for (size_t i = 0; i < n; i++) {
        i64 a;
        std::cin >> a;
        auto sum = g_ACC.back() + a;
        g_ACC.push_back(sum);
    }

    std::vector<size_t> left(n);
    std::vector<size_t> right(n);

    left[2] = 1;
    right[n - 2] = n - 1;

    for (size_t div = 3; div <= n - 2; div++) {
        left[div] = eqcut(0, div, left[div - 1], true);
    }

    /*
    for (size_t div = 2; div <= n -2; div++) {
        std::cout << div << ' ' << left[div] << ' ' << range_sum(0, left[div]) << ' ' <<  range_sum(left[div], div) <<  std::endl;
    }
    std::cout << "----------" << std::endl;
    */
    for (size_t rdiv = 3; rdiv <= n - 2; rdiv++) {
        size_t div = n - rdiv;
        right[div] = eqcut(div, n, right[div + 1], false);
    }
    /*
    for (size_t div = 2; div <= n -2; div++) {
        std::cout << div << ' ' << right[div] << ' ' << range_sum(div, right[div]) << ' ' <<  range_sum(right[div], n) << std::endl;
    }
    */

    i64 best = g_ACC.back();
    for (size_t div = 2; div <= n - 2; div++) {
        i64 p[4];
        p[0] = range_sum(0, left[div]);
        p[1] = range_sum(left[div], div);
        p[2] = range_sum(div, right[div]);
        p[3] = range_sum(right[div], n);

        i64 max = 0, min = g_ACC.back();
        for (size_t i = 0; i < 4; i++) {
            min = std::min(min, p[i]);
            max = std::max(max, p[i]);
        }

        best = std::min(best, max - min);
    }
    std::cerr << "hello" << std::endl;
    std::cout << best << std::endl;





    return 0;
}


Measured memory_bytes: 5104
def solve(n, cards)
    a = []
    b = []
    for j in 0..(n-1)
      m = cards[j][0]
      i = cards[j][1].to_i
      a.push([m, i])
      b.push([m, i])
    end

    qsort(a, 0, n-1)

    stable = true
    (0..n-2).each do |i|
      if (a[i][1] == a[i+1][1])
        if b.index(a[i]) > b.index(a[i+1])
          stable = false
          break
        end
      end
    end

    if stable
      puts("Stable")
    else
      puts("Not stable")
    end

    a.each do |x|
      puts x.join(" ")
    end
  end

  def qsort(a, p, r)
    if p < r
      q = partion(a, p, r)
      qsort(a, p, q-1)
      qsort(a, q+1, r)
    end
  end

  def partion(a, p, r)
    x = a[r][1]
    i = p - 1
    (p...r).each do |j|
      if a[j][1] <= x
        i += 1
        a[i], a[j] = a[j], a[i]
      end
    end
    a[i+1], a[r] = a[r] , a[i+1]
    return i+1
  end

n = gets.chomp.to_i
cards = []
n.times do
  card = gets.chomp.split
  cards.push(card)
end
solve(n, cards)

Measured memory_bytes: 59804
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;




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

    string ans;
    while (N != 0){
        ll r = N % 2;
        if (r < 0) r += 2;

        N = (N - r) / (-2);

        ans += (char)('0' + r);
    }

    reverse(ans.begin(), ans.end());
    if (ans == "") ans = "0";

    cout << ans << endl;
}



Measured memory_bytes: 3608
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//


ll gcd(ll a, ll b) {
    ll r = a % b;
    while(r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}




int main() {

    int N; cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    ll ans = a[0];
    rep(i,N - 1) ans = gcd(ans, a[i + 1]);
    out(ans);
    
    return 0;
}






Measured memory_bytes: 1400
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int main()
{
	int N;
	int T1,X1,Y1,T2,X2,Y2,mint,minx,miny;
	while( scanf(" %d",&N) != EOF ){
		int flag = 0,check = 0;
		if( N == 1 ){
			scanf(" %d %d %d",&T1,&X1,&Y1);
			if( X1 + Y1 <= T1 && (T1 - X1 - Y1) % 2 == 0 )
				flag = 1;
		}
		else if( N > 1 ){
			N = N - 1;
			scanf(" %d %d %d",&T1,&X1,&Y1);
			while( N-- ){
				flag = 0;
				scanf(" %d %d %d",&T2,&X2,&Y2);
				mint = T2 , minx = X2 , miny = Y2;
				int TT = T2 - T1, XX = abs(X2 - X1) , YY = abs(Y2 - Y1);
				if( XX + YY <= TT && (TT - XX - YY) % 2 == 0 )
					flag = 1;
				else	check = 1;
				T1 = mint , X1 = minx , Y1 = miny;
			}
		}
		if( flag == 1 && check == 0 )
			printf("Yes\n");
		else
			printf("No\n");
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;

void trace(int A[], int n) {
  int i;
  for(i=0; i<n; i++) {
    if (i>0) {
      printf(" ");
    }
    printf("%d", A[i]);
  }
  printf("\n");
}

int selectionSort(int A[], int n) {
  int minj = 0;
  int count = 0;
  for (int i=0; i<n-1; i++) {
    minj = i;
    for (int j=i; j<n; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    swap(A[i], A[minj]);
    if (i != minj) {
      count += 1;
    }
  }
  return count;
}

int main() {
  int n=0;
  int A[100];
  int c = 0;
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d", &A[i]);
  }

  c = selectionSort(A, n);
  trace(A, n);
  printf("%d\n", c);
}


Measured memory_bytes: 3216
//template---{{{
#include <bits/stdc++.h>

using namespace std;

//DEFINE---{{{
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b); i > (a); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
//end.DEFINE---}}}

//end.template ---}}}

int main()
{
    int H, W;
    char s[50][50];

    cin >> H >> W;

    int i, j;

    REP(i, H) {
        REP(j, W) {
            cin >> s[j][i];
        }
    }

    REP(i, H) {
        REP(j, W) {
            if (s[j][i] == '#') {
                if (s[j + 1][i] != '#' && s[j - 1][i] != '#' && s[j][i + 1] != '#' && s[j][i - 1] != '#') {
                    cout << "No" << endl;
                    return (0);
                }
            }
        }
    }

    cout << "Yes" << endl;

    return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<int,int>
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second

int main()
{   fastio ;
    int n,i,j,w ;
    cin>>n>>w ;
    int a[n],v[n] ;
    for (i = 0; i < n; ++i)
    {   cin>>a[i]>>v[i] ;
      	
    }  
    ll p[n+1][w+1] ;
    
    for (i = 0; i <= n; ++i)
    {   for (j = 0; j <= w; ++j)
        {   if(i==0||j==0) p[i][j]=0 ;
        	else if(j<a[i-1]) p[i][j]=p[i-1][j] ;
    	    else p[i][j]=max(v[i-1]+p[i-1][j-a[i-1]],p[i-1][j]) ;
        }
    	
    }
    ll sum=0 ;
    for (i = 0; i <=w ; ++i)
    {   sum=max(sum,p[n][i]) ;
    	
    }
    cout<<sum<<"\n" ;
    return 0 ;
}    

Measured memory_bytes: 79232
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string>
#include <iomanip>
#include <locale>
#include <list>
#include <bitset>
#include <tuple>
using namespace std;
#define FORN(i,m,n) for(int i=(m); i<int(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
typedef long long ll;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int x, y, a, b, c;
  cin>>x>>y>>a>>b>>c;
  ll ans = 0;
  vector<ll> A(a), B(b), C(c), v;
  FORN(i,0,a) cin>>A[i];
  FORN(i,0,b) cin>>B[i];
  FORN(i,0,c) cin>>C[i];
  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.rbegin(), C.rend());
  FORN(i,0,x) v.push_back(A[i]);
  FORN(i,0,y) v.push_back(B[i]);
  sort(v.begin(), v.end());
  int cur = 0;
  while(cur < v.size() && cur < C.size() && C[cur] > v[cur]) v[cur] = C[cur], cur++;
  FORN(i,0,v.size()) ans += v[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 4852
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff_AB = sum(A) - sum(B)

if diff_AB < 0:
	print(-1)
	exit()

Diff = []	
for i in range(n):
	diff = A[i] - B[i]
	Diff.append(diff)

Diff = sorted(Diff)

res = 0
for i in range(n):
	if Diff[i] < 0:
		res += 1
	else:
			if Diff[i] <= diff_AB:
				diff_AB -= Diff[i]
			else:
				diff_AB = 0
				res += 1

if diff_AB > 0:
	res += 1

print(res)


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

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

	int n, k;
	int a[200000];
	double ans(0), pre;

	cin >> n >> k;

	for (int i = 0; i < k; i++)
	{
		cin >> a[i];
		ans += a[i];
	}
	pre = ans;
	for (int i = k; i < n; i++)
	{
		cin >> a[i];
		pre = pre + a[i] - a[i - k];
		ans = max(ans, pre);
	}

	ans = (ans + k) / 2;
	cout.setf(ios::fixed);		
	cout.setf(ios::showpoint);
	cout.precision(12);		

	cout << ans;

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int S,E;
  if(B<=C){
    cout<<0<<endl;
  }
  else if(D<=A){
    cout<<0<<endl;
  }
  else{
    S=max(A,C);
    E=min(B,D);
    cout<<E-S<<endl;
  }
}

Measured memory_bytes: 256
S = input()

ans = 0

for bit in range(1 << (len(S) - 1)):
    f = S[0]

    for i in range(len(S) - 1):
        if bit & (1 << i):
            f += "+"
        f += S[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	ll N, K, Q;
	cin >> N >> K >> Q;
	vector<ll> P(N);
	rep(i, Q) {
		ll tmp;
		cin >> tmp;
		tmp--;
		P[tmp]++;
	}

	rep(i, N) {
		if (K-Q+P[i] > 0) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 1408
#include<stdio.h>
int P(int x)
{
	if(x<2)return 0;
	if(x==2)return 1;
	if(x%2==0)return 0;
	for(int i=3;i*i<=x;++i)if(x%i==0)return 0;
	return 1;
}
int main()
{
	int a,d,n,i;
	while(scanf("%d%d%d",&a,&d,&n),n)
	{
		for(i=a;;i+=d)if(P(i))if(!--n)break;
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 760
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

def combmod(n, k):
	p, q = 1, 1
	for i in range(1, k+1):
		p = p * (n-i+1) % mod
		q = q * i % mod
	return p * pow(q, mod-2, mod) % mod

X, Y = rl()

if (X+Y) % 3 != 0:
	print(0)
	exit()
if not (1/2 <= Y/X <= 2):
	print(0)
	exit()
n = (X+Y)//3
k = X-n
print(combmod(n,k))

Measured memory_bytes: 38640
N = input()
s = [raw_input() for _ in range(N)]

s = sorted([sorted(t) for t in s])
ans = 0
i = 0
while i<N:
  j = i
  while j<N and s[i]==s[j]:
    j += 1
  ans += (j-i)*(j-i-1)/2
  i = j
print ans


Measured memory_bytes: 31332
#include <iostream>


using namespace std;

int main()
{
int n ,x ,mx= -1;
scanf("%d",&n);
char s;
for(int i=0;i<=n;i++){
	scanf("%c",&s);
	if(s=='I'){
	x++;
	}
mx= max(x,mx);
	 if(s=='D'){
	x--;
	} }
printf("%d",mx);

    return 0;
}

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

int main() {
  int i, j, k;
  ll N, H, hight, count=0;
  bool judge;
  
  cin >> N;
  
  vector<ll> x(N);
  vector<ll> y(N);
  vector<ll> h(N);
  
  rep(i,N) cin >> x[i] >> y[i] >> h[i];
  
  rep(i,101){
    rep(j,101){
      judge = true;
      rep(k,N){
        if(h[k]!=0){
          H=llabs(x[k]-i)+llabs(y[k]-j)+h[k];
          break;
        }
      }
      rep(k,N){
        hight=H-llabs(i-x[k])-llabs(j-y[k]);
        if(h[k]!=max((ll)0,hight)){
          judge = false;
          break;
        }
      }
      if(judge==true){
        cout << i << " " << j << " " << H;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3576
#include<cstdio>
#include<cmath>
#include<iostream>
typedef long long ll;
using namespace std;

char a[100000];
int main()
{
	int N,i,sum = 0;
	scanf("%d",&N);
	for(i = 1; i <= N; i++)
	{
		sum = sum + i;
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, c; cin >> n >> c;
  VVI tab(c, VI(100010));
  for (int i = 0; i < n; i++) {
    int s, t, ch; cin >> s >> t >> ch;
    ch--;
    tab[ch][s]++;
    tab[ch][t + 1]--;
  }
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < 100005; j++) {
      tab[i][j + 1] += tab[i][j];
    }
  }
  VI sum(100005);
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < 100005; j++) {
      sum[j] += !!tab[i][j];
    }
  }
  cout << *max_element(sum.begin(), sum.end()) << '\n';
  return 0;
}

Measured memory_bytes: 12536
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

const int maxn = 1e6+7;

int dp[maxn][2];

int main(){
//	freopen("in","r",stdin);
	string s; cin >> s;
	reverse(s.begin(),s.end());
	dp[0][0] = s[0]-'0'; dp[0][1] = 10-(s[0]-'0');
	for(int i = 1;i < s.size();i++){
		int num = s[i]-'0';
		if(num==9) dp[i][0] = dp[i-1][0]+num;
		else dp[i][0] = min(dp[i-1][0]+num,dp[i-1][1]+num+1);
		dp[i][1] = min(dp[i-1][0]+10-num,dp[i-1][1]+9-num);
	}
	cout << min(dp[s.size()-1][0],dp[s.size()-1][1]+1) << endl;
}

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

int main(){
  ll a,b,c,k;cin>>a>>b>>c>>k;
  
  if(a>=k)cout<<k<<endl;
  else if(a+b>=k)cout<<a<<endl;
  else cout<<2*a+b-k<<endl;
}

Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
using namespace std;
using llong = long long;
using T = pair<int, pair<int, int>>;

int n, q;
int c[500005];
int cnt[500005];
vector<int> ans;
T query[500005];
int l, r;

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

    const int sqrtN = 512;

    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < q; i++) {
        cin >> query[i].first >> query[i].second.first;
        query[i].first--;
        query[i].second.second = i;
    }

    ans.resize(q);

    sort(query, query + q,
    [&](const T &l, const T &r) {
        if (l.first / sqrtN != r.first / sqrtN) return l.first < r.first;
        else return l.second.first < r.second.first;
    });

    int sum = 0;
    int l = 0;
    int r = 0;
    for (int i = 0; i < q; i++) {
        while (l > query[i].first) {
            l--;
            cnt[c[l]]++;
            if (cnt[c[l]] == 1) sum++;
        }
        while (r < query[i].second.first) {
            cnt[c[r]]++;
            if (cnt[c[r]] == 1) sum++;
            r++;
        }
        while (l < query[i].first) {
            cnt[c[l]]--;
            if (cnt[c[l]] == 0) sum--;
            l++;
        }
        while (r > query[i].second.first) {
            r--;
            cnt[c[r]]--;
            if (cnt[c[r]] == 0) sum--;
        }
        ans[query[i].second.second] = sum;
    }

    for (auto vs:ans) {
        cout << vs << '\n';
    }

    return 0;
}

Measured memory_bytes: 15452
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};

int w[107];
vector<pair<int,int> > g[107];
void add(int u, int v, int w){
    g[u].push_back(make_pair(v,w));
    g[v].push_back(make_pair(u,w));
}
int findTheCity(int n, vector<vector<int>>& edges, int dt) {
    for(int i = 0; i < (int)edges.size();i++){
        int u = edges[i][0];
        int v = edges[i][1];
        int w = edges[i][2];
        add(u,v,w);
    }
    
	
	int ans = inf;
	for(int i = 0; i < n; i++){
		clr(w,inf);
		w[i] = 0;
		for(int k = 1; k <= n-1; k++){
			for(int j = 0; j < n; j++){
				for(int l = 0; l < (int)g[j].size(); l++){
					int u = j;
					int v = g[j][l].first;
					int weigth = g[j][l].second;
					if(w[u] + weigth < w[v]){
						w[v] = w[u] + weigth;
					}
				}
			}
		}
		int cont = 0;
		cout<<i<<":\n";
        for(int k = 0; k < n; k++){
            if(k != i && w[k] <= dt){
				cout<< k<<"-"<<w[k];
                cont++;
            }
            cout<<endl;
        }
        
		ans = min(cont, ans);
	}
	
	return ans;
}

map<ll, ll> tab;	
ll solve(ll n){
	if(tab[n] != 0)
		return tab[n];
	if(n == 1)
		return 1;
	tab[n] = 1 + solve(n/2)*2;
	return tab[n];
}
int main(){
	ll h; cin>> h;
	cout<<solve(h);
	return 0;
}












Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;

typedef long long ll;
const int N(59);
const int mod(1e9 + 7);

ll n, m, ans;

struct Matrix
{
	ll val[N][N];
	Matrix(){ memset(val, 0, sizeof(val));}
	void to_E()
	{
		for (int i = 1; i <= n; i++)
		{
			val[i][i] = 1;
		}
	}
	Matrix operator * (const Matrix b)
	{
		Matrix c;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
			{
				for (int k = 1; k <= n; k++)
				{
					c.val[i][j] += val[i][k] * b.val[k][j];
					c.val[i][j] %= mod;
				}
			}
		}
		return c;
	}
};
Matrix a, c;

Matrix pow(Matrix a, ll b)
{
	Matrix ans;
	ans.to_E();
	while (b)
	{
		if (b & 1) ans = ans * a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}
int main()
{
	cin>>n>>m;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cin>>a.val[i][j];
		}
	}
	Matrix c = pow(a, m);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			ans += c.val[i][j];
			ans %= mod;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int m, n;
int w[200010], t[200010];
int dp[100010];
int c[20], b[20];

bool isOK(int i, int left, int right){
	return (c[i] >= w[right+1]-w[left]) && (b[i] >= t[right+1]-t[left]);
}

int search(int i, int num){
	int left = num-1;
	int right = m;
	while(right - left > 1){
		int mid = left + (right - left) / 2;
		if(isOK(i, num, mid)) left = mid;
		else right = mid;
	}
	
	return right;
}


int solve(int bit){
	if(bit == ((1 << n)-1)){
		return 0;
	}
	
	if(dp[bit] != -1) return dp[bit];	
	
	int ans = 0;
	for(int i = 0;i < n;i++){
	  if((bit & (1 << i)) == 0){
			int tmp = solve(bit | (1 << i));
			tmp = search(i, tmp);
			ans = max(ans, tmp);
		}
	}
	
	return dp[bit] = ans;
}			

int main(){
	cin >> m >> n;
	
	int wt, tt;
	for(int i = 0;i < m;i++){
		cin >> wt >> tt;
		w[i+1] = w[i] + wt;
		t[i+1] = t[i] + tt;
	}
	
	for(int i = 0;i < n;i++){
		cin >> c[i] >> b[i];
	}
	
	memset(dp,-1,sizeof(dp));
	
	cout << solve(0) << endl;	
}
	



Measured memory_bytes: 5032
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
typedef long double ld;

const ld INF = 1e18;
const int N = 602;

ld E[N], sp[N];
int out[N], argmax[N];
bool ok[N][N];
int n, m;
vi G[N];

ld go() {
	for(int i=1;i<=n;i++) E[i] = 0;
	E[n] = 0;
	for(int i=n-1;i>=1;i--) {
		int out = 0;
		for(int j:G[i]) {
			if(ok[i][j]) {
				E[i] += E[j];
				out++;
			}
		}
		if(out == 0) return INF;
		E[i] = E[i] / out + 1;
	}
	return E[1];
}

signed main()
{
	IO_OP;
	
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		int u, v;
		cin >> u >> v;
		G[u].PB(v);
		ok[u][v] = 1;
	}
	ld mn = go();
	E[0] = -INF;
	for(int i=1;i<n;i++)
		for(int j:G[i]) if(E[j] > E[argmax[i]]) argmax[i] = j;
	for(int i=1;i<n;i++) {
		ok[i][argmax[i]] = false;
		mn = min(mn, go());
		ok[i][argmax[i]] = true;
	}		
	cout << fixed << setprecision(10) << mn << endl;
}





Measured memory_bytes: 1792