akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    long long sa[n];//sa[i] = sum from a[0] to a[i]
    int seg[n][2];// left cut and right cut when the current cut is after i-th element
    long long t_left, t_right, t_sum;
    long long sum =0;
    long long mini;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        sum+= a[i];
        sa[i]= sum;
    }
    //pick position for left cut for each middle cut i
    t_left =a[0];
    t_right = a[1];
    seg[1][0]= 0;
    long long t_min;
    for(int i=2; i<n-2; i++)
    {
        t_sum = sa[i];
        t_right+=a[i];
        t_min = abs(t_right- t_left);
        seg[i][0]= seg[i-1][0];
        for(int j=seg[i-1][0]+1; j<i; j++)
        {
            if(abs((t_left+a[j])-(t_right-a[j]))<=t_min)
            {
                t_left+=a[j];
                t_right-=a[j];
                t_min = abs(t_right- t_left);
                seg[i][0]=j;
            }
            else
            {
                break;
            }
        }
    }
    //pick position for right cut for each middle cut i
    t_left =a[n-2];
    t_right = a[n-1];
    seg[n-3][1]= n-2;
    for(int i=n-4; i>=1; i--)
    {
        t_sum = sum- sa[i];
        t_left+=a[i+1];
        t_min = abs(t_right- t_left);
        seg[i][1]= seg[i+1][1];
        for(int j=seg[i+1][1]-1; j>i; j--)
        {
            if(abs((t_left-a[j+1])-(t_right+a[j+1]))<=t_min)
            {
                t_left-=a[j+1];
                t_right+=a[j+1];
                t_min = abs(t_right- t_left);
                seg[i][1]=j;
            }
            else
            {
                break;
            }
        }
    }
    mini = sum;
    long long temp;
    for(int i=1; i<n-2; i++)
    {
        temp =abs(min(min(sa[seg[i][0]], sa[i]-sa[seg[i][0]]), min(sa[seg[i][1]]-sa[i], sum - sa[seg[i][1]])) - max(max(sa[seg[i][0]], sa[i]-sa[seg[i][0]]), max(sa[seg[i][1]]-sa[i], sum - sa[seg[i][1]])));
        mini = min(mini, temp);
    }
    
    cout<<mini<<endl;
	return 0;
}


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

using namespace std;

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

int main() {
    char c;
    int cnt[26] = {};

    while (cin >> c) {
        if (isalpha(c)) {
            c = tolower(c);
            cnt[c - 'a']++;
        }
    }

    REP(i, 26) {
        printf("%c : %d\n", i + 'a', cnt[i]);
    }
    return 0;
}

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

int main() {
  
  int N;
  cin >> N;
    if (N%10 == 2 || N%10 == 4 || N%10 == 5
        || N%10 == 7 || N%10 == 9) {
      cout << "hon" << endl;
    }
    else if (N%10 == 3) {
      cout << "bon" << endl;
    }
    else {
      cout << "pon" << endl;
    }
  
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    double r; cin >> r;
    printf("%.16lf\n", r * 2.0 * 3.1415926535898);
    return 0;
}

Measured memory_bytes: 3776
#define mod 1000000007
#define PI acos(-1)
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF=0x7fffffffffffffff;
const int inf=0x7fffffff;
const int N=3e5+5;
clock_t start,finish;
void time_in(){start=clock();}
void time_out(){finish=clock();double tim=(double)(finish-start)/CLOCKS_PER_SEC;printf("Running time is %lf\n",tim);}
inline ll mul(ll a,ll b){ll s=0;while(b){if(b&1)s=(s+a)%mod;a=(a<<1)%mod;b>>=1;}return s%mod;}
inline ll pow_mul(ll a,ll b){ll s=1;while(b){if(b&1)s=mul(s,a);a=mul(a,a);b>>=1;}return s;}
inline ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}
inline bool read(int &ret){char c=getchar();int sgn;if(c==EOF)return 0;while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	sgn=((c=='-')?-1:1);ret=((c=='-')?0:(c-'0'));while(c=getchar(),c>='0'&&c<='9')ret=ret*10+(c-'0');ret*=sgn;return 1;}
inline void write(int x){if(x>9)write(x/10);putchar(x%10+'0');}
int fact[10]={1,1,2,6,24,120,720,5040,40320,362880};
int st[4][2]={1,0,0,1,-1,0,0,-1};
//vector<int>vt[N];
//priority_queue<int>q;
int t,cas;
int n,m,k;
int main()
{
	int a[100];
	while(~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		int ans=0;
		for(int i=1;i+1<n;i++)
		{
			if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]>a[i+1]&&a[i]<a[i-1]))ans++;
		}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int a[N], b[N];
  for(int i = 0; i < N; i++){
    cin >> a[i] >> b[i];
  }
  int count = 0; 
  for(int i = 0; i < N; i++){
    if(a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2]){
      count = 1;
    }
  }
  if(count == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3584
n=int(input())
abc=[list(map(int,input().split())) for i in range(n)]
dp=[[0]*3 for i in range(n)]
dp[0]=abc[0]
for i in range(1,n):
    dp[i][0]=max(dp[i-1][1]+abc[i][0],dp[i-1][2]+abc[i][0])
    dp[i][1]=max(dp[i-1][0]+abc[i][1],dp[i-1][2]+abc[i][1])
    dp[i][2]=max(dp[i-1][0]+abc[i][2],dp[i-1][1]+abc[i][2])
print(max(dp[-1]))

Measured memory_bytes: 74840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int n; char d[102];
    while(scanf("%d",&n),n){
        scanf("%s",d);
        int data[10],b=0; for(int i=0;i<10;i++) data[i]=0;
        for(int i=0;i<100;i++){
            int c=i%n;
            if(d[i]=='M'){ data[c]++;}
            if(d[i]=='S'){ b+=data[c]+1; data[c]=0;}
            if(d[i]=='L'){ data[c]+=b+1; b=0;}
        }
        sort(data,data+n);
        for(int i=0;i<n;i++) printf("%d ",data[i]);
        printf("%d\n",b);
    }    }

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

