akhauriyash/Code-Regression huggingface dataset:
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 300031;

vector<long long> v;

int n,m;
char board[151][151];

bool outside(int a,int b){
	return (a<0||a>=n||b<0||b>=m);
}

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	cin>>n>>m;
	for (int i=0;i<n;i++){
		string st;
		cin>>st;
		for (int j=0;j<m;j++){
			board[i][j]=st[j];
		}
	}

	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			if (board[i][j]!='#')
				continue;
			int can=0;
			for (int dx=-1;dx<=1;dx++){
				for (int dy=-1;dy<=1;dy++){
					if (abs(dx)+abs(dy)!=1)
						continue;
					if (outside(i+dx,j+dy))
						continue;
					if (board[i+dx][j+dy]=='#')
						can=1;
				}
			}
			if (!can){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}

	cout<<"Yes"<<endl;

//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 256
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  char str[3];
  cin >> str;
  bool seven = false;
  FOR(i, 0, 2){
    if (str[i] == '7') {
      seven = true;
      break;
    }
  }
  if (seven==true) {
    cout << "Yes" << "\n";
  } else {
    cout << "No" << "\n";
  }

}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
	string data;
	cin>>data;
	int longitud=data.size();
	string cambiado1=data;
	reverse(cambiado1.begin(),cambiado1.end());
	bool primero=true,segundo=true,tercero=true;

	if(data==cambiado1){
		primero=true;
	}
	else{
		primero=false;
	}
	string first=data.substr(0,(longitud-1)/2);;
	string cambiado2=first;
	reverse(cambiado2.begin(),cambiado2.end());
	if(first==cambiado2){
		segundo=true;
	}
	else{
		segundo=false;
	}
	string second=data.substr((longitud+1)/2,(longitud-1)/2);
	string cambiado3=second;
	reverse(cambiado3.begin(),cambiado3.end());
	if(second==cambiado3){
		tercero=true;
	}
	else{
		tercero=false;
	}

	if(primero &&  segundo && tercero){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void) {
  int n, q;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; i++) { cin >> S[i]; }
  cin >> q;
  vector<int> T(q);
  for (int i = 0; i < q; i++) { cin >> T[i]; }

  int count = 0;
  for (int i = 0; i < q; i++) {
    if (*lower_bound(S.begin(), S.end(), T[i]) == T[i])
      count++;
  }

  cout << count << endl;
}



Measured memory_bytes: 3352
module vector_int32_mod
    use,intrinsic :: iso_fortran_env
    type vector
        integer(int64),pointer:: array(:) =>null()
        integer(int64):: l
    contains
        procedure :: push_back => vector_regist
    end type

    interface vector
        module procedure vector_init
    end interface
    private
    public:: vector
