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

using namespace std;

typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;


void solve()
{
	ll n;
	cin>>n;
	ll ct=0,both=0,a=0,b=0;
	fr(i,0,n)
	{
		string str;
		cin>>str;
		fr(i,0,str.size()-1)
		{
			if(str[i]=='A'&&str[i+1]=='B')
			{
				ct++;
			}
			
		}
		if(str[0]=='B'&&str[str.size()-1]=='A')
		{
			both++;
		}
		else if(str[0]=='B')
		{
			b++;
		}
		else if(str[str.size()-1]=='A')
		{
			a++;
		}
	}
	if(both>0)
	{
		ct+=(both-1);
		if(a>0)
		{
			ct++;
			a--;
		}
		if(b>0)
		{
			ct++;
			b--;
		}
		ct+=min(a,b);
	}
	else
	{
		ct+=min(a,b);
	}
	cout<<ct<<endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}

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

int main(){
 int a;
  char f;
  cin>>a;
vector<string>c(a);
vector<int>d(26);
  vector<int>e(26);
  for(int i=0;i<26;i++){
    d[i]=1000;
  }
  for(int i=0;i<a;i++){
    cin>>c[i];
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<c[i].size();j++){
      for(int u=0;u<26;u++){
        if(c[i][j]-'a'==u){
          e[u]++;
        }
      } 
    }
     for(int j=0;j<26;j++){
       d[j]=min(d[j],e[j]);
       e[j]=0;
     }
  }
  for(int i=0;i<26;i++){
    f='a'+i;
    for(int j=0;j<100000;j++){
    if(d[i]!=0){
       cout<<f;
    d[i]--;
    }
      else{
        break;
      }
    }
  }
cout<<endl;
      
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>

using namespace std;

int main(){
  char str[20];
  cin >> str;
  for(int i = 0; i < 19; i++){
    if(i == 5 || i == 13)
      printf(" ");
    else
      printf("%c", str[i]);
  }
  cout << endl;

  return 0;
}

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

using namespace std;

template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}

int main()
{
    #ifdef Akshay
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int i,j,n,m,nx[100],ny[100],mx[100],my[100],ans[100],mn,temp;
    
    cin>>n>>m;
    
    for(i=0;i<n;i++)
    {
        cin>>nx[i]>>ny[i];
    }
    
    for(i=0;i<m;i++)
    {
        cin>>mx[i]>>my[i];
    }
    
    for(i=0;i<n;i++)
    {
        mn=abs(nx[i]-mx[0])+abs(ny[i]-my[0]);
        ans[i]=0;
        
        for(j=1;j<m;j++)
        {
            temp=abs(nx[i]-mx[j])+abs(ny[i]-my[j]);
            
            if(temp<mn)
            {
                mn=temp;
                ans[i]=j;
            }
            
        }
    }
    
    for(i=0;i<n;i++)
    {
        cout<<ans[i]+1<<endl;
    }

    
    return 0;
    
}


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

#define freopen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
#define abs(a) (a) < 0 ? -(a) : (a);
#define max(a, b) (a) > (b) ? (a) : (b)
#define min(a, b) (a) < (b) ? (a) : (b)
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
typedef long long var;

const int INF = 0x3f3f3f3f;

long long read();

int main() {
  var S = read();
  var a = sqrt(S);
  if (a * a == S) printf("0 0 %lld 0 0  %lld\n", a, a);
  else {
    a++;
    var near = a * a - S;
    printf("0 0 %lld 1 %lld %lld\n", a, near, a);
  }
  return 0;
}

long long read() {
  long long a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}


Measured memory_bytes: 128
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define rep(n) for(Int x = 0; x < n; x++)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (x[x.size()-1])

using namespace std;

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

struct Point {
  Int x, y;
  Point(Int x, Int y): x(x), y(y) {}
  Point(): x(0), y(0) {}

  bool operator< (const Point &p1) {
    return x < p1.x && y < p1.y;
  }
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Point & v) {
  Int x, y;
  in >> x; in >> y; v.x = x; v.y = y;
  return in;
}

bool compX (const Point &p1, const Point &p2) {
  return p1.x < p2.x;
}

bool compY (const Point &p1, const Point &p2) {
  return p1.y < p2.y;
}

Int A, B, C;

void input() {
  cin >> A >> B >> C;
}

