akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N 40
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
const long long int MOD = 1000000007;
const long long int INF = 100000000000000;

struct UF{
	int par[MAX_N];
	int rank[MAX_N];
	int si[MAX_N];

	void init(int n){
		rep(i,n){
			par[i] = i;
			rank[i] = 0;
			si[i] = 1;
		}
	}

	int find(int x){
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]){
			par[x] = y;
			si[y] += si[x];
		} else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
			si[x] += si[y];
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
} uf;

int n;
map<string,int> id;
map<P,int> dp;
int b[40];
int c[40];
vector<string> d[40];
vector<int> e[40];
vector<int> fa;
int ans = 0;

int func(ll bo, int now){
    if(now == fa.size()) return 0;
    if(dp.count(P(bo,now))) return dp[P(bo,now)];
    ll prebo = bo;
    int ret = 0;
    int f = fa[now];
    if(f == 0){
        ret = b[0];
        bo++;
        rep(i,e[f].size()){
            bo += (1LL<<e[f][i]);
        }
        //cout << ret << endl;
        ret += func(bo,now+1);
        dp[P(prebo,now)] = ret;
        //cout << func(bo,now+1) << endl;
        return ret;
    }
    if(bo&(1LL<<f)){
        dp[P(prebo,now)] = func(bo,now+1);
        return dp[P(prebo,now)];
    }
    bo += (1LL<<f);
    ret = func(bo,now+1);
    int ret2 = b[f];
    rep(i,e[f].size()){
        if(bo&(1LL<<e[f][i])) continue;
        bo += (1LL<<e[f][i]);
    }
    ret2 += func(bo,now+1);
    //cout << f << " " << bo << " " << now << " " << ret << " " << ret2 << endl;
    dp[P(prebo,now)] = max(ret,ret2);
    return max(ret,ret2);
}

void solve(){
    uf.init(n);
    rep(i,40) d[i].clear();
    rep(i,40) e[i].clear();
    fa.clear();
    id.clear();
    dp.clear();
    ans = 0;
    rep(i,n){
        string a;
        cin >> a >> b[i] >> c[i];
        id[a] = i;
        rep(j,c[i]){
            string tmp;
            cin >> tmp;
            d[i].push_back(tmp);
        }
    }
    rep(i,n){
        rep(j,c[i]){
            e[i].push_back(id[d[i][j]]);
            uf.unite(i,id[d[i][j]]);
        }
    }
    rep(i,n){
        if(uf.par[i] != i) continue;
        vector<int> now;
        dp.clear();
        rep(j,n){
            if(uf.find(j) != i) continue;
            now.push_back(j);
        }
        fa = now;
        ans += func(0,0);
        //cout << " " << ans << endl;
    }
    cout << ans << endl;
}

int main(){
    while(cin >> n){
        if(n == 0) break;
        solve();
    }
}

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

int main(void)
{
    int A,B,C,K;
    cin >> A >> B >> C >> K;

    int point;


    point = min(A,K);
    K = K - A;

    if((K==0)||(K-B)<=0){
        cout << point << endl;
    }

    else{
        cout << point - K + B << endl;
    }
    return 0;

}

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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 //998244353
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a,ll b){	if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;}	return ans;}
template <typename T> 
T Min(T a,T b){ return a<b?a:b; }
template <typename T>
T Max(T a,T b){ return a>b?a:b; }

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	ll n,k;cin>>n>>k; vl a(n); repi(i,n) cin>>a[i];
	sort(all(a));
	ll ans=0;
	repi(i,k) ans+=a[i];
	db(ans);
	
	/*
	int test1;cin>>test1;while(test1--){ 
		
	 }
	 //*/
return 0;
}



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

using namespace std;

int n;
vector<vector<int>> g; 
int timeT = 0;
vector<int> d, f;
 
void dfs(int node){
    timeT++;

    if(d[node] == 0){
        d[node] = timeT;
    }

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    timeT++;
    if(f[node] == 0){
        f[node] = timeT;
    }
    return;
}
    