contains
    function vector_init() result(vec)
        type(vector):: vec
        allocate(vec%array(1))
        vec%l = 0
    end function

    subroutine vector_regist(vec, v)
        class(vector):: vec
        integer(int64):: v

        if (vec%l+1 > size(vec%array)) call add_(vec)
        vec%l=vec%l+1
        vec%array(vec%l) = v
    end subroutine


    subroutine add_(vec)
        type(vector):: vec
        integer(int64),pointer:: tmp(:)
        integer(int64):: l

        tmp => vec%array
        l = size(vec%array)
        vec%array => null()
        allocate(vec%array(l*2))
        vec%array(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine
end module

program main
    use,intrinsic :: iso_fortran_env
    use vector_int32_mod
    implicit none
    integer(int64):: n,q,k,i
    integer(int64), allocatable:: a(:), b(:), c(:), x(:), y(:)
    integer(int64), allocatable:: k_dist(:)
    type(vector), allocatable:: to(:), d(:)
    
    read*, n
    allocate(a(n-1), b(n-1), c(n-1))
    allocate(to(n), d(n))
    allocate(k_dist(0:n))

    do i=1,n
        to(i) = vector()
        d(i) = vector()
    end do
    
    do i=1,n-1
        read*, a(i), b(i), c(i)
        call to(a(i))%push_back(b(i))
        call to(b(i))%push_back(a(i))
        call d(a(i))%push_back(c(i))
        call d(b(i))%push_back(c(i))
    end do

    read*, q,k
    allocate(x(q), y(q))
    k_dist(0)=0_8
    call dfs(k,0_8,0_8)

    do i=1,q
        read*, x(i), y(i)
    end do

    do i=1,q
        print'(i0)', k_dist(x(i)) + k_dist(y(i))
    end do
contains
    recursive subroutine dfs(self, from, distance)
        integer(int64), intent(in):: self, from, distance
        integer(int64):: i, next, next_d

        k_dist(self) = k_dist(from)+distance

        do i=1,to(self)%l
            next = to(self)%array(i)
            next_d = d(self)%array(i)
            if (next == from) cycle
            call dfs(next, self,next_d)
        end do
    end subroutine
end program main

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

int main () {
  int ans = 0, m = 0;

  rep(i,5) {
    int t, l;
    cin >> t;
    l = 10 - (t % 10);
    l %= 10;
    ans += t + l;
    m = max(m, l);
  }
  ans -= m;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <functional>
typedef long long ll;
using namespace std;
int main(){
    ll a,b;
    cin >> a >> b;

    if((max(a,b) - min(a,b)) % 2 != 0)cout << "IMPOSSIBLE" << endl;
    else{
        cout << min(a,b) + (max(a,b)-min(a,b))/2LL << endl;
    }
}


Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

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);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }

  ll x = 1;

  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

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

  std::string s;
  std::cin>>s;

  ll n=s.size();

  std::vector<std::vector<ll>> occur(26);

  rep(i,0,n)occur[s[i]-'a'].push_back(i);

  std::vector<ll> len(n,1);

  std::vector<ll> temp(26,0);

  temp[s[n-1]-'a']++;

  for(ll i=n-2;i>=0;i--){
    temp[s[i]-'a']++;
    len[i]=len[i+1];
    bool flag=true;
    rep(j,0,26)flag&=(temp[j]>0);

    if(flag){
      len[i]++;
      rep(j,0,26)temp[j]=0;
    }
  }

  std::string ans="";
  ll now=0;

  rep(i,0,len[0]){
    rep(j,0,26){
      auto itr=std::lower_bound(all(occur[j]),now);
      if(itr==occur[j].end()||len[now]-1==len[*itr+1]){
        ans+=(char)('a'+j);
        if(itr!=occur[j].end())now=*itr+1;
        break;
      }
    }
  }

  std::cout<<ans;

  return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
typedef pair<int,int> ipair;
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
 
ll mod = 1000000007;


int main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	int n,m;
	cin>>n>>m;
	vector<ipair> rec(n);
	for(int i=0;i<n;i++){
		cin>>rec[i].first>>rec[i].second;
	}
	sort(rec.begin(),rec.end());
	priority_queue<ipair, vector<ipair> > pq; 
	int  p = 0;
	ll re = 0;
	for(int i=m;i>0;i--){
		while(p<n&&((rec[p].first+i-1)<=m)){
			pq.push(make_pair(rec[p].second,rec[p].first));
			p++;
		}
		//cout<<p<<endl;
		if(!pq.empty()){
			ipair temp = pq.top();
			pq.pop();
			//cout<<temp.first<<" "<<i<<endl;
			re += temp.first;
		}
	}
	cout<<re<<endl;
	return 0;
}
 
//-------------------------//

Measured memory_bytes: 2168
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int a[MAXN];

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt(), C = readInt(), K = readInt();
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    }
    sort(a + 1, a + 1 + n);
    int r = 1;
    int ans = 0;                          
    for (int i = 1; i <= n; i++) {
		while (r < n && a[i] + K >= a[r + 1] && (r + 1 - i + 1) <= C) {
			r++;
		}   
		ans += 1;
		i = r;
		r = i + 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n;
  while(cin >> n, n){
    stringstream ans;
    while(n >= 10 || n < 0){
      int div = n / (-10);
      int mod = n % (-10);
      
      if(mod < 0){
	mod += 10;
	div += 1;
      }

      ans << mod;
      n = div;
    }

    string tmp = ans.str();
    reverse(tmp.begin(), tmp.end());

    if(n != 0)
      cout << n;
    cout << tmp << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    int maxx=x;
    int miny=y;
    rp(i,n){
        int a;
        cin >> a;
        chmax(maxx,a);
    }
    rp(i,m){
        int b;
        cin >> b;
        chmin(miny,b);
    }
    if(maxx<y&&miny>x&&maxx<miny){
        print("No War");
    }
    else print("War");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int A[1000],key,i,j,a,b;

  scanf("%d",&a);

  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }

  for(b=0;b<a;b++){
    printf("%d",A[b]);
    if(b<a-1) printf(" ");
    else printf("\n");
  }
  for (i=1;i<a;i++){
      key=A[i];
      j=i-1;
      while(j>=0&&A[j]>key){
           A[j+1]=A[j];
           j--;
       }
      A[j+1]=key;
      for(b=0;b<a;b++){
        printf("%d",A[b]);
        if(b<a-1) printf(" ");
        else printf("\n");
      }
  }

  return 0;
}





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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int x,y;
    cin>>x>>y;
    (x+y<10)?cout<<x+y :cout<<"error";
    cout<<endl;
    return 0;
}

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

