akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize "-Ofast"
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

vector<pair<ld, ld> > vv;
vector<ld> vb;
int f[220000];
int sz;
int n;

struct line {
	ll a, b, c;
};

line l[220000];

void add(int x) {
	for (; x < sz; x |= (x + 1))
		f[x] += 1;
}

int get(int x) {
	int ans = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		ans += f[x];
	return ans;
}

ld solve() {
	ld lb = -3e8;
	ld rb = 3e8;
	ll nd = ((ll)(n) * (n - 1) / 2 + 1) / 2;
	for (int it = 0; it < 70; ++it) {
		ld mid = (lb + rb) / 2;
		ll cur = 0;
		vv.clear();
		vb.clear();
		for (int i = 0; i < n; ++i) {
			ld y = (l[i].c - l[i].a * mid) / l[i].b;
			vv.emplace_back(y, (ld)l[i].a / l[i].b);
			vb.push_back((ld)l[i].a / l[i].b);
		}
		sort(vv.begin(), vv.end());
		sort(vb.begin(), vb.end());
		sz = vb.size();
		memset(f, 0, sizeof(f[0]) * sz);
		for (int i = vv.size() - 1; i >= 0; --i) {
			int x = lower_bound(vb.begin(), vb.end(), vv[i].second) - vb.begin();
			cur += get(x);
			add(x);
		}
		if (cur >= nd)
			rb = mid;
		else
			lb = mid;
	}
	return (lb + rb) / 2;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lld%lld%lld", &l[i].a, &l[i].b, &l[i].c);
	ld x = solve();
	for (int i = 0; i < n; ++i)
		swap(l[i].a, l[i].b);
	ld y = solve();
	printf("%.20Lf %.20Lf\n", x, y);
	return 0;
}




Measured memory_bytes: 5492
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = readLine()?.split(" ")?.map(String::toLong) ?: return
    val mod = (1e9 + 7).toLong()

    var total = 0L
    for (b in 0..60) {
        val bn = 1L shl b
        val n0 = a.count { it and bn == 0L }.toLong()
        val n1 = n - n0
        total = (total + (bn % mod) * (n0 * n1 % mod)) %mod
    }
    println(total.toString())
}

Measured memory_bytes: 95412
fun main(args: Array<String>) {
    var x = readLine()!!.toInt()
    while (true) {
        var flag = false
        for (i in 2 .. Math.sqrt(x.toDouble()).toInt()) {
            if (x % i == 0) {
                flag = true
                continue
            }
        }
        if (!flag) {
            return println(x)
        } else {
            x++
        }
    }
}

Measured memory_bytes: 31828
(k, a, b) = map(int, input().split())
invest_duration = k - a + 1
invest_gain = b - a
invest_gain = int(invest_duration / 2) * invest_gain + a + (1 if 1 == (invest_duration % 2) else 0)
print(invest_gain if invest_gain > (k + 1) else (k + 1))

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	string str;
	cin >> str;
	string str2;
	str2 += str;
	int size = str.size();
	reverse(str2.begin(),str2.end());


	if (str == str2) {
		string str3 = str.substr(0, (size - 1) / 2);
		string str4 = "";
		str4 += str3;
		reverse(str4.begin(), str4.end());

		if (str3 == str4) {
			string str5 = str.substr((size + 2) / 2, (size / 2));
			string str6;
			str6 += str5;
			reverse(str6.begin(), str6.end());

			if (str5 == str6) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";

	return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())

head = []
tail = []
flip = 0

for i in range(q):
    query = input().split()
    if query[0] == "1":
        flip ^= 1
    else:
        f = int(query[1]) - 1
        c = query[2]
        if (f ^ flip) == 0:
            head.append(c)
        else:
            tail.append(c)

if flip:
    head, tail = tail, head
    s = s[::-1]

head = "".join(head)
tail = "".join(tail)

print(head[::-1] + s + tail)

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

using namespace std;
using ll = long long;
using pii = std::pair<int, int>;

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
const int mn = 1e6 + 5;

int n, q;
char s[mn];

ll query(int k) {
    ll dmCnt = 0, ans = 0;
    ll cntd = 0, cntm = 0;
    for (int i = 1; i <= n; i++) {
        if (i - k >= 1) {
            if (s[i - k] == 'D') {
                cntd--;
                dmCnt-=cntm;
            }
            if (s[i - k] == 'M') {
                cntm--;
            }
        }
        if (s[i] == 'D') {
            cntd++;
        }
        if (s[i] == 'M') {
            cntm++;
            dmCnt += cntd;
        }
        if (s[i] == 'C') {
            ans += dmCnt;
        }
    }
    return ans;
}

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif

    scanf("%d", &n);
    scanf("%s", s + 1);
    scanf("%d", &q);
    while (q--) {
        int k;
        scanf("%d", &k);
        printf("%lld\n", query(k));
    }
    return 0;
}

