akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+50;
const ll inf=1e18;
inline int gi() {
  char ch=getchar(); int q=0,x=0;
  while(ch<'0'||ch>'9') q=(ch=='-'?1:q),ch=getchar();
  while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int n,a[N]; ll s[N],ans=inf;
int main(){
  cin>>n;
  for (int i=1; i<=n; ++i)
    a[i]=gi(),s[i]=s[i-1]+a[i];
  int l=1,r=3;
  for (int i=2; i<n-1; ++i){
    while(l<i)
      if (min(s[l],s[i]-s[l])<min(s[l+1],s[i]-s[l+1]))
	++l;
      else
	break;
    while(r<n)
      if (min(s[r]-s[i],s[n]-s[r])<min(s[r+1]-s[i],s[n]-s[r+1]))
	++r;
      else
	break;
    ans=min(ans,max(s[l],max(s[i]-s[l],max(s[r]-s[i],s[n]-s[r])))-min(s[l],min(s[i]-s[l],min(s[r]-s[i],s[n]-s[r]))));
  }
  cout<<ans;
  return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n,q;
    char s[1000003];
    int k;
    Scd(n);
    Scs(s);
    Scd(q);
    Rep(i,n){
    }

    ll ans = 0;
    ll d,m,dm;
    Rep(i,q){
        Scd(k);
        ans = 0;
        d=0;m=0;dm=0;
        Rep(j,n){
            if( j >= k ){
                if( s[j-k] == 'D' ){
                    d--;
                    dm-=m;
                }
                if( s[j-k] == 'M' ){
                    m--;
                }
            }
            if( s[j] == 'D' ){
                d++;
            }
            if( s[j] == 'M' ){
                m++;
                dm+=d;
            }
            if( s[j] == 'C' ){
                ans += dm;
            }
        }
        printf ("%llu\n", ans);
    }

    return 0;
}



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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector < int > a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << (a[0]+a[1]==a[2] ? "Yes": "No");
    return 0;
}



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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9+7;

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