int main(){
    int n, num[110], a=0, b=0;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &num[i]);
    }
    sort(num, num+n);
    bool bob = false;
    for(int i=n-1; i>=0; i--){
        if(bob){
            b += num[i];
            bob = false;
        } else {
            a+= num[i];
            bob = true;
        }
    }
    printf("%d\n", a-b);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

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

    int max_cnt = 0, cnt;
    std::string max_lenght_str = "";
    std::string max_cnt_str = "";
    std::string str;
    std::map<std::string, int> str2cnt;

    while (std::cin >> str) {
        std::transform(str.begin(), str.end(),
                       str.begin(), ::tolower);
        if (str.size() > max_lenght_str.size()) {
            max_lenght_str = str;
        }
        cnt = ++str2cnt[str];

        if (max_cnt < cnt) {
            max_cnt = cnt;
            max_cnt_str = str;
        }
    }

    std::cout << max_cnt_str << " " << max_lenght_str << std::endl;

    return 0;
}

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

int main() {
  int N;
  int a,b,c,d,e;
  cin >> a >> b>>c>>d>>e;

  if(a==0){
    cout << 1 << endl;
  }
  else if(b==0){
    cout << 2 << endl;
  }
  else if(c==0){
    cout << 3 << endl;
  }
  else if(d==0){
    cout << 4 << endl;
  }
  else if(e==0){
    cout << 5 << endl;
  }
}


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

int main(){
	
	string s; cin>>s;
	int a = 0,b = 0;
	for(auto xx : s) { if(xx == 'B') b++; else a++;}
	if(a && b) cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
	
	
	
	
}

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

using namespace std;
using ll=long long;

void solve() {
    int n, T;
    cin >> n >> T;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }

    ll sum = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] > a[i-1]+T) sum += T;
        else sum += a[i]-a[i-1];
    }
    sum += T;
    cout << sum;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
 
