akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 100005
inline int max(int a,int b)
{
	if(a>b)	return a;
	return b;
}
long long l,r,n,a[maxn],c[maxn<<1+5],pre[maxn];
inline int lowbit(int x)
{
	return x&(-x);
}
inline void modify(int place,long long val)
{
	for(int i=place;i<=(maxn<<1+5);i+=lowbit(i))
		c[i]+=val;
}
inline long long query(long long place)
{
	long long ans=0;
	for(int i=place;i;i-=lowbit(i))
		ans+=c[i];
	return ans;
}
bool check(int x)
{
	memset(c,0,sizeof(c));
	pre[0]=0;
	for(int i=1;i<=n;++i)
		pre[i]=pre[i-1]+(a[i]>=x?1:-1);
	long long ans=0;
	for(int i=0;i<=n;++i)
	{
		ans+=query(pre[i]+maxn);
		modify(pre[i]+maxn,1ll);
	}
	return ans>=n*(n+1)/4;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]),r=max(r,a[i]);
	int mid;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(check(mid))	l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 51712
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <math.h>

using namespace std;

typedef long long ll;

int main(){
    ll H, N;
    cin >> H >> N;
    vector<ll> A(N);
    for (int i = 0; i < N;i++)
        cin >> A[i];

    for (int i = 0; i < N;i++){
        H -= A[i];
    }
    if(H <= 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#! python3
# printRectangle.py - 長方形を描くプログラム

flag = True
rectangles = []
while flag:
    size = [int(i) for i in input().split()]
    H = size[0]
    W = size[1]
    if H == 0:
        flag = False
        break

    rectangle = []
    for h in range(H):
        row = []
        for w in range(W):
            row.append('#')
        rectangle.append(row)
    rectangles.append(rectangle)

for rectangle in rectangles:
    for row in rectangle:
        print(''.join(row))
    print('')


Measured memory_bytes: 5976
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  string before, after;
  before = "ATCG";
  after = "TAGC";
  map<char, char> m;
 for(int i = 0; i < 4; i++) 
  m[before[i]] = after[i];
  
  cout << m[S[0]] << endl;
}
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char** argv){
	int a, c;
    int* b;
    int* d;
    int* e;
    cin>>a; b=new int[a];  
    for(int _a=0; _a<a; ++_a) cin>>b[_a];
  	
  	cin>>c; d=new int[c]; e=new int[c];
    for(int _a=0; ; ++_a){
        cin>>d[_a]; cin>>e[_a];
        if(cin.eof()) break;
    }
    
    for(int _a=0; _a<c; ++_a){
        int val=0;
     	for(int _b=0; _b<a; ++_b){
          if(d[_a]-1==_b){
            val+=e[_a]; 
          }else{
            val+=b[_b]; 
          }
       //   std::cerr<<_a<<" "<<val<<endl;
       }
       std::cout<<val<<std::endl;
    }
  
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedLists #-}

module Main where

import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.List
import Control.Applicative
import Control.Monad
import Data.Char

main :: IO ()
main = do
  [a, b, c] <- map read . words <$> getLine
  print $ solve a b c

solve :: Int -> Int -> Int -> Int
solve a b c = (\(_, _, _, res) -> res)
  . thirdProcess
  . secondProcess
  . firstProcess $ sorted (a, b, c, 0) where
  sorted :: (Int, Int, Int, Int) -> (Int, Int, Int, Int)
  sorted (a', b', c', res) = (\[a'', b'', c''] -> (a'', b'', c'', res)) $ sub a' b' c' where
    sub :: Int -> Int -> Int -> [Int]
    sub a''' b''' c''' = sort [a''', b''', c''']
  firstProcess :: (Int, Int, Int, Int) -> (Int, Int, Int, Int)
  firstProcess (a', b', c', res)
    | b' == c'              = (a', b', c', res)
    | otherwise             = firstProcess (a' + 1, b' + 1, c', res + 1)
  secondProcess :: (Int, Int, Int, Int) -> (Int, Int, Int, Int) 
  secondProcess (a', b', c', res)
    | a' >= b'              = (a', b', c', res)
    | otherwise             = secondProcess (a' + 2, b', c', res + 1)
  thirdProcess :: (Int, Int, Int, Int) -> (Int, Int, Int, Int)
  thirdProcess (a', b', c', res)
    | a' == b'              = (a', b', c', res)
    | otherwise             = (a', b' + 1, c' + 1, res + 1)

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

using namespace std;

#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forlr(i, l, r) for (int i = int(l); i < int(r); i++)
#define repeat(n) for (int hjfjke = 0; hjfjke < int(n); hjfjke++)
#define all(c) c.begin(), c.end()
#define ll long long

const int mod = 1000000007;

vector<vector<int>> a;

int n;

vector<vector<int>> mult(vector<vector<int>> &a, vector<vector<int>> &b) {
    auto result = vector<vector<int>>(n, vector<int>(n, 0));

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                result[i][j] = (result[i][j] + a[i][k] * 1ll * b[k][j]) % mod;

    return result;
}

vector<vector<int>> bin(vector<vector<int>> &a, long long n) {
    if (n == 1)
        return a;

    n--;

    vector<vector<int>> res = a;

    while (n) {
        if (n & 1)
            res = mult(res, a);

        a = mult(a, a);

        n /= 2;
    }

    return res;
}

int32_t main() {
    std::iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);


    long long k;
    cin >> n >> k;
    a = vector<vector<int>>(n, vector<int>(n));

    forn(i,n) forn(j, n) cin >> a[i][j];

    a = bin(a, k);

    int ans = 0;
    forn(i, n)
    forn(j, n)
    ans = (ans + a[i][j]) % mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
S = input()
cntC = 0
cnt_ = 0
ans = "WA"
N = len(S)
if S[0] == 'A':
  for i in range(2, N-1):
    if S[i] == 'C':
      cntC += 1
    elif S[i].islower():
      cnt_ += 1
  if cntC == 1 and cnt_ == N-4:
    if S[1].islower() and S[N-1].islower():
      ans = "AC"
print(ans)

Measured memory_bytes: 61900
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const int m = 1000005;

int main() {
  IOS;
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  vector<int> cnt(m, 0);

  for (int x: a) {
    if(cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < m; i+=x) cnt[i]++;
  }
  int ans = 0;
  for (int x: a) {
    if (cnt[x] == 1) ans++;
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 7952
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
#define dmin(x, y) ((x) < (y) ? (x) : (y))
#define dmax(x, y) ((x) > (y) ? (x) : (y))
#define checkmax(x, y) ((x) < (y) ? ((x) = (y)) : (x))
#define checkmin(x, y) ((x) > (y) ? ((x) = (y)) : (x))
#define ms(data_name) memset(data_name, 0, sizeof(data_name))
#define msn(data_name, num) memset(data_name, num, sizeof(data_name))
#define For(i, j) for(reg int (i) = 1; (i) <= (j); ++(i))
#define For0(i, j) for(reg int (i) = 0; (i) < (j); ++(i))
#define Forx(i, j, k) for(reg int (i) = (j); (i) <= (k); ++(i))
#define Forstep(i , j, k, st) for(reg int (i) = (j); (i) <= (k); (i) += (st))
#define fOR(i, j) for(reg int (i) = (j); (i) >= 1; (i)--)
#define fOR0(i, j) for(reg int (i) = (j) - 1; (i) >= 0; (i)--)
#define fORx(i, j, k) for(reg int (i) = (k); (i) >= (j); (i)--)
#define tour(i, u) for(reg int (i) = head[(u)]; (i) != -1; (i) = nxt[(i)])
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int rdint() {
  int aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
ll rdll() {
  ll aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
const int MAXN = 2e5 + 10;
struct Node {
  int beg, end;
  bool operator <(const Node &rhs) const {
    return end == rhs.end ? beg < rhs.beg : end < rhs.end;
  }
} a[MAXN];
int n;
inline void work() {
  n = rdint();
  For(i, n) {
    a[i].beg = rdint();
    a[i].end = rdint();
  }
  sort(a + 1, a + n + 1);
  int now = 0;
  For(i, n) {
    if(now + a[i].beg <= a[i].end) {
      now += a[i].beg;
    } else {
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
}
int main() {
  // freopen("input.txt", "r", stdin);
  work();
  return 0;
}


Measured memory_bytes: 2816
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i64 = read();

    let mut x: i64 = 0;
    let mut mutn: i64 = n;

    while mutn > 0 {
        x += mutn % 10;
        mutn /= 10;
    }

    if n % x == 0 {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	
	cin>>W>>H>>x>>y>>r;
	
	if(x<W&&y<H){
		if(x+r<W&&y+r<H){
			if(x>0&&y>0){
			cout<<"Yes"<<endl;
			return 0;;
			}
			}
			}
	else{
		cout<<"No"<<endl;
		return 0;
		 }
		 
	if(x<=W&&y<=H){
		if(x+r<=W&&y+r<=H){
			if(x>0&&y>0){
			cout<<"Yes"<<endl;
			return 0;
			}
		}
		}
	if(x<r||y<r){
		cout<<"No"<<endl;
		return 0;
		}
	
	return 0;
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX 1000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

int main(){
    int n,q;
    cin >> n >> q;
    vector<ll> A(n);
    int ans = 0;
    Rep(i,n){
        cin >> A[i];
    }
    sort(All(A));
    Rep(i,q){
        ll r,l;
        cin >> l >> r;
        int s = lower_bound(All(A),l)-A.begin();
        int e = upper_bound(All(A),r)-A.begin();
        cout << e-s << endl;
    }
    //cout << ans+1 << endl;
    //cin >> n;
}


Measured memory_bytes: 3536
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  uint64_t A, b, C;
  string B;
  cin >> A >> B;
  B.erase(1, 1);
  b = stoi(B);
  C = A * b / 100;
  cout << C << endl;
}


Measured memory_bytes: 3196
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	string s;
	cin >> s;
	rep(i, sz(s)) {
		if (s[i] == '?') s[i] = 'D';
	}
	cout << s << endl;
}

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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 1e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
	int n;
	cin >> n;
	if (n >= 500)
	{
		cout << (n / 500) * 1000 + (n % 500) / 5 * 5 << endl;
	}
	else
	{
		cout << n / 5 * 5 << endl;
	}
	return 0;
}




Measured memory_bytes: 764
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

import fractions
import itertools

def main():
    n = int(input())
    ab = [list(map(int,input().split())) for _ in range(n)]
    ab = sorted(ab,key=lambda x:x[1],reverse=True)
    cd = [list(map(int,input().split())) for _ in range(n)]
    cd = sorted(cd,key=lambda x:x[0])

    ans = 0
    for blue in cd:
        for red in ab:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                red[1] = 201
                break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5332
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;
const ll FINAL = 0x0ba9876543210ll;

struct Data
{
	ll s;
	int d;
	bool f;
	Data(ll s, int d, bool f) : s(s), d(d), f(f) {}
};

int bfs(ll init)
{
	if(init == FINAL)
		return 0;
	
	const int move[13][5] = {
		{2, -1},
		{2, 5, -1},
		{0, 1, 3, 6, -1},
		{2, 7, -1},
		{5, -1},
		{1, 4, 6, 9, -1},
		{2, 5, 7, 10, -1},
		{3, 6, 8, 11, -1},
		{7, -1},
		{5, 10, -1},
		{6, 9, 11, 12, -1},
		{7, 10, -1},
		{10, -1}
	};
	
	unordered_set<ll> visited[2];
	queue<Data> Q;
	Q.push(Data(init, 0, false));
	Q.push(Data(FINAL, 0, true));
	visited[0].insert(init);
	visited[1].insert(FINAL);
	int now[2] = {0};
	
	while(!Q.empty()){
		Data data = Q.front();
		Q.pop();
		now[data.f] = data.d + 1;

		for(int i=0, cnt=2; cnt; ++i){
			if(((data.s>>(i*4)) & 0xfll) == 0){
				for(int j=0; move[i][j]!=-1; ++j){
					ll next = data.s;
					next &= ~((0xfll << (i*4)) | (0xfll << (move[i][j]*4)));
					next |= ((data.s >> (move[i][j]*4)) & 0xfll) << (i*4);
					
					if(visited[!data.f].find(next) != visited[!data.f].end())
						return now[0] + now[1];

					if(visited[data.f].find(next) == visited[data.f].end()){
						visited[data.f].insert(next);
						if(data.d <= 8)
							Q.push(Data(next, data.d+1, data.f));
					}
				}
				--cnt;
			}
		}
	}
	return -1;
}

int main()
{
	for(;;){
		int input[13];
		rep(i, 13){
			scanf("%d", &input[i]);
			if(input[i] == -1)
				return 0;
		}

		ll init = 0;
		rep(i, 13)
			init = (init << 4) | input[12-i];

		int ans = bfs(init);
		if(ans == -1)
			puts("NA");
		else
			printf("%d\n", ans);
	}
}

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

int main(void){
    string s;
    int win = 0;
    cin >> s;

    for(int i = 0;i < s.size();i++){
        if(s[i] == 'o')     win++;
    }
    win += 15-s.size();
    if(win > 7) cout << "YES" << endl;
    else        cout << "NO" << endl;
    return 0;
}

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

for i in range(1, N+1):
    if i >= K:
        P += (N-i+1) / N
        break

    else:
        n = 1
        while i*n < K:
            n *= 2
        P += 1 / (N*n)


print(P)

Measured memory_bytes: 2940
N,K = map(int,input().split())
x = list(map(int, input().split()))
ans = 10**10
for i in range(N-K+1):
    temp_ans1 = abs(x[i]) + abs(x[i+K-1]-x[i])
    temp_ans2 = abs(x[i+K-1])+abs(x[i]-x[i+K-1])
    # temp_ans2 = abs(x[N-1-i]) + abs(x[N-1-i-K]-x[N-1-i])
    # temp_ans2 = abs(x[-(i+1)]) +abs(x[-(i+K)] - x[i+1])
    ans = min(ans,temp_ans1,temp_ans2)
    # ans = min(ans,temp_ans1    ans = min(ans,temp_ans1,temp_ans2)
print(ans)


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

int n;
string x;
int d;
string ans;

int main() {
  cin >> n;
  cin >> x;
  cin >> d;

  ans = x;

  for(int i = 0; i < n; i++ ){
    if(d == 0) break;
    if(x[i] == '0'){
      ans[i] = '1';
      d--;
    }
    
  } 

  for(int i = n-1; i >= 0; i-- ){
    if(d == 0) break;
    if(x[i] == '1'){
      ans[i] = '0';
      d--;
    }
  }

  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  cout << p.at(n / 2) - p.at(n / 2 - 1);
}

Measured memory_bytes: 640
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {

  ll n;
  cin >> n;
  ll a[200100];
  rep(i, n) cin >> a[i];

  rep(i, n) {
    if (a[i] > (ll)i) {
      cout << -1 << endl;
      return 0;
    }
  }
  

  ll ans = 0;
  int i = n - 1;
  while (i > 0) {
    ans += a[i];
    while (a[i] - a[i - 1] == 1) i--;
    i--;
    if (i >= 0 && a[i] < a[i + 1] - 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  
  cout << ans << endl;

  return 0;

}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
signed main() {
    cin >> N;
    int ans = LLONG_MAX;
    for (int i = 0; i < 110000; i++) {
        int q = 9 * i;
        int r = (N - q) / 6 * 6;
        int cur = 0;
        cur += N - q - r;
        if (q > N) { break; }
        while (q /= 9) { cur += q % 9; }
        while (r /= 6) { cur += r % 6; }
        chmin(ans, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	string ans;
	while (n > 0) {
		n--;
		ans += char((n % 26) + 'a');
		n /= 26;
	}
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=100010;
int u[N],v[N],parent[N];
ll ans[N];
//initialize parent[]={-1}
int find(int x)
{
  int root=x;
  //identify the root
  while(parent[root]>=0) root=parent[root];
  //path compression
  while(x!=root)
  {
    int old=x;
    x=parent[x];
    parent[old]=root;
  }
  return root;
}
bool merge(int x,int y)
{
  //identify roots
  x=find(x);
  y=find(y);
  if(x==y) return false;
  //parent[x] is the negated size of set containing x.
  if(parent[x]>parent[y]) swap(x,y);
  parent[x]+=parent[y];
  parent[y]=x;
  return true;
}
int main()
{
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=m;i++) cin>>u[i]>>v[i];
  memset(parent,-1,sizeof(parent));
  ans[m]=1ll*n*(n-1)/2;
  for(int i=m-1;i>=1;i--)
  {
    int p1=find(u[i+1]),p2=find(v[i+1]),x=-1*parent[p1],y=-1*parent[p2];
    // cout<<p1<<" "<<p2<<" "<<x<<" "<<y<<endl;
    if(merge(p1,p2)) ans[i]=ans[i+1]-1ll*x*y;
    else ans[i]=ans[i+1];
  }
  for(int i=1;i<=m;i++) cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 3328
#C

n = int(input())
x = list(map(int,input().split()))

y = [i ** 2 for i in x]

if sum(x) % n == 0:
    
    print(sum(y)-((sum(x) ** 2) // n))
else:
    t = sum(x) // n
    #a = n * p ** 2 - 2 * p * sum(x) + sum(y)
    print(min(n * (t ** 2) - 2 * t * sum(x) + sum(y),n * ((t + 1) ** 2) - 2 * (t + 1) * sum(x) + sum(y)))



Measured memory_bytes: 3060
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
time = T[0] + K
answer = 0
passenger = 0
for i, t in enumerate(T):
    if time < t or passenger == C:
        answer += 1 # i-1までのバス
        passenger = 0
        time = t + K
    
    passenger += 1
    if i == N - 1:
        answer += 1
print(answer)


Measured memory_bytes: 7488
#include <iostream>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

const int MAXN = 100010;

struct Node {
	int x, y;
}node[MAXN];
unordered_map<int, unordered_set<int>> mx, my;
int uf[MAXN], ufcnt[MAXN];
int find(int a) {
	if (uf[a] == a)
		return a;
	return uf[a] = find(uf[a]);
}
void uni(int a, int b) {
	int fa = find(a), fb = find(b);
	if (fa == fb)
		return ;
	// cout<<"Uni Node"<<a<<" Node"<<b<<endl;
	if (ufcnt[fa] > ufcnt[fb])
		uf[fb] = fa, ufcnt[fa] += ufcnt[fb];
	else
		uf[fa] = fb, ufcnt[fb] += ufcnt[fa];
}

int main() {
	int n;
	cin>>n;
	for (int i=0; i<n; i++) 
		uf[i] = i, ufcnt[i] = 1;

	for (int i=0; i<n; i++) {
		cin>>node[i].x>>node[i].y;

		if (mx.find(node[i].x) != mx.end())
			uni(i, *mx[node[i].x].begin());
		else
			mx[node[i].x].insert(i);

		if (my.find(node[i].y) != my.end())
			uni(i, *my[node[i].y].begin());
		else
			my[node[i].y].insert(i);
	}
	mx.clear();
	my.clear();

	for (int i=0; i<n; i++) {
		int gpid = find(i);
		mx[gpid].insert(node[i].x);
		my[gpid].insert(node[i].y);
		// cout<<"Group "<<gpid<<" size="<<ufcnt[gpid]<<endl;
	}

	long long ans = 0;
	bool visited[MAXN];
	memset(visited, 0, sizeof(visited));
	for (int i=0; i<n; i++) {
		int gpid = find(i);
		if (visited[gpid])
			continue;
		visited[gpid] = 1;
		ans += (long long)mx[gpid].size() * (long long)my[gpid].size() - (long long)ufcnt[gpid];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 16920
// problem C
// from https://atcoder.jp/contests/abc172/tasks/abc172_c
#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 200*1000 + 10;
int a[MAXN], b[MAXN];
long sa[MAXN], sb[MAXN];

int main () {
    ios::sync_with_stdio(false);

    int n, m, k;
    cin >> n >> m >> k;
    fill(sa, sa+n, 0L);
    fill(sb, sb+m, 0L);

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sa[i] = sa[i-1] + a[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        sb[i] = sb[i-1] + b[i];
    }
    
    int max_books = 0;
    // Start with reading 0 books from 2nd shelve and reading all from first shelve
    // Change y appropriately.
    int y = 0;
    for (int x = n; x >= 0; x--) {
        long time_for_first = sa[x];
     
        while (y+1 <= m && time_for_first + sb[y+1] <= k) {
          // We can actually read y+1 books, given time_for_first
          y = y+1;
        }
        if (time_for_first + sb[y] <= k) {
          max_books = max(max_books, x+y);
        }
    }
    cout << max_books << endl;
    return 0;
}


Measured memory_bytes: 8344
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s.size()<26){
    map<char,int> mp;
    for(int i=0;i<s.size();i++){
      mp[s[i]]++;
    }
    cout<<s;
    for(int i=0;;i++){
      if(mp[(char)('a'+i)]==0){
        cout<<(char)('a'+i)<<endl;
        return 0;
      }
    }
  }else{
    if(s=="zyxwvutsrqponmlkjihgfedcba")
      cout<<-1<<endl;
    else{
      int mi;
      for(int i=24;;i--){
        if(s[i]<s[i+1]){
          mi=i;
          break;
        }
      }
      char mm='z'+1;
      for(int i=mi+1;i<26;i++){
        if(s[i]>s[mi]&&s[i]<mm){
          mm=s[i];
        }
      }
      cout<<s.substr(0,mi)<<mm<<endl;
    }
  }
}
          

Measured memory_bytes: 256
s = list(input())
t = list(input())

a = [0] * (len(s) - len(t) + 1)

for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i + j] != t[j]:
            a[i] += 1

print(min(a))

Measured memory_bytes: 9136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 100005
using namespace std;
typedef long long ll;
int n;
int main() {
	cin>>n;
	int res = n * 800;
	cout<<res-(n/15)*200<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
    int H,W;SCD2(H,W);getchar();
    char a[101][101];
    
    REP(i,H){
        REP(j,W){
            scanf("%c",&a[i][j]);
        }
        getchar();
    }
    
    REP(i,W+2){
        printf("#");
    }
    printf("\n");
    
    REP(i,H){
      printf("#");
        REP(j,W){
            printf("%c",a[i][j]);
        }
       printf("#");
       printf("\n");  
    }
    
        
    REP(i,W+2){
        printf("#");
    }
    printf("\n");
    
    
   	return 0;
}

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

int main(){
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> a(h, vector<char>(w));
  
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  for (int i = 0; i < h; i++){
    bool flag;
    for (int j = 0; j < w; j++){
      if (a.at(i).at(j) == '.'){
        flag = true;
        continue;
      }
      else{
        flag = false;
        break;
      }
    }
    if (flag){
      for (int j = 0; j < w; j++){
        a.at(i).at(j) = '-';
      }
    }
  }
  
  for (int i = 0; i < w; i++){
    bool flag;
    for (int j = 0; j < h; j++){
      if (a.at(j).at(i) == '.' || a.at(j).at(i) == '-'){
        flag = true;
        continue;
      }
      else{
        flag = false;
        break;
      }
    }
    if (flag){
      for (int j = 0; j < h; j++){
        a.at(j).at(i) = '-';
      }
    }
  }
  
  for (int i = 0; i < h; i++){
    bool flag = false;
    for (int j = 0; j < w; j++){
      if (a.at(i).at(j) != '-'){
        cout << a.at(i).at(j);
        flag = true;
      }
    }
    if (flag){
      cout << endl;
    }
  }
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define grep(i,u) for (int i = head[u],v = e[i].v; i; v = e[i = e[i].nxt].v)
#define il inline
#define LL long long
#define ULL unsigned LL
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
using namespace std;
il LL read() {
	LL res = 0,f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -f; ch = getchar();}
	while (isdigit(ch)) {res = res*10+ch-'0'; ch = getchar();} return res*f;
}
namespace qiqi {
	const int N = 1e5+5; int n,siz[N],fa[N]; pair<LL,int> a[N];
	void main() {
		int x; LL d = 0; n = read(); rep(i,1,n) {a[i] = mp(read(),i); siz[i] = 1;} sort(a+1,a+n+1);
		drep(i,n,2) {x = upper_bound(a+1,a+n+1,mp(a[i].fi-n+siz[i]*2,0))-a; if (a[x].fi != a[i].fi-n+siz[i]*2) {puts("-1"); return;} siz[fa[i] = x] += siz[i]; d += siz[i];}
		if (d != a[1].fi) {puts("-1"); return;} rep(i,2,n) printf("%d %d\n",a[i].se,a[fa[i]].se);
	}
}
int main() {
	qiqi::main(); return 0;
}

Measured memory_bytes: 6076
import java.util.*;
import java.io.*;
public class Main {
    public static int arr[];
    public static int dp[] ;
    public static int solve(int k){
        
        dp = new int[k+1];
        for(int i = 0 ; i <= k ; i++){
            dp[i] = -1;
        }

        if(k < 0){
            return 0;
        }
        
        dp[0] = 0;
        
        for(int i = 1 ; i <= k ; i++){
            dp[i] = 0;
            for(int j = 0 ; j < arr.length ; j++){
                if(i-arr[j] >= 0 && dp[i - arr[j]] == 0){
                    dp[i] = 1;
                }
            } 
        }

        return dp[k];
    }
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        arr = new int[n];
        for(int i = 0 ; i < n ; i++){
            arr[i] = s.nextInt();
        }

        int ans = solve(k);

        if(ans == 1) System.out.println("First");
        else System.out.println("Second");
    }
}

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



int main() {
ll A, B, C;
cin >> A >> B >> C;
vector<ll> rei(A);
vector<ll> denshi(B);
ll rban[200000];
ll dban[200000];
ll wari[200000];

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

for(int i = 0; i < B; i++){
cin >> denshi[i];
}
for(int i = 0; i < C; i++){
cin >> rban[i] >> dban[i] >> wari[i];
rban[i]--;
dban[i]--;
}
ll reimin = *min_element(rei.begin(), rei.end());
ll denshimin = *min_element(denshi.begin(), denshi.end());
ll ans = reimin + denshimin;

for(int i = 0; i < C; i++){
ll kakaku = rei[rban[i]] + denshi[dban[i]] - wari[i];
ans = min(ans, kakaku);
}
cout << ans << endl;
}

Measured memory_bytes: 6272
import sys

def main():
    s = sys.stdin.readline().rstrip()
    
    ATCG = set('ATCG')
    res = 0
    cnt = 0
    for char in s:
        if char in ATCG:
            cnt += 1
        else:
            res = max(res, cnt)
            cnt = 0
    res = max(res, cnt)

    print(res)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;



int main(){
	LL n,mn=0;
	cin>>n;
	FORQ(i,1,100000){
		LL a=i;
		LL b=n/a;
		if(1LL*a*b!=n)continue;
		int d1=0,d2=0;
		while(a||b){
			if(a)d1++;
			if(b)d2++;
			a/=10;
			b/=10;
		}
		d1=max(d1,d2);
		if(!mn||d1<mn){
			//cout<<i<<endl;
			mn=d1;
		}
	}
	cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,v,j,k,N;
	scanf("%d" ,&N);
	int A[N];
	for(i = 0; i < N; i++){
		scanf("%d" ,&A[i]);
	}
	for(i = 0; i < N; i++){
		if(i==N-1){
			printf("%d\n",A[i]);
		}
		else{
			printf("%d ",A[i]);
		}
	}
	for(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;		
		for(k = 0; k < N; k++){
			if(k==N-1){
				printf("%d\n",A[k]);
			}
			else{
				printf("%d ",A[k]);
			}
		}
	}
	
	
	
}


Measured memory_bytes: 2024
dp = Array.new(5) { Array.new(4001, 0) }
dp[0].fill(0..1000) { 1 }

for i in 1...4
  for j in 0..4000
    for k in 0..1000
      break if j - k < 0
      dp[i][j] += dp[i - 1][j - k]
    end
  end
end

while line = gets
  n = line.chomp.to_i
  puts dp[3][n]
end

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

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??????????????????
		int list [] = new int [3];
		//1????????????
		String str = sc.nextLine(); 
		
		//??????
		String[] strLine = str.split(" ");
		
		//??????1??????????´?
		int a = Integer.parseInt(strLine[0]);
		int b = Integer.parseInt(strLine[1]);
		int c = Integer.parseInt(strLine[2]);
		
		//?°????????????????????????????
		Arrays.sort(strLine);
		//??¨???
		System.out.println(strLine[0] + " " + strLine[1] + " " +strLine[2]);

	}
}

Measured memory_bytes: 26064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 2147483647;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const ll LLMAX = 9223372036854775805;
const int MAXN = 9999;

int main(){
    int n;
    cin >> n;
    map<int,int> m;
    for(int x = 1;x*x <=n;x++){
        for(int y = 1;y*y<=n;y++){
            for(int z = 1;z*z<=n;z++){
                int temp = x*x + y*y + z*z + x*y + y*z + z*x;
                m[temp]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout << m[i] << endl;
    }

}

Measured memory_bytes: 5324
from collections import deque 

n, k = map(int, input().split())
vs_ = deque(map(int, input().split()))

max_v = 0

import copy

for a in range(k+1):
  for b in range(k+1-a):
    for c in range(k+1-a-b):
      vs = copy.copy(vs_)
      us = []
      for x in range(a):
        if vs:
          us.append(vs.popleft())
        else:
          break
      for y in range(b):
        if vs:
          us.append(vs.pop())
        else:
          break
      #print(us)
      us.sort(reverse=True)
      for z in range(c):
        if len(us) and us[-1]<0:
          us.pop()
        else:
          break
      if sum(us) >= max_v:
        max_v = sum(us)

print(max_v)

      
  

Measured memory_bytes: 60252
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long x=0;
    int m=1000000000,hu=0;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        x+=abs(a[i]);
        if(a[i]<0)hu++;
        m=min(m,abs(a[i]));
    }
    if(hu%2)cout<<x-m*2<<endl;
    else cout<<x<<endl;
    return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct mint
{
  ll v;
  mint() : v(0) {}
  mint(ll v) : v((v % MOD + MOD) % MOD) {}
  mint pow(ll t) const;
  mint inv() const;
};
mint& operator+=(mint& a, mint b) { return a = a.v + b.v; }
mint& operator-=(mint& a, mint b) { return a = a.v - b.v; }
mint& operator*=(mint& a, mint b) { return a = a.v * b.v; }
mint operator+(mint a, mint b) { return a += b; }
mint operator-(mint a, mint b) { return a -= b; }
mint operator*(mint a, mint b) { return a *= b; }
mint operator-(mint a) { return 0 - a; }

mint& operator/=(mint& a, mint b) { return a *= b.inv(); }
mint operator/(mint a, mint b) { return a /= b; }
mint mint::pow(ll t) const
{
  if (!t)
    return 1;
  mint a = pow(t >> 1);
  a *= a;
  if (t & 1)
    a *= *this;
  return a;
}
mint mint::inv() const { return pow(MOD - 2); }

struct mset
{
  vector<mint> fact;  // n! (mod MOD)
  vector<mint> ifact; // k!^{M-2} (mod MOD)
  mset(int n) : fact(n + 1), ifact(n + 1)
  {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint perm(int n, int k)
  { // nPk (mod MOD)
    if (k < 0 || n < k)
      return 0;
    return fact[n] * ifact[n - k];
  }
  mint comb(int n, int k)
  { // nCk (mod MOD)
    if (k < 0 || n < k)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

void solve()
{
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  vector<mint> left(N);
  vector<mint> right(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        continue;
      if (j < i) {
        if (a[i] > a[j])
          left[i] += 1;
      } else {
        if (a[i] > a[j])
          right[i] += 1;
      }
    }
  }
  // dump(left, right);
  mint k = K - 1;
  k = (k + 1) * k / 2;
  dump(k.v);
  mint ans = 0;
  for (int i = 0; i < N; i++) {
    ans += right[i] * K;
    ans += (left[i] + right[i]) * k;
    dump(i, ans.v);
  }
  cout << ans.v << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
s = input()

chenge_01 = 0
chenge_10 = 0

for i in range(len(s)):
    if i%2 == 0:
        if s[i] == '0':
            chenge_01 += 1
        else:
            chenge_10 += 1
    else:
        if s[i] == '1':
            chenge_01 += 1
        else:
            chenge_10 += 1

print(min(chenge_01,chenge_10))


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {

        public static bool[] haming = new bool[1000001];

        public static void setHaming(int n) {
            if (n > 1000000) { return; }
            if (haming[n]) { return; }
            haming[n] = true;
            setHaming(n * 2);
            setHaming(n * 3);
            setHaming(n * 5);
        
        }
       
        public static void Main(String[] args) {
            setHaming(1);
            string line;
            while ((line = Console.ReadLine()) != null) {
                string[] strs = line.Split(' ');
                int n = int.Parse(strs[0]);
                if (n == 0&&strs.Length==1) { break; }
                int m = int.Parse(strs[1]);

                int count = 0;
                for (int i = n; i <= m; i++) {
                    if (haming[i]) count++;
                }
                Console.WriteLine(count);

            }
        }


    }

}

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

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 2e4 + 1;


void solve() {
	int n, m, pp;
	cin >> n >> m >>pp;
	vector<pair<int, pair<int, int>>> edges(m);
	for (int i = 0; i < m; i++) {
		int from, to, c;
		cin >> from >> to >> c;
		from--; to--;
		edges[i] = { c, {from, to} };
	}

	vector<int> d(n, -INF);
	d[0] = 0;
	for (int i = 0; i < n - 1; i++) {
		for (auto& p : edges) {
			int w = p.first;
			int from = p.second.first;
			int to = p.second.second;
			if (d[from] != -INF && d[to] < d[from] + w - pp) {
				d[to] = d[from] + w - pp;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (auto& p : edges) {
			int w = p.first;
			int from = p.second.first;
			int to = p.second.second;
			if (d[from] != -INF && d[to] < d[from] + w - pp) {
				d[to] = INF;
				if (to == n - 1) {
					cout << -1;
					return;
				}
			}
		}
	}

	cout << max(0LL, d.back());
}


signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int n = arr[0];
        int m = arr[1];
        int[] heightArr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var nodeArr = new Node[n];
        for (int i = 0; i < n; i++)
        {
            nodeArr[i] = new Node(heightArr[i]);
        }
        for (int i = 0; i < m; i++)
        {
            int[] arrTwo = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int a = arrTwo[0];
            int b = arrTwo[1];
            nodeArr[a - 1].Children.Add(nodeArr[b - 1]);
            nodeArr[b - 1].Children.Add(nodeArr[a - 1]);
        }
        int sum = 0;
        foreach(Node node in nodeArr)
        {
            if (node.goodNode()) sum++;
        }
        Console.WriteLine(sum);
    }





}

public class Node
{
    public int Height { get; set; }

    public Node(int height)
    {
        this.Height = height;
    }

    public List<Node> Children = new List<Node>();

    public bool goodNode()
    {
        foreach(Node child in Children){
            if(this.Height <= child.Height)
            {
                return false;
            }
        }
        return true;
    }

}



Measured memory_bytes: 44796
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        //入力
        long n = long.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = a[i] * 2;
        }
        // x0 = 0 のとき
        long offset = 0;
        for (int i = 0; i < n; ++i)
        {
            offset = a[i] - offset;
        }
        long x = offset / 2;

        // 復元
        long cur = x;
        StringBuilder ans = new StringBuilder("");
        for (int i = 0; i < n; ++i)
        {
            ans.Append(cur);
            ans.Append(" ");
            cur = a[i] - cur;
        }
        //出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 32092
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

template <typename T>
class BIT {
  vector<T> tree_;

 public:
  BIT(int n) : tree_(n, 0) {}
  void Add(int i, T x) {
    for (i++; i <= tree_.size(); i += i & -i) {
      tree_[i - 1] += x;
    }
  }

  T Sum(int s) {
    T ans = 0;
    for (s++; s > 0; s -= s & -s) {
      ans += tree_[s - 1];
    }

    return ans;
  }

  T Sum(int l, int r) { return Sum(r - 1) - Sum(l - 1); }
};

int main(int argc, const char *argv[]) {
  using ll = long long;
  int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }

  vector<vector<int>> tree(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  int k = 0;
  vector<int> in(n), out(n);
  function<void(int, int)> dfs;
  dfs = [&](int v, int p) {
    in[v] = k++;
    for (int u : tree[v]) {
      if (u != p) {
        dfs(u, v);
      }
    }

    out[v] = k;
  };

  dfs(0, -1);

  vector<vector<int>> vs(n);
  for (int i = 0; i < n; i++) {
    vs[c[i] - 1].push_back(i);
  }

  auto c2 = [](ll n) -> ll { return n * (n + 1) / 2; };
  ll tot = c2(n);
  BIT<ll> d(n);
  for (int i = 0; i < n; i++) {
    d.Add(i, 1);
  }

  for (int i = 0; i < n; i++) {
    ll ans = tot;
    vector<int> &nvs = vs[i];
    sort(nvs.begin(), nvs.end(), [&](int a, int b) { return in[a] > in[b]; });
    vector<pair<int, int>> history;
    for (int v : nvs) {
      int cnt = 1;
      for (int u : tree[v]) {
        if (in[u] < in[v]) {
          continue;
        }

        int num = d.Sum(in[u], out[u]);
        ans -= c2(num);
        cnt += num;
      }

      d.Add(in[v], -cnt);
      history.emplace_back(in[v], cnt);
    }

    ans -= c2(d.Sum(0, n));
    for (auto p : history) {
      d.Add(p.first, p.second);
    }

    cout << ans << '\n';
  }

  return 0;
}

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

int main() {
    string s, t; cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        if (t.at(i) != s.at(i)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(){
  int n,n1,n2,n3,n4;
  int i,j,k,l;
  while(scanf("%d", &n) != EOF){
    int m=0;
    for(i=0;i<10;i++){
      n1=n-i;
      for(j=0;j<10;j++){
	n2=n1-j;
	for(k=0;k<10;k++){
	  n3=n2-k;
	  for(l=0;l<10;l++){
	    n4=n3-l;
	    
	    if(n4==0)
	      m++;
	  } 
	} 
      } 
    }
    printf("%d\n",m);
  }
  return 0;
}

Measured memory_bytes: 2604