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

typedef std::pair <int, int> pr;
const int N = 100054;

int n, V;
int a[N], b[N];
int ck[N], p[N], size[N];
pr D[N];

int ancestor(int x) {return p[x] == x ? x : (p[x] = ancestor(p[x]));}

inline bool Union(int x, int y) {
	if ((x = ancestor(x)) == (y = ancestor(y))) return true;
	return size[x] < size[y] ? (p[x] = y, size[y] += size[x]) : (p[y] = x, size[x] += size[y]);
}

int main() {
	int i, j, ans = 0; V = 0;
	scanf("%d", &n), ++n;
	for (i = 1; i < n; ++i) scanf("%d", a + i), *a ^= a[i];
	for (i = 1; i < n; ++i) scanf("%d", b + i), *b ^= b[i];
	for (i = 0; i < n; ++i) D[i] = pr(a[i], i);
	std::sort(D, D + n);
	for (i = 0; i < n; ++i) a[D[i].second] = (i && D[i].first == D[i - 1].first ? V - 1 : (D[V] = D[i], V++));
	for (i = 0; i < n; ++i) {
		j = std::lower_bound(D, D + V, pr(b[i], 0)) - D;
		if (j == V || D[j].first != b[i]) return puts("-1"), 0;
		b[i] = j;
	}
	for (i = 0; i < n; ++i) ++ck[a[i]], --ck[b[i]];
	if (std::count(ck, ck + V, 0) != V) return puts("-1"), 0;
	std::iota(p, p + V, 0), std::fill(size, size + V, 1);
	for (i = 0; i < n; ++i) if (a[i] != b[i]) Union(a[i], b[i]), ++ans;
	for (i = 0; i < V; ++i) ans += p[i] == i && size[i] != 1;
	ans -= (*a == *b ? size[ancestor(*a)] != 1 : 2);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, a[200005] = {}, ans = 0;

int main() {
	cin >> n;
	ll cnt = n - 2;
	rep(i, n)cin >> a[i];
	if (n == 2) {
		cout << max(a[0], a[1]) << endl;
		return 0;
	}
	stable_sort(a, a + n,greater<ll>());
	ans += a[0];
	rep(i, n - 1) {
		ans += a[i + 1];
		cnt--;
		if (cnt <= 0)break;
		ans += a[i + 1];
		cnt--;
		if (cnt <= 0)break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9+7;

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){ans = ans*base;}
        base *= base;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}

int cnt[123456];

int main(){
    //freopen("ip.txt", "rt", stdin);
    //freopen("op.txt", "wt", stdout);
    int n;
    cin >> n;
    vector <int> vec(n);
    map <int,int> mp;
    for(int i = 0; i < n; i++){
        cin >> vec[i];
        cnt[vec[i]]++;
        //cout << vec[i] << endl;
    }
    int ans = 0;
   for(int i = 0; i <= 1e5; i++){
       if(i == 0){
          if(ans < cnt[i]+cnt[i+1]) ans = cnt[i]+cnt[i+1];
       }
       else{
          ans = max(ans, cnt[i-1]+cnt[i+1]+cnt[i]);
       }
   }
    cout << ans;
}


Measured memory_bytes: 1024
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main()
{

    int n, p;
    cin >> n >> p;
    vector<int64_t> as(n);
    for (auto& a : as)
    {
        cin >> a;
    }
    vector<vector<int64_t>> dp(n + 1, vector<int64_t>(n + 1, 0));

    dp[0][0] = 1;

    for (int i = 1; i <= n; i++)
    {
        dp[i][0] += dp[i - 1][as[i - 1] % 2];
        dp[i][0] += dp[i - 1][0];
        dp[i][1] += dp[i - 1][(as[i - 1] + 1) % 2];
        dp[i][1] += dp[i - 1][1];
    }
    cout << dp[n][p] << endl;
}

Measured memory_bytes: 256
N = int(input())
MOD = 10**9+7
nums = list(map(int, input().split()))
B = [0 for _ in range(60)]
for num in nums:
  for i in range(60):
    if num>>i&1:
      B[i] += 1
answer = 0
for i, b in enumerate(B):
  if b > 0:
    answer = (answer+b*(N-b)*2**i)%MOD
print(answer)


Measured memory_bytes: 124596
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
M = Y[N//2]
if N%2==1:
    M2 = Y[N//2 + 1]
    for i in range(N):
        if X[i] > M:
            print(M)
        else:
            print(M2)
else:
    M2 = Y[N//2 - 1]
    for i in range(N):
        if X[i] < M:
            print(M)
        else:
            print(M2)

Measured memory_bytes: 93780
s = input()
flag = False
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        flag = True
        j = i-1
        break
    if i > 2 and s[i] == s[i - 2]:
        flag = True
        j = i-2
        break
if flag:
    print(j+1, i+1)
else:
    print(-1, -1)

Measured memory_bytes: 39536
P32 = 3.times.to_a.permutation(2) # no dup

def init
  [0] * 3
end

def max(*ns)
  ns.max
end

n = gets.to_i
# [a, b, c][]
ts = Array.new(n) { gets.split.map(&:to_i) }

dp = [init]
n.times do |i|
  dp << init
  P32.each do |(j, k)|
    # change max
    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + ts[i][k])
  end
end

p dp.last.max


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    ll n, ans = 0;
    cin >> n;
    vector<pair<ll, ll>> plus(n);
    ll a[n], b[n];
    rep(i, n){
        cin >> a[i] >> b[i];
        plus[i] = make_pair(a[i] + b[i], i);
    }
    sort(RALL(plus));
    rep(i, n){
        if(i % 2 == 0){
            ans += a[plus[i].second];
        } else{
            ans -= b[plus[i].second];
        }
    }
    print(ans);
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

const ll N = 1e5 + 5;
vector<ll>g[N],b[N];
set<ll>cur;
ll sz,n;
bool vis[N];

void dfs(ll node){
	vis[node] = 1;
	cur.insert(node);
	for(ll x : g[node]){
		if(!vis[x]){
			dfs(x);
		}
	}
}

void doit(){
	ll m,k,i,j,x,y;
	cin >> n >> m >> k;
	while(m--){
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	while(k--){
		cin >> x >> y;
		b[x].pb(y);
		b[y].pb(x);
	}
	vector< ll >ans(n+3);
	rep(i,1,n+1){
		if(!vis[i]){
			cur.clear();
			dfs(i);
			for(auto x : cur){
				ans[x] = cur.size() - 1;
				ans[x] -= g[x].size();
				for(auto y : b[x]){
					if(cur.count(y))ans[x]--;
				}
			}
		}
	}
	rep(i,1,n+1)cout << ans[i] << " ";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 20680
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

a,b,c,k=LI()
if k<=a:
    ans = k
elif k<=a+b:
    ans = a
elif k>a+b:
    # a - cの枚数(k-(a+b))
    ans = a - (k - (a + b))
print(ans)

Measured memory_bytes: 27088
#include <stdio.h>
#include <algorithm>

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

  int minv;
  int maxv;
  for (int i = 0; i < N; i++) {
    int R;
    scanf("%d", &R);
    if (i == 0) {
      maxv = -1001001001;
      minv = R;
      continue;
    }
    maxv = std::max(maxv, R - minv);
    minv = std::min(minv, R);
  }

  printf("%d\n", maxv);

  return 0;
}



Measured memory_bytes: 2744
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
 
#define test        int tc;cin>>tc;while(tc--)


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

    bool ok=false;
    for(int i=0;i<n;i++){
        if(arr[i]%2==0){
            if(arr[i]%3==0 || arr[i]%5==0)
                continue;
            else{
                ok=true;
                break;
            }
        }
    }
    if(ok)
        cout<<"DENIED"<<endl;
    else
        cout<<"APPROVED"<<endl;
        
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int sum = 0;
        for (int i = n - 1; i >= 0; i--) {
            sum += i;
        }
        for (int i = m - 1; i >= 0; i--) {
            sum += i;
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int x[N],y[N];
    map<pair<int,int>,int> m;
    rep(i,N){
        cin>>x[i]>>y[i];
    }
    rep(i,N){
        for(int j=i+1;j<N;j++){
            int a=x[j]-x[i];
            int b=y[j]-y[i];
            if(a<0) {
                a*=-1;
                b*=-1;
            }
            if(a==0) b=abs(b);
            m[make_pair(a,b)]++;
        }
    }
    int ans=0;
    for(auto p:m){
        ans=max(ans,p.second);
    }
    cout << N-ans << endl;
    




}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final List<Point> reds = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            reds.add(new Point(scanner.nextInt(), scanner.nextInt()));
        }

        final List<Point> blues = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            blues.add(new Point(scanner.nextInt(), scanner.nextInt()));
        }

        reds.sort(Comparator.comparingInt(point -> point.x));
        blues.sort(Comparator.comparingInt(point -> point.y));
        Collections.reverse(reds);

        int counter = 0;
        for (int i = 0; i < n; i++) {
            final Point red = reds.get(i);
            for (int j = 0; j < blues.size(); j++) {
                final Point blue = blues.get(j);
                if (red.x < blue.x && red.y < blue.y) {
                    counter++;
                    blues.remove(j);
                    break;
                }
            }
        }

        System.out.println(counter);
    }

    static class Point {
        int x;
        int y;

        Point(final int x, final int y) {
            this.x = x;
            this.y = y;
        }
    }
}