int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if((0<=x-r&&x+r<=W)&&(0<=y-r&&y+r<=H))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3112
n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]#F[i]は(i+1)番目の店の営業の有無のリスト
P = [list(map(int, input().split())) for _ in range(n)]#P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト

ans = (-1) * 10 ** 9
for i in range(2 ** 10):
    if sum(map(int, list(str(i)))) == 0:
        continue
    cnt_lst = [0 for _ in range(n)]
    for d in range(5):
        for t in range(2):
            dt = 2 * d + t
            if i & (2 ** dt) != 0:
                for j in range(n):
                    cnt_lst[j] += F[j][dt]
    buf = 0
    for j in range(n):
        buf += P[j][cnt_lst[j]]
    ans = max(buf, ans)
print(ans)

Measured memory_bytes: 3064
try:
    while True:
        P= list(map(float,input().split()))
        a, b, c, q = [complex(P[i*2],P[i*2+1]) for i in range(4)]
        x,y,z= a-q,b-q,c-q
        xx= (x.conjugate()*y).imag
        yy= (y.conjugate()*z).imag
        zz= (z.conjugate()*x).imag
        if (xx>0 and yy>0 and zz>0) or (xx<0 and yy<0 and zz<0):
            print("YES")
        else:
            print("NO")
except EOFError: 
    pass


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	vector<int> b(n);
	for (int i=0; i<n; i++) cin >> b[i];

	vector<int> ret;
	for (int i=0; i<n; i++) {
		int it = -1;
		for (int j=0; j< n- i; j++) {
			if (b[j] == j + 1) it = j;
		}
		if (it==-1) {
			cout << -1 << endl;
			return 0;
		} else {
			ret.push_back(it + 1);
			b.erase(b.begin() + it);
		}
	}
	
	for (int i=n-1; i>-1; i--) {
		cout << ret[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    bool chk=false;
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    for(int k=0; k<K+1; k++)
    {
    for(int i=0; i<K+1; i++)
        {
            for(int j=0; j<K+1; j++)
            {
                if((C*pow(2,j)>B*pow(2,i)&&B*pow(2,i)>A*pow(2,k))&&(i+j+k)<=K)
                {
                    chk=true;
                }
            }
        }
    }
    if(chk)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
}


Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s1,s2;
	int flag=0;
	cin>>s1>>s2;
	if(s2.size()!=(s1.size()+1)){
		cout<<"No";
		flag=1;
	}
	if(flag==0){
		while(s1[0]==' '){
			s1.erase(s1.begin());
		}
		while(s2[0]==' '){
			s2.erase(s2.begin());
		}
		const string::size_type cols = s1.size();
		
	for(long unsigned int i=0;i<cols;i++){
		if(s1[i]!=s2[i]){
			cout<<"No";
			flag=1;
          break;
		}
	}
    }
	if(flag==0)
	cout<<"Yes";
}

Measured memory_bytes: 3592
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val h = IntArray(n) { readLine()!!.toInt() }
        .sorted()
    val d = IntArray(n - k + 1) { h[it + k - 1] - h[it] }
        .min()
    println(d)
}


Measured memory_bytes: 46680
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict

dic = defaultdict(int)

n, m = li()
a = list(li())
key = set()


for ai in a:
    dic[ai] += 1
    key.add(ai)

for _ in range(m):
    bi, ci = li()
    dic[ci] += bi
    key.add(ci)

res = n
ans = 0
for ki in sorted(list(key), reverse=True):
    if res - dic[ki] >= 0:
        ans += ki*dic[ki]
        res -= dic[ki]
    else:
        ans += ki*res
        res = 0

    if res == 0:
        break
print(ans)


Measured memory_bytes: 40860
using System;
using System.Linq;