int main(){
    
    cin >> n;

    d.assign(n + 1, 0);
    f.assign(n + 1, 0);

    g.assign(n + 1, vector<int>());

    for(int i = 0; i < n; i++)
    {
        int nod, numOut;
        cin  >> nod >> numOut;
        for(int j = 0; j < numOut; j++)
        {
            int temp;
            cin >> temp;
            g[nod].push_back(temp);
        }
    }
    
    for(int i = 1; i <= n; i++)
    {
        if(d[i] == 0){
            dfs(i);
        }
    }

    for(int i = 1; i <= n; i++)
    {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {

    int N;
    cin >> N;
    vector<P> p(N);
    rep(i,N) {
        cin >> p[i].first;
        p[i].second = i + 1;
    }

    sort(p.begin(), p.end());

    set<int> s;
    ll ans = 0;
    rep(i,N) {
        s.insert(p[i].second);
        decltype(s)::iterator it = s.find(p[i].second);
        ll count = 1;
        if (it != s.begin()) {
            --it;
            count *= p[i].second - *it;
            ++it;
        } else {
            count *= p[i].second;
        }
        if (++it != s.end()) {
            count *= *it - p[i].second;
        } else {
            count *= N - p[i].second + 1;
        }
        ans += count * p[i].first;
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 14344
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G();
		int Y = I[0], X = I[1];
		var map = new bool[X, Y];
		for (int y = 0; y < Y; y++)
		{
			var s = ReadLine();
			for (int x = 0; x < X; x++) map[x, y] = s[x] == '#';
		}
		var dx = new[]{ 0, -1, -1, 0, 1, -1, 1, 1, 0 };
		for (int y = 0; y < Y; y++)
		{
			for (int x = 0; x < X; x++)
			{
				if (map[x, y]) Write('#');
				else
				{
					var s = 0;
					for (var i = 0; i < 8; i++)
					{
						int p = x + dx[i], q = y + dx[i + 1];
						if (0 <= p && p < X && 0 <= q && q < Y && map[p, q]) s++;
					}
					Write(s);
				}
			}
			WriteLine();
		}
	}
}


Measured memory_bytes: 13268
/// {{{ Author: Wang, Yen-Jen
// include
#include <bits/stdc++.h>

// using
using namespace std;

// types
typedef long long ll;
typedef pair<int,int> pii;

// macro
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin() , (x).end()
#define REP(i , n) for(int i = 0; i < int(n); i++)
#define REP1(i , a , b) for(int i = a; i <= int(b); i++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LC o<<1 , l , m
#define RC o<<1|1 , m + 1 , r
#define MS(x , v) memset(x , (v) , sizeof(x))

// input
inline bool SR(int &x) {
  return scanf("%d",&x) == 1;
}

inline bool SR(ll &x) {
  return scanf("%lld",&x) == 1;
}

inline bool SR(double &x) {
  return scanf("%lf",&x) == 1;
}

inline bool SR(char *s) {
  return scanf("%s",s) == 1;
}

inline bool RI() {
  return true;
}

template<typename I , typename... T> inline bool RI(I &x , T&... tail) {
  return SR(x) && RI(tail...);
}

// output
inline void SP(const int x) {
  printf("%d",x);
}

inline void SP(const ll x) {
  printf("%lld",x);
}

inline void SP(const double x) {
  printf("%.16lf",x);
}

inline void SP(const char *s) {
  printf("%s",s);
}

inline void PL() {
  puts("");
}

template<typename I , typename... T> inline void PL(const I x , const T... tail) {
  SP(x);
  if(sizeof...(tail)) putchar(' ');
  PL(tail...);
}

// debug
#define WangYenJen

#ifdef WangYenJen
template<typename I> void _DOING(const char *s , I&& x) {
  cerr << s << " = " << x << endl;
}

template<typename I , typename... T> void _DOING(const char *s , I&& x , T&&... tail) {
  int c = 0;
  while(*s != ',' || c != 0) {
    if(*s == '(' || *s == '[' || *s == '{') c++;
    if(*s == ')' || *s == ']' || *s == '}') c--;
    cerr << *s++;
  }
  cerr << " = " << x << " , ";
  _DOING(s + 1 , tail...);
}

#define DEBUG(...) \
do {\
  fprintf(stderr , "%s: Line %d - ",__PRETTY_FUNCTION__,__LINE__);\
  _DOING(#__VA_ARGS__ , __VA_ARGS__);\
} while(0);

#else
#define DEBUG(...)

#endif

// constant number
const int INF = 0x3f3f3f3f;
const ll INF64 = 0x3f3f3f3f3f3f3f3fll;

// random function
inline int RAND() {
  static int x = 880301;
  return (x = x * 0xdefaced + 1) % 0x7fffffff;
}
/// }}}

int main() {
  ll a, b, c;
  RI(a, b, c);
  ll ans = INF64;
  if (c & 1) ans = a * b;
  else ans = 0;
  if (b & 1) ans = min(ans, a * c);
  else ans = 0;
  if (a & 1) ans = min(ans, b * c);
  else ans = 0;
  PL(ans);
  return 0;
}


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

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

    vector<pair<int, int>> p(n), p2(n);
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;

        p.at(i).first = x;
        p.at(i).second = y;
    }
    
    sort(p.begin(), p.end());

    long long ans = LLONG_MAX;
    
    for (int left = 0; left <= n - k; left++)
    {
        for (int right = left + k; right <= n; right++)
        {
            vector<pair<long long, long long>> pn;
            for (int i = left; i < right; i++)
            {
                pn.push_back(make_pair(p.at(i).second, p.at(i).first));
            }
            
            sort(pn.begin(), pn.end());

            for (int down = 0; down <= (int)pn.size() - k; down++)
            {
                for (int up = down + k; up <= (int)pn.size(); up++)
                {
                    long long maxX = -1000000000;
                    long long minX = 1000000000;
                    long long maxY = -1000000000;
                    long long minY = 1000000000;
                    for (int j = down; j < up; j++)
                    {
                        maxX = max(maxX, pn.at(j).second);
                        minX = min(minX, pn.at(j).second);
                        maxY = max(maxY, pn.at(j).first);
                        minY = min(minY, pn.at(j).first);
                    }
                    
                    ans = min(ans, abs(maxX - minX) * abs(maxY - minY));
                }
            }
            
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
a,b,c = map(int,input().split(" "))

def takahashi(l):
    if l[0] % 2 == 0:
        return [l[0]//2,l[1]+l[0]//2]
    else:
        return [(l[0]-1)//2,l[1]+(l[0]-1)//2]

def aoki(l):
    if l[1] % 2 == 0:
        return [l[0]+l[1]//2,l[1]//2]
    else:
        return [l[0]+(l[1]-1)//2,(l[1]-1)//2]

ary = [a,b]
for i in range(c):
    if i % 2 == 0:
        ary = takahashi(ary)
    else:
        ary = aoki(ary)
    # print("now:",i,"->",ary)
print(ary[0],ary[1])



Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define BEGIN true
#define END false

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

    string S;
    char C;
    int Q, T, F;
    bool head=BEGIN;
    cin >> S >> Q;
    rep(i, Q){
        cin >> T;
        if(T==1) head = !head;
        else{
            cin >> F >> C;
            if((F==1 && head==BEGIN) || (F==2 && head==END)) S.insert(S.begin(), C); 
            else S.insert(S.end(),C);
        }
    }

    if(head == END) reverse(all(S));
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 912
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll M, D;

  cin >> M >> D;

  ll ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= D; j++) {
      if (i == ((j / 10) * (j % 10)) && j/10 >= 2 && j%10 >= 2){
        ans++;
      } 
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
N = str(N) 

if(int(N[-1]) == 3):
  print("bon")
elif(int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8):
  print("pon")
else:
  print("hon")

Measured memory_bytes: 9116
n,m=map(int, input().split())
x = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
v=[0]*n
w=[]
z=0
count=0
ans=0
for i in range(2**n):
    for j in range(n):
        if ((i >> j) & 1):
            v[j]=1
    w.append(v)
    v=[0]*n
for i in range(2**n):
    for j in range(m):
        for k in range(1,len(x[j])):
            z+=(w[i][x[j][k]-1])
        if z%2==p[j]:
            count+=1
        z=0
    if count==m:
        ans+=1
    count=0

print(ans)

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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

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


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, m;
  std::cin >> n >> m;
  std::vector<int64_t> a(n);
  std::cin >> a;
  std::sort(a.begin(), a.end(), std::greater<int64_t>());
  auto ra = a;
  std::reverse(ra.begin(), ra.end());

  std::map<int64_t, int64_t> map;

  const auto count = [&](const int64_t sum) {
    int64_t ans = 0;
    for (int64_t i = 0; i < n; i++) {
      const auto index = n - i - 1;
      const auto itr =
          std::lower_bound(ra.cbegin(), ra.cend(), sum - ra[index]);
      const auto num = std::distance(itr, ra.cend());
      ans += num;
      if (num == 0) {
        break;
      }
    }
    return ans;
  };

  int64_t min = 2 * a.back(), max = 2 * a.front();
  map[max] = count(max);
  map[min] = count(min);
  if (m < map[max]) {
    std::cout << max * m << std::endl;
    return 0;
  }
  if (map[min] <= m) {
    std::cout << 2 * n * summation(a.cbegin(), a.cend()) << std::endl;
    return 0;
  }
  while (true) {
    const auto next = (min + max) / 2;

    if (map.find(next) != map.cend()) {
      break;
    }

    map[next] = count(next);
    if (map[next] < m) {
      max = next;
    } else if (m < map[next]) {
      min = next;
    } else {
      max = min = next;
    }
  }

  std::vector<int64_t> sum(a.size() + 1, 0);
  sum[0] = 0;
  for (int64_t i = 1; i <= a.size(); i++) {
    sum[i] = sum[i - 1] + a[i - 1];
  }

  int64_t ans = 0;
  for (int64_t i = 0; i < n; i++) {
    const auto index = n - i - 1;
    const auto itr = std::lower_bound(ra.cbegin(), ra.cend(), min - ra[index]);
    const auto num = std::distance(itr, ra.cend());
    ans += a[i] * num + sum[num];
    if (num == 0) {
      break;
    }
  }

  ans -= (map[min] - m) * min;

  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 2560
H,W,K=map(int,input().split())

L=[]
E=[0 for i in range(W+2)]
L.append(E)
for i in range(H):
    l=[0]+list(input())+[0]
    L.append(l)
L.append(E)

#print(L)
cnt=1
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i][j]=="#":
            L[i][j]=cnt
            cnt+=1
#print(L)
for i in range(1,H+1):
    num=0
    for j in range(1,W+1):
        if num>0 and L[i][j]==".":
            L[i][j]=num
        elif L[i][j]!=".":
            num=L[i][j]
    num=0
    for j in range(1,W+1):
        if L[i][W+1-j]!=".":
            num=L[i][W+1-j]
        elif num!=0 and L[i][W+1-j]==".":
            L[i][W+1-j]=num
        
for i in range(1,H):
    if L[i+1][1]==".":
        L[i+1]=L[i]
        
for i in range(1,H):
    if L[H-i][1]==".":
        L[H-i]=L[H-i+1]


for i in range(1,H+1):
    print(*L[i][1:W+1])


Measured memory_bytes: 53720
n = int(input())
dat = list(map(int, input().split()))
dat.sort()
x = dat[-1]
xx = x / 2
dat = dat[:-1]
mindiff = 999999999999999999999999999
minnum = None
for i in range(n-1):
    if abs(xx-dat[i]) < mindiff:
        mindiff = abs(xx-dat[i])
        minnum = dat[i]
print(x, minnum)

Measured memory_bytes: 62704
N = int(input())

ans = 0
for n in range(105, N + 1):
    if n % 2 == 0:
        continue
    divisor = 0
    for i in range(1, n + 1):
        if n % i == 0:
            divisor += 1
    if divisor == 8:
        ans += 1
print(ans)


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

a.sort()

def cost(a, y):
    ans = 0
    for i in a:
        ans += (i - y) * (i - y)
    return ans

# binary search

left = a[0]
right = a[n-1]

while left < right:
    center = (left + right) // 2
    if cost(a, center) < cost(a, center+1):
        right = center
    else:
        left = center + 1

print(cost(a, left))

Measured memory_bytes: 62968
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int N, M, K, p[20][1010];
int sum(int L1,int R1,int L2,int R2){
    return  p[L2][R2] + p[L1 - 1][R1 - 1] - p[L1 - 1][R2] - p[L2][R1 - 1] ;
}
void solve(){
	cin>>N>>M>>K;
	rep(i,0,N){
		string s;
		cin>>s;
		rep(j,0,M){
			if(s[j]=='1')p[i+1][j+1] = 1;
		}
	}
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i][j - 1]; }
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i - 1][j]; }
    int res = 1E9;
	for(int bits = 0 ;bits<(1<<(N-1));bits++){
		VI cut;
		for(int i=0;i<N-1;i++){
			if((bits>>i)&1){
				cut.pb(i+1);
			}
		}
		cut.pb(N);
		int  pcol = 1,ans=sz(cut)-1;
		int ok = 1;
		for(int i=1;i<=M;i++){
			int f=1,prow=1;
			for(int j=0;j<sz(cut);j++){
				if(sum(prow,pcol,cut[j],i)>K){
					f = 0;
					break;
				}
				prow = cut[j]+1;
			}
			if(!f){
				ans++;
				if(pcol==i){
					ok = 0;
					break;
				}
				pcol = i;
			}
		}
		if(ok)res = min(res,ans);
	}
	cout<<res;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
char c[11];
cin>>c;
int i=0;
while(i<10){
if(i+1==10){
cout<<c[i]<<endl;
}else{
if(i==3){
cout<<'8';
}else{
cout<<c[i];
}
}
i++;
}
return 0;
}

Measured memory_bytes: 256
// AGC013_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    ll N;
    cin >> N;
    vector<ll> vec(N), vec_diff(N-1);
    REP(i, N) cin >> vec[i];
    for (ll i = 1; i < N; ++i) {
        vec_diff[i-1] = vec[i] - vec[i-1];
    }
    
    // calculation
    if (N <= 2) {
        cout << 1 << "\n";
    } else {
        // 増加・減少をどう捉えるか
        ll idx_start = -1;
        bool flag_equal, flag_updown;
        for (ll i = 0; i < N-1; ++i) {
            flag_equal = (vec_diff[i] == 0);
            if (flag_equal) {
                continue;
            } else {
                flag_updown = (vec_diff[i] > 0);
                idx_start = i;
                break;
            }
        }
        
        if (idx_start == -1) {
            // 一度も変化がなかった
            cout << 1 << "\n";
        } else {
            ll res = 1, diff;
            bool flag_before = flag_updown;  // 初めのup down を保存
            bool flag_flat = false;
            for (ll i = idx_start + 1; i < N-1; ++i) {
                diff = vec_diff[i];
                if (diff == 0) {
                    // 非増加減少
                    continue;
                } else {
                    flag_updown = diff > 0;  // 増加なら true
                    if (flag_flat) {
                        // flat な目線で見る時
                        flag_flat = false;
                    } else {
                        // flag の変化があった時に それを数える
                        if (flag_before != flag_updown) {
                            res += 1;
                            flag_flat = true;
                        }
                    }
                }
                flag_before = flag_updown;
            }
            cout << res << "\n";
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
struct edge {int /*from,*/to,cost;};

main(){
    string s;
    cin >> s;
    reverse(ALL(s));
    REP(i,LEN(s)){
        if(s.substr(i,5)=="maerd" || s.substr(i,5)=="esare") i += 4;
        else if(s.substr(i,6)=="resare") i+= 5;
        else if(s.substr(i,7)=="remaerd") i+= 6;
        else {
            puts("NO");
            return 0;
        }
    }
 
    puts("YES");
    return 0;
}


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

int32_t main()
{
    long long N, P;
    string S;

    cin >> N >> P;
    cin >> S;

    if (P != 5 && P != 2)
    {
        long long *cnt = new long long [P];
        for(long long i=0; i<P; i++)
        {
            cnt[i] = 0;
        }
        long long pow10 = 1;
        long long mod = 0;
        for (long long i = 0; i < N; i++)
        {
            pow10 = pow10 % P;
            mod = (((S[N - 1 - i] - 48) * pow10) % P + mod) % P;
            cnt[mod]++; //同じ剰余の数を数える
            pow10 *= 10;
            //cout << mod << endl;
        }

        long long all_cmb = cnt[0];
        for (long long n = 0; n < P; n++)
        {
            //cout << n << ":" << cnt[n] << endl;
            all_cmb += cnt[n] * (cnt[n] - 1) / 2;
        }

        cout << all_cmb << endl;

        delete [] cnt;
    }
    else
    {
        long long cnt = 0;
        for (long long i = 0; i < N; i++)
        {
            if((S[i] - 48) % P == 0)
            {
                cnt += i + 1;
            }
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int n,a,b,t[1001],ans;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&t[i]);
		if(t[i]<a||t[i]>=b)
			ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
#include <map>
using namespace std;

int main()
{
	int x;
	cin >> x;
	if (x >= 30)
		cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	fsc := NewFastScanner()
	a := fsc.Next()
	b := fsc.Next()
	c := fsc.Next()

	fmt.Println(string(a[0]) + string(b[1]) + string(c[2]))
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}

func (s *FastScanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 640
process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	"use strict"
	const S = lines[0];
	
	const format = [+(S[0]+S[1]), +(S[2]+S[3])].
		map(a => +(a>=1 && a<=12));
	let ans = (new Map(
		[["00", "NA"],
		["01", "YYMM"],
		["10", "MMYY"],
		["11", "AMBIGUOUS"]])).get(format.join(""))
		
	console.log(ans);
});

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

int main(void)
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int sec = 0;
    if (C <= B && A <= D)
    {
        //if (A == C && B == D)
        //    sec = B - A; // or D - C
        if (A <= C && D <= B)
            sec = D - C;
        else if (A <= C && B <= D)
            sec = B - C;
        else if (C <= A && B <= D)
            sec = B - A;
        else 
            sec = D - A;
    }
    cout << sec << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ETozanAndGezan {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        int bmin = INF;
        int s = 0;
        REP(i, N) {
            int a, b;
            cin >> a >> b;
            s += a;
            if (a > b) {
                bmin = min(bmin, b);
            }
        }
        if (bmin == INF) {
            cout << 0 << endl;
            return;
        }
        cout << s - bmin << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ETozanAndGezan solver;
    solver.solve(in, out);
    return 0;
}


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

int main(void){
        double a, b, t;
        scanf("%lf %lf %lf", &a, &b, &t);
        t *= M_PI / 180.0;

        double s = a*b*sin(t)/2.0;
        double l = a + b + sqrt(a*a + b*b - 2*a*b*cos(t));
        double h = s/a*2;

        printf("%lf %lf %lf\n", s, l, h);
        return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
        ifstream in("input.txt");
        ofstream out("output.txt");
        #define cin in
        #define cout out
#endif
int main(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	vector<int> dp(n+1,1e9);
	int k=2;
	dp[0]=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<i+1+k;j++)
			if(j<n)
				dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
	cout<<dp[n-1];
} 

Measured memory_bytes: 1024
<?php

while (true) {
    $stdin = preg_split('/ /', trim(fgets(STDIN)));
    $m = intval(array_shift($stdin)); // 中間試験
    $f = intval(array_shift($stdin)); // 期末試験
    $r = intval(array_shift($stdin)); // 再試験
    $sum = $m + $f;
    
    if ($m == -1 && $f == -1 && $r == -1) {
        return;
    }
    
    if ($m == -1 || $f == -1) {
        print("F\n");
    } elseif ($sum < 30) {
        print("F\n");
    } elseif (30 <= $sum && $sum < 50) {
        if ($r < 50) {
            print("D\n");
        } else {
            print("C\n");
        }
    } elseif (50 <= $sum && $sum < 65) {
        print("C\n");
    } elseif (65 <= $sum && $sum < 80) {
        print("B\n");
    } else {
        print("A\n");
    }
}

Measured memory_bytes: 6652
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int K = in.nextInt();
		
		int a = K/2;
		if(K%2==0) {
			
			System.out.println(a*a);
		}else {
			System.out.println((a+1)*a);
				
		}
		
	
		in.close();
	}
}


Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll n, k; cin >> n >> k;
    ll res = 1;
    rep(i,0,n){
        res = min(res*2, res+k);
    }
    cout << res << endl;
}


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


int main(){
	
	int n,m,l;
	cin >> n >> m >> l;
	long long a[n][m],b[m][l],c[n][l];
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			cin >> a[i][j];
		}
	}
	for(int i = 0;i < m;i++){
		for(int j = 0;j < l;j++){
			cin >> b[i][j];
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < l;j++){
			c[i][j] = 0;
			for(int k = 0;k < m;k++){
				c[i][j] += a[i][k]*b[k][j];
			}
			cout << c[i][j];
			if(j != l-1)cout << " ";
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

int main(void){
	int a, b;
	string op;
	cin >> a >> op >> b;
	if(op=="+"){
		cout << a+b << endl;
	}else {
		cout << a-b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x, y;
    cin >> x >> y;
    cout << (abs(x-y) < 2?"Brown":"Alice") << endl;
}

Measured memory_bytes: 3660
/******************/
/*  Binary Trees  */
/******************/
#include <stdio.h>
#define MAX 25
#define NIL -1

/* Struct Declaration */
typedef struct node {
  int parent;
  int left;
  int right;
}Node;

/* Prototype Declaration */
void setDepth(int, int);
void printChildren(int);
int setHeight(int);

/* Global Variables */
Node U[MAX];
int depth[MAX], height[MAX];

int main () {
  int i, j, n, id, data, r, h;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    U[i].parent = NIL;
    U[i].left = NIL;
    U[i].right = NIL;
  }

  for ( i = 0; i < n; i++ ) {
    scanf("%d", &id);
    for ( j = 0; j < 2; j++ ) {
      scanf("%d", &data);
      if ( j == 0 ) U[id].left = data;
      else U[id].right = data;

      U[data].parent = id;
      
    }
  }

  for ( i = 0; i < n; i++ ) {
    if( U[i].parent == NIL ) r = i;
  }

  setDepth(r, 0);
  h = setHeight(r);

  for ( i = 0; i < n; i++ ) printChildren(i);

  return 0;
  
}

void setDepth(int u, int p) {
  depth[u] = p;

  if ( U[u].right != NIL ) setDepth(U[u].right, p + 1);
  if ( U[u].left != NIL ) setDepth(U[u].left, p + 1);
}

int setHeight(int u) {
  int a, b;
  
  a = 0;
  b = 0;

  if ( U[u].left != NIL ) a = setHeight(U[u].left) + 1;
  if ( U[u].right != NIL ) b = setHeight(U[u].right) + 1;

  if ( a > b ) height[u] = a;
  else if ( a < b ) height[u] = b;
  else height[u] = a;

  return height[u];

}

void printChildren(int u) {
  int c = U[u].left;

  printf("node %d: ", u);
  printf("parent = %d, ", U[u].parent);
  printf("sibling = ");
  if ( U[u].parent != NIL && U[U[u].parent].left == u ) printf("%d, ", U[U[u].parent].right);
  else if ( U[u].parent != NIL && U[U[u].parent].right == u ) printf("%d, ", U[U[u].parent].left);
  else printf("-1, ");
  printf("degree = ");
  if( U[u].left == NIL && U[u].right == NIL ) printf("0, ");
  else if ( U[u].left != NIL && U[u].right != NIL ) printf("2, ");
  else printf("1, ");
  printf("depth = %d, ", depth[u]);
  printf("height = %d, ", height[u]);

  if ( U[u].parent == NIL ) printf("root");
  else if ( U[u].left == NIL && U[u].right == NIL ) printf("leaf");
  else printf("internal node");
  printf("\n");
}

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

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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    for(int i = 0; i < N;i++){
        cin >> A[i];
    }
    for(int i = 0; i < N;i++){
        cin >> B[i];
    }
    for(int i = 0; i < N -1 ;i++){
        cin >> C[i];
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans += B[i];
    }
    for(int i = 0; i < N - 1; i++){
        if(A[i] + 1 == A[i+1]){
            ans += C[A[i]-1];
        }
    }

    cout << ans << endl;

}

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

int main(void){
 
  string s;
  cin >> s;
  
  int count = 0;
  
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '1') count++;
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,ans=0;
vl v(26,0);
float ff;
string s;
ll solve(){
    rep(i,4){
        v[s[i]-'A']++;
    }
    sort(all(v));
    reverse(all(v));
    if(v[0]==2&&v[1]==2){
        cout<<"Yes"<<endl;
        return 1;
    }
    cout<<"No"<<endl;
    return 0;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>s;
 
    solve();    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str):
    counter = 0
    l = len(S)
    for i in range(l//2):
        if S[i] != S[l-i-1]:
            counter += 1
    print(counter)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from bisect import bisect_left

X = int(input())

N = 10 ** 6 + 10
# N = int(input())
def primes(n):
    import math
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(math.sqrt(n)) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

prime_lst = primes(N)

tmp = bisect_left(prime_lst, X)
print (prime_lst[tmp])

Measured memory_bytes: 14084
N, M = map(int, input().split())

# Union-Find
parent = [i for i in range(N)]
rank = [1] * N
def get_root(node):
  global parent
  if parent[node] == node:
    return node
  root = get_root(parent[node])
  parent[node] = root
  return root

def union(a, b):
  global parent
  global rank
  root_a = get_root(a)
  rank_a = rank[root_a]
  root_b = get_root(b)
  rank_b = rank[root_b]
  if root_a == root_b:
    return
  if rank_a < rank_b:
    parent[root_a] = root_b
  else:
    parent[root_b] = root_a
    if rank_a == rank_b:
      rank[root_a] += 1

for _ in range(M):
    a, b = map(int, input().split())
    union(a-1, b-1)

s = set()
for i in range(N):
    s.add(get_root(i))
print(len(s)-1)


Measured memory_bytes: 21520
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
int main(){
    int n;
    cin >> n;
    double t,a;
    cin >> t >> a;
    vector<pair<double,int>>h;
    rep(i,n){
        int x;
        cin >> x;
        h.emplace_back(abs(a-(t-x*0.006)),i+1);
    }
    sort(h.begin(),h.end());
    cout << h[0].second << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  cin >> n >> m;
  lep(i,0,n){
    lep(j,0,n){
      if(i + j > n)continue;
      if((m - (i * 10000) - (j * 5000)) / 1000 == n - i - j){
        cout << i <<  " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}

Measured memory_bytes: 256