Measured memory_bytes: 26964
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,s=0,s1=0;
	scanf("%d\n%d",&a,&s);
	if(a<s)
		s=a;
	scanf("%d\n%d",&b,&s1);
	if(b<s1)
		s1=b;
	s+=s1;
	printf("%d",s);
	return 0;
} 

Measured memory_bytes: 256
import statistics
N = int(input())
AB = [map(int, input().split()) for _ in range(N)]
A,B = [list(i) for i in zip(*AB)]
if N%2 == 1:
    low_med = statistics.median(A)
    high_med = statistics.median(B)
    print(high_med - low_med +1)
else:
    low_med = statistics.median(A)
    high_med = statistics.median(B)
    print(int(2 * (high_med - low_med) +1))

Measured memory_bytes: 118384
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int N;
  cin >> N;
  if((N/10)%111==0||(N%1000)%111==0){
    puts("Yes");
  }else{
    puts("No");
  }
}

Measured memory_bytes: 256
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    N = I()

    ans = 0
    for i in range(1, N+1):
        ans += 0 if i % 3 == 0 or i % 5 == 0 else i
    print(ans)
    
main()


Measured memory_bytes: 9364
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    string s; cin >> s;
    int hl = s.size() / 2;
    int ans = 0;
    for(int i = 0; i < hl; ++i) {
        if(s[i] != s[s.size()-1-i])  {
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    int n,ans=0;
    int k0=0,k1=0,k2=0;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        for(int j=0;j<s.length()-1;j++){
            if(s[j]=='A'){
                if(s[j+1]=='B')ans++;
            }
        }
        if(s[0]=='B'){
            if(s[s.length()-1]=='A')k0++;
            else k1++;
        }
        else{
            if(s[s.length()-1]=='A'){
                k2++;
            }
        }
    }
    if(k0==0)ans+=min(k1,k2);
    else{
        if(k1+k2==0)ans+=k0-1;
        else ans+=k0+min(k1,k2);
    }
    cout<<ans<<endl;
    return 0;
}


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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    void solve(){
        int n;
        cin>>n;
        string s;
        map<string ,int>mp;
        for(int i=0;i<n;i++){
            cin>>s;
            mp[s]++;
        }
        cout<<"AC x "<<mp["AC"]<<"\n";
        cout<<"WA x "<<mp["WA"]<<"\n";
        cout<<"TLE x "<<mp["TLE"]<<"\n";
        cout<<"RE x "<<mp["RE"]<<"\n";
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
// Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int n;
    cin >> n;
    vector<Int> h(n);
    for (Int i = 0; i < n; i++) cin >> h[i];
    bool update = true;
    Int cnt = 0;
    while (update) {
        update = false;
        bool x = false;
        for (Int i = 0; i < n; i++) {
            if (h[i] > 0) {
                update = true;
                x = true;
                h[i]--;
            }
            else {
                if (x) {
                    cnt++;
                    x = false;
                }
            }
        }
        if (x) cnt++;
    }
    dump(cnt);
    return 0;  
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

typedef unsigned long long LL;

using namespace std;

int main() {
	string S;
	cin >> S;
	vector<int>a(26, 1);
	for (int i = 0; i < S.length(); i++) {
		if (0 <= S[i] - 'a' && S[i] - 'a' <= 26) {
			a[S[i] - 'a'] = 0;
		}
	}
	string answer = "";
	if (S.length() != 26) {
		for (int i = 0; i < 26; i++) {
			if (a[i] != 0) {
				answer = S + char('a' + i);
				break;
			}
		}
	}
	else {
		vector<int>b(26, 0);
		for (int i = 25; i > -1; i--) {
			bool flag = false;
			for (int j = S[i] - 'a'; j < 26; j++) {
				if (b[j] == 1) {
					char buffer = j + 'a';
					answer = S.substr(0, i) + buffer;
					flag = true;
					break;
				}
				b[S[i] - 'a'] = 1;
			}
			if (flag) {
				break;
			}
		}
	}
	if (answer == "") {
		cout << -1 << endl;
	}
	else {
		cout << answer << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
   int n,a,b; cin >> n >> a >> b;
   string s; cin >> s;

   int count = 0;
   int soto_count = 0;

   for(int i = 0; i < n; i++){
      if(s[i] == 'a'){
         if(count < a + b){
            cout << "Yes" << endl;
            count++;
         }else{
            cout << "No" << endl;
         }
      }else if(s[i] == 'b'){
         if(count < a + b && soto_count < b){
            cout << "Yes" << endl;
            count++;
            soto_count++;
         }else{
            cout << "No" << endl;
         }
      }else cout << "No" << endl;
   }
   return 0;
}

Measured memory_bytes: 896
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var A = int.Parse(inputs[1]);
        var B = int.Parse(inputs[2]);
        var C = int.Parse(inputs[3]);
        var l = new int[N];
        for (int i = 0; i < N; i++)
        {
            l[i] = int.Parse(Console.ReadLine());
        }

        var mp = dfs(0, 0, 0, 0, l, N, A, B, C);
        Console.WriteLine(mp);

    }

    static int dfs(int depth, int a, int b, int c, int[] l, int N, int A, int B, int C)
    {
        if (depth == N)
        {
            bool isTarget = a > 0 && b > 0 && c > 0;
            if (!isTarget)
            {
                return 100000000;
            }
            var mp = Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c) - 30;
            return mp;
        }

        var result1 = dfs(depth + 1, a, b, c, l, N, A, B, C);
        var result2 = dfs(depth + 1, a + l[depth], b, c, l, N, A, B, C) + 10;
        var result3 = dfs(depth + 1, a, b + l[depth], c, l, N, A, B, C) + 10;
        var result4 = dfs(depth + 1, a, b, c + l[depth], l, N, A, B, C) + 10;

        var result = Math.Min(result1, result2);
        result = Math.Min(result, result3);
        result = Math.Min(result, result4);
        return result;
    }

}