void solve() {
  if (A + B + C >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 384
n,k = gets.chomp.split(" ").map(&:to_i)
p = Array.new(n,0)
k.times do
  d = gets.to_i
  a = gets.chomp.split(" ").map(&:to_i)
  a.each do |x|
    p[x-1] += 1
  end
end
puts p.count(0)

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

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

    map<string, int> x;

    int N;
    cin >> N;

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

    int M;
    cin >> M;

    for(int i = 0; i < M; i++) {
        string t;
        cin >> t;
        x[t]--;
    }

    int ans = 0;

    for(auto&& i = begin(x); i != x.end(); i++) {
        ans = max(ans, i -> second);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll a[220000];
int main(){
    ll n,ans=0;
    cin>>n;
    rep(i,0,n)cin>>a[i];
    sort(a,a+n);
    rep(i,0,n-2){
        rep(j,i+1,n-1){
            rep(k,j+1,n){
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]){
                    if(a[k]<a[i]+a[j])ans++;
                }
            }
        }
    }
    cout<<ans;

}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    int h,w,d;
    cin >> h >> w >> d;
    vector<vector<ll>> grid(h,vector<ll>(w));
    vector<pair<ll,ll>> ap(h*w+1);

    REP(i,h){
        REP(j,w){
            cin >> grid[i][j];
            ap[grid[i][j]] = pair<ll,ll>(i,j);
        }
    }

    vector<vector<ll>>  cost(d,vector<ll>(1));
    REP(i,d){
        cost[i][0] = 0;
        for(int j = 1;j * d + i <= h*w;j++){
            pair<ll,ll> cp = ap[j*d+i];
            pair<ll,ll> pp = ap[(j-1)*d + i];
            cost[i].push_back(cost[i][j-1] + abs(cp.first - pp.first)+abs(cp.second - pp.second));
        }
    }

    int q;
    cin >> q;
    vector<ll> L(q);
    vector<ll> R(q);

    REP(i,q){
        cin >> L[i] >> R[i];
    }



    REP(i,q){
        cout << cost[R[i]%d][R[i]/d] - cost[L[i]%d][L[i]/d] << endl;
    }

    return 0;
}

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

int main() {
  int K, S;
  cin >> K >> S;

  int counter = 0;
  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      if (S - X - Y >= 0 && S - X - Y <= K) counter++;
    }
  }

  cout << counter << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int ans=0,k=0,i,j,n,m,a[510][510],b,c,stack[101010],y[510];
while(1){
scanf("%d\n%d\n",&n,&m);
if(n==0 && m==0){
break;
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
a[i][j]=0;
}
}
for(i=0;i<=n;i++){
y[i]=0;
}
for(i=0;i<m;i++){
scanf("%d %d\n",&b,&c);
a[b][c]=1,a[c][b]=1;
}
for(i=1;i<=n;i++){
if(a[1][i]==1){
stack[k]=i;
y[i]=1,k++,ans++;
}
}
for(i=0;i<k;i++){
for(j=2;j<=n;j++){
if(a[stack[i]][j]==1 && y[j]==0){
ans++,y[j]=1;
}
}
}
printf("%d\n",ans);
ans=0,k=0;
}
return 0;
}


Measured memory_bytes: 2680
n,m = map(int, input().split())
link = [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    link[a].append(b)
    link[b].append(a)

visited = [0]*n
ans = 0

def dfs(now, prev):
    global ans

    if sum(visited) == n:
        ans += 1

    for i in link[now]:
        if i != now and visited[i] == 0:
            visited[i] = 1
            dfs(i, now)
            visited[i] = 0

visited[0] = 1
dfs(0,-1)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
    int n,m,p;
    long long int ans=0;
    while(1==1)
    {
        int x[105]={0};
        scanf("%d %d %d\n",&n,&m,&p);
        if(n==0&&m==0&&p==0)break;
        int sum=0;
        for(int q=0;q<n;q++)
        {
            scanf("%d\n",&x[q]);
            sum+=x[q];
        }
        if(x[m-1]==0)
        {
            printf("0\n");
        }
        else
        {
            ans=sum*(100-p)/x[m-1];
            printf("%lld\n",ans);
        }
    }
    return 0;
}