Measured memory_bytes: 1280
function Main(input) {
	input = input.trim();
	var a = Number(input.split(" ")[0]);
	var b = Number(input.split(" ")[1]);
	var myList = [a+b,a-b,a*b];
	var ret = Math.max(myList[0],myList[1],myList[2]);
	if(ret == -0){
		ret = 0;
	} 
	console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
        int n, m, p;
        string s;
        cin >> n >> m;

        vector<int> v1(n);
        vector<int> v2(n);


        for (int i = 0; i < m; ++i){
                cin >> p >> s;
                if(s=="AC"){
                        v1[p-1] = 1;
                }
                if(v1[p-1]==0 && s=="WA"){
                        v2[p-1] += 1;
                }
        }

        int o1 = 0;
        int o2 = 0;
        for (int i = 0; i < n; i++){
                if(v1[i] == 1){
                        o1 += 1;
                        o2 += v2[i];
                }
        }
        cout << o1 << endl;
        cout << o2 << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int n,k,a[55],h;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
     cin>>n>>k;
     for(int i=1;i<=n;i++)
     {
     	cin>>a[i];
     }
	 sort(a+1,a+n+1,cmp);
	 for(int i=1;i<=k;i++)
     {
     	h=h+a[i];
     }
     cout<<h<<endl;
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  int ans=1000000000;
  for(int i=-100;i<=100;i++){
    int x=0;
    for(int j=0;j<n;j++){
      x+=(a[j]-i)*(a[j]-i);
    }
    ans=min(ans,x);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int n,ans=0;
	long long d;
	cin>>n>>d;
	for(int i=1;i<=n;i++)
	{
		long long x,y;
		cin>>x>>y;
		x=abs(x);
		y=abs(y);
		if(abs(x*x+y*y)<=abs(d*d)) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3644
Public Class Test
    Public Shared Sub Main()
        Dim c() As String
        c = Split(Console.ReadLine())
        If (Ss(c(0)) < Ss(c(1))) Then
            Console.WriteLine("<")
        ElseIf (Ss(c(0)) > Ss(c(1))) Then
            Console.WriteLine(">")
        Else
            Console.WriteLine("=")
        End If
    End Sub
    Public Shared Function Ss(ByVal input As String) As Integer
        Select Case input
            Case "A"
                Return 10
            Case "B"
                Return 11
            Case "C"
                Return 12
            Case "D"
                Return 13
            Case "E"
                Return 14
            Case "F"
                Return 15
            Case Else
                Return input
        End Select
    End Function
End Class

Measured memory_bytes: 22224
#include<iostream>
#include<math.h>
using namespace std;

int r,c;
bool state[10][10000];
bool linemap[10][10000];
int mapcount;
int getnum(bool status[10][10000]){
	int num=0;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			if(status[i][j])num++;
		}
	}
	return num;
}

void adjust(){
	
		for(int j=0;j<c;j++){
			int num0=0,num1=0;
			for(int k=0;k<r;k++){
				if(linemap[k][j])num1++;
				else num0++;
			}
			if(num0>num1){
				for(int k=0;k<r;k++){
					linemap[k][j]=1-linemap[k][j];
				}
			}
		}
	
}
int creatlinemap(){
	int max=0;
	for(int i=0;i<mapcount;i++){
		for(int j=0;j<r;j++){
			if(i&(1<<j)){
				for(int k=0;k<c;k++){
					linemap[j][k]=state[j][k];
				}
				
			}
			else{
				for(int k=0;k<c;k++){
					linemap[j][k]=1-state[j][k];
				}
			}
		}
		adjust();
		int tmp=getnum(linemap);
		if(tmp>max)	max=tmp;			
	}
	return max;	
}


int main(){

	while(cin>>r>>c){
		if(r*c==0)return 0;
		mapcount=(int)pow(2.0,r);
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				cin>>state[i][j];
			}
		}
		
		cout<<creatlinemap()<<endl;
	}
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;
 