Measured memory_bytes: 11220
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n);
    rep(i,n) {
        cin >> c[i];
        a[i].resize(m);
        rep(j,m) {
            cin >> a[i][j];
        }
    }
    int ans = INT_MAX;
    vector<int> sum(m);
    bool canAchieve = false;
    for (int bit = 0; bit < (1<<n); bit++)
    {
        int price = 0;
        rep(i,m) sum[i] = 0;

        // 参考書i
        rep(i,n) {
            if (bit & (1<<i)) {
                price += c[i];
                // アルゴリズムj
                rep(j,m) {
                    sum[j] += a[i][j];
                }
            }
        }
        
        bool allX = true;
        rep(i,m) {
            if (sum[i] < x) {
                allX = false;
                break;
            }
        }
        if (allX) {
            ans  = min(ans, price);
            canAchieve = true;
        }
    }
    if (canAchieve) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    ll *a = new ll[n];
    ll tmp = 1; 
    for (int i = 0; i < n; i++)
        cin >> a[i];

    ll ans = 0;
    for (int i = 0; i < n; i++)
        ans += a[i]-1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    map<string,int>mp;
    rep(i,n){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans=0;
    for(auto& p :mp){
        int x=p.second;
        ans+=(ll)x*(x-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <stdio.h>

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

void insertionSort(int A[], int N){
  int j, i, v;
  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;
    trace(A, N);
  }
}

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

  scanf("%d", &N);
  for(i=0; i<N; i++) scanf("%d", &A[i]);
  trace(A, N);
  insertionSort(A, N);

  return 0;
}



Measured memory_bytes: 3224
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

ll mod = 1e9 + 7;
vi inv(200010);

ll nck(int n, int k)
{
    ll res = 1;
    for (int i = 0; i < k; i++) {
        res = res * (n - i) % mod * inv[i + 1] % mod;
    }
    return res;
}

ll fastpow(ll a, int b)
{
    ll res = 1;
    while (b > 0) {
        if (b & 1) {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    ll ans = fastpow(2, n);
    inv[1] = 1;
    for (int i = 2; i < 200010; i++) {
        inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
    }
    cout << (ans - nck(n, a) + mod - nck(n, b) + mod - 1 + mod) % mod << endl;

    return 0;
}

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

using namespace std;

#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define int long long
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define MOD 1000000007

const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};

int n, i;

signed main()
{
    fast_IO;
    int test = 1;
    // cin >> test;
    while(test--)
    {
        string s;
        cin >> s;
        int r = 0;
        int ans = 0;
        for(i = 0; i < 3; i++)
        {
            if(s[i] == 'R')
                r++;
            else
            {
                ans = max(ans, r);
                r = 0;
            }
        }
        ans = max(ans, r);
        cout << ans << endl;
    } 
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(string, S);
  
  char f = S[0];
  if(f != S[1] || f != S[2]) {
    fin("Yes");
  } else {
    fin("No");
  }
}

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

int main(void){
    int n;
    string s;
    map<string, int> mp;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        mp[s] += 1;
    }
    cout<<((mp.size()==4)?"Four":"Three")<<endl;
}

Measured memory_bytes: 256
n = int(input())
list_ = [-1] + [int(input()) for _ in range(n)]

def solve():
    next_ = list_[1]
    list_[1] = -1
    count = 1
    if next_ == 2:
        return count
    if next_ == -1:
        return -1

    while True:
        prev = next_
        next_ = list_[prev]
        list_[prev] = -1
        count += 1
        if next_ == 2:
            return count
        if next_ == -1:
            return -1

print(solve())


Measured memory_bytes: 7852
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCore {
	public class Program {
		static void Main (string[] args) {
			int[] nq = Console.ReadLine ().Split (' ').Select (x => int.Parse (x)).ToArray ();
			int n = nq[0];
			int q = nq[1];
			string s = Console.ReadLine ();
			int[] ls = new int[q];
			int[] rs = new int[q];
			for (int i = 0; i < q; i++) {
				int[] lr = Console.ReadLine ().Split (' ').Select (x => int.Parse (x)).ToArray ();
				ls[i] = lr[0] - 1;
				rs[i] = lr[1] - 1;
			}

			int[] v = new int[n];
			int count = 0;
			bool isA = false;
			for (int i = 0; i < n; i++) {
				if (s[i] == 'A') {
					isA = true;
				} else if (isA && s[i] == 'C') {
					++count;
					isA = false;
				} else {
					isA = false;
				}
				v[i] = count;
			}

			//ACACTACG
			//01122233

			for (int i = 0; i < q; i++) {
				Console.WriteLine (v[rs[i]] - v[ls[i]]);
			}
		}
	}
}

Measured memory_bytes: 17336
#include <bits/stdc++.h>
using namespace std;
long long primes[50000]={0};
int total=0,vis[100005]={0};
int a[100001];
void ol()
{
	long long i,j;
	primes[0]=1;
	for(i=2;i<=100000;i++)
	{
		if(!vis[i])
		{
			primes[primes[0]++]=i;
			if(!vis[(i+1)/2]&&i%2==1)
				total++;
		}
		a[i]=total;
		for(j=1;j<primes[0];j++)
		{
			if(i*primes[j]<=100000)
				vis[i*primes[j]]=1;
			if(i%primes[j]==0)
				break;
		}
	}
	return;
}
int main()
{
	int n,i,x,y,j=0,k,len=0;
	ol();
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		printf("%d\n",a[y]-a[x-1]);
	}
	return 0;
} 