Measured memory_bytes: 2032
n=gets.to_i
a=[]
$<.map{|s|
x,l=s.split.map &:to_i
a<<[x-l,x+l]
}
a.sort_by!{|s,t|t}
c=0
u=a[0][0]
a.map{|s,t|
if u<=s
c+=1
u=t
end
}
p c

Measured memory_bytes: 13560
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(void){

    double N,T,A,ans;
    
    cin >> N >> T >> A;
    
    vector<double> vec(N);
    REP(i,N) cin >> vec[i];
    
    REP(i,N){
       vec[i] = T - 0.006*vec[i];    
    }

   double min = 9999999999;

   ans=0;

   for(int i=0;i<N;i++){
       if(A-vec[i]>0){
           if(min > A-vec[i]){
               min = A-vec[i];
               ans= i+1;
           }
       }else{
           if(min>-1*(A-vec[i])){
               min = -1*(A-vec[i]);
               ans = i+1;
           }
       }
   }

   cout << ans << endl;
   
}

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

int main() {
    ll n,t;
    std::cin >> n>>t;
    vector<pair<ll,ll>> ab(n);
    
    for (int i = 0; i < n; i++) {
        std::cin >> ab[i].first>>ab[i].second;
    }
    
    sort(ab.begin(), ab.end(), [](auto const& lhs, auto const& rhs) {
        if( lhs.first != rhs.first){
            return lhs.first < rhs.first;            
        }else{
            return lhs.second > rhs.second;   
        }
    });

    ll res = 0;
    
    vector<vector<ll>> dp(n+1,vector<ll>(t+1,0));
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < t; j++) {
            
            if(i>0){
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
            }
            
            if(j+ab[i].first<t){
                dp[i+1][j+ab[i].first] = max(dp[i][j+ab[i].first],dp[i+1][j+ab[i].first]);
                dp[i+1][j+ab[i].first] = max(dp[i+1][j+ab[i].first], dp[i][j] + ab[i].second);
                res = max(res,dp[i+1][j+ab[i].first]);
            }else{
                res = max(res,dp[i][j] + ab[i].second);
            }
        }
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i)-1 = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{	
    ll a, b, c;
    cin >> a >> b >> c;
    bool ok = false;

    REP(i, b) if((a*(i+1) % b) == c) ok = true;
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 3508
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int N;
bool ask(ll x)
{
    printf("? %lld\n", x);
    fflush(stdout);
    char s[2];  scanf(" %s", s);
    // if ((to_string(x) <= to_string(N) && x <= N) || (to_string(x) > to_string(N) && x > N)) s[0] = 'Y';
    // else s[0] = 'N';
    return (s[0] == 'Y');
}
void done(ll x)
{
    printf("! %lld\n", x);
    fflush(stdout);
}
ll full[12];
int getlen()
{
    full[1] = 1;
    for (int i = 2; i <= 11; i++) full[i] = full[i - 1] * 10;
    int l = 1, r = 10; 
    while (l < r)
    {
        int mid = (l + r + 1) >> 1;
        if (!ask(full[mid])) r = mid - 1;
        else l = mid;
    }
    if (l == 10) 
    {
        l = 1, r = 10;
        while (l < r)
        {
            int mid = (l + r) >> 1;
            if (ask(full[mid] + 1)) r = mid;
            else l = mid + 1;
        }
        done(full[l]);
        exit(0);
    }
    return l;
}
int main()
{
    // scanf("%d", &N);
    int len = getlen(); // printf("len = %d\n", len);
    ll now = 0;
    for (int i = 1; i <= len; i++)
    {
        int l = 0, r = 9; if (i == 1) l = 1;
        while (l < r)
        {
            int mid = (l + r + 1) >> 1;
            if (!ask((now * 10 + mid) * full[len + 2 - i])) l = mid;
            else r = mid - 1;
        }
        now = now * 10 + r;
    }
    done(now + 1); // assert(now + 1 == N);
    return 0;   
}

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

using namespace std;

const int maxw = 500000;

template <class T, class U = int>
struct KnuthMorrisPratt {
	static const int maxn = maxw;

	int n;
	T p[maxn];
	U f[maxn + 1];

	KnuthMorrisPratt() : n(0) {

	}

	U & operator [] (const int & x) {
		return f[x];
	}

	void build(const T * first, const T * last) {
		const T * & p = first;
		n = last - first;
		memcpy(this->p, p, sizeof p[0] * n);
		f[0] = f[1] = 0;
		for (int i = 1, k; i < n; i++) {
			for (k = f[i]; k > 0 && p[k] != p[i]; k = f[k]);
			if (p[k] == p[i])
				k++;	
			f[i + 1] = k;
		}
	}
};

char w[maxw + 1];
KnuthMorrisPratt<char> KMP, KMPr;

inline bool valid(const int & n, const int & l) {
	return n % l > 0 || n == l;
}

pair<int, int> answer() {
	int n = strlen(w);
	KMP.build(w, w + n);
	reverse(w, w + n);
	KMPr.build(w, w + n);

	int l = n - KMP[n];
	if (valid(n, l))
		return make_pair(1, 1);
	else if (l > 1) {
		int ans = (n / l - 2) * (l - 1);
		for (int i = 1; i < l; i++) {
			for (int j = 0; j < 2; j++) {
				int z = j ? n - i : i;
				int x = z - KMP[z], y = n - z - KMPr[n - z];
				if (valid(z, x) && valid(n - z, y))
					ans++;
			}
		}
		if (n == l * 2) {
			int r = l - KMP[l];
			if (valid(l, r))
				ans++;
		}
		return make_pair(2, ans);
	} else
		return make_pair(n, 1);
}

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

	cin >> w;

	pair<int, int> ans = answer();

	cout << ans.first << '\n';
	cout << ans.second << '\n';

	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin>>n;
    long long int a[n],f[n+2],s=0;
    f[0]=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        //cout<<a[i]<<"\n";
    }
    f[0]=0;
    f[n]=INT_MAX;
    f[1]=abs(a[1]-a[0]);
    s+=f[1];
    for(int i=2;i<n;i++){
        f[i] = min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
        
        s+=f[i];
    }
    // for(int i=0;i<n;i++){
    //     cout<<f[i]<<"\n";
    // }
    cout<<f[n-1];
    return 0;
    
}