int main() {
    string result = "ABC";
    string S;
    cin >> S;

    if (S == "ABC") {
        result = "ARC";
    }

    cout << result << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll h,w;
char s[410][410];
ll che[200100];
const ll MAX_N=200100;

ll par[MAX_N];
ll ran[MAX_N];
ll sizeb[MAX_N];
ll sizew[MAX_N];
void init(ll n){
	for(ll i=0;i<n;i++){
		par[i]=i;
		ran[i]=0;
		ll x=i%w;
		ll y=i/w;
		if(s[y][x]=='.'){
			sizew[i]=1;
			sizeb[i]=0;
		}else{
			sizew[i]=0;
			sizeb[i]=1;
		}
	}
}

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

void unite(ll x,ll y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	
	if(ran[x]<ran[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(ran[x]==ran[y])ran[x]++;
	}
	sizeb[x]=sizeb[y]+sizeb[x];
	sizeb[y]=sizeb[x];
	sizew[x]=sizew[y]+sizew[x];
	sizew[y]=sizew[x];
	
}

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

int main(){
	cin>>h>>w;
	REP(i,h)
		REP(j,w)cin>>s[i][j];
	init(h*w);
	REP(i,h){
		REP(j,w){
			if(j+1<w&&s[i][j]!=s[i][j+1]){
				unite(i*w+j,i*w+j+1);
			}
			if(i+1<h&&s[i][j]!=s[i+1][j]){
				unite(i*w+j,(i+1)*w+j);
			}
		}
	}
	/*REP(i,h){
		REP(j,w){
			cout<<find(i*w+j)<<" ";
		}
		cout<<endl;
	}*/
	REP(i,200100){
		che[i]=0;
	
	}
	ll ans=0;
	REP(i,h){
		REP(j,w){
			if(che[find(i*w+j)]==1)continue;
			ans+=sizeb[find(i*w+j)]*sizew[find(i*w+j)];
			che[find(i*w+j)]=1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"

using namespace std;

#include <cstdio>
#include <cstring>


int main() {
    string s;
    cin >> s;
    string s1 = s.substr(0, 4);
    string s2 = s.substr(4, 8);
    cout << s1 << ' ' << s2 << endl;

}

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

using namespace std;

int main(){
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for(int i=0; i < N; i++){
        cin >> a[i];
    }

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

    int sum = 0;
    int joy = 0;

    for (int i = 0; i < N; i++){
        sum += a[i];
        if(sum > x)
            break;
        joy++;
    }

    if(sum < x)
        joy--;

    cout << joy << endl;
}

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

namespace ABC046
{
	class Q2
	{
		static void Main()
		{
			List<int> buff = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
			int N = buff[0];
			int K = buff[1];

			int sum = K * (int)Math.Pow(K - 1, N - 1);
			Console.WriteLine(sum);
		}
	}
}


Measured memory_bytes: 3032
n = int(input())
arr = list(map(int, input().split()))

judgement = True

for i in arr:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            continue
        else:
            print("DENIED")
            judgement = False
            break

if judgement:
    print("APPROVED")

Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main(void){
  int i, len, tmp1=0, tmp2, ans;
  char roman[101];

  while(scanf("%s", roman) != EOF){
    len = strlen(roman);
    ans = 0;
    tmp2 = 1;
    for(i = len-1; i >= 0; i--){
      switch(roman[i]){
      case 'I':
	tmp1 = 1;
	break;
      case 'V':
	tmp1 = 5;
	break;
      case 'X':
	tmp1 = 10;
	break;
      case 'L':
	tmp1 = 50;
	break;
      case 'C':
	tmp1 = 100;
	break;
      case 'D':
	tmp1 = 500;
	break;
      case 'M':
	tmp1 = 1000;
	break;
      }
      if(tmp1 >= tmp2){
	ans += tmp1;
      }else{
	ans -= tmp1;
      }
      tmp2 = tmp1;
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

#define debug(args...) //fprintf (stderr, args)
const int maxn = 1e5 + 10;

int n;
vector <int> adj[maxn];

int dp[2][maxn];

void dfs (int v, int par)
{
	dp[0][v] = 1;

	int x = 0;
	bool y = false;

	for (int i = 0; i < adj[v].size(); ++i)
	{
		int u = adj[v][i];

		if (u == par)
			continue;

		dfs (u, v);

		if (!dp[1][u])
		{
			dp[0][v] = 0;
			
			if (!x)
				x = u;
			else
				y = true;
		}
	}

	if (y)
	{
		debug ("%d. %d %d\n", v, dp[0][v], dp[1][v]);
		return;
	}

	for (int i = 0; i < adj[v].size(); ++i)
	{
		int u = adj[v][i];

		if (u == par)
			continue;

		if (dp[0][u] && (!x || x == u))
			dp[1][v] = 1;
	}

	debug ("%d. %d %d\n", v, dp[0][v], dp[1][v]);
}

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

	for (int i = 1; i <= n - 1; ++i)
	{
		int a, b;
		scanf ("%d %d", &a, &b);
		adj[a].push_back (b);
		adj[b].push_back (a);
	}

	dfs (1, -1);

	debug ("%d %d\n", dp[0][1], dp[1][1]);

	if (dp[1][1])
		printf ("Second\n");
	else
		printf ("First\n");

	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T> inline string tostr(T x) {
    ostringstream sout;
    sout<<x;
    string str = sout.str();
    if (str.size() == 1) str = "0" + str;
    return str;
}


int h, m, s;

string conv(int se) {
    int rh = se / 3600;
    int rm = (se % 3600) / 60;
    int rs = se % 60;
    
    return tostr(rh) + ":" + tostr(rm) + ":" + tostr(rs);
}

int main() {
    while (cin >> h >> m >> s) {
        if (h == -1) break;
        
        int res1 = 7200 - (h * 3600 + m * 60 + s);
        int res2 = (7200 - (h * 3600 + m * 60 + s)) * 3;

        cout << conv(res1) << endl;
        cout << conv(res2) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1224
#include<iostream>

using namespace std;

int main(){
  int n=1, s=1000;
  cin >> n >> s;
  s = s/1000;
  bool exist = false;
  for(int x=0; x<=n; x++){
    if((s-n-9*x)>=0 && (s-n-9*x)%4==0){
      int y = (s-n-9*x)/4;
      int z = n-(x+y);
      if(0<=z && y<=n){
        cout << x << ' ' << y << ' ' << z << endl;
        exist = true;
        break;  //ちなみに、breakを消すと全パターンを出力
      }
    }
  }
  if(!exist)
    cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-09-23 06:02:38
*/

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

int main()
{
    for (int i = 1; i <= 5; i++) {
        int temp;
        cin >> temp;

        if (temp != i) {
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3608
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N, K;
  cin >> N >> K;
  vi P(N);
  cin >> P;
  int mx = -1, s = 0;
  rep(i, 0, K) { s += P[i] + 1; }
  mx = s;
  rep(i, K, N) {
    s -= P[i - K] + 1;
    s += P[i] + 1;
    chmax(mx, s);
  }
  cout << mx / 2.0 << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 1792
n = int(input())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2,n):
    min1 = dp[i-1]+abs(h[i-1]-h[i])
    min2 = dp[i-2]+abs(h[i-2]-h[i])
    dp[i] = min(min1,min2)
print(dp[n-1])

Measured memory_bytes: 13980
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[200000], i, b[200000], j;
bool c;
int main() 
{
  cin>>n;
  for(i=0; i<n; i++)
  {
    cin>>a[i];
  }
  sort(a, a+n);
  for(i=1; i<n; i++)
  {
    if(a[i-1]==a[i])
    {
      c=1;
      break;
    }
  }
  if(c==1)
  {
    cout<<"NO"<<endl;
  }
  else
  {
    cout<<"YES"<<endl;
  }
}

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

double dist(int x1, int x2, int y1, int y2) {
  return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}

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

  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());

  double d = 0.0, k = 0.0;

  do {
    k++;
    for (int i = 0; i < n - 1; i++)
      d += dist(p[i].first, p[i + 1].first, p[i].second, p[i + 1].second);

  } while (next_permutation(p.begin(), p.end()));

  cout << fixed << setprecision(15) << d / k << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,m,q=mii()
arr=[]
for i in range(q):
    a,b,c,d=mii()
    arr.append([a,b,c,d])
ans=0
for i in combinations_with_replacement(list(range(1,m+1)),n):
    temp=0
    for j in arr:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            temp+=j[3]
    ans=max(temp,ans)
print(ans)

Measured memory_bytes: 72960
#include<cstdio> 
#include<algorithm>
#define ll long long
#define MN 110001
using namespace std;
int read_p,read_ca,read_f;
inline int read(){
    read_p=0;read_ca=getchar();read_f=1;
    while(read_ca<'0'||read_ca>'9') {if (read_ca=='-') read_f=-1;read_ca=getchar();}
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p*read_f;
}
int n,m,a[MN];
ll mmh=1e18;
ll _abs(ll x){return x<0?-x:x;}
ll min(ll a,ll b){return a<b?a:b;}
inline ll work(){
	ll s=a[1],mmh=0;
	for (int i=2;i<=n;i++){
		if (((s<0)^(a[i]+s<0))&&a[i]+s!=0) {s+=a[i];continue;}
		if (s<0) mmh+=_abs(s+a[i]-1),s=1;else mmh+=_abs(s+a[i]+1),s=-1;
	}
	return mmh;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	if (a[1]==0) a[1]=1,mmh=min(mmh,work()+1),a[1]=-1,mmh=min(mmh,work()+1);else{
		mmh=work();
		m=a[1];
		if (a[1]<0) a[1]=1,mmh=min(work()+_abs(m-1),mmh);
		if (a[1]>0) a[1]=-1,mmh=min(work()+_abs(m+1),mmh);
	}
	printf("%lld\n",mmh);
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]){

    bool all_visited = true;

    for (int i = 0; i < N; i++){
        if (visited[i] == false){
            all_visited = false;
        }
    }

    if (all_visited == true){
        return 1;
    }else{
        int ret = 0;

        for (int i = 0; i < N; i++){
            if (graph[v][i] == true && visited[i] == false){
            visited[i] = true;
            ret += dfs(i, N, visited);
            visited[i] = false;
            }
        }
        return ret;
    }
}



int main(){

    int N, M;
    cin >> N >> M;

    for (int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        graph[a - 1][b - 1] = true;
        graph[b - 1][a - 1] = true;
    }

    bool visited[nmax];
    for (int i = 0; i < nmax; i++){
        visited[i] = false;
    }
    visited[0] = true;
    
    cout << dfs(0, N, visited) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  size_t pos = s.find("ABC");
  while (pos != -1) {
	pos = s.find("ABC", pos + 1);
    ++cnt;
  }
  cout << cnt << endl;
}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int a, b, c, k, ans = 0;
    cin >> a >> b >> c >> k;

    ans += min(a, k);
    k -= a+b;
    if(k > 0){
        ans -= min(c, k);
    }

    cout << ans << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 3808
n, k = map(int, input().split())

MOD = 10 ** 9 + 7
N = n + 10
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i - 1] * i % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD
        
for i in range(1, k + 1):
    ans = nCk(n - k + 1, i) * nCk(k - 1, i - 1)
    ans %= MOD
    print(ans)

Measured memory_bytes: 9312
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)

int N;
long long K;
vector<int> A, B;
vector<int> dp, nxt, same[200200];

void print_result(int piv) {
    if (piv == -1) return;
    while (piv < N) {
        if (nxt[piv] <= N) {
            piv = nxt[piv];
            continue;
        } else {
            cout << A[piv++] << endl;
        }
    }
}

int main() {

    cin >> N >> K;

    A.resize(N);
    REP(i, N) cin >> A[i];

    // B : Aを2回繰り返した配列
    REP(i, 2 * N) B.emplace_back(A[i % N]);

    // same[i] : 数iが格納されているindexのvector
    REP(i, 2 * N) same[B[i]].emplace_back(i);

    // nxt[i] : Bの中で, B[i]と同じ数が次に現れるindexの次のindex
    nxt.resize(N);
    REP(i, N) nxt[i] = *upper_bound(same[B[i]].begin(), same[B[i]].end(), i) + 1;

    int cur = 0;
    while (true) {
        if (nxt[cur] > N) {         // 数列を跨ぐとき
            dp.emplace_back(cur);
        }
        if (nxt[cur] % N == 0) {    // 1巡終了
            dp.emplace_back(-1);    // 数列sが空
            break;
        }
        cur = nxt[cur] % N;
    }

    print_result(dp[(K - 1) % (int)dp.size()]);

}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);

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

    set<ll> used;

    while(k>0){
        if(used.size() == n) break;
        vint f(n+2,0);
        rep(i,n){
            ll l,r;
            l = max(1ll, (i+1)-a[i]);
            r = min(n+1, (i+1) + a[i] + 1);
            if(l==1 && r == n+1){
                used.insert(i);
            }
            f[l]++;
            f[r]--;

        }
        rep(i,n+1){
            f[i+1] += f[i];
        }
        rep(i,n){
            a[i] = f[i+1];
        }
        // for(auto e:f) cout<<e<<" "; cout<<endl;
        k--;
    }

    if(k>0){
        rep(i,n) cout<<n<<" "; cout<<endl;
    }else{
    rep(i,n) cout<<a[i]<<" "; cout<<endl;
    }



    return 0;

}

Measured memory_bytes: 15696
# _*_ coding:utf-8 _*_
#  Atcoder_Beginning_Contest049-C
#  TODO https://atcoder.jp/contests/abc049/tasks/arc065_a
#  TODO 参考サイトからの文字列逆転を活用＋replace関数を利用
def solveProblem(givenStr):

	strT1 = "dream"
	strT2 = "dreamer"
	strT3 = "erase"
	strT4 = "eraser"
	givenStr = givenStr[::-1]
	strList = [strT2[::-1],strT4[::-1],strT1[::-1],strT3[::-1]]
	while len(givenStr) > 0:
		stripFlag = False
		for word in strList:
			givenSubStr=givenStr[0:len(word)]
			if givenSubStr == word:
				givenStr=givenStr.replace(word,"",1)
				stripFlag = True
		if stripFlag == False:
			break
	if len(givenStr) == 0:
		answer="YES"
	else:
		answer="NO"
	return answer

if __name__ == '__main__':
	S = str(input().strip())
	solution = solveProblem(S)
	print("{}".format(solution))


Measured memory_bytes: 3316
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String strs;
		int value = 0;
		int ans = 0;
		Map<String, Integer> map = new HashMap<String, Integer>();

		for(int i=1;i<=N;i++){
			strs = sc.next();	
			if (map.containsKey(strs)){
				value = map.get(strs)+1;
				map.put(strs, value);
			}
			else{
				map.put(strs, 1);
			}

		}

		for (String key : map.keySet()) {
			ans=ans+1;
		}
		System.out.println(ans);
    }
}

Measured memory_bytes: 68592
#include <iostream>
#include <iomanip>
#include <vector>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    ll x = 0,n;
    cin >> n;
    vector<ll> a(n);
    repi(i,n,0){
        cin >> a[i];
        if(n%2){
            x += i%2 * - 2 * a[i] + a[i];
        }else{
            x += (i+1)%2 * -2 * a[i] + a[i];
        }
    }
    cout << x << " ";
    repi(i,n - 1,0){
        x = 2 * a[i] - x;
        cout << x << " ";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 2048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            String S = Console.ReadLine();
            String[] line = S.Split(' ');

            int[] A = new int[N-1];
            int[] res = new int[N+1];

            for(int i=0; i<N-1; i++)
            {
                A[i] = int.Parse(line[i]);
                res[A[i]]++;
            }

            for(int i=1; i<=N; i++)
            {
                Console.WriteLine(res[i]);
            }
            


        }
    }
}

Measured memory_bytes: 42908
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define P           pair<int, int>

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

int modpow(int a, int b) {
    int ans = 1;
    while(b) {
        if(b%2) ans = mul(ans, a);    
        b /= 2; a = mul(a, a);
    }   return ans;
}

void solve() { 
    int n; cin >> n;
    int a[n];
    map<int, int> cnt;
    map<int, int> fo;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
        if(fo.find(a[i]) == fo.end()) {
            fo[a[i]] = i+1;
        }
    }
    vector<int> v;
    for(auto it : cnt) {
        v.push_back(it.first);
    }
    int ans[n+1]; memset(ans, 0, sizeof ans);
    reverse(v.begin(), v.end()); 
    int k = v.size();
    int prv = 0;
    int pi = n+1;
    for(int i=0; i<k; i++) {
        int dif = v[i] - (i+1==k ? 0 : v[i+1]);
        int ind = min(fo[v[i]], pi);
        pi = min(pi, ind);
        int tot = cnt[v[i]] + prv;
        prv += cnt[v[i]];
        //cout << v[i] << " " << tot << " " << dif << endl;
        ans[ind] += dif*tot;
    }
    for(int i=1; i<=n; i++) {
        cout << ans[i] << endl;
    }
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;
}





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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    
    if(abs(b - a) % 2 == 0)
    {
        cout << "Alice" << endl;
        return 0;
    }
    cout << "Borys" << endl;
    return 0;
}


Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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 Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> a(n),b(n),c(n),x(n),y(n),z(n);
  rep(i,n) cin>>a[i]>>b[i]>>c[i];
  x[0]=a[0];y[0]=b[0];z[0]=c[0];
  rep(i,n-1){
    x[i+1]=a[i+1]+max(y[i],z[i]);
    y[i+1]=b[i+1]+max(x[i],z[i]);
    z[i+1]=c[i+1]+max(x[i],y[i]);
  }
  cout<<max(x[n-1],max(y[n-1],z[n-1]))<<endl;
}