Measured memory_bytes: 1536
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
  n <- readInt
  ps <- getLine
  let (x, _) = calc ps
      (_, y) = calc $ reverse ps
  putStrLn $ replicate (-x) '(' ++ ps ++ replicate y ')'

calc :: String -> (Int, Int)
calc ps = go maxBound minBound 0 ps
  where go t u _ "" = (t, u)
        go t u v (x:xs)
          | x == '('  = go t             (max u (v+1)) (v+1) xs
          | otherwise = go (min t (v-1)) u             (v-1) xs

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


Measured memory_bytes: 508
import sys
from collections import Counter

cin = sys.stdin
# cin = open("in.txt", "r")

def line2N():
    return map(int, cin.readline().split())

a,b,c,x,y = line2N()
ans1 = a*x + b*y
g = min(x,y)
ans3 = c*2*g + a*(x-g) + b*(y-g)
h = max(x,y)
ans4 = c*2*h


print(min(ans1, ans3, ans4))


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

#define int long long int 

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

    int lcm=time[0];
    for(int i=1;i<n;i++)
        lcm=(lcm/__gcd(lcm,time[i]))*time[i];
    cout<<lcm<<endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;
	public class Main{
		public static void main(String args[]){
			Scanner sc = new Scanner(System.in);
			int c1=0;
			int c2=0;
			while(sc.hasNext()){
				String str = sc.nextLine();
				String num[] = str.split(",",0);
				int a = Integer.parseInt(num[0]);
				int b = Integer.parseInt(num[1]);
				int c = Integer.parseInt(num[2]);
				if(c<b){
					if(c<a){
						continue;
					}
				}
				if(c * c == a * a + b * b){
					c1++;
				}else{
					c2++;
				}
			}
			System.out.println(c1);
			System.out.println(c2);
		}
	}

