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

long long dp[200100][10];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 10; j++) {
            dp[i][j] = -1e18;
        }
    }
    int offset = 4;
    dp[0][0+offset] = 0;
    dp[1][1+offset] = a[0];
    dp[1][0+offset] = 0;
    for (int i = 2; i <= n; i++) {
        for (int j = 2; j <= min(i, 4); j++) {
            for (int k = -4; k < 5; k++) {
                // dp[i-j][k+offset]
                // (i-j)/2 + k + 1 = x + i/2;
                int x = (i-j)/2 + k + 1 - i/2;
                if (x > 4 || x < -4) continue;
                dp[i][x+offset] = max(dp[i][x+offset], dp[i-j][k+offset] + a[i-1]);
            }
        }
        for (int k = -4; k < 5; k++) {
            int x = (i-1)/2 + k - i/2;
            if (x > 4 || x < -4) continue;
            dp[i][x+offset] = max(dp[i][x+offset], dp[i-1][k+offset]);
        }
    }
    cout << dp[n][0+offset] << "\n";
    return 0;
}

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

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    char ch;
    cin >> ch;
    if(ch>='a' && ch<='z') cout << "a";
    else cout << "A";
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int n;
int Adj[101][101] = { 0 };
int d[101];

typedef struct{
	int max;
	int num;
	int front;
	int rear;
	int *que;
}Queue;

void Init(Queue *q, int max);
void Enque(Queue *q, int x);
void Deque(Queue *q, int *x);


int main(void){
	int u, k, v;
	int i, j;

	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		scanf("%d %d", &u, &k);
		for (j = 1; j <= k; j++){
			scanf("%d", &v);
			Adj[u][v] = 1;
		}
	}

	Queue que;
	Init(&que, n*n);
	for (i = 1; i <= n; i++){
		d[i] = -1;
	}

	d[1] = 0;
	Enque(&que, 1);
	while (que.num != 0){
		Deque(&que, &u);
		for (v = 1; v <= n; v++){
			if (Adj[u][v] == 1){
				if (d[v] == -1 || d[v] > d[u] + 1){
					d[v] = d[u] + 1;
					Enque(&que, v);
				}
			}
		}
	}

	for (i = 1; i <= n; i++){
		printf("%d %d\n", i, d[i]);
	}

	return 0;
}

void Init(Queue *q, int max){
	q->max = max;
	q->num = q->front = q->rear = 0;
	q->que = calloc(max, sizeof(int));
}

void Enque(Queue *q, int x){
	q->num++;
	q->que[q->rear++] = x;
	if (q->rear == q->max)
		q->rear = 0;
}

void Deque(Queue *q, int *x){
	q->num--;
	*x = q->que[q->front++];
	if (q->front == q->max)
		q->front = 0;
}

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