class J
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToLookup(x => x);
		var d = Enumerable.Range(0, 4).Select(i => a[i].Count()).ToArray();
		var s = Enumerable.Range(0, 4).Select(i => d.Skip(i).Sum()).ToArray();

		var dp = new double[s[3] + 1, s[2] + 1, s[1] + 1];
		for (int i = 0; i <= s[3]; i++)
			for (int j = 0; i + j <= s[2]; j++)
				for (int k = 0, r; (r = i + j + k) <= s[1]; k++)
					dp[i, j, k] = r == 0 ? 0 : (n +
						i * (i > 0 ? dp[i - 1, j + 1, k] : 0) +
						j * (j > 0 ? dp[i, j - 1, k + 1] : 0) +
						k * (k > 0 ? dp[i, j, k - 1] : 0)) / r;
		Console.WriteLine(dp[d[3], d[2], d[1]]);
	}
}


Measured memory_bytes: 224480
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

ans = 0
memo = [0]*(n+1)
for i in range(n):
    if t[i] == "r":
        if i-k >= 0 and memo[i-k] == 1:
            pass
        else:
            ans += p
            memo[i] = 1
    elif t[i] == "s":
        if i-k >= 0 and memo[i-k] == 2:
            pass
        else:
            ans += r
            memo[i] = 2
    else:
        if i-k >= 0 and memo[i-k] == 3:
            pass
        else:
            ans += s
            memo[i] = 3
print(ans)

Measured memory_bytes: 4084
#include<iostream>
#include<cmath>
using namespace std;
static const int MAX_N = 100000;
int main(){
	int N;
	cin >> N;
	int nt = 0, nx = 0, ny = 0;
	for(int i = 0; i < N; i++){
		int t, x, y;
		cin >> t >> x >> y;
		int dt = t - nt, dxy = abs(x - nx) + abs(y - ny);
		if(dt < dxy || (dt - dxy) % 2 != 0){
			cout << "No" << endl;
			return 0;
		}
		nt = t, nx = x, ny = y;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll A, B;
	string S;
	cin >> A >> B >> S;

	string ans = "Yes";

	rep(i, A + B + 1) {
		if (i == A) {
			if (S[i] != '-') { ans = "No"; }
		}

		else { if (S[i]<'0' || S[i]>'9') { ans = "No"; } }
	}

	cout << ans;

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include<stdio.h>

int main(void){
   int N,M;
   scanf("%d %d",&N,&M);
   int n[M];
   for(int i=0;i<M;i++){
      scanf("%d",&n[i]);
      N -=n[i];
   }
   if(N>=0){
      printf("%d",N);
   }else{
      printf("%d",-1);
   }
   return 0;
}


Measured memory_bytes: 1744
#include<iostream>

void Sort(int a[], int n) 
{
   int i, j, min, temp;
   for (i = 0; i < n - 1; i++) {
      min = i;
      for (j = i + 1; j < n; j++)
      if (a[j] < a[min])
      min = j;
      temp = a[i];
      a[i] = a[min];
      a[min] = temp;
   }
}
int main()
{
	int n,wrong=0;
	std::cin>>n;
	int arr[n],sortedarr[n];
	for(int i=0;i<n;i++)
	{
		std::cin>>arr[i];
		sortedarr[i]=arr[i];
	}	
	Sort(sortedarr,n);
	for(int i=0;i<n;i++)
	{
		if(arr[i]!=sortedarr[i])
			wrong++;
	}
	if(wrong<=2)
		std::cout<<"YES";
	else
		std::cout<<"NO";

	return 0;
}


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

using namespace std;

string s = "CODEFESTIVAL2016";

int main(){
	string t;
	cin >> t;
	int res = 0;
	for(int i = 0; i < t.size(); i++)
	res += t[i] != s[i];
	printf("%d\n", res);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int a[3];
  rep(i,3) cin >> a[i];
  sort(a,a+3);
  int k;cin >> k;
  int ans = a[2];
  ans = ans*pow(2,k);
  cout << ans+a[0]+a[1] << endl;
}


Measured memory_bytes: 256
M[100],i,j,h,s;char*N[100],B[],c;main(n,m){for(;scanf("%d%d",&n,&m)*n;printf("%d\n",s)){for(i=n;i--;)scanf("%as%d",N+i,M+i);for(s=0;m--;)for(scanf("%s",B),i=n;i--;s+=M[i]*!h)for(h=j=0;c=N[i][j];)h|=c-B[j++]&&c-42;}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
#define pb push_back
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
}
vector<int> edge[MAXN];
int dp[MAXN];
inline void dfs(int u){
	if(dp[u]) return;
	for(auto v : edge[u]){
		dfs(v);
		dp[u]=max(dp[u],dp[v]+1);		
	}
	return;
}
int main(){
	int n,m;
	read(n),read(m);
	for(int i=0;i<m;++i){
		int u,v;
		read(u),read(v);
		edge[u].pb(v);
	}
	int ans(0);
	for(int i=1;i<=n;++i){
		dfs(i);
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long[] sa = new long[N + 1];
		for(int i=0;i<N;i++){
			sa[i + 1] = sa[i] + A[i];
		}
		long[] sb = new long[M + 1];
		for(int i=0;i<M;i++){
			sb[i + 1] = sb[i] + B[i];
		}
//Console.WriteLine("ok");
		int ma = 0;
		int r = M;
		int l = 0;
		for(;r>=0;r--){
			if(sb[r] > K) continue;
			while(l < N && sa[l] + sb[r] <= K) l++;
			
			int cnt = r + l - 1;
			if(sa[l] + sb[r] <= K) cnt = r + l;
			ma = Math.Max(ma, cnt);
			
		}
		
		Console.WriteLine(ma);
	}
	int N,M;
	long K;
	long[] A,B;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1]; K = d[2];
		A = rla();
		B = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

Measured memory_bytes: 1156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
      	int x_1 = input.nextInt();
      	int y_1 = input.nextInt();
      	int x_2 = input.nextInt();
      	int y_2 = input.nextInt();
      	int height = y_2 - y_1;
      	int width = x_2 - x_1;
      
      	System.out.print((x_2 - height) + " " + (y_2 + width) + " " + (x_1 - height) + " " + (y_1 + width));
    }
}