P h[3000];
int main() {
    int n;
    while (scanf("%d", &n), n) {
        rep(i, n)scanf("%d%d", &h[i].first, &h[i].second);
        sort(h, h + n);
        int Max = 0;
        rep(i, n) {
            for (int j = i + 1; j < n; j++) {
                int x = h[j].first - h[i].first,
                    y = abs(h[j].second - h[i].second);
                if (!x)continue;
                P a = { h[i].first,h[i].second + x },
                    b = { h[j].first,h[j].second + x };
                if (h[i].second < h[j].second) {
                    a.first -= y; b.first -= y;
                }
                else {
                    a.first += y; b.first += y;
                }
                if (binary_search(h, h + n, a) && binary_search(h, h + n, b))
                    Max = max(Max, (x + y)*(x + y) - x*y * 2);
            }
        }
        printf("%d\n", Max);
    }
}

Measured memory_bytes: 3128
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    R,G,B,N=MI()
    ans=0
    for r in range(0,N+1,R):
        for g in range(0,N+1-r,G):
            b=N-r-g
            if b%B==0:
                ans+=1
                
    print(ans)

main()


Measured memory_bytes: 81520
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
int main(){
  long long i, j, n, x, ans=0, flag=0;
  cin >> n >> x;
  int a[n];
  for(i=0; i<n; i++)
    cin >> a[i];
  sort(a, a+n);
  for(i=0; i<n; i++){
    if(a[i]<=x){
      ans++;
      x-=a[i];
      if(i==n-1) flag++;
    }
  }
  if(x!=0&&flag>0) ans--;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a_list=list(map(int,input().split()))
b_list=[]
for i in range(n-1):
  d=a_list[i]-a_list[i+1]
  if(d>=0):
    b_list.append(d)
    a_list[i+1]+=d
    
ans=sum(b_list)
print(ans)

Measured memory_bytes: 31996
using System;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder {
    public class Program {
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(' ');
            int[] Ns = new int[Keys.Length];
            for (int i = 0; i < Keys.Length; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }
        static void Main() {
            int s = int.Parse(Console.ReadLine());
            List<int> As = new List<int>();
            int i = 1;
            while (!As.Contains(s)) {
                As.Add(s);
                if (s % 2 == 0) {
                    s /= 2;
                } else {
                    s = s * 3 + 1;
                }
                i++;
            }
            Console.WriteLine(i);
        }
    }
}


Measured memory_bytes: 13024
using System;
class Program
{
    static void Main()
    {
        string n = Console.ReadLine();
        if (n[0] == n[1]  && n[1] == n[2] || n[1] == n[2] && n[2] == n[3])
        {
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
from heapq import *
import sys;input=sys.stdin.readline
Q, = map(int, input().split())
qs = []
c = 0
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        c += 1
    else:
        a, b = int(q[1]), int(q[2])
        qs.append((a, b, c))
        c = 0
if c:
    qs.append((a, b, c))

R = [10**18]
L = [10**18]
ss = 0
for a, b, c in qs:
    xs = []
    if c:
        x = heappop(L)
        for _ in range(c):
            print(-x, ss)
        heappush(L, x)
    x = heappop(R)
    y = -heappop(L)
    if x < a:
        heappush(R, a)
        heappush(R, a)
        heappush(L, -x)
        heappush(L, -y)
        ss += a-x
    elif y > a:
        heappush(L, -a)
        heappush(L, -a)
        heappush(R, x)
        heappush(R, y)
        ss += y-a
    else:
        heappush(L, -a)
        heappush(R, a)
        heappush(L, -y)
        heappush(R, x)
    ss += b


Measured memory_bytes: 122332
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    ll N, M, D;
    cin >> N >> M >> D;
    ll beauty_pairs = N + ((D > 0) ? max((ll)0, (N-D)-(D+1)+1) : 0);
    printf("%.10lf\n", (double)beauty_pairs / (double)(N * N) * (double)(M-1));
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
int A[10],B[10];
int C[3];

signed main(){
	cin>>N>>M;
	REP(i,M){
		cin>>A[i]>>B[i];
		A[i]--;
	}
	int R,R2;
	if(N==1){
		R=0,R2=9;
	}
	else if(N==2){
		R=10,R2=99;
	}
	else{
		R=100,R2=999;
	}
	for(int i=R;i<=R2;i++){
		deque<int> v;
		string s=to_string(i);
		REP(j,s.size()){
			v.push_back(s[j]-'0');
		}
		bool flag=true;
		REP(j,M){
			if(v[A[j]]!=B[j]){
				flag=false;
			}
		}
		if(flag==true){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll N,Q;
    string S;
    cin >> N >> S >> Q;
    vector<ll> memo[26];
    rep(j,N){
        memo[S[j]-'a'].push_back(j);
    }

    ll type,i,l,r;
    char c;
    rep(j,Q){
        cin >> type;
        if(type == 1){
            cin >> i >> c;
            //int d = S[i] - 'a';
            rep(k,26){
                auto itr = lower_bound(memo[k].begin(),memo[k].end(),i-1);
                if(itr == memo[k].end() || *itr != i-1)continue;
                memo[k].erase(itr);
                itr = lower_bound(memo[c-'a'].begin(),memo[c-'a'].end(),i-1);
                memo[c-'a'].insert(itr,i-1);
            }
        }else{
            cin >> l >> r;
            ll cnt = 0;
            rep(k,26){
                auto itr = lower_bound(memo[k].begin(),memo[k].end(),l-1);
                if(itr == memo[k].end())continue;
                if(*itr <= r-1){
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
    }


}

Measured memory_bytes: 7032
h,w,m=map(int,input().split())
H=[0 for i in range(h)]
W=[0 for i in range(w)]
s=set()
for i in range(m):
    a,b=map(int,input().split())
    H[a-1]+=1
    W[b-1]+=1
    s.add((a,b))
hma=max(H)
wma=max(W)
h_index=[x for x, v in enumerate(H) if v==hma]
w_index=[y for y, v in enumerate(W) if v==wma]
val=-1
for p in h_index:
    for q in w_index:
        if not (p+1,q+1) in s:
            val=0
            break
print(hma+wma+val)

Measured memory_bytes: 166752
while True:
    HW = input()
    HW_list = HW.split(" ")
    H = int(HW_list[0])
    W = int(HW_list[1])
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i % 2 == 0:
            if W % 2 == 0:
                print("#." * int(W / 2))
            elif W % 2 == 1:
                print("#." * int((W - 1) / 2) + "#")
        elif i % 2 == 1:
            if W % 2 == 0:
                print(".#" * int(W / 2))
            elif W % 2 == 1:
                print(".#" * int((W - 1) / 2) + ".")
    print()


Measured memory_bytes: 5616
def examA():
    N = I()
    A = LI()
    ans = 0
    for i in range(N-1):
        if A[i+1]==A[i]:
            A[i+1] = 101
            ans +=1
    print(ans)
    return

def examB():
    T = I()
    ans = ["Yes"]*T
    for i in range(T):
        A, B, C, D = LI()
        if A<B:
            ans[i] = "No"
            continue
        if D<B:
            ans[i] = "No"
            continue
        if C>=B:
            continue


    return

def examC():
    N = I()
    S = SI()
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    loop = 2**N
    for i in range(loop):
        curR = ""; curB = ""
        curR2 = ""; curB2 = ""
        for j in range(N):
            if i&(1<<j)==(1<<j):
                curR +=S[j]
                curR2 +=S[j+N]
            else:
                curB +=S[j]
                curB2 +=S[j+N]
        d1[(curR,curB)] +=1
        d2[(curR2,curB2)] +=1
    ans = 0
    for key,i in d1.items():
        cur = i*d2[(key[1][::-1],key[0][::-1])]
        ans +=cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examC()


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

using namespace std;

typedef long long int ll;


int main()
{
   ios::sync_with_stdio(false);
   ll n;
   cin>>n;
   int i;
   unordered_map<string,int> mp;
   mp["AC"]=0;
   mp["WA"]=0;
   mp["TLE"]=0;
   mp["RE"]=0;
   for(i=0;i<n;++i){
       string tmp;
       cin>>tmp;
       mp[tmp]++;
   }
   unordered_map<string,int>::iterator itr;
   cout<<"AC x "<<mp["AC"]<<"\n";
   cout<<"WA x "<<mp["WA"]<<"\n";
   cout<<"TLE x "<<mp["TLE"]<<"\n";
   cout<<"RE x "<<mp["RE"]<<"\n";
}


Measured memory_bytes: 3688
#include <iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=0;
    if(d<=a+b)ans=min(a,d);
    else ans=a-(d-a-b);
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int a[105],c,b;
  cin >> c;
  for (int i = c;i > 0;i--){
    cin >> a[i];
  }
  for (int i = c;i > 0;i--){
    int b =c - i + 1;
    cout << a[b] ;
    if (b < c){
      cout << " ";
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3100
# Bellman-Ford Algorithm

def bellman_ford(s):
    '''
    始点sから各頂点への最短距離を求める (重み付き有向グラフ)
    '''
    dist = [float('inf')] * v
    dist[s] = 0

    for i in range(v):
        update = False
        for p, q, cost in edge:
            if dist[p] != float('inf') and dist[q] > dist[p] + cost:
                dist[q] = dist[p] + cost
                update = True
        if not update:
            break
        if i == v - 1:  # 負閉路が存在する場合はFalseを返す
            return False

    return dist


################################
v, e, r = map(int, input().split())  # v:頂点数, e:辺の数

edge = []  # edge[i]:[始点,終点,重み]
for _ in range(e):
    s, t, d = map(int, input().split())
    edge.append([s, t, d])

res = bellman_ford(r)

if not res:
    print('NEGATIVE CYCLE')
else:
    for v in res:
        if v == float('inf'):
            print('INF')
        else:
            print(v)


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <atcoder/segtree>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using namespace std;
using namespace atcoder;
typedef long long ll;

template <typename T> void printvec(const vector<T>& v) {
	for(int i = 0; i < SZ(v); i++) {
		if (i) cout << " ";
		cout << v[i];
	}
	cout << "\n";
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x,y);
}

bool predicate(ll mid) {
	return mid>10;
}

ll bin_search(ll lo, ll hi) {
	int sign = lo < hi ? 1 : -1;
	lo*=sign;
	hi*=sign;
	hi++;
	while(lo < hi) {
		ll mid = floorDiv(lo+hi,2);
		if (!predicate(sign*mid)) {
			lo = mid+1;
		} else {
			hi = mid;
		}
	}
	return sign*lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return 0;
}

int n, k;

int query(int x, segtree<int, op, e> &seg) {
	int left = max(0,x-k);
	int right = min(300000,x+k)+1;
	return seg.prod(left,right);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> k;
	
	vector<int> nums(n);
	for(int i = 0; i < n; i++){
		cin >> nums[i];
	}
	
	segtree<int, op, e> seg(300005);
	
	for(int i = n-1; i>=0; i--){
		int ans = query(nums[i],seg);
		seg.set(nums[i],ans+1);
	}
	
	cout << seg.all_prod() << "\n";
	
}


Measured memory_bytes: 9796
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define DEBUG(x) cerr << #x << " = " << x << endl
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
signed main() {
  string S; cin >> S;
  int n = S.size();
  int c = 0;
  REP(i,n) {
    if(S[i] == 'p') c--;
  }
  cout << c + (n / 2) << endl;
}


Measured memory_bytes: 640
def main():
    N,p = map(int, input().split())
    S = input()
    S = S[::-1]

    if p==2 or p==5:
        ans = 0
        for i,s in enumerate(S):
            if int(s)%p==0:
                ans += N-i
        print(ans)
    else:
        # modpを作成
        modp_counter = [0] * p
        modp = 0
        modp_counter[0] = 1 # 割り切れるやつが入る場所の初期値を1にしておかないと、1つ割り切れるやつがきたときにpair_count+=0となってしまう(pair_count+=1になるべきなのに)
        pair_count = 0
        d = 1
        for s in S:
            modp = (int(s)*d%p+modp)%p
            pair_count += modp_counter[modp]
            modp_counter[modp] += 1
            d *= 10
            d %= p # 計算量削減
        print(pair_count)

main()


Measured memory_bytes: 3500
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N = NI()
    s = 0
    for _ in range(N-1):
        u,v = LI()
        if u > v: u,v = v,u
        s += u * (N-v+1)
    a = 0
    for i in range(N+1):
        a += (i+1) * i // 2
    print(a - s)
if __name__ == '__main__':
    main()

Measured memory_bytes: 76068
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    String s=sc.next();
    boolean fL=s.charAt(0)=='L';
    int ya=1;
    for(int i=0;i<n-1;i++){
      if(s.charAt(i)!=s.charAt(i+1)){
        ya++;
      }
    }
//    System.err.println(ya);
    while(ya>=2&&k>0){
      if(ya>=3){
        ya-=2;
      }else{
        ya--;
      }
      k--;
    }
    System.out.println(n-ya);
  }
}

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

long long lcm(long long x, long long y) {
  long long z = x * y;
  if (x < y) {
    long long tmp = x;
    x = y;
    y = tmp;
  }
  long long r = x % y;
  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return z / y;
}

int main(void) {
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  long long begin = A - 1;
  long long ans = (B - (B / C) - (B / D) + (B / lcm(C, D)));
  ans -= (begin - (begin / C) - (begin / D) + (begin / lcm(C, D)));
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}
 
signed main()
{
	int n,m;
	n=read();
	m=read();
	int gs=0;
	while(1)
	{
		if(n<1) break;
		n/=m;
		gs++;
	}
	printf("%lld\n",gs);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9 + 7;
const int N = 5000 + 5;
const int dx[] = { 0, 0, -1, 1, -1, -1, 1, 1 };
const int dy[] = { -1, 1, 0, 0, -1, 1, -1, 1 };
using namespace std;

int n, k, a[N];
bitset<N> sum;
bool judge(int x) {
	if (a[x] >= k)
		return 1;
	sum.reset();

	sum[0] = 1;
	for (int i = 1; i <= n; i++)
		if (i != x)
			sum |= sum << a[i];

	for (int i = k - 1; i >= k - a[x]; i--)
		if (sum[i])
			return true;
	return false;
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		a[i] = min(a[i],k);
	}
	sort(a + 1, a + n + 1);

	int left = 0, right = n + 1;
	while (left < right) {
		int mid = (left + right) >> 1;
		if (judge(mid))
			right = mid;
		else
			left = mid + 1;
	}
	printf("%d\n", left - 1);
	return 0;
}


Measured memory_bytes: 3860
/*
Problem Number: ABC177E
Problem Name: Coprime
Notes: 
*/

#include <bits/stdc++.h>
#define endl "\n"
#define ll long long

using namespace std;

int sp[int(1e6)+1];

int main(){
    cin.tie(0) -> sync_with_stdio(0);
    
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    int gcd = a[0];
    for(int i = 1; i < n; i++)
        gcd = __gcd(gcd, a[i]);
    if(gcd > 1){
        cout << "not coprime" << endl;
        return 0;
    }

    memset(sp, 0, sizeof(sp));
    for(int i = 2; i < int(1e6)+1; i++)
        if(!sp[i])
            for(int j = i; j < int(1e6)+1; j+=i)
                if(!sp[j])
                    sp[j] = i;

    bool primes[int(1e6)];
    memset(primes, 0, sizeof(primes));
    for(int i = 0; i < n; i++){
        int ai = a[i];
        while(ai != 1){
            int spi = sp[ai];
            if(primes[spi]){
                cout << "setwise coprime" << endl;
                return 0;
            }
            primes[spi] = 1;
            while(ai % spi == 0)
                ai /= spi;
        }
    }

    cout << "pairwise coprime" << endl;
    
    return 0;
}

Measured memory_bytes: 12380
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 200

int n, time = 0;
int color[N], d[N], f[N], A[N][N];


void  DFSVisit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  
  
  for(v=1; v <= n; v++){
    if((color[v]== WHITE) && (A[u][v] == 1)) DFSVisit(v);
  }
   
  color[u] = BLACK;
   f[u] = ++time;
   
}

void DFS(){
  int u;
  for(u=1; u <= n; u++){
    color[u] = WHITE;
  }

  for(u=1; u <= n; u++){
    if(color[u] == WHITE) DFSVisit(u);
  }
  
}





int main(void){
  int i, j,  u, v, k; 
  
  scanf("%d", &n);
  
  for(i=1; i<=n; i++){
    for(j=1; j<=n; j++){
      A[i][j] = 0;
    }
  }
  
  for(i=1; i<=n; i++){
    scanf("%d%d", &u, &k);
    for(j=1; j<=k; j++){
      scanf("%d", &v);
      A[u][v] = 1;
    }
    
  }
  
  DFS();
  
  for(i=1; i<=n; i++) printf("%d %d %d\n", i, d[i], f[i]);
  
return 0;
}

Measured memory_bytes: 680
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    
    int a,b,c,memo = 0;
  	cin >>a >> b >> c;
  	memo += a+b+c;
  	memo += max(a,max(b,c))*9;
  	cout <<  memo << endl;
}

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

#include <iostream>
#include <fstream>

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

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

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

using namespace std;

typedef pair<int, int> P;

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

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

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> B(N - 1), A(N, INF);
        REP(i, N - 1) {
            cin >> B[i];
        }
        REP(i, N - 1) {
            A[i] = min(A[i], B[i]);
            A[i + 1] = min(A[i + 1], B[i]);
        }

        int res = 0;
        REP(i, N) res += A[i];
        cout << res << endl;

    }
};


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

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


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long LL;
const int MX=131077;
const LL inf=0x3f3f3f3f3f3f3f3fLL;
int n,s[MX][2],sv[MX][2],sz[MX];
int fa[MX],fv[MX];

typedef pair<LL,LL> pll;
#define fr first
#define se second
#define mp make_pair
vector<pll>q[MX];
typedef vector<pll>::iterator vit;
typedef vector<pll>::reverse_iterator vrit;
void dfs(int k,LL v){
	sz[k]=0;
	q[k].clear();
	if(!s[k][0])sz[k]=1,q[k].push_back(mp(0,0));
	else{
		dfs(s[k][0],v),dfs(s[k][1],v);
		if(q[s[k][0]].empty()||q[s[k][1]].empty())return;
		static vector<pll>t;
		t.clear();
		if(sz[s[k][0]]>sz[s[k][1]])swap(s[k][0],s[k][1]),swap(sv[k][0],sv[k][1]);
		vit it=q[s[k][1]].begin();
		for(vit i=q[s[k][0]].begin();i!=q[s[k][0]].end();i++){
			#define CHK(it,i) ((it)->fr+(i)->se+sv[k][0]+sv[k][1]<=v)
			while((it+1)!=q[s[k][1]].end()&&CHK(it+1,i))it++;
			if(CHK(it,i))t.push_back(mp(i->fr+sv[k][0],it->se+sv[k][1]));
			#undef CHK
		}
		it=t.begin();vrit rit=t.rbegin();
		while(it!=t.end()||rit!=t.rend()){
			if(it==t.end()||(rit!=t.rend()&&rit->se<=it->fr)){
				if(q[k].empty()||q[k].rbegin()->se>rit->fr)
				q[k].push_back(mp(rit->se,rit->fr));
				rit++;
			}else{
				if(q[k].empty()||q[k].rbegin()->se>it->se)
				q[k].push_back(*it);
				it++;
			}
		}
		//if(v==13){
			//for(vit it=q[k].begin();it!=q[k].end();it++)
			//fprintf(stderr,"%d %d %d %d %d\n",k,it->u,it->v,it->lu,it->lv);
		//}
	}
	sz[fa[k]]+=sz[k];
}
bool ck(LL v){
	dfs(1,v);
	return !q[1].empty();
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++)scanf("%d%d",&fa[i],&fv[i]);
	for(int i=2;i<=n;i++){
		if(s[fa[i]][0])s[fa[i]][1]=i,sv[fa[i]][1]=fv[i];
		else s[fa[i]][0]=i,sv[fa[i]][0]=fv[i];
	}
	LL l=0,r=131072LL*131072LL;
	while(l<r){
		LL mid=(l+r)>>1;
		if(ck(mid))r=mid;else l=mid+1;
	}
	printf("%lld\n",l);
	//while(1);
	return 0;
}


Measured memory_bytes: 29928
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

ll N, M, K;
ll A[200000], B[200000];
ll deci=0;
bool can_clear(ll index){
    //cout<<deci<<sp<<index<<sp<<B[index]<<endl;
    return deci+B[index]<=K;
}

//条件に合致する最大indexを二分探索 O(logN)
//-2...全indexがみたす -1...条件に合致するものがない
ll nibutan_max(ll min, ll max){
  //評価関数can_clear(ll　value) を指定すること
  ll left=min, right=max;
  ll ans;
  while(true){
      //cout<<left<<" " <<right<<endl; //debug用
      if(left==right){
          if(can_clear(right)) return right;
          else return -1;
      }
      if(left+1==right){
        if(can_clear(right)){
          if(right==max) return max;
          else return right;
        }
        else{
          if(can_clear(left)) return left;
          else return -1;
        }
        break;
      }
      ll nibutan=(left+right)/2;
      bool can_do_it=can_clear(nibutan);
      if(can_do_it) left = nibutan;
      else right = nibutan;
  }
}



int main(void){
    cin>>N>>M>>K;

    rep(i, N){
        cin>>A[i];
        if(i!=0) A[i]+=A[i-1];
    }
    rep(i, M){
        cin>>B[i];
        if(i!=0) B[i]+=B[i-1];
    }
    ll Maxim=0;
    deci=0;
    Maxim=max(Maxim, nibutan_max(0,M-1)+1);
    rep(i, N){
        deci=A[i];
        if(deci>K) break;
        Maxim=max(Maxim, i+1+nibutan_max(0,M-1)+1);
    }
        cout<<Maxim<<endl;
    return 0;
}


Measured memory_bytes: 6732
#include <bits/stdc++.h>
using namespace std;
//I must AC!!!!!!!!!!!!
typedef long long ll;
int main() {
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	if(x / k >= d) {
		cout << x - k * d << endl; 
	}
	else {
		ll ans = x % d;
		ll stp = (x - ans) / d;
		
		if((k - stp) % 2 == 1)ans = abs(ans - d);
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
  vector<int> v(3);
  cin>>v[0]>>v[1]>>v[2];
  vector<int> a={5,5,7};
  vector<int> b={5,7,5};
  vector<int> c={7,5,5};
  if(v==a||v==b||v==c){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  
}

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		var c = new LinkedList<char>();
		for(int i = 0; i < s.Length; i++)
		{
			c.AddLast(s[i]);
		}
		
		int cnt = 0;
		while(c.Count > 0)
		{
			if(c.First.Value == c.Last.Value)
			{
				c.RemoveFirst();
				if(c.Count > 0)
					c.RemoveLast();
			}
			else if(c.First.Value == 'x')
			{
				cnt++;
				c.RemoveFirst();
			}
			else if(c.Last.Value == 'x')
			{
				cnt++;
				c.RemoveLast();
			}
			else
			{
				Console.WriteLine(-1);
				return;
			}
		}
		Console.WriteLine(cnt);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


Measured memory_bytes: 21724
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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 = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    string s;
    cin >> s;
    int red = 0,blue = 0;
    int ans = 0;
    for(int i = 0;i < s.length();i++){
        if(s[i] == '1'){
            //青が来た
            if(red > 0){
                red--;
                ans += 2;
            }else{
                blue++;
            }
        }else{
            if(blue > 0){
                blue--;
                ans += 2;
            }else{
                red++;
            }
        }
    }
    //cout << red << " " << blue << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int a[] = new int[200];
		for (int i=A;i<B;i++) {
			a[i]++;
		}
		for (int i=C;i<D;i++) {
			a[i]++;
		}
		int count =0;
		for (int i=0;i<200;i++) {
			if (a[i]==2) {
				count ++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35568
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        v: [i32; n],
        c: [i32; n],
    }
    println!("{}",v.iter().zip(c.iter()).map(|(v, c)| v - c).filter(|&x| x > 0).sum::<i32>());
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}




int N;
int a[100010];

int main () {
  cin >> N;

  Rep(i, N) {
    int tmp; cin >> tmp; 
    a[tmp]++;
  }

  if (N % 2 == 1) {
    bool flg = true;

    if (a[0] != 1) flg = false;

    for (int k=2;k<N;k+=2) {
      if (a[k] != 2) {
        flg = false;
        break;
      }
    }

    if (flg) {
      ll ans = 1;
      Rep(i, (N-1)/2) {
        ans *= 2;
        ans %= MOD;
      }
      cout << ans << "\n";
    } else {
      cout << 0 << "\n";
    }
  } else {
    bool flg = true;

    for (int k=1;k<N;k+=2) {
      if (a[k] != 2) {
        flg = false;
        break;
      }
    }

    if (flg) {
      ll ans = 1;
      Rep(i, N/2) {
        ans *= 2;
        ans %= MOD;
      }
      cout << ans << "\n";
    } else {
      cout << 0 << "\n";
    }
  }
}

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

int main() {
    int S; cin >> S;
    while(S--) {
        int X, Y, W, H; cin >> X >> Y >> W >> H;
        int N; cin >> N;
        int res = 0;
        while(N--) {
            int x, y; cin >> x >> y;
            if(X <= x && x <= X + W && Y <= y && y <= Y + H) res++;
        }
        cout << res << endl;
    }
}

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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};

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

    if(A==B&&B==C){
        if(A%2==1) cout<<0<<endl;
        else cout<<-1<<endl;
        return 0;
    }
    int ans=0;
    while(A%2==0&&B%2==0&&C%2==0){
        ans++;
        ll sum=A+B+C;
        A=(sum-A)/2;
        B=(sum-B)/2;
        C=(sum-C)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

//dp[i][j]:コインをi枚投げたとき、表がj枚出る確率
long double dp[3000][3000];

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;cin >> N;
    vector<long double> coins(N);
    for(int i = 0;i<N;i++) cin >> coins.at(i);
    for(int i = 0;i<3000;i++) for(int j = 0;j<3000;j++) dp[i][j] = 0.0;
    dp[0][0] = 1.0;
    for(int i = 0;i<N;i++){
        for(int j = 0;j<=i;j++){
            dp[i+1][j] += dp[i][j]*(1.0-coins.at(i));
            dp[i+1][j+1] += dp[i][j]*coins.at(i);
        }
    }
    long double ans = 0.0;
    for(int j = 0;j<=N;j++){
        if(N-j < j){
            ans += dp[N][j];
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int lb = 1e5+1;
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        int b;
        cin >> b;
        ans += min(lb, b);
        lb = b;
    }
    ans += lb;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256