Measured memory_bytes: 4992
mc = []
nc = []

M = int(input())
for m in range(0,M):
	mc.append(input())

N = int(input())
for n in range(0,N):
	nc.append(input())

max_num = 0
for i in range(0,M):
	stre = mc[i]
	count_dict = mc.count(stre) + nc.count(stre)*-1
	if (max_num <= count_dict):
		max_num = count_dict
	
print(max_num)

Measured memory_bytes: 3064
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import  java.io.*;
import  java.math.*;
import java.nio.Buffer;
import java.sql.SQLSyntaxErrorException;
import  java.util.*;
import  java.text.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


public class Main {


    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);

        String ans=cin.next();
        if(ans.charAt(2)==ans.charAt(3)&&ans.charAt(4)==ans.charAt(5)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    string s, t;
    cin >> s >> t;
    SORT(s);
    sort(ALL(t), greater<char>());

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    long long n, m;
    cin >> n >> m;
    if (n >= 3 && m >= 3) {
        cout << (n - 2) * (m - 2) << endl;
    } else if (n == 2 || m == 2) {
        cout << 0 << endl;
    } else if (n == 1 && m == 1) {
        cout << 1 << endl;
    } else if (n == 1 && m == 3) {
        cout << 1 << endl;
    } else if (n == 3 && m == 1) {
        cout << 1 << endl;
    } else if (n == 3 && m == 3) {
        cout << 1 << endl;
    } else if (n >= 3) {
        cout << (n - 2) << endl;
    } else if (m >= 3) {
        cout << m - 2 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,k;
int main()
{
    scanf("%d%d",&n,&k);
    if(k!=1)printf("%d\n",n-k);
    else printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define maxn 200005
#define ll long long
#define ld double
#define mod 998244353
using namespace std;
int n, k, a[maxn];
int ns[maxn], cnt = 0;
int fl[maxn];
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	a[0] = 0;
	while(1)
	{
		if(k < 0) break;
		int mpl = 0;
		for(int j = 1; j <= n; j++)
			if(!a[j] && !fl[j])
			{
				cout<<-1<<endl;
				return 0;
			}
			else if(!fl[j] && a[j] > a[mpl])
				mpl = j;
		if(mpl == 0)
		{
			k--;
			for(int j = 1; j <= n; j++)
				fl[j] = 0;
			fl[ns[cnt]] = 1;
		}
		else
		{
			ns[++cnt] = mpl;
			a[mpl]--, fl[mpl] = 1;
		}
	}
	cout<<cnt<<endl;
	for(int i = 1; i <= cnt; i++)	
		cout<<ns[i]<<" ";
	cout<<endl;
	return 0;
}
 

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll X;

signed main(){
    cin >> X;
    for(ll A=-200; A<=200; A++){
        for(ll B=-200; B<=200; B++){
            if(A*A*A*A*A - B*B*B*B*B == X){
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
}

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

int cnt[51][51] = {};

int main() {
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= a; i++) {
		for (int j = 1; j <= b; j++) {
			char tmp;
			cin >> tmp;
			if (tmp == '#') {
				cnt[i-1][j-1]++;
				cnt[i-1][j]++;
				cnt[i-1][j+1]++;
				cnt[i][j - 1]++;
				cnt[i][j] -= 10000;
				cnt[i][j + 1]++;
				cnt[i + 1][j - 1]++;
				cnt[i + 1][j]++;
				cnt[i + 1][j + 1]++;
			}
		}
	}
	for (int i = 1; i <= a; i++) {
		for (int j = 1; j <= b; j++) {
			if (cnt[i][j] < 0) cout << "#";
			else cout << cnt[i][j];
		}
		cout << endl;
	}
	
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    s += t[t.size()-1];
    if(s == t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3656
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, k: usize, mut p: [usize; n], c: [isize; n]);

    for i in 0..n {
        p[i] -= 1;
    }

    let mut ans = (1 << 30) * -1;

    for i in 0..n {
        let mut pos = p[i];
        let mut sum = c[i];
        let mut v = Vec::new();
        v.push(c[i]);
        while i != pos {
            v.push(c[pos]);
            sum += c[pos];
            pos = p[pos];
        }
        let v_size = v.len();
        let mut v_r = vec![0; v_size];
        v_r[0] = v[0];
        for i in 1..v_size {
            v_r[i] = v_r[i - 1] + v[i];
        }

        for i in 0..v_r.len() {
            if i + 1 > k {
                break;
            }
            let mut buff = v_r[i];
            if 0 < sum {
                buff += sum * ((k - i - 1) / v.len()) as isize;
            }

            if ans < buff {
                ans = buff;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2432
from collections import Counter
n = int(input())
ns = list(map(int, input().split()))
dic = Counter(ns)
dic = {key:value for key, value in dic.items() if value>=2}
if len(dic) < 2:
    print(0)
else:
    sorted_dic = sorted(dic.items(), key=lambda x: x[0])
    if sorted_dic[-1][1] >= 4:
        print(sorted_dic[-1][0]**2)
    else:
        print(sorted_dic[-1][0] * sorted_dic[-2][0])


Measured memory_bytes: 18592
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;  cin >> s;
    s[3] = '8';
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
(defn daydream []
  (let [s (apply str (vec (reverse (read-line))))
        divide '("maerd" "remaerd" "esare" "resare")
        l (count s)]
    (loop [cnt 0 pos 0 flg 0]
      (if (and (< cnt 4) (< pos l))
          (if (>= (count s) (+ (count (nth divide cnt)) pos))
              (if (= (subs s pos (+ (count (nth divide cnt)) pos)) (nth divide cnt))
                  (recur 0 (+ pos (count (nth divide cnt))) 1)
                  (recur (inc cnt) pos 0))
              (if (= (subs s pos) (nth divide cnt))
                  (recur 0 (+ pos (count (nth divide cnt))) 1)
                  (recur (inc cnt) pos 0)))
          (if (= flg 1) "YES" "NO")))))

(println (daydream))

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

j = -1
m = -1
for i in range(n):
  t = abs(a[i])
  if t > m:
    j = i
    m = t
print(2*(n-1))
for i in range(n):
  if i == j:
    continue
  print(str(j+1)+" "+str(i+1))

if a[j]>0:
  for i in range(n-1):
    print(str(i+1)+" "+str(i+1+1))
else:
  for i in range(n-1):
    print(str(n-1-i+1)+" "+str(n-1-(i+1)+1))


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int n, pa = 0, pb = 0;
    cin >> n;
    if (!n) return 0;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      if (a == b) {
        pa += a;
        pb += b;
      } else
        (a > b ? pa : pb) += a + b;
    }
    cout << pa << ' ' << pb << endl;
  }
}

Measured memory_bytes: 0
from collections import defaultdict

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


def solve(count):
    ans = 0
    for a in sorted(count, reverse=True):
        cnt = count[a]
        if cnt <= 0:
            continue
        ma = 1 << (a.bit_length())
        b = ma - a
        if b in count and count[b] > 0:
            if a == b:
                pair = cnt // 2
            else:
                pair = min(cnt, count[b])
                count[b] -= pair
            ans += pair
    return ans


count_e = defaultdict(lambda: 0)
count_o = defaultdict(lambda: 0)
for a in aaa:
    if a % 2 == 0:
        count_e[a] += 1
    else:
        count_o[a] += 1

print(solve(count_e) + solve(count_o))


Measured memory_bytes: 30916
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n,m;
vector<pair<ll,pll>> edge;
vector<ll> uft;

void init(){
    for(int i=0;i<n;i++){uft[i]=i;}
}

ll parent(ll w){
    return uft[w]==w?w:uft[w]=parent(uft[w]);
}

void merge(ll a,ll b){uft[parent(a)]=parent(b);}

ll cul(ll a){
    init();
    ll mx=edge[a].F;
    for(ll i=a;i<edge.size();i++){
        if(parent(edge[i].S.F)!=parent(edge[i].S.S)){
            merge(edge[i].S.F,edge[i].S.S);
            mx=edge[i].F;
        }
    }
    for(int i=1;i<n;i++){if(parent(0)!=parent(i)){return E;}}
    return mx-edge[a].F;
}





int main(){
    while(cin>>n>>m){
        if(n==0){break;}
        uft.resize(n);
        edge.resize(m);
        for(auto &I:edge){cin>>I.S.F>>I.S.S>>I.F; I.S.F--; I.S.S--;}
        sort(edge.begin(),edge.end());
        ll mi=E;
        for(int i=0;i<m;i++){mi=min(mi,cul(i));}
        cout<<(mi==E?-1:mi)<<endl;
    }
    
    return 0;
}



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


void fib(int);

int fibst[45];
int main(){
    int n;

    scanf("%d",&n);
    fib(0);
    printf("%d\n",fibst[n]);
}

void fib(int n){
    if(n>44)
        return;
    if(n==0){
        fibst[n]=1;
        fib(n+1);
    }
    else if(n==1){
        fibst[n]=1;
        fib(n+1);
    }
    else{
        fibst[n]=fibst[n-1]+fibst[n-2];
        fib(n+1);
    }
}



Measured memory_bytes: 2088
#include<stdio.h>
int main(void){
    int r,c;
    int A[100][100];
    int X[100],Y[100];
    int i,j,n=0;

    scanf("%d %d",&r,&c);

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

   for(i=0;i<r;i++){
       X[i]=0;
        for(j=0;j<c;j++){
            printf("%d ",A[i][j]);
            X[i]+=A[i][j];
            if(j==c-1){
                printf("%d\n",X[i]);
                n+=X[i];
            }
        }
    }

    for(i=0;i<r;i++){
       
        for(j=0;j<c;j++){
            if(i==0) Y[j]=0;
            Y[j]+=A[i][j];
            if(i==r-1){
                printf("%d ",Y[j]);
            }
        }
    }
    printf("%d\n",n);
 


    return 0;
}


Measured memory_bytes: 2108
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
int dp[100001][2];


int  mulmod(int a, int b) 
{ 
    int res = 0; // Initialize result 
    a = a % mod; 
    while (b > 0) 
    { 
        // If b is odd, add 'a' to result 
        if (b % 2 == 1) 
            res = (res + a) % mod; 
  
        // Multiply 'a' with 2 
        a = (a * 2) % mod; 
  
        // Divide b by 2 
        b /= 2; 
    } 
  
    // Return result 
    return res % mod; 
} 

int ways(int i,int par,int constrain,vector<vector<int>> &tree)
{
    if(tree[i].size()==0)
    {
        // uska koi child nhi hai....
        // recursion krte last mei aa gaye hain....
        return constrain?1:2;
    }
    else
    {
        if(dp[i][constrain]!=-1)
           return dp[i][constrain];
        
        if(!constrain)
        {
            // it can be both black and white.....
            int option1=1;  // white paint kiya ith node pr...
            for(auto child:tree[i])
            {
                if(child!=par)
                   //option1=((option1%mod)*(ways(child,i,0,tree)%mod))%mod;
                   option1=mulmod(option1,ways(child,i,0,tree));
            }
            int option2=1; // black paint kr diya ith node pr...
            // ab child pr constrain hoga...
            for(auto child:tree[i])
            {
                if(child!=par)
                   //option2=((option2%mod)*(ways(child,i,1,tree)%mod))%mod;
                   option2=mulmod(option2,ways(child,i,1,tree));
            }
            return dp[i][constrain]=(option1%mod+option2%mod)%mod;
        }
        else
        {
            // ith node is under constrain it can be white only..
            // bcz parent is black.....
            int option1=1;
            for(auto child:tree[i])
            {
                if(child!=par)
                   //option1=((option1%mod)*(ways(child,i,0,tree)%mod))%mod;
                   option1=mulmod(option1,ways(child,i,0,tree));
            }
            return dp[i][constrain]=option1%mod;
        }
    }
}

int solve(int n,vector<vector<int>> &tree)
{
    memset(dp,-1,sizeof(dp));
    return ways(1,-1,0,tree);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    vector<vector<int>> tree(n+1);
    for(int i=1;i<=n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    cout<<solve(n,tree);
    

    return 0;
}







Measured memory_bytes: 17644