Measured memory_bytes: 22996
/**
*    author:  souzai32
*    created: 21.08.2020 23:18:47
**/

#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
typedef long long ll;
using namespace std;

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<pair<int,bool>>> xy(n,vector<pair<int,bool>>(n));
    int x,y;
    rep(i,n){
        cin >> a[i];
        rep(j,a[i]){
            cin >> x >> y;
            xy[i][j]=make_pair(x-1,y);
        }
    }
    bool ans;
    int num=0;

    for(int bit=0; bit<(1<<n); bit++){
        // cout << bitset<8>(bit) << endl;
        ans=true;
        for(int i=0; i<n; i++){
            if(bit&(1<<i)){
                for(int j=0; j<a[i]; j++){
                    if(get<1>(xy[i][j])&&!(bit&(1<<get<0>(xy[i][j])))){
                        ans=false; //cout << 0;
                    }else if(!get<1>(xy[i][j])&&bit&(1<<get<0>(xy[i][j]))){
                        ans=false; //cout << 0;
                    }//else cout << 1;
                    //cout << endl;
                }
            }
        }
        if(ans) num=max(num,__builtin_popcount(bit));
    }

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3608
from heapq import heappop, heappush
N = int(input())
P = list(map(int, input().split()))

heap = []
count = 0

for i in range(N):
    heappush(heap, P[i])
    minimum = heappop(heap)
    if minimum >= P[i]:
        count += 1
    heappush(heap, minimum)

print(count)

Measured memory_bytes: 24872
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;
int K;
ull A[100005];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> K;
  REP(i,K) cin >> A[i];
  ull mians, maans;
  // min
  ull demand_l = 2, demand_h = 2;
  RREP(i,K){
    if(demand_h >= A[i]){
      ull minA = A[i]*((demand_l + A[i] - 1)/A[i]);
      ull maxA = A[i]*(demand_h/A[i]);
      demand_l = minA;
      demand_h = maxA + A[i] - 1;
    }else{
      cout << -1 << endl;
      return 0;
    }
    cerr << demand_l << ' ' << demand_h << endl;
  } 
  mians = demand_l;
  maans = demand_h;
  if(mians > maans){
    cout << -1 << endl;
    return 0;
  }
  cout << mians << ' ' << maans << endl;
  return 0;
}


Measured memory_bytes: 1024
/* ITP1_9_C */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      int n = Integer.parseInt(br.readLine());
      int taro = 0, hanaco = 0;

      for(int i = 0; i < n; i++){
        String[] str = br.readLine().split(" ");
        String taro_card = str[0];
        String hanaco_card = str[1];
        int comp = taro_card.compareTo(hanaco_card);

        if(comp > 0) taro += 3;
        else if(comp < 0 ) hanaco += 3;
        else if(comp == 0){
          taro++;
          hanaco++;
        }
      }
      System.out.println(taro + " " + hanaco);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

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

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

string s;