Measured memory_bytes: 1792
class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = -1 
  
n = int(input())
nodes = [0] * 101
for i in range(n):
    data = input().split()
    V = list(map(int, data[2:]))
    V.sort(reverse = True)
    nodes[int(data[0])] = Node(V)
  
l = [1,]
l_old = []
cnt = 0

while len(l) > 0:
    l_old = l
    l = []
    for i in l_old:
        if nodes[i].d == -1:
            nodes[i].d = cnt
            V = nodes[i].V
            for j in V:
                if not j in l:
                    if nodes[j].d == -1:
                        l.append(j)
    cnt += 1
for i in range(1, n+1):
    if not isinstance(nodes[i], int):
        print(i, nodes[i].d)

Measured memory_bytes: 7792
p=print
r=range
m=60
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i+1)
def d(x,i):
	for t in r(30):b(p:=i+t+30);a(q:=p+1,n,q);[*map(b,r(q,i+m))];a(i+m,x,i+t,1);b(p);a(q,i+t,q)
p(n:=3934)
a(0,1,n)
a(2,n,n,1)
a(0,n,3)
a(1,n,4)
d(3,9)
d(4,m)
for t in r(m):a(2,2,2);[t-31<s<30!=(a(8+t-s,m+s,5),a(n,5,6,1),a(2,6,2))for s in r(t)]

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

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: i64 = read();
    let m: i64 = read();
    let k: i64 = read();

    let mut only_n: Vec<i64> = Vec::new();
    let mut possible: Vec<i64> = Vec::new();

    for i in 0..=n {
        only_n.push(i * m);
        possible.push(i * m);
    }

    for row in 0..=n {
        for column in 0..=m {
            possible.push(only_n[row as usize] + (n - 2 * row) * column);
        }
    }

    //println!("{:?}", only_n);
    //println!("{:?}", possible);

    if let Some(_) = possible.iter().find(|&&x| x == k) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 9908
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>

using namespace std;