using namespace std;

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

    for(int i=0;i<=50;i++){
        for(int j=0;j<=25;j++){
            if(i+j==x&&2*i+4*j==y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3628
class Combination:
    def __init__(self, mod, max_n):
        self.MOD = mod
        self.MAX_N = max_n

        self.f = self.factorial(self.MAX_N)
        self.f_inv = [self.inv(x) for x in self.f]

    def inv(self,x):
        return pow(x, self.MOD-2, self.MOD)
    
    def factorial(self, n):
        res = [1]
        for i in range(1,n+1):
            res.append(res[-1] * i % self.MOD)
        return res
    
    def comb(self, n, r):
        return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD

N, K = map(int,input().split())

CB = Combination(10**9+7,10000)

for i in range(1,K+1):
    if i > N-K+1:
        print(0)
    else:
        print(CB.comb(N-K+1,i) * CB.comb(K-1,i-1) % CB.MOD)

Measured memory_bytes: 9964
#include<stdio.h>
int main(void)
{
	int b1,b2,b3;
	scanf("%d %d %d",&b1,&b2,&b3);
	if((b1==1&&b2==0&&b3==0)||(b1==0&&b2==1&&b3==0)||(b1==0&&b2==0&&b3==0)){
		printf("Close\n");
	}
	else{
		printf("Open\n");
	}
	return 0;
}

Measured memory_bytes: 1012
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

template<typename T>
int compress(vector<T>& v) {
    vector<T> x(v);
    sort(x.begin(), x.end());
    x.resize(unique(x.begin(), x.end()) - x.begin());

    unordered_map<T, int> m;
    for(size_t i = 0; i < x.size(); i++) {
        m[x[i]] = i;
    }

    for(size_t i = 0; i < v.size(); i++) {
        v[i] = m[v[i]];
    }

    return x.size();
}
struct BIT{
    vector<LL> sums;
    BIT(int n) : sums(n) {}

    // v[at] += by
    void add(int at, LL by) {
        while(at < sums.size()){
            sums[at] += by;
            at |= at + 1;
        }
    }

    // v[0] + ... + v[at]
    LL get(int at) {
        LL res = 0;
        while(at >= 0) {
            res += sums[at];
            at = (at & (at + 1)) - 1;
        }
        return res;
    }

    // --- optional ---
    int size() const { return sums.size(); }
    LL operator [](int idx) const { return sums[idx]; }
};

int main(){
    iostream_init();
    int N;
    while(cin >> N) {
        vector<int> p(N);
        vector<int> l(N);
        REP(i, N) cin >> p[i];
        REP(i, N) cin >> l[i];

        vector<LL> s(N);
        s[0] = p[0];

        REP(i, N-1) s[i+1] = s[i] + p[i+1];

        vector<LL> w = s;
        compress(w);
        BIT bit(N+2);
        long long ans = 0;
        REP(i, N) {
            ans += bit.get(N) - bit.get(w[i]);
            bit.add(w[i], 1);
        }

        sort(s.begin(), s.end());
        REP(i, s.size()) {
            int a = (i - 1 >= 0 ? s[i-1] : 0);
            int b = s[i];
            if(b - a < l[i]) {
                ans = -1;
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

/* vim:set foldmethod=marker: */

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


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  a.push_back(0);

  bool low = true;
  int tmp = 10010010;
  vector<int> ch;
  for (int num : a) {
    if (low) {
      if (tmp < num) {
        ch.push_back(tmp);
        low = false;
      }
    } else {
      if (tmp > num) {
        ch.push_back(tmp);
        low = true;
      }
    }
    tmp = num;
  }

  ll ans = 1000;
  for (int i = 0; i < ch.size()/2; ++i) {
    ll t = ans/ch[2*i];
    ans -= t*ch[2*i];
    ans += t*ch[2*i+1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3680
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(i, n)    for(int i = 0; (i) < (1 << (n)); ++(i))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n, m, x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, n){
        cin >> c[i];
        rep(j, m)
            cin >> a[i][j];
    }

    int ans = INF9;
    repbit(bit, n){
        int cost = 0;
        vector<int> us(m, 0);
        rep(i, n){
            ifbit(bit, i){
                cost += c[i];
                rep(j, m)
                    us[j] += a[i][j];
            }
        }

        rep(j, m){
            if(us[j] < x) break;
            if(j == m - 1) chmin(ans, cost);
        }
    }

    cout << (ans == INF9 ? -1 : ans) << endl;

return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
 
int main() {
  	int day, hw, req[10000] = {};
  	cin >> day >> hw;
  	for (int i = 0; i < hw; ++i) {
    	cin >> req[i];
      	day -= req[i];
    }
  	if (day >= 0) {
    	cout << day;
    } else {
    	cout << "-1";
    }
  cout << endl;
	return 0;
}

Measured memory_bytes: 3652
package main

import "fmt"

func main(){
	var S string
	var f1, f2 int
	fmt.Scan(&S)
	f1 = 0
	f2 = 0

	if S[0] == 'A' {
		if 'a' <= S[1] && S[1] <= 'z' {
			f1++
		}
	}
	for i := 2 ; i <= len(S)-2 ; i++ {
		if S[i] == 'C' {
			f1++
		}else{
			f2++
		}
	}

	if 'a' <= S[len(S)-1] && S[len(S)-1] <= 'z' {
		f1++
	} 
	if f1 == 3 && f2 == len(S) - 4 {
		fmt.Println("AC")
	}else {
		fmt.Println("WA")
	}
	//fmt.Println(f1, f2)
	/*	for i := 1 ; i < len(S) ; i++ {
			if i == 1 && i == len(S)-1{
				if 'a' <= S[i] && S[i] <= 'z' {
					if 2 <= i && i <= len(S)-2 {
						if S[i] == 'C'{ f++ }
					}
				}
			}
		}
		
		
	}*/
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];
 
 
int main () {
    char s[3];
    scanf("%s", s);

    if(s[0] == '7' || s[1] =='7' || s[2] =='7')printf("Yes\n");
    else printf("No\n");


}

Measured memory_bytes: 3652
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int n, m;
    cin >> n >> m;
    int num[3] = { -1, -1, -1 };
    for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        s--; // 1 -> 0
        if (num[s] == -1) {
            num[s] = c;
        } else {
            if (num[s] != c) {
                cout << "-1" << endl;
                return 0;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            if (num[i] == -1) {
                if (n == 1) {
                    cout << 0; // 1桁の場合は1桁目に0を選べる
                } else {
                    cout << 1; // 複数桁の1桁目は1が最小なので1を選ぶ
                }
            } else if (num[i] == 0) {
                if (n == 1) {
                    cout << 0; // 1桁の場合は1桁目が0で良い
                } else {
                    cout << "-1" << endl; // 複数桁で1桁目が0になるのは不可
                    return 0;
                }
            } else {
                cout << num[i];
            }
        } else {
            if (num[i] == -1) {
                cout << 0;
            } else {
                cout << num[i];
            }
        }
    }
    cout << endl;
    return 0;
}


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


int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

//long long  factorial(long long n) {
//    if (n > 0) {
//        return n * factorial(n - 1);
//    } else {
//        return 1;
//    }
//}
long long  factorial(long long n, long long depth) {
    if (n > 1) {
        depth++;
        return factorial(n / 2, depth);
    } else {
        return depth;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}



//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
  int  a ,b, c, d, e, X, Y ,r;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
 long long  A[200003]={};
//  int  A[100003]={};
  int  B[100003]={};
  long long  C[100003][100001]={};

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
  char u[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p=0,q=0;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int min =100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  long long sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
  double per=0; 
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;

  scanf("%s %s", &s, &t);
  scanf("%d %d", &a, &b);
  scanf("%s", &u);
  
  if(strcmp(s,u)==0) a=a-1;
  if(strcmp(t,u)==0) b=b-1;

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


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

int main(){
    int n, m;
    cin >> n >> m;
    int a[n][2] = {{0}};
    int b[m][2] = {{0}};

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

    for(int i = 0; i < m; i++)
    {
        cin >> b[i][0] >> b[i][1];
    }

    
    for(int i = 0; i < n; i++)
    {
        long int min_dist = 1000000000;
        long int dist = 0;
        int ans = 0;
        for(int j = 0; j < m; j++)
        {
            dist = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]);
            if(dist < min_dist){
                min_dist = dist;
                ans = j;
            }
        }
        cout << ans + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int N, M;
    cin >> N >> M;
    int sum = 0;
    rep(i, 0, M) {
        int a;
        cin >> a;
        sum += a;
    }
    if(sum > N) {
        cout << "-1" << endl;

    } else {
        cout << N - sum << endl;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>

int main(){
    std::string s;
    std::cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
    {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 3620
using System;

namespace ABC075_C___Bridge
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var edges = new int[NM[1], 2];
            for (int i = 0; i < NM[1]; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                edges[i, 0] = ab[0];
                edges[i, 1] = ab[1];
            }

            var bridgeCount = 0;
            for (int removeEdge = 0; removeEdge < NM[1]; removeEdge++)
            {
                var union = new UnionFind(NM[0]);
                for (int edge = 0; edge < NM[1]; edge++)
                {
                    if (edge == removeEdge) continue;
                    union.unite(edges[edge, 0], edges[edge, 1]);
                }
                if (union.RootCount(1) != NM[0]) bridgeCount++;
            }
            Console.WriteLine(bridgeCount);
        }
    }
    public class UnionFind
    {
        private int[] parents;
        // 同じ根に属する枝の数を格納する
        private int[] rootCount;

        public int RootCount(int branch)
        {
            return rootCount[root(branch)];
        }

        public UnionFind(int count)
        {
            parents = new int[count + 1];
            rootCount = new int[count + 1];
            for (int i = 0; i < count + 1; i++)
            {
                parents[i] = i;
                rootCount[i] = 1;
            }
        }

        private int root(int N)
        {
            if (parents[N] == N) return N;
            return parents[N] = root(parents[N]);
        }

        //木を併合する際に、枝の数も合算する
        public void unite(int X, int Y)
        {
            int rootX = root(X);
            int rootY = root(Y);
            if (rootX == rootY) return;
            rootCount[rootX] += rootCount[rootY];
            parents[rootY] = rootX;
        }

        public bool sameRoot(int X, int Y)
        {
            return root(X) == root(Y);
        }

    }
}


Measured memory_bytes: 13268
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	int N;
	int[] L;

	public void solve() {
		N = nextInt();
		L = new int[N * 2];
		for(int i = 0;i < N * 2;i++){
			L[i] = nextInt();
		}

		Arrays.sort(L);

		int ans = 0;
		for(int i = 0;i < N;i++){
			ans += Math.min(L[2 * i],L[2 * i + 1]);
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int main(){
  ll n,a,b,c,d,e; cin >>n >>a >>b >>c >>d >>e;
  ll m = min(a,min(b,min(c,min(d,e))));
  cout << 4+(n+m-1)/m << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;

const ll INF = 9223372036854775807;
const int inf = 2147483647;

ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}


int res;
int a[3];
int main() {
    REP(i,3){
        cin >> a[i];
    }
    sort(a,a+3);
    res = a[1]-a[0]+a[2]-a[1];
    put(res);
    return 0;
}


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

def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return n * 3 + 1

def main():
    s = int(input())
    arr = [s]

    for _ in range(1000000):
        s = f(s)
        if s in arr:
            break
        arr.append(s)

    print(len(arr)+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N[1000001];     //write about default thing and 1000000 instead of 1e6

int main(){
  int n,count=0;
  cin>>n;
  int a[n];
  unordered_set<int> s;
  for(int i=0;i<n;i++){
    cin>>a[i];
    s.insert(a[i]);
    N[a[i]]++;
  }
  vector<bool> v(1e6+1,true);
  int c;
  for(auto x:s){
    c=2*x;
    while(c<=1e6){
      v[c]=false;
      c+=x;
    }
  }
  for(int i=0;i<n;i++){
    if(v[a[i]] && N[a[i]]==1)count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 15448
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A + 1):
    for b in range(B + 1):
        q = (X - (500 * a + 100 * b)) / 50
        if q >= 0 and q <= C:
            ans += 1
print(ans)


Measured memory_bytes: 3060
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

class WeightedUnionfind():
    def __init__(self,n):
        self.par =[i for i in range(n+1)]
        self.rank =[0]*(n+1)
        self.weight =[0]*(n+1)

    def find(self,x):
        if self.par[x]==x:
            return x

        else:
            y =self.find(self.par[x])
            self.weight[x]+=self.weight[self.par[x]]
            self.par[x]=y
            return y

    def union(self,x,y,w):
        rx=self.find(x)
        ry=self.find(y)
        if self.rank[rx]<self.rank[ry]:
            self.par[rx]=ry
            self.weight[rx]=w-self.weight[x]+self.weight[y]
        else:
            self.par[ry]=rx
            self.weight[ry]=-w-self.weight[y]+self.weight[x]
            if self.rank[rx]==self.rank[ry]:
                self.rank[rx]+=1
    def same(self,x,y):
        return self.find(x)==self.find(y)

    def diff(self,x,y):
        return self.weight[x]-self.weight[y]

n,m=MI()
wuf=WeightedUnionfind(n)
for i in range(m):
    l,r,d=MI()
    #print(l,r,d,end=" ")
    #print(wuf.same(l,r))
    if wuf.same(l,r):
        #print(wuf.diff(l,r))
        if wuf.diff(l,r)!=d:
            print("No")
            sys.exit()
    else:
        wuf.union(l,r,d)
print("Yes")



    
    



    


        


    
    


    

    
            
        
        
    
    
    
    

    
    


    
    

        
        
    


    

Measured memory_bytes: 16296
#include <iostream>
#include <math.h>

#define N 50050

using namespace std;

int main(void){
	bool isprime[N];
	for(int i=0;i<N;i++) isprime[i]=true;
	int upto = (int)sqrt(N);
	for(int i=2;i<=upto;i++){
		if(isprime[i]){//消されてなければその倍数を消す
			for(int j=2;i*j<=N;j++) isprime[i*j] = false;
		}
	}
	int n;
	while(cin >> n){
		int prm1,prm2;
		for(int i=n-1;i>1;--i){
			if(isprime[i]){
				prm1 = i;
				break;
			}
		}
		for(int i=n+1;i<N;++i){
			if(isprime[i]){
				prm2 = i;
				break;
			}
		}
		cout << prm1 << " " << prm2 << "\n";
	}
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    bool flg = false;
    rep(i, 0, s.length())
    {
        if (s[i] == 'A' && s[i + 1] == 'C')
        {
            flg = true;
        }
    }
    if (flg)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3580
/* Author haleyk10198 */
/* 作者:  haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>
 
#define MOD 1000000007
#define LINF (1LL<<60)
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))
#define pb(x) push_back((x))
#define vi vector<int>
#define vvi vector<vi>
#define EPS 1e-9
 
using namespace std;
 
/**FACEPALM INTENSIFIES**/

int vis[50][100010];
int n;

ll f(ll x){
	int ret = 0;
	while(x)
		ret += x%10, x /= 10;
	return ret;
}

void dfs(int rem, int dist){
	if(dist > 45) return;
	if(vis[dist][rem]) return;
	vis[dist][rem] = 1;
	for(int i = 0; i < 10; i++)
		dfs((rem*10+i)%n, dist+i);
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	
	cin >> n;
	for(int i = 1; i < 10; i++)
		dfs(i, i);
	
	for(int i = 1; i <= 45; i++)
		if(vis[i][0]){
			cout << i << endl;
			return 0;
		}
	return 0;
}	

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

int n, a[202020], ans[202020];

int main(){
cin >> n;
for(int i =1; i<=n ; i++){
    cin >> a[i];
}
if(n%2==1){
    int x = n/2 +1;
    ans[x]=a[1];
    int t = 2;
    for(int i =1; i<x; i++){
        ans[x+i]=a[t++];
        ans[x-i]=a[t++];
    }
}
if(n%2==0){
    int x = n/2 +1;
    ans[x]=a[1];
    int t = 2;
    for(int i =1;i<x; i++){
        ans[x-i]=a[t++];
        if(t>n)break;
        ans[x+i]=a[t++];
    }
}
for(int i =1; i<=n; i++){
    cout << ans[i] << " ";
}


return 0;}


Measured memory_bytes: 3712
N = int(input())
T, A = map(int, input().split())

H = list(map(int, input().split()))

dif = []

for i, h in enumerate(H):
  # print(h)
  temp = T - h*0.006
#  print(temp)
  diff = abs(A - temp)
  dif.append([diff, i+1])

dif = sorted(dif)

print(dif[0][1])

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int A,B,C;
cin>>A>>B>>C;
cout<<max(C-(A-B),0)<<"\n";
return 0;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(k+a[0])
a = a[::-1]
max = 0

for i in range(len(a)-1):
    l = a[i]-a[i+1]
    if l > max:
        max = l
print(k-max)


Measured memory_bytes: 77516
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<iomanip>
#include<string>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e5+10;
int main()
{
    ll x,mo=100;
    cin>>x;
    int ans=0;
    while(mo<x)
    {
        mo=mo+mo*0.01;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <deque>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    string S,T;
    cin >> S >> T;
    ll ans=0;
    for(int i=0;i<3;i++){
        if(S[i]==T[i])ans++;
    }
    cout << ans << endl;

    return 0;
}

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

#define N 30
#define P 1000003

#define max(a,b) (a>b?a:b)

int main() {
	int n, x, c, dp[P], p[P], ans;
	for(int i=0; i<P; ++i) p[i] = 1;
	p[0] = p[1] = 0;
	for(int i=2; i<P; ++i) {
		if(p[i]&&i<P/i) for(int j=i*i; j<P; j+=i) p[j]=0;
	}
	while(1) {
		cin >> n >> x;
		if(!n&&!x) break;
		ans = 0;
		for(int i=0; i<=x; ++i) dp[i] = 0;
		dp[0] = 1;
		for(int i=0; i<n; ++i) {
			cin >> c;
			for(int j=0; j<=x-c; ++j) {
				if(dp[j]) {
					dp[j+c] = 1;
					if(p[j+c]) ans = max(ans, j+c);
				}
			}
		}
		if(ans==0) cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 8968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a,b;
const ll INF = 1000000000000000000;
const int mod = 1000000007;
const int N = 100005;
ll s[N];
int dp[N];
int p1, p2;
int ans = 0;
int sum = 0;
int main(){
    scanf("%d%lld%lld",&n,&a,&b);
    for (int i = 1; i <= n; i++) scanf("%lld",&s[i]);
    if (a >= b) swap(a,b);
    dp[0] = 1;
    s[0] = -INF;
    s[n+1] = INF*2;
    for (int i = 2; i <= n; i++){
        if (s[i] - s[i-2] < a) {
            printf("0");
            return 0;
        }
    }
    for (int i = 1; i <= n+1; i++){
        while (p2 < i && s[i]-s[p2] >= b){
            //printf("%lld: can extend to %lld, add %d\n",s[i],s[p2],dp[p2]);
            sum += dp[p2];
            sum %= mod;
            p2++;
        }
        //printf("dp[%d] = %d\n",i,sum);
        dp[i] = sum;
        if (s[i] - s[i-1] < a){
            while (p1 < i-1){
                //printf("shrink to %lld, remove %d\n",s[p1],dp[p1]);
                if (p1 < p2) {
                    sum += mod-dp[p1];
                    sum %= mod;
                }
                dp[p1] = 0;
                p1++;
            }
        }
        /*for (int j = 0; j <= i; j++){
            printf("%d ",dp[j]);
        }
        printf("\n");
        printf("now sum = %d\n",sum);*/
    }
    printf("%d",dp[n+1]);
}



Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string S;

void input()
{
    cin >> S;
}

long long count(const vector<int>& A)
{
    long long ans = 0;
    int expect = 0;
    for (int i = 0; i < A.size(); ++i)
    {
        if (A[i] == 1)
        {
            ans += i - expect++;
        }
    }
    return ans;
}

long long solve()
{
    int p = 0;
    long long ans = 0;
    while (p < S.size())
    {
        while (p < S.size() && (S[p] == 'C' || S[p] == 'B' && (p + 1 == S.size() || S[p + 1] != 'C')))
        {
            ++p;
        }
        vector<int> current;
        while (p < S.size() && (S[p] == 'A' || p + 1 < S.size() && S[p] == 'B' && S[p + 1] == 'C'))
        {
            if (S[p] == 'A')
            {
                current.push_back(0);
                ++p;
            }
            else
            {
                current.push_back(1);
                p += 2;
            }
        }
        if (!current.empty())
        {
            ans += count(current);
        }
    }
    return ans;
}

int main()
{
    input();
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>



int main (void) {
  int A, B, C, X;
  std::cin >> A >> B >> C >> X;

  int ans = 0;
  for(int i=0; i<=A; i++){
    for (int j=0; j<=B; j++){
      if ( (X-(500*i+100*j)) >= 0 && (X-(500*i+100*j))/50 <= C ) ans++;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main()
{
 int a;
 string s;
 
 
 
 cin >> a ;
 cin>>s;
 if(a>=2800&&a<5000)
 {
   
   if (a>=3200)
 cout << s ;
 
 else if (a<3200)
 {
     
 cout << "red";
 
 }
 
 
     
 }
 
 
 
 
 
    return 0;
}

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

void trace(int A[], int N) {
  for (int i = 0; i < N; i++) {
    if ( i > 0 ) cout << " ";
    cout << A[i];
  }
  cout << endl;
}

void insertSort(int A[], int N) {
  int j, v;
  for (int i = 1; i < N; i++) {
    v = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}

int main() {
  int N, j;
  int A[100];
  cin >> N;

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

  trace(A, N);
  insertSort(A, N);

  return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string str;
    int len;
    cin >> len;
    cin >> str;

    int count = 0;
    int i = 0;
    for (; i <= len -3;)
    {
        if (str[i] == 'A' && str[i + 1] == 'B' && str[i + 2] == 'C')
        {
            count++;
            i = i + 3;
        }
        else
            i = i + 1;
    }
    cout << count;
    return 0;
}



Measured memory_bytes: 256
def solve(n, b, shouldbe):
	s = 0
	while n > 0:
		s += n % b 
		n /= b
	return s == shouldbe

import math

n = input()
s = input()
d = n-s
if d < 0:
	print -1
elif d == 0:
	print n + 1
else:
	ans = 98766531231223232232232329876653123122323223223232
	for i in range(1, int(math.sqrt(d))+2):
		if d % i == 0:
			if solve(n, i+1, s): 
				ans = min(ans, i+1)
			if solve(n, d/i + 1, s):
				ans = min(ans, d/i + 1)
	if ans == 98766531231223232232232329876653123122323223223232:
		print -1
	else: print ans


Measured memory_bytes: 9840
n = int(input())
a = list(map(int,input().split()))

money = 0
for i in range(n-1):
  money += abs(a[i+1]-a[i])
money += abs(a[0])+abs(a[-1])


print(money - abs(a[0]) - abs(a[0]-a[1]) + abs(a[1]))
for i in range(1,n-1):
  print(money - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]))
print(money - abs(a[-1]) - abs(a[-1]-a[-2]) + abs(a[-2]))

Measured memory_bytes: 14172
def a(seats)
  seats[seats.index("#")] = "A"
end

def b(seats, n)
  (n - 1).downto(0) do |i|
    if (i - 1 < 0 || seats[i - 1] != "A") && seats[i + 1] != "A" &&
        seats[i] == "#"
      seats[i] = "B"
      return
    end
  end
  seats[seats.index("#")] = "B"
end

def c(seats, n)
  if seats.count("#") == n
    idx = n / 2
  else
    n.times do |i|
      if seats[i] != "#"
        if seats[i + 1] == "#"
          idx = i + 1
          break
        elsif i - 1 >= 0 && seats[i - 1] == "#"
          idx = i - 1
          break
        end
      end
    end
  end
  seats[idx] = "C"
end

def d(seats, n)
  idx = 0
  if seats.count("#") != n
    max_dist = 0
    n.times do |i|
      d = nearest_dist(seats, i)
      if d > max_dist
        max_dist = d
        idx = i
      end    
    end
  end
  seats[idx] = "D"
end

def nearest_dist(seats, i)
  dist = 0
  dist += 1 until /[A-D]/ =~ seats[i + dist] ||
                  (i - dist >= 0 && /[A-D]/ =~ seats[i - dist])
  dist
end

until (given = gets.split.map(&:to_i)) == [0, 0]
  n, m = given
  seats = "#" * n
  m.times do
    case gets.chomp
    when "A" then a(seats)
    when "B" then b(seats, n)
    when "C" then c(seats, n)
    when "D" then d(seats, n)
    end
  end
  puts seats
end



Measured memory_bytes: 7132
import sys

def qsort(seq):
    if seq == []:
        return seq
    return qsort([x for x in seq[1:] if x < seq[0]]) + seq[0:1] + qsort([x for x in seq[1:] if x >= seq[0]])

data_set = []

for i in range(0, 10):
    data_set.append(int(input()))

rank = qsort(data_set)

for i in range(0,3):
    print(rank.pop(-1))

Measured memory_bytes: 7748
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 110000;
const int maxk = 12;

int n,m,Q;
int col[maxn];
struct edge{int y,nex;}a[maxn<<1]; int len,fir[maxn];
inline void ins(const int x,const int y){a[++len]=(edge){y,fir[x]};fir[x]=len;}

int e[maxn][3];
bool v[maxn][maxk];
struct node{int x,p;};
queue<node>q;

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		ins(x,y); ins(y,x);
	}
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++) scanf("%d%d%d",&e[i][0],&e[i][1],&e[i][2]);
	
	for(int i=Q;i>=1;i--)
	{
		int cc=e[i][2];
		q.push((node){e[i][0],e[i][1]});
		while(!q.empty())
		{
			const node now=q.front(); q.pop();
			if(v[now.x][now.p]) continue;
			if(!col[now.x]) col[now.x]=cc;
			for(int j=now.p;j>=0&&!v[now.x][j];j--) v[now.x][j]=true;
			if(now.p==0) continue;
			for(int k=fir[now.x],y=a[k].y;k;k=a[k].nex,y=a[k].y)
				q.push((node){y,now.p-1});
		}
	}
	for(int i=1;i<=n;i++) printf("%d\n",col[i]);
	
	return 0;
}


Measured memory_bytes: 6400
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

int N,A[2][100];
//int dp[2][100];


int main()
{
	cin>>N;
	rep(j,2) rep(i,N){
		cin>>A[j][i];
	}
	rep1(i,N-1) A[0][i]+=A[0][i-1];
	A[1][0]+=A[0][0];
	rep1(i,N-1) A[1][i]+=max(A[1][i-1],A[0][i]);
	cout<<A[1][N-1]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() { 
    int a[3], ans = 3;
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    if(a[0] == a[1]) {
        ans--;
    }
    if(a[1] == a[2]) {
        ans--;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;

int main() {
    ll K, S;
    cin >> K >> S;
    ll ans = 0;
    for(int x=0; x<=K && x <= S; ++x) {
        for(int y=0; y<=K && x+y <= S; ++y) {
            if(S-x-y <= K) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, alice, bob int
	fmt.Scan(&n)
	cards := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}
	sort.Ints(cards)
	for i := range cards {
		if i%2 == 0 {
			alice += cards[n-i-1]
		} else {
			bob += cards[n-i-1]
		}
	}
	fmt.Println(alice - bob)
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=1e6+10;
int zero[]={0,1,2,3,4,5,6,7,8,9,1};
int one[]={1,9,8,7,6,5,4,3,2,1,0};
//dp[i][0/1]:有没有给后面留10 
int dp[N][2],v;
char s[N];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	v=s[1]-'0';
	dp[1][0]=min(zero[v],1+one[v]);
	dp[1][1]=min(zero[v+1],1+one[v+1]);
	for(int i=2;i<=n;++i)
	{
		v=s[i]-'0';
		dp[i][0]=min(dp[i-1][0]+min(zero[v],1+one[v]),dp[i-1][1]+min(one[v],1+zero[v]));
		dp[i][1]=min(dp[i-1][0]+min(zero[v+1],1+one[v+1]),dp[i-1][1]+min(one[v+1],1+zero[v+1]));//dp[i-1][1]+1+min(zero[v+1],1+one[v+1])
	}
	printf("%d\n",dp[n][0]);
	return 0;
}

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

using ull = unsigned long long;
struct RollingHash_Mersenne {
	const ull MASK30 = (1ULL << 30) - 1;
	const ull MASK31 = (1ULL << 31) - 1;
	const ull MASK61 = (1ULL << 61) - 1;
	const ull MOD = MASK61;
	const ull POSITIVIZER = MOD << 2;
	vector<ull> hash, power;

	RollingHash_Mersenne(const string &s, ull base = 10007) {
		int sz = (int)s.size();
		hash.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = CalcMod(Mul(power[i], base));
			hash[i + 1] = CalcMod(Mul(hash[i], base) + s[i]);
		}
	}

	template <class T>
	RollingHash_Mersenne(const vector<T> &v, ull base = 10007) {
		int sz = (int)v.size();
		hash.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = CalcMod(Mul(power[i], base));
			hash[i + 1] = CalcMod(Mul(hash[i], base) + v[i]);
		}
	}

	// a * b と mod が等しい数を返す
	// 結果は (1UL << 63) + 3 - (1UL << 31) * 3 以下
	ull Mul(ull a, ull b) {
		ull au = a >> 31;
		ull ad = a & MASK31;
		ull bu = b >> 31;
		ull bd = b & MASK31;
		ull mid = ad * bu + au * bd;
		ull midu = mid >> 30;
		ull midd = mid & MASK30;
		return au * bu * 2 + midu + (midd << 31) + ad * bd;
	}

	// mod 2^61-1を計算する
	ull CalcMod(ull x) {
		ull xu = x >> 61;
		ull xd = x & MASK61;
		ull res = xu + xd;
		if(res >= MOD) res -= MOD;
		return res;
	}

	ull get(int l, int r) { return CalcMod(hash[r] + POSITIVIZER - Mul(hash[l], power[r - l])); }

	ull connect(ull h1, ull h2, ull h2len) { return CalcMod(Mul(h1, power[h2len]) + h2); }

	// Longest Common Prefix
	int LCP(int l_this, int r_this, RollingHash_Mersenne &other, int l_other, int r_other) {
		int len = min(r_this - l_this, r_other - l_other);
		int low = 0, high = len + 1;
		while(high - low > 1) {
			int mid = (low + high) / 2;
			if(get(l_this, l_this + mid) == other.get(l_other, l_other + mid))
				low = mid;
			else
				high = mid;
		}
		return low;
	}
};

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

int main() {
	int n;
	string s;
	cin >> n >> s;

	RollingHash_Mersenne rh(s, rand() % 10007 + 3);
	int res = 0;
	rep(i, n) {
		rep(j, n) {
			if(j <= i) continue;
			int a = rh.LCP(i, n, rh, j, n);
			//	cout << a << endl;
			res = max(res, min(a, j - i));
		}
	}
	cout << res << endl;
}

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

using namespace std;

int main()
{
  int n, x, all = 0, min = 100000, ans;

  scanf("%d %d", &n, &x);

  vector<int> m(n);

  for (int i = 0; i < n; i++)
  {
    scanf("%d", &m[i]);
    all += m[i];
    if (m[i] < min)
      min = m[i];
  }

  x -= all;
  ans = x / min + n;

  printf("%d", ans);
}

Measured memory_bytes: 256
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=2e5+5,inf=2e9;

multiset<int>R,B;
ll Rmx=-inf,Rmn=inf,Bmx=-inf,Bmn=inf,ans;

int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

struct bags {
	int v1,v2;

	bags() {}

	bags(int _v1,int _v2) {
		v1=_v1,v2=_v2;
	}

	bool operator<(const bags &a)const {
		return v1<a.v1;
	}
}p[maxn];

ll calc() {
	return 1ll*(*R.rbegin()-*R.begin())*(*B.rbegin()-*B.begin());
}

int main() {
	int n=read();
	for(int i=1;i<=n;i++) {
		int x=read(),y=read();
		if(x>y)swap(x,y);
		p[i]=bags(x,y);
		R.insert(x),B.insert(y);
	}
	sort(p+1,p+n+1);
	ans=calc();
	for(int i=1;i<=n;i++) {
		int x=p[i].v1,y=p[i].v2;
		R.erase(R.find(x)),B.insert(x);
		B.erase(B.find(y)),R.insert(y);
		ans=min(ans,calc());
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define endl '\n'
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define add push_back
#define MAXN 200005

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

    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n, d;
	cin >> n >> d;
	vector<vector<double>> ps;
	for (int i = 0; i < n; i++)
	{
		vector<double> point(d);
		for (int j = 0; j < d; j++)
		{
			cin >> point[j];
		}
		ps.push_back(point);
	}
	int ans = 0;
	for (int i = 0; i < n-1; i++)
		for (int j = i+1; j < n; j++)
		{
			double squD = 0;
			for (int k = 0; k < d; k++)
			{
				squD += (ps[i][k] - ps[j][k]) * (ps[i][k] - ps[j][k]);
			}
			if (fabs(pow((long)sqrt(squD), 2) - squD) < 1e-10) ans++;
		}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
typedef pair<int,int> PI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXS
LL n,m,v,p;
VL zb;

bool mozna(int p1){
	
	if(p1<0)
		return false;
	
	LL nad=m*(v-1);			//powiekszamy zb[p1] o m pkt
	int mks=p-1,prog=zb[p1]+m;
	
	REP(i,n){
		if(zb[i]>prog)
			mks--;
	}
	if(mks<0)
		return false;
	
	mks=p-1;
	FORD(i,n-1,0){
		if(i==p1)
			continue;
		if(mks){
			nad-=m;
			mks--;
		}
		else
			nad-=min(m,prog-zb[i]);
	}
//	cout<<p1+1<<" "<<zb[p1]<<" "<<nad<<"\n";
	return nad<=0;
	
}

int main(){
	
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m>>v>>p;
	
	zb.resize(n);
	REP(i,n)
		cin>>zb[i];
	sort(ALL(zb));
	
	int k=n-1;
	for(int p1=n/2;p1>=1;p1/=2){
		while(mozna(k-p1))
			k-=p1;
	}
	cout<<n-k;
	
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

# define inOut(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
# define RESET(a) memset(a,0,sizeof(a))
# define MEMO(a) memset(a,-1,sizeof(a))
# define DEBUG puts("Debug-Has-Come-Until-Here")


typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	cin.tie(NULL);

	int a,b,hitung;
	while(scanf("%d %d", &a,&b) != EOF){
		hitung = 0;
		a = a+b;
		if (a == 0)hitung = 1;
		while(a >0){
			hitung ++;
			a/=10;
		}
		printf("%d\n", hitung);
	}
	return 0;
}

Measured memory_bytes: 3148