int main() {
	cin >> s;
	rep(i, 3)cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 3616
using System;
using System.Linq;
class Program
{
  static void Main()
  {
    string[] inputs = Console.ReadLine().Split();
    int n = int.Parse(inputs[0]);
    int iH = int.Parse(inputs[1]);
    int iW = int.Parse(inputs[2]);
    int count = 
      Enumerable.Range(0, n)
      	.Select(x => Console.ReadLine().Split().Select(int.Parse).ToArray())
      	.Count(x => x[0] >= iH && x[1] >= iW);
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 13396
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

N,T = map(int, input().split())
A = list(map(int, input().split()))

Amin = [A[0]] + [0]*(N-1)
for i in range(1,N):
    if A[i] < Amin[i-1]: Amin[i] = A[i]
    else: Amin[i] = Amin[i-1]

B = A[0] - Amin[0]
for i in range(1,N): B = max(B, A[i]-Amin[i])

ans = 0
for i in range(N):
    if A[i] - Amin[i] == B:
        ans += 1

print(ans)

Measured memory_bytes: 23456
import java.util.Scanner;
public class Main {
   
    public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in);
String s=sc.nextLine();
if((s.charAt(2)==s.charAt(3)&&s.charAt(4)==s.charAt(5))){
    System.out.println(" Yes ");
}
else
            System.out.println(" No ");

    } 
}

Measured memory_bytes: 22740
#include<stdio.h>

int main(void){

  int a = 0;
  int b = 0;
  int s = 0;
  int d = 0;
  scanf("%d",&a);
  scanf("%d",&b);
  s = a*b;
  d = a*2+b*2;
  printf("%d %d\n",s,d);

  return 0;
}

  



Measured memory_bytes: 2036
def solve():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    x = sum([1+ P[i] for i in range(K)])
    prob = x/2
    for i in range(1,N - K + 1):
        x += P[i+K-1]-P[i-1]
        prob = max(prob, x / 2)
    print(prob)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 24804
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Control.Arrow
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    [n,m] <- r'
    as <- r m
    print $ max (-1) $ n - (U.sum as)



Measured memory_bytes: 4740
while True:
  scores = list(map(int, input().split()))
  if scores[0] == scores[1] == scores[2] == -1:
    break
  if (scores[0] == -1) or (scores[1] == -1):
    print("F")
  elif scores[0] + scores[1] >= 80:
    print("A")
  elif 80 > scores[0] + scores[1] >= 65:
    print("B")
  elif 65 > scores[0] + scores[1] >= 50:
    print("C")
  elif (50 > scores[0] + scores[1] >= 30) and (scores[2] >= 50):
    print("C")
  elif 50 > scores[0] + scores[1] >= 30:
    print("D")
  else:
    print("F")


Measured memory_bytes: 5596
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  if((abs(c-a) <= d) || ((abs(a-b) <= d) && (abs(c-b)<= d))){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
  return 0;
  }

Measured memory_bytes: 384
from sys import stdin
K, N = [int(x) for x in stdin.readline().rstrip().split()]
l = [int(x) for x in stdin.readline().rstrip().split()]

l.sort()

l2 = []

for i in range(N-1):
    l2.append(l[i+1] - l[i])

l2.append(l[0] + K - l[N-1])

ans = K - max(l2)

print(ans)

Measured memory_bytes: 26420
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
 
int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	
 
const ll mod=1e9+7;
const int INF=INT_MAX/2;

int main(){
	int n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++){
		if(i%3!=0 && i%5!=0){
			sum+=i;
		}
	}
	cout<<sum<<endl;
}
 

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

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

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

ll mod=1e9+7;

int main(){
  int A,B;
  cin >> A >> B;
  bool ans=false;
  int a;
  rep(i,1001){
    if((i*2)/25==A&&i/10==B){
      a=i;
      ans=true;
      break;
    }
  }
  if(ans){
    cout << a << endl;
  }
  else{
    cout << "-1" << endl;
  }
    
}
      
  
  
  

Measured memory_bytes: 256
def f(A, b):
    return sum(abs(a - (b + i + 1)) for i, a in enumerate(A))
N = int(input())
A = [int(x) for x in input().split()]
left, right = -10**9, 10**9
while left + 2 < right:
    diff = (right - left) // 3
    m1 = left + diff
    m2 = m1 + diff
    if f(A, m1) > f(A, m2):
        left = m1
    else:
        right = m2
print(min(f(A, i) for i in range(left, right + 1)))


Measured memory_bytes: 87636
import kotlin.comparisons.*
import java.util.*

const val MOD = 1000000007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun ceil(x: Double) = Math.ceil(x)
fun log2(x: Double) = Math.log(x) / 0.6931471805599453

fun main(args: Array<String>) {
  val n = readI()
  val uvw = Array(n + 1) { mutableSetOf<Pair<Int, Int>>() }
  repeat(n - 1) {
    val (u, v, w) = readIs()
    val even = w % 2
    uvw[u].add(v to even)
    uvw[v].add(u to even)
  }
  val d = IntArray(n + 1) { -1 }
  val q = ArrayDeque<Int>()
  d[1] = 0
  q.add(1)
  while (q.isNotEmpty()) {
    val node = q.remove()
    for (cur in uvw[node]) {
      if (d[cur.first] != -1) continue
      d[cur.first] = d[node] xor cur.second
      q.add(cur.first)
    }
  }
  for (i in 1..n) {
    println(d[i])
  }
}