int main() {
    int n, k, x, sum = 0;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> x;
        sum += min(x, abs(x - k)) * 2;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    vector<int64_t>dp(31, 0);
    dp[0] = 1;
    for (int64_t i=1; i<=30; i++) {
        int64_t pattern = 0;
        pattern += dp[i-1];
        if (i > 1) pattern += dp[i-2];
        if (i > 2) pattern += dp[i-3];
        dp[i] = pattern;
    }

    int N;
    while (cin >> N) {
        if (N == 0) break;
        int64_t count = dp[N] / 3650;
        if (dp[N] % 3650 > 0) {
            count += 1;
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3004
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



template<typename T>
class Segtree{
  public:
  using F = function<T(T,T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;
  Segtree(){};
  Segtree(F f,T ti): f(f),ti(ti){}
  void init(int N){
    n = 1;
    while(n < N)n <<= 1;
    dat.assign(n << 1,ti);
  }
  void build(const vector<T> &v){
    int N = v.size();
    init(N);
    rep(i,N)dat[n+i] = v[i];
    for(int i = n-1;i >= 0;i--)dat[i] = f(dat[(i << 1)|0],dat[(i << 1)|1]);
  }
  void set(int k,T x){
    dat[k+=n] = x;
    while(k >>= 1){
      dat[k] = f(dat[(k << 1)|0],dat[(k << 1)|1]);
    }
  }
  T get(int l,int r){
    T vl = ti,vr = ti;
    for(l += n,r += n;l < r;l >>= 1,r >>= 1){
      if(l & 1)vl = f(vl,dat[l++]);
      if(r & 1)vr = f(dat[--r],vr);
    }
    return f(vl,vr);
  }
};

int main(){
  
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i,n)cin >> v[i];
  Segtree<ll> seg([](ll a,ll b){return __gcd(a,b);},0ll);
  seg.build(v);
  ll res = 0;
  rep(i,n){
    ll l = v[i];
    seg.set(i,0);
    ll k = __gcd(seg.get(0,i),seg.get(i,n));
    seg.set(i,l);
    res = max(res,k);
  }
  cout << res << "\n";
  


  return 0;
}

Measured memory_bytes: 6120
class Unionfind:
  def __init__(self,n):
    self.Tree=[i for i in range(n)]
    self.rank=[0]*n

  def find(self,x):
    if x==self.Tree[x]:
      return x
    else:
      root=self.find(self.Tree[x])
      self.Tree[x]=root
      return root

  def unite(self,x,y):
    s1=self.find(x)
    s2=self.find(y)
    if s1==s2:
      pass
    else:
      if self.rank[s1]>self.rank[s2]:
        self.Tree[s2]=s1
      elif self.rank[s1]<self.rank[s2]:
        self.Tree[s1]=s2
      else:
        self.Tree[s2]=s1
        self.rank[s1]+=1

N,M=map(int,input().split())        
uf=Unionfind(N)        
for i in range(M):
  x,y,w=map(int,input().split())
  uf.unite(x-1,y-1)
used=[False]*N
ans=0
for i in range(N):
  uf.find(i)
  if not used[uf.Tree[i]]:
    ans+=1
  used[uf.Tree[i]]=True
  
print(ans)
#print(uf.Tree)        

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N+1);
    for ( int i = 1; i < N+1; ++i){
        cin >> a.at(i);
    }
    
    vector<int> ans(N+1);
    for ( int i = N; i >= 1; --i){
        int sum = 0;
        int cnt = 2;
        while ( cnt * i <= N ){
            sum += ans.at(cnt*i);
            cnt += 1;
        }
        ans.at(i) = ( sum + a.at(i) )% 2;
    }
    
    int M = 0;
    vector<int> b;
    for ( int i = 1; i <= N; ++i){
        if ( ans.at(i) == 1 ){
            b.push_back(i);
            M += 1;
        }
    }
    
    cout << M << endl;
    for ( int i = 0; i < b.size(); ++i){
        cout << b.at(i) << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3064
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) 

I=sys.stdin.readline

 #s="abcdefghijklmnopqrstuvwxyz"

"""
x_move=[-1,0,1,0,-1,1,1,-1]
y_move=[0,1,0,-1,1,1,-1,-1]
"""
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


	
	

	

def main():
	n,x,t=mi()
	print(t*math.ceil(n/x))


	


	
	
	
		







	












	
	
	





if __name__ == '__main__':
	main()

Measured memory_bytes: 9568
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split()
        x[k] = v
    n = int(sys.stdin.readline().rstrip())
    y = []
    for i in range(n):
        a = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

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

int main() {
  int n,k;
  cin >> n;
  k = n;
  int x = 10,t = 0;
  for (int i = 0; i < 8; i++) {
    t += n % 10;
    n /= 10;
  }
  if (k % t == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3668
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
arr = np.array(lst, np.int64)
mod = 10 ** 9 + 7
c = []

while arr.any():
    c1 = np.count_nonzero(arr & 1)
    c.append(c1 * (n - c1))
    arr >>= 1
print(sum([(v * 2 ** i) for i, v in enumerate(c)]) % mod)

Measured memory_bytes: 48792
//abc133_e.cpp
//Sat Oct 12 11:18:47 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
ll MOD = 1000000007;

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

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

	queue<int> q;
	q.push(0);
	ll visited[n];
	fill(visited,visited+n,-1);
	visited[0] = 0;
	ll parent[n];
	fill(parent,parent+n,-1);
	parent[0] = -1;
	ll ans = 1;
	ll prevvisited = -1;
	ll prevparent = -2;
	ll count = 0;
	while (q.size()){
		ll start = q.front();
		q.pop();
		ll color = k;
		if (visited[start] == 1){
			color = k-1;
		}else if (visited[start]>1){
			color = k-2;
		}
		if (prevparent!=parent[start]){
			count = 0;
			prevparent = parent[start];
		}else {
			count++;
		}
		color = color - count;
		if (color == 0){
			cout << 0 << endl;
			return 0;
		}
		ans = ans * color % MOD;
//		cout << start << " " << visited[start] << " " << color << " " << ans << endl;
		for (int i=0;i<G[start].size();i++){
			int end = G[start][i];
			if (visited[end]==-1){
				q.push(G[start][i]);
				visited[end] = visited[start]+1;
				parent[end] = start;
			}
		}
	}

//	for (int i=0;i<n;i++){
//		cout << i << " " << visited[i] << endl;
//	}
	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 8436
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

use std::iter::Iterator;

fn main() {
    input! {
        n:usize,
        v:[i32; n],
        c:[i32; n],
    }

    let mut sum = 0;

    for i in 0..n {
        let xy : i32 = (v[i] - c[i]) as i32;
        if xy > 0 {
            sum = sum + xy;
        }
    }

    println!("{}", sum);
}


Measured memory_bytes: 4352
while True:
	n=int(input())
	ans=0
	if n==0:
		break
	for i in range(2,n):
		ave=n/i
		if ave==int(ave):
			if ave-i//2>0 and i%2!=0:
				ans+=1
		elif ave==int(ave)+0.5:
			if ave-i//2>0:
				ans+=1
	print(ans)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = 3.14159265359;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    while (a >= b){
        k--;
        b *= 2;
    }
    while (b >= c){
        k--;
        c *= 2;
    }
    if (k >= 0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
#!/usr/bin/env python3


def num(l, r, n):
    r = min(r, n)
    if r >= l:
        return r - l + 1
    else:
        return 0


def solv(n):
    return num(1, 9, n) + num(100, 999, n) + num(10000, 99999, n)


if __name__ == '__main__':

    N = int(input())

    ans = solv(N)

    print(ans)


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

int main()
{
    string a;
    cin>>a;
    if(a=="Sunny")
    {
        cout<<"Cloudy"<<endl;
    }
    else if(a=="Cloudy")
    {
        cout<<"Rainy"<<endl;
    }
    else if(a=="Rainy")
    {
        cout<<"Sunny"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
from math import gcd
def lcm(a,b):
    return a//gcd(a,b)*b
def lcm(ab):
    l=len(ab)
    ret=ab[0]
    for i in range(1,l):
        ret=ret//gcd(ab[i],ret)*ab[i]
    return ret
def count2(a):
    ret=0
    while a%2==0:
        a//=2
        ret+=1
    return 2**ret
n,m=map(int,input().split())
A=list(map(int,input().split()))
#これはいらないです
if any(i%2 for i in A):
    exit(print(0))
A=[i//2 for i in A]
#全体の最小公倍数
p=lcm(A)
c=count2(p)
#2で割り切れる回数が同じでないものがある場合
if any(i%c for i in A):
    exit(print(0))
x=m//p
#print(p//c)
print(-(-x//2))

Measured memory_bytes: 20632
// By Atul Rathore

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007



int main()
{
	fastio;
	int s,w;
	cin>>s>>w;
	if(w>=s)cout<<"unsafe";
	else cout<<"safe";  
	
	
	
}


Measured memory_bytes: 3640
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

const int dekai = 2000000000;

int main() {
	int n;
	cin >> n;
	int a[110000];
	int b = dekai;
	int rec;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (b > a[i]) {
			b = a[i];
			rec = i;
		}
	}
	while (true) {
	
		for (int i = 0; i < n; i++) {
			if (i != rec) a[i] %= a[rec];
		}
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i];
		}
		if (sum == a[rec]) break;
		for (int i = 0; i < n; i++) {
			if (b > a[i] && a[i] != 0) {
				b = a[i];
				rec = i;
			}
		}

	}


	cout << a[rec] << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, t, a;
  cin >> n >> t >> a;

  vector<int> h(n);
  for (int i = 0 ; i < n; i++) cin >> h[i];

  int ans = -1;
  double min_value = INFINITY;
  double ab;

  for (int i = 0 ; i < n ; i++) {
    ab = abs(a - (t - h[i] * 0.006));
    if(min_value > ab) {
      ans = i;
      min_value = ab;
    }
  }

  cout << ans + 1  << endl;
}

Measured memory_bytes: 256
class Kaiden
  def initialize(k, a, b)
    @k = k
    @a = a
    @b = b
  end

  def solve
    if @a <= @b && @a >= @k
      1
    elsif @a <= @b
      -1
    else
      i = (@k - @b + @a - @b - 1) / (@a - @b)
      [1, 2 * i - 1].max
    end
  end
end

def run
  k, a, b = gets.scan(/\d+/).map(&:to_i)
  puts Kaiden.new(k, a, b).solve
end

run


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

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    double s = w * h / 2.0;
    cout << s << " ";

    cout << ((x == w / 2.0 && y == h / 2.0) ? 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools

N = int(input())
sft = ("0", "3", "5", "7")

num = itertools.product(sft, sft, sft,sft, sft, sft,sft, sft, sft)

cnt = 0
for x in num:
    stnum = "".join(x)
    if stnum.find("3") != -1 and stnum.find("5") != -1 and stnum.find("7") != -1:
        tmp = str(int(stnum))
        if tmp.find("0") == -1:
            if N >= int(tmp):
                cnt = cnt + 1
print(cnt)


Measured memory_bytes: 44396
//
//  abc170_a.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll INF = 1000000000000000000;
#define PI 3.14159265

ll limitpow (int x, int n) {
  if (n==0) return 1;
  ll u = limitpow(x, n/2);
  if (u > 1000000000 || u < 0) return -1;
  u = (u*u);
  if (u > 1000000000 || u < 0) return -1;
  if (n%2==1) u = (u*x);
  if (u > 1000000000 || u < 0) return -1;
  return u;
}

int main() {
  for (int i = 0; i < 5; i++) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << i+1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=105;
const int inf=0x3f3f3f3f;
int n,m;
int mp[maxn][maxn];
struct edge{
    int a,b,c;

}e[1005];

void floyd(){
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                mp[i][j]=min(mp[i][k]+mp[k][j],mp[i][j]);
            }
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i==j)    mp[i][j]=0;
            else mp[i][j]=inf;
        }
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        mp[a][b]=mp[b][a]=c;
        e[i].a=a,e[i].b=b,e[i].c=c;
    }
    floyd();
    int ans=m;
    for(int i=0;i<m;i++){
        bool flag=false;
        for(int s=1;s<=n;s++){
            int u=e[i].a,v=e[i].b,w=e[i].c;
            if(mp[s][u]+w==mp[s][v]){
                flag=true;
            }
        }
        if(flag)    ans--;
    }
    cout<<ans<<endl;
   // getchar();
    //getchar();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N, K;
ll h[MAX_N + 1];
ll d[MAX_N + 1];

void solve()
{
  sort(h, h + N);
  ll ans = INT_MAX;
  for (int i = 0; i <= N - K; i++) {
    ans = min(ans, h[i + K - 1] - h[i]);
  }
  cout << ans << endl;
}

int main(void)
{
  cin >> N >> K;
  REP(i, N) cin >> h[i];
  solve();
  return 0;
}


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

using namespace std;
using ll =long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;

const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){ cin.sync_with_stdio(0);
    ll A, B, C, K; cin >> A >> B >> C >> K;


    ll result = min(A, K);
    ll num = A + B;

    ll add = max(0ll, K - num);
    result -= add;

    cout << result << endl;
} //cin.tie(0) bei schnellem Wechseln



Measured memory_bytes: 3652
fun main(args: Array<String>) {
    val n= readLine()!!.toInt()
    val t= readLine()!!.split(" ").map { it.toInt() }
    val m= readLine()!!.toInt()
    val px= (1..m).map { readLine()!!.split(" ").map { it.toInt() } }

    val time = t.sum()
    val drink = px.map { t[it[0]-1]-it[1] }
    drink.forEach { println(time-it) }

}

Measured memory_bytes: 37876
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]


def recur(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(a - A) + abs(b - B) + abs(c - C)
    return min([recur(i + 1, a, b, c),
                recur(i + 1, a + l[i], b, c) + (10 if a > 0 else 0),
                recur(i + 1, a, b + l[i], c) + (10 if b > 0 else 0),
                recur(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])


print(recur(0, 0, 0, 0))


Measured memory_bytes: 3064
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a,T2 b){if (b>a) a=b;}
template <class T1, class T2>inline void gmin(T1 &a,T2 b){if (b<a) a=b;}
ll x,y;
int main(){
    read(x),read(y);
    int cnt=1;
    for (ll i=1;i<=61;i++){
        if (x*(1LL<<i)<=y) cnt++;
        else break;
    }
    cout<<cnt<<endl;
    //cout<<(ll)(log(1.0*y/x)/log(2.0))+1LL<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if( (a * b) % 2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}

	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll k;cin >> k;
    ll n=50;vl v(n);
    rep(i,n)v[i]=49;
    ll d=k/n;
    rep(i,n){
        v[i]+=d;
    }
    ll p=k%n;
    rep(i,p){
        rep(j,n){
            if(j==i){
                v[j]+=n;
            }
            else v[j]--;
        }
    }
    cout << n <<endl;
    rep(i,n)cout << v[i] <<" ";
    cout <<endl;
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof (a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

string S;
int k;
set<string> SET;

int main() {
	cin >> S;
	cin >> k;
	for (int i = 0; i < (int)S.length(); ++i) {
		string tmp = "";
		for (int j = i; j < (int)S.length(); ++j) {
			tmp += S[j];
			int counter = 0;
			//cout << tmp << "\n";
			if (SET.find(tmp) == SET.end()) {
				SET.insert(tmp);
				++counter;
				if (sz(SET) > k) {
					auto it = --SET.end();
					SET.erase(it);
				}
			}
			if (counter == k) break;
		}
	}

	string ans;
	for (int i = 1; i <= k; ++i) {
		ans = *SET.begin();
		SET.erase(SET.begin());
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N,T;
P M[100005];

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

    cin >> N >> T;

    for (int i = 0;i < N;i++){
        ll A,B; cin >> A >> B;
        M[i] = P(A,B);
    }

    sort(M,M+N);

    vector<vector<ll> > dp(N+5,vector<ll>(T+5000,0));

    ll ans = 0;

    for (int i = 0;i < N;i++){
        for (int j = 0;j < T;j++){
            dp[i+1][j+M[i].first] = max(dp[i+1][j+M[i].first], dp[i][j]+M[i].second);
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            ans = max(dp[i+1][j+M[i].first],ans);
            ans = max(dp[i+1][j],ans);
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 188288
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		long H = sc.nextInt(), W = sc.nextInt();

		/* divided by three rows or cols */
		long ans = (H % 3 == 0 || W % 3 == 0) ? 0 : Math.min(H, W);

		/* divided by one rows */
		for(long i = 1; i < H; i++) {
			long upper = i * W, lower_left = (H - i) * ((W + 1) / 2), lower_right = H * W - upper - lower_left;
			ans = Math.min(ans, Math.max(upper, Math.max(lower_left, lower_right)) - Math.min(upper, Math.min(lower_left, lower_right)));
		}

		/* divided by one cols */
		for(long i = 1; i < W; i++) {
			long left = i * H, right_upper = (W - i) * (H / 2), right_lower = H * W - left - right_upper;
			ans = Math.min(ans, Math.max(left, Math.max(right_upper, right_lower)) - Math.min(left, Math.min(right_upper, right_lower)));
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;

int main(){
  int N;
  cin >> N;
  double A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A, A+N);
  for(int i=0;i<N-1;i++){
    A[i+1] = (A[i]+ A[i+1])/2;
  }
  cout << fixed << setprecision(10);
  cout << A[N-1] << endl;
}

Measured memory_bytes: 256