Measured memory_bytes: 26088
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define cases int tc;cin>>tc;while(tc--)
#define N 200003
#define M 1003
#define inf LLONG_MAX
#define Arena ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//int mod=1e9+7;
//int mod=998244353;

signed main()
{
    Arena

    string s;
    cin>>s;
    int n=s.size(),i,j;
    int ca=0,ans=0;
    for(i=0;i<=n-3;++i)
    {
        if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C')
            ++ca,ans+=ca,s[i+2]='A',++i,--ca;
        else if(s[i]=='A')
            ++ca;
        else
            ca=0;
    }
    cout<<ans;



    return 0;
}


Measured memory_bytes: 720
N = input()

ans = 0
def dfs(m):
    global ans
    if len(set(m)) == 3 and int(m) <= int(N):
        #print(m, ans)
        ans += 1

    if len(m) < len(N):
        for c in "357":
            dfs(m+c)

dfs("")
print(ans)


Measured memory_bytes: 2940
n = int(input())
opened = [int('0b' + input().replace(' ', ''), 2) for i in range(n)]
prise = [list(map(int, input().split())) for i in range(n)]

ans = -float('INF')
for i in range(1,int('10000000000', 2)):
    cnt = [0 for i in range(n)]
    for j in range(10):
        if 1<<j & i == 0:
            continue
        for k in range(n):
            if 1<<j & opened[k]:
                cnt[k] += 1
    tmp = sum([prise[k][cnt[k]] for k in range(n)])
    if tmp > ans:
        # print(bin(i), tmp, [prise[k][cnt[k]] for k in range(n)], cnt)
        ans = tmp