Measured memory_bytes: 114116
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using Int = int64_t;
int main() {
    int N;
    cin >> N;
    vector<Int> A(N + 1), B(N);
    for (auto& i : A) cin >> i;
    for (auto& i : B) cin >> i;
    Int ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        auto m = min(B[i], A[i + 1]);
        ans += m + min(B[i] - m, A[i]);
        A[i] -= min(A[i], B[i] - m);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int n,m,ans=0;
vector<int> v[10];


void dfs(int g,bool r[]){
  int cnt=0;
  FOR(i,10){
    if(r[i]){
      cnt++;
    }
  }
  
  if(cnt==n){
    ans++;
    return;
  }
  FOR(i,v[g].size()){
    if(!r[v[g][i]]){
      r[v[g][i]]=1;
      dfs(v[g][i],r);
      r[v[g][i]]=0;
    }
  }
}

int main(){
    cin >> n >> m;
    int a[100],b[100];
    bool reached[10]={0};
    FOR(i,m){
      cin >> a[i] >> b[i];
      v[a[i]].push_back(b[i]);
      v[b[i]].push_back(a[i]);
    }
    reached[1]=1;
    dfs(1,reached);

    cout << ans << endl;
}

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

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

int const N=3e5+10,oo=1e9,M=2e5+3;
ll const OO=1e18;
int mod=998244353;
double const eps=1e-4,PI=acos(-1);

ll fst(ll n,ll p){
    if(p==0)return 1;
    ll res=fst(n,p>>1);
    res=res*res;
    if(p&1)res=res*n;
    return res;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,p;
    cin>>n>>p;
    ll an=1;
    for(ll i=2;i*i<=p;i++){
        if(p%i==0){
            int cnt=0;
            while(p%i==0){
                cnt++;
                p/=i;
            }
            an*=fst(i,cnt/n);
        }
    }
    if(p>1)if(n==1)an*=p;
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

h, w = Is()
A = LIR(h)
ANS = []
for i in range(h-1):
    for j in range(w):
        if A[i][j] % 2 != 0:
            ANS.append((i, j, i+1, j))
            A[i+1][j] += 1

for j in range(w-1):
    if A[h-1][j] % 2 != 0:
        ANS.append((h-1, j, h-1, j+1))
        A[h-1][j+1] += 1

print(len(ANS))
for x, y, xd, yd in ANS:
    print("{} {} {} {}".format(x+1, y+1, xd+1, yd+1))


Measured memory_bytes: 88920
#include<bits/stdc++.h>
#define mod 2019
#define mod1 998244353
#define Mmax 1000005
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
bool comp(pair<li,pair<li,li>>a,pair<li,pair<li,li>>b)
{
  if(a.first<b.first)
  return 1;
  else if(a.first>b.first)
  return 0;
  else
  {
    return a.second.first<b.second.first;
  }
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
void bfs(vector<li>v[],li visit[],li s,li ans[])
{
  deque<li>q;
  q.push_back(s);
  visit[s]=1;
  while(!q.empty())
  {
    li x=q.front();
    q.pop_front();
    for(auto i=v[x].begin();i!=v[x].end();i++)
    {
      if(!visit[*i])
      {
        q.push_back(*i);
        visit[*i]=1;
      }
    }
  }
}
void dfs(vector<li>v[],li visit[],li s)
{
  visit[s]=1;
  cout<<s<<" ";
    for(auto i=v[s].begin();i!=v[s].end();i++)
    {
      if(!visit[*i])
      {
        dfs(v,visit,*i);
      }
    }
}
vector<li>factor(li n)
{
  vector<li>v;
  if(n%2==0)
  {
    while(n%2==0)
    n/=2;
    v.push_back(2);
  }
  for(li i=3;i<=sqrt(n);i+=2)
  {
    if(n%i==0)
    {
      while(n%i==0)
      n/=i;
      v.push_back(i);
    }
  }
  if(n>1)
  v.push_back(n);
  return v;
}
int main()
{
fast_io
string s;
cin>>s;
li x=0,i,j,p,flag=0;
map<li,vector<li>>m,m1;
m[0].push_back(s.length());
for(i=s.length()-1;i>=0;i--)
{
  x+=(s[i]-'0')*mpow(10,s.length()-i-1);
  x=x%2019;
  m[x].push_back(i);
}
li count=0,prev=0;
for(auto i=m.begin();i!=m.end();i++)
{
li p=(i->second).size();
  count+=(p*(p-1))/2;
}
cout<<count;
return 0;
}


Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  if (A > B) {
    ans = 0;
  } else if (N == 1) {
    if (A == B)
      ans = 1;
  } else if (N == 2) {
    ans = 1;
  } else {
    ans = (B - A) * (N - 2) + 1;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n, k, sum, x;
  cin >> n >> k;
  sum = 1;
  for(int i = 0; i < n; i++, sum = x){
    int a, b;
    a = sum * 2;
    b = sum + k;
    if (a >= b){
      x = b;
    }
    else{
      x = a;
    }
  }
  cout << sum << endl;
}
    
      


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

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

int disp[10] = {
0b1111110, 
0b0110000, 
0b1101101, 
0b1111001, 
0b0110011,
0b1011011, 
0b1011111, 
0b1110010, 
0b1111111, 
0b1111011,};

int main(){
	while(true){
		int n;
		cin>>n;
		if(n==-1) break;
		
		int state = 0;
		REP(i, n){
			int x;
			cin>>x;
			int a = disp[x];
			int c = state ^ a;
			REP(i, 7) printf("%d", (c>>i)%2);
			printf("\n");
			state = a;
		}
	}
}

Measured memory_bytes: 1148
n = gets.chomp.to_i
d = gets.chomp.split(" ").map(&:to_i)
ans = 0
n.times do |i|
    res = 0
    n.times do |j|
        next if i == j
        res += d[j]
    end
    ans += res * d[i]
end
puts ans/2

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define test ll t;cin>>t;while(t--)
#define rep(i,k,n) for(ll i=k;i<n;i++)
#define MOD 998244353
#define fast  ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define pb push_back
#define mod 1000000007
#define MAX 100000
ll inv_euclid(ll a, ll m = MOD) {ll m0 = m; ll y = 0, x = 1; if (m == 1)return 0; while (a > 1) {ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t;} if (x < 0)x += m0; return x;}
ll power(ll x, ll y, ll p)  { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
ll max(ll a, ll b) {if (a > b)return a; return b;}
ll min(ll a, ll b) {if (a < b)return a; return b;}
ll ssum(ll n) {return (n * (n + 1)) / 2;}
ll gcd(ll a, ll b) {if (b == 0)return a; return gcd(b, a % b);}


void mult(ll a[][2] , ll b[][2]) {
	ll c[2][2];
	rep(i, 0, 2) {
		rep(j, 0, 2) {
			c[i][j] = 0;
			rep(k, 0, 2)
			c[i][j] = (c[i][j] % mod + ( a[i][k] * b[k][j]) % mod) % mod;
		}
	}
	rep(i, 0, 2)
	rep(j, 0, 2)
	a[i][j] = c[i][j];
}

ll fib(ll n, ll a, ll b) {
	ll I[2][2] = {{1, 0}, {0, 1}};
	ll A[2][2] = {{0, 0}, {1, (b / a)}};
	while (n) {
		if (n % 2)
			mult(I, A);
		mult(A, A);
		n /= 2;
	}
	return a * I[0][0] + b * I[1][0];
}



int main() {


	ll n, k;
	cin >> n >> k;
	ll a[n];
	rep(i, 0, n) {
		cin >> a[i];
	}
	vector<ll> dp(n + 1, 1e18);
	dp[0] = 0;
	rep(i, 0, n) {
		rep(j, i + 1, min(n, i + k + 1))
		dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
	}
	// rep(i, 0, n)
	// cout << dp[i] << "\n";
	cout << dp[n - 1];
}







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

int main() {
  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=k){
    cout<<k<< endl;
    return 0;
  }
  if(a+b>=k){
    cout<<a<< endl;
    return 0;
  }
  else{
    cout<<a+a+b-k<< endl;
  }
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> v(3);
    cin >> v[0] >> v[1] >> v[2];
    vector<int> t(n);
    REP(i, n){
        char c;
        cin >> c;
        if(c == 'r') t[i] = 2;
        else if(c == 's') t[i] = 0;
        else t[i] = 1;
    }

    ll score = 0;
    vector<int> h(n);
    REP(i, n){
        if(i < k){
            score += v[t[i]];
            h[i] = t[i];
        }else{
            if(t[i] == h[i-k]){
                h[i] = -1;
                continue;
            }
            score += v[t[i]];
            h[i] = t[i];
        }
        
    }

    cout << score << endl;

    return 0;
}


Measured memory_bytes: 1024
list2=[]
a,b=map(int,input().split())
if a>=b:
    k=0
    c=list(map(int,input().split()))
    for i in c:
        k=k+i
    for j in c:
        if j>=(k)/(4*b):
            list2.append(j)
    g=len(list2)
    if b <= g:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
main = do
  a <- getLine
  b <- getLine
  let ans = compute a b
  putStrLn $ msg ans

msg LT = "LESS"
msg GT = "GREATER"
msg EQ = "EQUAL"

compute :: String -> String -> Ordering
compute a b =
  case compare (length a) (length b) of
    EQ -> foldr decide EQ $ zipWith compare a b
    cp -> cp

decide EQ rest = rest
decide cmp _   = cmp


Measured memory_bytes: 380
#include <stdio.h>

void swap(int *x,int *y){
  int stn;
  stn = *x;
  *x = *y;
  *y = stn;
}

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(b>c){
    swap(&c,&b);
  }
  if(a>b){
    swap(&a,&b);
  }
  if(b>c){
    swap(&b,&c);
  }
  printf("%d",a+b);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int i;
  ll x, y;
};

bool sort_x(const ST& a, const ST& b){
  return a.x < b.x;
}
bool sort_y(const ST& a, const ST& b){
  return a.y < b.y;
}

struct DIFF {
  int a, b;
  ll diff;
};
bool operator<(const DIFF& a, const DIFF& b){
  return a.diff > b.diff;
}

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){ //if new link, then true.
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){ //if same set, then true.
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};



int main(){
  int N;
  cin >> N;
  vector<ST> v;
  rep(i,N){
    ST st;
    st.i = i;
    cin >> st.x >> st.y;
    v.push_back(st);
  }

  UnionFind uf(N);
  priority_queue<DIFF> que;
  
  sort(ALLOF(v), sort_x);
  rep(i,N-1){
    DIFF diff;
    diff.a = v[i].i;
    diff.b = v[i+1].i;
    diff.diff = llabs(v[i].x - v[i+1].x);
    que.push(diff);
  }
  sort(ALLOF(v), sort_y);
  rep(i,N-1){
    DIFF diff;
    diff.a = v[i].i;
    diff.b = v[i+1].i;
    diff.diff = llabs(v[i].y - v[i+1].y);
    que.push(diff);
  }

  ll ret = 0;
  while(!que.empty()){
    DIFF diff = que.top(); que.pop();
    if(uf.check(diff.a, diff.b)) continue;
    ret += diff.diff;
    uf.link(diff.a, diff.b);
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 11120
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <list>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll> A;
    vector<ll> B;
    vector<ll> dif;
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        A.push_back(a);
        
    }
    for(int i=0;i<N;i++){
        ll b;
        cin >> b;
        B.push_back(b);
        dif.push_back(A[i]-B[i]);
    }
    sort(dif.begin(),dif.end());
    ll ans=0;
    int ct=0;
    for(int i=0;;i++){
        if(dif[i]>=0) break;
        else{
            ans+=abs(dif[i]);
            ct++;
        }
    }
    ll num=0;
    for(int i=N-1;i>=0;i--){
        if(num>=ans) break;
        if(dif[i]<=0) break;
        else {
            num+=dif[i];
            ct++;
        }
    }
    cout << (ans<=num?ct:-1) << endl;
}

Measured memory_bytes: 3444
#include <stdio.h>
 
int main()
{
    long long int inp,a;
    int b;
    char nama[100];
    scanf("%lld",&inp);
    int i=0;
    while(inp!=0)
	{
        inp--;
        b = inp%26;
        nama[i] ='a'+ b;
        inp=inp/26;
        i++;
    }
 
    for(int j=i-1;j>=0;j--)
	{
        printf("%c",nama[j]);
    }
    
    return 0;
}

Measured memory_bytes: 1652
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

diff = [abs(i - X) for i in x]

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

ans = diff[0]

for i in range(N - 1):
    ans = gcd(ans, diff[i + 1])

print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b + 1) / 2 << endl;
}

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