class Main {
    public static void main (String[] args){
    	Scanner sc=new Scanner(System.in);
    	int n=sc.nextInt();
    	int k=sc.nextInt();
    	int now=1;
    	for (int i = 0; i < n; i++) {
		     now=Math.min(now+k,now*2);
    	}
    	
 System.out.println(now);
    	
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll P = 1e9+7;
const ll N = 1e6+7;


//A sieve to effectivelly factorise numbers in a range(= size)
// A number is a prime if sieve[i] == i;

vector<	ll> sieve(N);
void factor_sieve()
{
	iota(sieve.begin(),sieve.end(),0);
 
	for(ll i=2;i*i<=N;++i)
	{
		if(sieve.at(i) == i)
		{
			for(ll j = i*i;j<N;j+=i)
				if(sieve.at(j) == j)sieve.at(j) = i;
		}
	}
}


int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll t=1;
	// cin>>t;

	while(t--){
		ll n;
		cin>>n;
		vector<ll> v(n);
		for(ll i=0;i<n;++i) cin>>v[i];

		factor_sieve();
		bool ok = true;
		vector<ll> hash(N);
		for(auto x : v){

			while(x != 1){
				ll f = sieve[x];
				if(hash[f]) {ok = false; break;}
				else hash[f]++;
				while(x%f == 0) x /= f;
			}
		}

		if(!ok){
			ll gg = 0;
			for(auto &x : v) gg = __gcd(gg,x);
			if(gg == 1) cout<<"setwise coprime\n";
			else cout<<"not coprime\n";
		}
		else cout<<"pairwise coprime\n";



	}	

	return 0;
}	


Measured memory_bytes: 26696
n,x=map(int,input().split())
A=list(map(int,input().split()))
C=A[:]
s2=0
for i in range(n-1):
    v=C[n-1-i]+C[n-2-i]
    if v>x:
        s2+=v-x
        C[n-2-i]=0 if x<=C[n-1-i] else x-C[n-1-i]
print(s2)

Measured memory_bytes: 14068
#include <iostream>
#include <unordered_map>
#include <vector>
#include <set>
#include <string.h>
#include <algorithm>
#define mod 1000000007
#define inf 1LL<<61
#define ll long long
#define pr pair<int,int>
#define all vec.begin(),vec.end()
#define rep(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int res = a * 100 + b *10 + c;
	if(res % 4 == 0)
		cout << "YES";
	else 
		cout << "NO";
	return 0;
}



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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  VI a(n);
  rep(i, n) cin >> a[i];
  VI b(m), c(m);
  rep(i, m) { cin >> b[i] >> c[i]; }
  vector<PII> p(m);
  rep(i, m) {
    p[i].first = c[i];
    p[i].second = b[i];
  }
  sort(all(p), greater<>());
  priority_queue<int, VI, greater<int>> que;
  rep(i, n) { que.push(a[i]); }
  rep(i, m) {
    bool flag = false;
    while(que.top() < p[i].first && p[i].second > 0) {
      flag = true;
      que.pop();
      que.push(p[i].first);
      p[i].second--;
    }
    if(flag == false && p[i].second > 0)
      break;
  }
  ll ans = 0;
  while(que.empty() == false) {
    ans += que.top();
    // cout << que.top() << endl;
    que.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2812
#include <stdio.h>
#define NAME_LEN 20
#define MAX 100000

typedef struct {
	char name[NAME_LEN];
	int time;
} Process;

Process a[MAX];
int top, first;

void push(Process p)
{
	top = (top + 1) % MAX;
    a[top] = p;
}

Process pop(void)
{
	Process tmp = a[first];
	first = (first + 1) % MAX;
	return tmp;
	
}

int main(void)
{
	int n, q, i;
	int timer = 0;
	scanf("%d %d", &n, &q);
	for (i = 0; i < n; i++) {
		scanf("%s %d", a[i].name, &(a[i].time));
	}

	first = 0;
	top = n - 1;
	while (((top + 1) % MAX) != (first % MAX)) {
		Process pro;
		pro = pop();
		if (pro.time <= q) {
			timer += pro.time;
			printf("%s %d\n", pro.name, timer);
		}
		else {
			timer += q;
			pro.time -= q;
			push(pro);
		}
	}

	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <limits>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const int INF = numeric_limits<int>::max();

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

  int x[N], y[N];
  rep(i, N) {
    in(x[i]); in(y[i]);
  }

  if (N == 1) {
    out(1);
    return 0;
  }
  int ans = INF;
  rep(i, N) rep(j, N) {
    if (i == j)
      continue;
    int p = x[i] - x[j];
    int q = y[i] - y[j];
    int tmp = 0;
    rep(k, N) rep(l, N) {
      if (k == l)
        continue;
      if (x[k] - x[l] == p && y[k] - y[l] == q)
        ++tmp;
    }
    ans = min(ans, N - tmp);
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

double temp(int t, int h) {
    double s = t-h*0.006;
    return s;
}

int main() {
    int n;
    cin >> n;
    string w;
    vector<string> W(n);
    set<string> SW;
    rep(i,n) {
        cin >> w;
        W[i] = w;
        SW.insert(w);
    }
    if (W.size() != SW.size()) {
        cout << "No" << "\n";
        return 0;
    }
    for(int i=1; i<n; ++i)  {
        if (W[i-1].substr(W[i-1].size()-1) != W[i].substr(0,1)) {
            cout << "No" << "\n";
            return 0;
        }
    }
        cout << "Yes" << "\n";
}


Measured memory_bytes: 256
gets.to_i
A = gets.chomp.split(" ").map(&:to_i)

C = Hash.new{|h, k| h[k] = 0}
A.each{|a| C[a] += 1}

puts C.inject(0){|r, (k, v)| r + (k > v ? v : (k < v ? v-k : 0))}


Measured memory_bytes: 18180
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
using namespace std;

struct Energy_Collector{
 long long int cost;
 long long int number;
};

bool cmp(const Energy_Collector &a, const Energy_Collector &b){
 return a.cost<b.cost;
}

int main(void){
 long long int sum=0;
 long long int N,M;
 long long int cnt=0;
 Energy_Collector a;
 vector<Energy_Collector> A;
 cin>>N>>M;

 for(int i=0;i<N; i++){
  cin>>a.cost>>a.number;
  A.push_back(a);
 }

 sort(A.begin(),A.end(),cmp);

/* for(int i=0; i<N; i++){
  cout<<A[i].cost<<" "<<A[i].number<<endl;
 }
*/ 
 for(int i=0; i<N; i++){
  if(A[i].number>=M){
   sum+=(A[i].cost*M);
   break;
  }
  else{
   sum+=(A[i].cost*A[i].number);
   M-=A[i].number;
  }
 }
 cout<<sum<<endl;
 return 0;
}

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

#define MOD 1000000007

int main()
{
  ll n, m, k;
  cin >> n >> m >> k;

  vi a, b;
  rep(i, n)
  {
    ll _a;
    cin >> _a;
    a.push_back(_a);
  }

  rep(i, m)
  {
    ll _b;
    cin >> _b;
    b.push_back(_b);
  }

  int ans = 0;

  ll a_k = 0;
  int a_index = -1;

  ll b_k = 0;
  int b_index = -1;

  // b読める分だけ読む
  while(b_index + 1 < b.size() && b_k + b[b_index + 1] <= k) {
    b_index++;
    b_k += b[b_index];
  }

  for (int i = 0; i <= n; i++)
  {
    if (i > 0)
    {
      a_index++;
      a_k += a[a_index];
    }

    // bを減らす
    while (a_k + b_k > k && b_index >= 0)
    {
      b_k -= b[b_index];
      b_index--;
    }

    if (a_k + b_k <= k)
    {
      ans = max(ans, a_index + b_index + 2);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
ll a[114514];
int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		ll ta,tb;
		cin>>ta>>tb;
		a[ta]++;
		a[tb]++;
	}
	for(int i=1;i<=n;i++){
		if(a[i]%2==1){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;


class Main{
	static long ans=0;
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		while(true) {
			int before=sc.nextInt();
			int after=sc.nextInt();
			int sum=sc.nextInt();
			if(before*after*sum==0) {
				break;
			}
			else {
				int min=(sum*100+(99+before))/(100+before);	//2つとも切り捨て無い時
				int kiri1=min+1;	//片方切り捨ての時
				int kiri2=min+2;	//どちらも切り捨ての時
				int[] dp1=new int[sum*3];
				int[] dp2=new int[sum*3];
				int[] dp3=new int[sum*3];
				Arrays.fill(dp1, 0);
				Arrays.fill(dp2, 0);
				Arrays.fill(dp3, 0);
				int max=0;

				for(int i=1; i<sum*3; i++) {
					if(i>0 && min-i>0) {
						if(i*(100+before)/100+(min-i)*(100+before)/100==sum) {		//消費税改定前の税抜きの値段にそれぞれに税を賦課した時に条件を満たすか
							dp1[i]=i*(100+after)/100+(min-i)*(100+after)/100;
							max=Math.max(max, dp1[i]);
						}
					}
				}

				for(int i=1; i<sum*3; i++) {
					if(i>0 && kiri1-i>0) {
						if(i*(100+before)/100+(kiri1-i)*(100+before)/100==sum) {		//消費税改定前の税抜きの値段にそれぞれに税を賦課した時に条件を満たすか
							dp2[i]=i*(100+after)/100+(kiri1-i)*(100+after)/100;
							max=Math.max(max, dp2[i]);
						}
					}
				}

				for(int i=1; i<sum*3; i++) {
					if(i>0 && kiri2-i>0) {
						if(i*(100+before)/100+(kiri2-i)*(100+before)/100==sum) {		//消費税改定前の税抜きの値段にそれぞれに税を賦課した時に条件を満たすか
							dp3[i]=i*(100+after)/100+(kiri2-i)*(100+after)/100;
							max=Math.max(max, dp3[i]);
						}
					}
				}
				pl(max);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 31668
#include<stdio.h>

int isPrime(int x);

int main(){
  int x,y,i;
  int cnt = 0;
  
  scanf("%d", &y);
  for ( i = 0; i < y; i++ ){
    scanf("%d", &x);
    if ( isPrime(x) ) cnt++;
  }
  
  printf("%d\n", cnt);
  return 0;
}

int isPrime(int x){
  int i;
  if ( x < 2 ) return 0;
  else if ( x == 2 ) return 1;
  if ( x % 2 == 0 ) return 0;
  for ( i = 3; i*i <= x; i+=2 ){
    if ( x % i == 0 ) return 0;
  }
  return 1;
}


Measured memory_bytes: 2104
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------
int main(void){
  ll N,K;cin>>N>>K;
  ll h[N+1];REPS(i,N)cin>>h[i];
  
  vi dp(N*2+2,INF);dp[1]=0;
  REPS(i,N){
    REPS(k,K) dp[i+k]=min( dp[i+k],dp[i]+labs(h[i+k]-h[i]) );
  }
  cout<<dp[N]<<endl;
  return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a, b;
        
        a = sc.nextInt();
        b = sc.nextInt();
        
        if(a<b){
            System.out.println("a < b");
        }else if(a>b){
            System.out.println("a > b");
        }else if(a==b){
            System.out.println("a == b");
        }
    }
}



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

using namespace std;

#define MAX_N 2000
#define MAX_C 2000

typedef long long ll;

ll C, N;

ll v[MAX_N], w[MAX_N];

ll dp[MAX_N+1][MAX_C+1];

void solve()
{

    for(ll i = 0; i < N; i++)
    {
        for(ll j = C; j >= 1; j--)
        {
            
            if(j < w[i])
            {
                dp[i+1][j] = dp[i][j];
            } else {
                if(dp[i][j] >= dp[i][j-w[i]] + v[i])
                {
                    dp[i+1][j] = dp[i][j];
                } else {
                    dp[i+1][j] = dp[i][j-w[i]] + v[i];
                }
            }
        }
    }

    cout << dp[N][C] << '\n';

}

int main() {

    cin >> N >> C;
    
    for(ll i = 0; i < N; i++)
        cin >> w[i] >> v[i];

    solve();

    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define llint long long
int main() {
    llint n,m;
    cin>>n>>m;
    vector<pair<int,int>> vec;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        vec.push_back(make_pair(b,a));
    }
    sort(all(vec));
    int ans=0;
    int t=0;
    rep(i,m){
        if (vec[i].second>=t){
            ans+=1;
            t=vec[i].first;
        }
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 1400
# Generated by AtcoderGreedy on 2018-05-10
# ABC085 C
# Your code here
$N, $Y = gets.chomp.split(' ').map(&:to_i)

if $N * 10_000 < $Y
  puts '-1 -1 -1'
  exit(0)
end

(0..$N).each do |i|
  (0..($N - i)).each do |j|
    if i * 10_000 + j * 5000 + ($N - i - j) * 1000 == $Y
      puts "#{i} #{j} #{($N - i - j)}"
      exit(0)
    end
  end
end

puts '-1 -1 -1'


Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
	int n;
	long long x;
	long long ans=1;
	long long tmp;
	bool overflow=false;
	long long limit=1000000000000000000;

	cin >> n;

	for(int i=0 ; i<n ; i++) {
		cin>>x;
		if(x==0) {
			overflow = false;
			ans=0;
		}
		if(ans!=0) {
			tmp = ans * x;
			if(tmp>limit || ans>tmp) {
				ans = 0;
				overflow = true;
			} else {
				ans = tmp;
			}
		}
	}

	if(overflow) {
		ans = -1;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.buffer.readline


def solve(mid):
    """のぞいてもいいカードならTrueを返す"""
    dp = 1
    mask = (1 << k) - 1
    if k <= a[mid]:
        return False
    for i, weight in enumerate(a):
        if i == mid:
            continue
        dp |= dp << min(weight, k + 10)
        dp &= mask
    return dp >> (k - a[mid]) == 0
     

n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
ok = 0
ng = n
if not solve(ok):
    print(0)
    exit()

while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok + 1)

Measured memory_bytes: 41964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  string s;
  cin >> s;

  int height = 0;
  int cnt = 0;
  for (auto&& i : s) {
    if (i == 'S') height++;
    else {
      if (height == 0) {
        cnt++;
      } else {
        height--;
      }
    }
  }

  cout << height+cnt << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define MAX_N 100005

ll factorial[MAX_N];
void make_factorial_tableMOD(){
    factorial[0] = 1;
    for(int i = 1; i < MAX_N; i++){
        factorial[i] = factorial[i-1]*i%MOD;
    }
}

ll bisection_powerMOD(ll x,ll y){
    if(y==0)        { return 1; }
    ll t = bisection_powerMOD(x*x%MOD,y/2);
    if(y%2==1)      { t = t*x%MOD; }
    return t;
}

ll nCrMOD(int n, int r){
    if(n<r || n<=0 || r<0){return 0;}
    ll a = factorial[n];
    ll b = a*bisection_powerMOD(factorial[r],(MOD-2))%MOD;
    ll c = b*bisection_powerMOD(factorial[n-r],MOD-2)%MOD;
    return c % MOD;
}


int main(){
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(all(a));
    make_factorial_tableMOD();
    ll ans = 0;
    ll nck = nCrMOD(n, k) + MOD;
    for(int i = 0; i < n-1; i++){
        //dbg(i);
        ll t = (nCrMOD((n-i-1), k)+nCrMOD(i+1,k))%MOD;
        ll ok = (nck-t+MOD)%MOD;
        //dbg(ok);
        ans += ok * (a[i+1]-a[i]);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n,n) {
	int SUM = 0;
		for (int i = 1; i <= n / 4; i++) {
			int a;
			cin >> a;
			SUM += a;
		}
		cout << SUM << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
N = input()
L=len(N)

DP=[[N]*2 for _ in range(L+1)]
DP[0][0]=0
DP[0][1]=1

for i,n in enumerate(N,1):
    DP[i][0]= min(DP[i-1][0]+int(n),DP[i-1][1]+10-int(n))
    DP[i][1] = min(DP[i-1][0]+int(n)+1,DP[i-1][1]+9-int(n))

print(DP[L][0])


Measured memory_bytes: 199128
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// tree<key, mapped = null_type, cmp = less<key>, rb_tree_tag, tree_order_statistics_node_update> name; order_of_key find_by_order

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fs first
#define sc second
#define abs(a) ((a) < 0 ? -(a) : (a))
#define sqr(a) ((a) * (a))

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

inline pair<pair<bool, bool>, pair<string, bool> > useinout();

#ifdef SOL
double starttime;
#endif

void initialization() {
#ifdef SOL
	starttime = 1000. * clock() / CLOCKS_PER_SEC;
	if (useinout().fs.fs)
		freopen("input.txt", "r", stdin);
	if (useinout().fs.sc)
		freopen("output.txt", "w", stdout);
#else
	srand(__rdtsc());
	const string file = useinout().sc.fs;
	if (!file.empty()) {
		freopen((file + ".in").c_str(), "r", stdin);
		freopen((file + ".out").c_str(), "w", stdout);
	} else
	if(useinout().sc.sc) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
}

int solution();

void finish(int exitval) {
	fflush(stdout);
#ifdef SOL
	fprintf(stderr, "\n-----------------\nexit value: %d\ntime: %.3lf ms\n-----------------\n", exitval, 1000. * clock() / CLOCKS_PER_SEC - starttime);
#endif
}

int main() {
	initialization();
	finish(solution());
	return (0);
}

const double eps = 1e-9;
const int mod = (int) 1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;



int solution() {

	ll q, h, s, d;
	scanf("%lld%lld%lld%lld", &q, &h, &s, &d);
	h = min(q * 2, h);
	s = min(h * 2, s);
	d = min(s * 2, d);
	ll a;
	scanf("%lld", &a);
	ll ans = 0;
	ans += (1ll * a / 2) * d;
	ans += (1ll * a % 2) * s;
	printf("%lld", ans);

	return (0);
}

inline pair<pair<bool, bool>, pair<string, bool> > useinout() {
	return (mp(mp(0, 0), mp("", 0)));
}

//by Andrey Kim


Measured memory_bytes: 256
using System;

namespace Constest
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            /*
                        string[] stArrayData = line.Split(' ');
                        int n = int.Parse(stArrayData[0]);
            */
            int i = 0;
            foreach(char c in line)
            {
                i += c - '0';
            }
            if((i % 9) == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int main() {
    int A, B; cin >> A >> B;
    if (A <= 5) {
        cout << 0 << endl;
    } else if(A <= 12) {
        cout << B / 2 << endl;
    } else {
        cout << B << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using System.Threading.Tasks;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var ha = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine((ha[0] + ha[1] - 1) / ha[1]);
    }
}



Measured memory_bytes: 11348
#include<iostream>
#include <cstdio>
#include<algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 100 + 7;

ll n, k;
ll dp[maxn][3];

int main() {
  scanf("%lld%lld", &n, &k);
  dp[1][1] = 1;
  if(k<=n) dp[k][1] = 1;
  for(int i = 0; i < n; ++i) {
    if(i+1 <= n) {
      dp[i+1][0] += dp[i][1];
      dp[i+1][1] += dp[i][0];
    }
    if(i+k <= n) {
      dp[i+k][1] += dp[i][0];
    }
  }
  ll ans = 0;
  for(int i = 1; i <= n; ++i) {
    ans += dp[i][1];
  }
  printf("%lld\n", ans);

  return 0;
}



Measured memory_bytes: 3216
n, m = map(int, input().split())
a, b = [], []
for i in range(n):
  a.append(input())
for i in range(m):
  b.append(input())
  
ans = False
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = True
    for k in range(m):
      if a[i+k][j:j+m] != b[k]:
        flag = False
    if flag:
      ans = True

if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9092
#include <cstdio>
#define int long long
using namespace std;
int n,m,a[55],f[55][8005],ans;
signed main(){
	scanf("%lld %lld",&n,&m);
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		for(int j=i;j>0;j--)
			for(int k=m*n;k>=a[i];k--)
				f[j][k]+=f[j-1][k-a[i]];
	for(int i=1;i<=n;i++)
		ans+=f[i][i*m];
	printf("%lld",ans);
	return 0;
}

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


void solve(long long N, std::vector<long long> A){
    // i番目で区切って、前後の差が最小のところを探す
    int sum = 0;
    if(A.size() == 2){
        cout << abs(A[0] - A[1]) << endl;
        return;
    }
    vector<long long> B(A.size());
    B[0] = A[0];
    for(int i =1; i < B.size(); i++){
        B[i] = B[i-1] + A[i];
    }
    long long ans = B[B.size()-1];
    for(int i = 1; i < B.size()-1; i++){
        long long diff = abs( B[i] -  (B[B.size()-1] - B[i]));
        if(diff < ans){
            ans = diff;
        }
    }

    cout << ans << endl;


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>		
using namespace std;
typedef long long ll;
#define ff first
#define ss second
#define forl(n) for(int i=0;i<n;i++)
#define forp(i,n) for(int i=0;i<n;i++)
#define fort(i,m,n) for(int i=m;i<n;i++)
#define fora(arr,n) for(int i=0;i<n;i++) cin>>arr[i];
#define begud(k) cout<<"\t-->"<<#k<<" = "<<k<<"\n";
#define endl "\n";
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll res = power(a,b/2);
	if(b%2==0)
		return res*res;
	return a*res*res;
}
// bool cust(const pair<int,int> &a,const pair<int,int> &b)                
// {
//     return (a.first > b.first); 
// } 

//const int MX = 100005;
#define inf 10000000000
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 	int n;
 	cin>>n;
 	int a[n][3];
 	fort(i,0,n)
 	{
 		fort(j,0,3)
 		{
 			cin>>a[i][j];
 		}
 	}
 	ll dp[n][3] = {};
 	fort(i,0,3)
 	{
 		dp[0][i] = max(a[0][(i+1)%3],a[0][(i+2)%3]);
 	}	
 	fort(i,1,n)
 	{
		fort(j,0,3)
		{
			dp[i][j] = a[i][j] + max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
		} 		
 	}
 	ll p = 0;
 	fort(i,0,3)
 	{
 		p = max(p,dp[n-1][i]);
 	}
 	cout<<p<<endl;
    //cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;
const int N=2e5+5;
int a[N];


int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
        cin>>a[i],a[i]-=(i+1);
    sort(a,a+n);
    long long ans=0;
    for(int i=0;i<n;i++)
        ans+=abs(a[i]-a[n/2]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024