print(ans)
# print(bin(2^10-1))
# [print(bin(i)) for i in opened]


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
	ll s;
	if(k > 1){
		s = k*facctorialMethod(k-1);
	} else {
		s = 1;
	}
	return s;
}
vl primes(ll n){
	vl x(n);
	REP(i, n){
		x[i] = 0;
	}
	for(ll i = 2; i < sqrt(n) + 2; i++){
		while(n % i == 0){
			n /= i;
			x[i-1] += 1;
		}
	}
	if(n > 1){
		x[n-1] += 1;
	}
	return x;
}
const ll mod = 1000000007;
const ll INF = 1e9;

// 変数定義start(vectorはresizeしようね)
string S;
// 変数定義end

void solve(){
	cin >> S;
	bool flag = false;
	if(S.size() > 9){
		cout << "NO" << endl;
	} else {
		for(ll i = 0; i < S.size() -1; i++){
			if(S.substr(i,1) == "A" && S.substr(i+1,1) == "A"){
				flag = true;
			}
			if(S.substr(i,1) == "K" && S.substr(i+1, 1) == "A"){
				flag = true;
			}
			if(S.substr(i,1) == "I" && S.substr(i+1, 1) == "A"){
				flag = true;
			}
		}
		for(ll i = 0; i < S.size(); i++){
			if(S.substr(i, 1) != ""){
				if(S.substr(i,1) == "A"){
					S.erase(i, 1);
					i--;
				}
			}
		}
		if(S == "KIHBR" && flag == false){
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
          using namespace std;
          #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
          #define M_PI 3.14159265358979323846
          #define data data_
          #define ff first
          #define ss second
          #define pb push_back
          #define ll long long
          #define ld long double

          int main()
          {
            tani_nachi_ke  

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

            int mx = 0;
            for(int i = k; i <= n; i++)
                mx = max(mx,a[i] - a[i-k]);

            cout << setprecision(9) << fixed;

            cout << ((double)(mx + k))/2.0 << endl;
            
         
               return 0;
          }

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>

int mil(int y, int m, int d) {

	int year=((y-1)/3)*200+(y-1-(y-1)/3)*195;
	int month;

	if(y%3==0)
		return year+(m-1)*20+d;
	else {
		if(m%2==0) {
			month=(m/2-1)*19+(m/2)*20;
			return year+month+d;
		}
		else {
			month=(m/2)*19+(m/2)*20;
			return year+month+d;
		}

	}
}

int main() {

	int n;
	int *y,*m,*d,*answer;
	int i;

	scanf("%d",&n);
	y=(int *)malloc(n * sizeof(int));
	m=(int *)malloc(n * sizeof(int));
	d=(int *)malloc(n * sizeof(int));
	answer=(int *)malloc(n * sizeof(int));

	for(i=0;i<n;i++) {
		scanf("%d %d %d",&y[i],&m[i],&d[i]);
		answer[i]=mil(1000,1,1)-mil(y[i],m[i],d[i]);
	}

	for(i=0;i<n;i++)
		printf("%d\n",answer[i]);

	free(y);
	free(m);
	free(d);
	free(answer);

	return 0;
}

Measured memory_bytes: 596
A = int(input())
colors = [0] * 8
l_n = list(map(int,input().split()))
if [i for i in l_n if 1 <= i <= 399] != []:
        colors[0] = 1
for j in range(1,8):
    if [i for i in l_n if 0+(j*400) <= i <= 399+(j*400)] != []:
        colors[j] = 1
ans_m = colors.count(1)
all_colors = len([i for i in l_n if 3200 <= i])
if all_colors == A:
    print(1,all_colors)
else:
    print(ans_m,ans_m+all_colors)

Measured memory_bytes: 3064
#include<iostream> 
#include<vector> 
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    
    int n, m, k, t;
    cin >> n >> m;
    vector<int> p(n), on(n, 0);
    vector<vector<int>> s(m, vector<int>(n, 0));
    for (int i = 0; i < m; i++) {
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            scanf("%d", &t);
            s[i][t-1] = 1;
        }
    }

    for (int i = 0; i < m; i++) scanf("%d", &p[i]);

    int maxi = 1 << n;
    int ans = 0;
    for (int pat = 0; pat < maxi; pat++) {
        bool ok = true;
        for (int i = 0; i < m; i++) {
            int on = 0;
            for (int j = 0; j < n; j++) {
                if (s[i][j] && (pat >> j & 1)) on++;
            }
            if (on % 2 != p[i]) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define MAXN 200010
using namespace std;

char s[MAXN],t[MAXN];
int n,v[MAXN],pre[26];

int main()
{
	scanf("%s",s);scanf("%s",t);n=strlen(s);
	memset(pre,-1,sizeof pre);
	for (int i=0;i<n;i++){v[i]=pre[s[i]-'a'];pre[s[i]-'a']=i;}
	memset(pre,-1,sizeof pre);
	for (int i=0;i<n;i++)
	{
		if (pre[t[i]-'a']!=v[i])
		{
			puts("No");
			return 0;
		}
		pre[t[i]-'a']=i;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
  
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	cout << a[0];
	for(int i = 1; i < n; i++){
		if(a[i] != a[i - 1])cout << ' ' << a[i];
	}
	cout << '\n';
    return 0;
}



Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  string S;
  cin >> S;
  ll count_even_0 = 0;
  ll count_odd_0 = 0;

  rep(i, S.size()) {
    char c = S[i];
    if (i % 2 == 0) {
      if (c == '0') {
        count_even_0++;
      }
    } else {
      if (c == '0') {
        count_odd_0++;
      }
    }
  }
  // debug(count_even_0);
  // debug(count_odd_0);

  ll ans = 0;
  if (S.size() % 2 == 0) {
    if (count_even_0 < count_odd_0) {
      ans = count_even_0 + (S.size() / 2 - count_odd_0);
    } else {
      ans = count_odd_0 + (S.size() / 2 - count_even_0);
    }
    COUT(ans);
  } else {
    if (count_even_0 == count_odd_0) {
      ans = count_odd_0 + (S.size() / 2 - count_even_0);
      COUT(ans);
      return 0;
    }
    if (count_even_0 < count_odd_0) {
      ans = count_even_0 + (S.size() / 2 - count_odd_0);
    } else {
      ans = count_odd_0 + ((S.size() + 1) / 2 - count_even_0);
    }
    COUT(ans);
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int uchiha=1e5+5;
int arr[uchiha];
long long m=1000000007;
int main()
{
int a,b;
cin>>a>>b;
if(a==13&&b==1){
    cout<<"Bob";
    return 0;
    }
    else if(a==1&&b==13){
        cout<<"Alice";
        return 0;
    }
else if(a>b&&b!=1)
    cout<<"Alice";
else if(b>a&&a!=1)
    cout<<"Bob";
else
    cout<<"Draw";
}

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

int main(){
    long n, k;
    cin >> n;
    cin >> k;
    n = abs(n-k*(n/k));
    while(k <= 2*n){
        n = abs(n-k);
        if(n==abs(n-k)){
            break;
        }
    }
    cout << n << "\n";
    return 0;
}

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

using namespace std;

const int Nmax = 1e5+5;
int n, ans=0, j, i, t[Nmax], k, c;

int main()
{
   // freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> c >> k;

    for(i=1; i<=n; ++i) cin >> t[i];
    sort(t+1, t+n+1);

    if(c == 1)
    {
        cout << n << '\n';
        return 0;
    }

    ans = 0; j = 1;
    for(i=1; i<=n; ++i)
    {
        if(t[j]+k < t[i]) ++ans, j = i;
            else if(i-j+1 == c) ++ans, j = i+1;
    }

    if(j != n+1) ++ans;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-

N, W = list(map(int, input().split()))
Z = []
for i in range(N):
    Z.append(list(map(int, input().split())))

dp = [[0] * (W+1) for _ in range(N+1)]

for i, z in enumerate(Z):
    #print(i)
    for w in range(W+1):
        if w -z[0] >= 0:
            dp[i+1][w] = max(dp[i][w-z[0]]+z[1], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
    #print(dp)

print(max(dp[-1]))


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

int main(void){
    int n,a,b,count=0,countf=0;
    scanf("%d%d%d",&n,&a,&b);
    char s[n+20];
    scanf("%s",s);
    for (int i=0; i<n; i++){
        if (s[i]=='a'){
            if (count<a+b){
                printf("Yes\n");
                count++;
            } else {
                printf("No\n");
            }
        } else if (s[i]=='b'){
            if (count<a+b && countf<b){
                printf("Yes\n");
                count++;
                countf++;
            } else {
                printf("No\n");
            }
        } else {
            printf("No\n");
        }
    }
	return 0 ;
}

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

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

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int digitsum(int N){
    int res = 0;
    while(N){
        res += N%10;
        N /= 10;
    }
    return res;
}

int main(void){
    int N; cin >> N;
    cout << (N%digitsum(N) ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import heapq

n = readint()
parent = [-1] + [readint()-1 for i in range(n-1)]
child = [0]*n
leaf = [1]*n
for x in parent[1:]:
    leaf[x] = 0
    child[x] += 1

score = [0]*n
leaf = [(score[i],i) for i in range(n) if leaf[i]==1]
heapq.heapify(leaf)

while leaf:
    s,c = heapq.heappop(leaf)
    p = parent[c]
    score[p] = max(score[p],s)+1
    child[p]-=1
    if child[p]==0:
        if p!=0:
            heapq.heappush(leaf,(score[p],p))

print(score[0])



Measured memory_bytes: 88696