int main()
{
	int n,F=1,a,x,y;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a>>x>>y;
		if (x+y<=a && (a-x-y)%2==0) continue;
		else{
			F=0;
			break;
		}
	}
	if (F==1) cout<<"Yes";
	else	  cout<<"No";
	
	return 0;
}

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

int main() {
	long long int a,ans;
	double b;
	cin>>a>>b;
	b*=100;
	b=round(b);
	long long int c=(long long int)(b);
	ans=a*c;
	cout<<ans/100<<endl;
	return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
const int N=1<<19;
int n,a[N],id[N][2];
bool cmp(int x, int y){
    return a[x]<a[y];
}
int main(){
    scanf("%d",&n);
    for (int i=0;i<(1<<n);i++)
        scanf("%d",&a[i]);
    a[(1<<n)]=-1;
    id[0][0]=0,id[0][1]=(1<<n);
    for (int i=1;i<(1<<n);i++){
        id[i][0]=i,id[i][1]=(1<<n);int x[4];
        for (int j=0;j<n;j++)if (i&(1<<j)){int _i=i^(1<<j);x[0]=id[i][0],x[1]=id[i][1],x[2]=id[_i][0],x[3]=id[_i][1];sort(x,x+4,cmp);id[i][0]=x[3],id[i][1]=x[2]==x[3]?x[1]:x[2];}
    }
    int mx=0;
    for (int i=1;i<(1<<n);i++){
        mx=max(mx,a[id[i][0]]+a[id[i][1]]);
        printf("%d\n",mx);
    }
    return 0;
}

Measured memory_bytes: 6820
n = int(input())
a = [ int(x) for x in input().split() ]

a.sort(reverse=True)

n = a[0]
r = -1
t = a[0]
for aa in a[1:]:
    if abs(n/2-aa) <= t:
        r = aa
        t = abs(n/2-aa)

print(n, r)


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

import sys
sys.setrecursionlimit(10000000)

def readInts():
  return [int(s) for s in input().split(" ")]

def next_color(c, exclude):
  if c == exclude:
    return c + 1
  else:
    return c

def traverse(N, edges, k, ans, v, exclude = 0):
  c = next_color(1, exclude)
  for (b, i) in edges[v]:
    ans[i] = c
    traverse(N, edges, k, ans, b, c)
    c = next_color(c + 1, exclude)

def main():
  N = readInts()[0]
  edges = [[] for _ in range(N)]
  counts = [0 for _ in range(N)]
  for i in range(N-1):
    a, b = readInts()
    a -= 1
    b -= 1
    edges[a].append((b, i))
    counts[a] += 1
    counts[b] += 1

  k = max(counts)
  ans = [0 for _ in range(N-1)]
  traverse(N, edges, k, ans, 0)

  print(k)
  for i in range(N-1):
    print(ans[i])

if __name__ == "__main__":
  main()


Measured memory_bytes: 83340
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	string n;
	cin >> n;
	ff(i, 0, n.size()) {
		if (n[i] == '9') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256