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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define scanf nope
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return x<p.x||(x==p.x && y<p.y);}
	bool operator==(P p) const { return x==p.x && y==p.y; }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P p1, P p2) const { return (p1 - *this).cross(p2 - *this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

typedef Point<double> P;
pair<vi, vi> ulHull(const vector<P>& S) {
    vector<int> Q(sz(S));
    iota(all(Q), 0);
    sort(all(Q), [&S](int a, int b){ return S[a] < S[b]; });
    vi U, L;
    trav(it, Q) {
        while (sz(U) > 1 && S[U[sz(U)-2]].cross(S[it], S[U.back()]) <= 0) U.pop_back();
        while (sz(L) > 1 && S[L[sz(L)-2]].cross(S[it], S[L.back()]) >= 0) L.pop_back();
        U.push_back(it);
        L.push_back(it);
    }
    return make_pair(U, L);
}

vi convexHull(const vector<P>& S) {
    vi u, l;
    tie(u, l) = ulHull(S);
    if (sz(S) <= 1) return u;
    u.pop_back();
    reverse(all(u));
    u.pop_back();
    u.insert(u.end(), all(l));
    if (sz(u) == 2 && S[u[0]] == S[u[1]]) u.pop_back();
    return u;
}

vector<pii> antipodal(const vector<P>& S, const vi& U, const vi& L) {
    vector<pii> A;
    int i = 0;
    int j = sz(L) - 1;
    while (i < sz(U) - 1 || j > 0) {
        A.emplace_back(U[i], L[j]);
        if (i == sz(U) - 1) --j;
        else if (j == 0) ++i;
        else if ((S[U[i+1]].y - S[U[i]].y) * (S[L[j]].x - S[L[j-1]].x) >
                 (S[U[i+1]].x - S[U[i]].x) * (S[L[j]].y - S[L[j-1]].y)) ++i;
        else --j;
    }
    return A;
}

pii polygonDiameter(const vector<P>& S) {
    vi U, L;
    tie(U, L) = ulHull(S);
    pair<double, pii> ans;
    trav(it, antipodal(S, U, L)) {
        ans = max(ans, make_pair((S[it.first] - S[it.second]).dist2(), it));
    }
    return ans.second;
}

int main() {
    int N;
    cin >> N;
        vector<P> P(N);
        rep(i,0,N) cin >> P[i].x >> P[i].y;
        pii ret = polygonDiameter(P);
        cout << setprecision(10) << fixed << (P[ret.first] - P[ret.second]).dist() << endl;
}

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

bool lead(int j, char leader) {
	int leadernum;

	if(leader == 'J')
		leadernum = 1;
	if(leader == 'O')
		leadernum = 2;
	if(leader == 'I')
		leadernum = 4;

	if(int(j & leadernum) == 0) {
		return false;
	} else {
		return true;
	}

}

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int n, i, j, k;
	char leader[1000];
	int dp[1000][8] = {0};
	int ans = 0;

	cin >> n >> leader;

	for(i = 0; i < n; i++) {
		for(j = 0; j < 8; j++) {
			if(i == 0) {
				if(int(j & 1) != 0 && lead(j, leader[i])) {
					dp[i][j] = 1;
				}
			} else {
				for(k = 0; k < 8; k++) {
					if(int(j & k) != 0 && lead(j, leader[i])) {
						dp[i][j] += dp[i-1][k];
						dp[i][j] %= 10007;
					}
				}
			}
		}
		
	}

	for(i = 0; i < 8; i++) {
		ans += dp[n-1][i];
		ans %= 10007;
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 1204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) {
		InputStreamReader in = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(in);
		try {
			String str = reader.readLine();
			int x = Integer.parseInt(str);

			if(x >= 1 && x <= 100){

				System.out.println(x*x*x);
			}
		} catch (IOException e) {
	
			e.printStackTrace();
		}



	}

}

Measured memory_bytes: 24328
#include <stdio.h>
int main(void)
{
    int i,j;
    int H,W;
    for(;;){
        scanf("%d %d",&W,&H);
        if(H+W==0) 
            break;
        for(i=0;i<W;i++){
            for(j=0;j<H;j++){
                if(i*j==0||i+1==W||j+1==H){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
from itertools import product
N, M = map(int,input().split())
cakes = []
for _ in range(N):
    cakes.append(list(map(int,input().split())))
ans = 0
for i, j, k in product([-1,1], repeat = 3):
    L = []
    for x, y, z in cakes:
        L.append(i * x + j * y + k * z)
    L.sort(reverse = True)
    ans = max(ans, sum(L[:M]))
    L.clear()
print(ans)

Measured memory_bytes: 3384
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
cost = 0
i = 0
while i<N:
    a,b = A[i]
    if cnt+b<=M:
        cnt += b
        cost += a*b
    else:break
    i += 1
if cnt<M:
    a,b = A[i]
    cost += (M-cnt)*a
print(cost)

Measured memory_bytes: 90936
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll h, w;
    cin >> h >> w;
    ll ans;
    if ((h * w) % 3 == 0) {
        ans = 0;
    }
    else {
        ans = (((h / 3) + 1) * w) - ((h / 3) * w);
        if ((((w / 3) + 1) * h) - ((w / 3) * h) < ans) {
            ans = (((w / 3) + 1) * h) - ((w / 3) * h);
        }
        for (ll i = 1; i <= h - 1; i++) {
            ll a = i * w;
            ll b = (h - i) * (w / 2);
            ll c = (h - i) * (w - (w / 2));
            if (max(max(a, b), c) - min(min(a, b), c) < ans) {
                ans = max(max(a, b), c) - min(min(a, b), c);
            } 
        }
        for (ll i = 1; i <= w - 1; i++) {
            ll a = i * h;
            ll b = (w - i) * (h / 2);
            ll c = (w - i) * (h - (h / 2));
            if (max(max(a, b), c) - min(min(a, b), c) < ans) {
                ans = max(max(a, b), c) - min(min(a, b), c);
            } 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def custom_round(number, ndigits=0):
    if type(number) == int:
        return number
    d_point = len(str(number).split('.')[1])
    if ndigits >= d_point:
        return number
    c = (10 ** d_point) * 2
    return round((number * c + 1) / c, ndigits)

N=int(input())
a=list(map(int,input().split()))
ans=0
ave=custom_round(sum(a)/N,0)
for i in range(N):
    ans+=(a[i]-ave)**2
print(int(ans))

Measured memory_bytes: 3064
#ABC125 B
# -*- coding: utf-8 -*-
#N
#a1 a2 a3 ... aN
N = int(input())
V_list = [int(e) for e in input().split()]
C_list = [int(e) for e in input().split()]

ans=0

for i in range(N):
  if V_list[i]-C_list[i] > 0:
    ans=ans+V_list[i]-C_list[i]
    
print(ans)

Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val Hsum :Long = readLine()!!.split(" ")
        .map { it.toInt() }
        .sortedByDescending { it }
        .drop(K)
        .sumByLong { it.toLong() }
    println("$Hsum")
}

inline fun <T> Iterable<T>.sumByLong(selector: (T) -> Long): Long {
    var sum = 0L
    for (element in this) {
        sum += selector(element)
    }
    return sum
}

Measured memory_bytes: 109680
import numpy as np

N,T = map(int, input().split())
item = [None]*N
for i in range(N):
  w,v = map(int,input().split())
  item[i] = [w,v]
item.sort(key=lambda x:x[0])

dp = np.zeros(T, dtype=int)
ans=0
for i in range(N):
    w,v=item[i]
    ans=max(ans,dp.max()+v)
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
print(ans)

Measured memory_bytes: 12584
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    string n;
    cin >> n;
    int counter = 0;
    string ans = "No";
    for (size_t i = 0; i < n.size(); i++)
    {
        if(n[i]==n[i+1])counter++;
        else counter = 0;
        if(counter == 2) {
            ans = "Yes";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin >> n >> d;
    int x[n][d];
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < d;j++)
        {
            int a;
            cin >> a;
            x[i][j] = a;
        }
    }
    int count = 0;
    for(int i = 0;i < n;i++)
    {
        for(int j = i + 1;j < n;j++)
        {
            double distance = 0;
            for(int k = 0;k < d;k++)
            {
                distance += pow(fabs(x[i][k] - x[j][k]),2);
            }
            if(sqrt(distance) == int(sqrt(distance)))
            {
                count++;
            }
        }
    }
    cout << count;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a[10000],i,n,min,max;
	long sum;
	
	scanf("%d",&n);
	scanf("%d",&a[0]);
	min = a[0];
	max = a[0];
	sum = a[0];
	
	for(i=1;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]<min) min = a[i];
		if(a[i]>max) max = a[i];
		sum = sum + a[i];
	}
		
	printf("%d %d %ld\n",min,max,sum);

	return 0;
}

Measured memory_bytes: 1864
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();

		for (int i = 0; i < m; i++) {
			String str = sc.next();
			HashSet<String> hs = new HashSet<String>();

			for (int t = 1; t < str.length(); t++) {
				String a = str.substring(0, t);
				String b = str.substring(t, str.length());
				String ra = Reverse(a);
				String rb = Reverse(b);

				hs.add(a + b);
				hs.add(a + rb);
				hs.add(ra + b);
				hs.add(ra + rb);
				hs.add(b + a);
				hs.add(b + ra);
				hs.add(rb + a);
				hs.add(rb + ra);

			}
			System.out.println(hs.size());
		}

		sc.close();
	}

	public static String Reverse(String s) {
		StringBuffer sb = new StringBuffer(s);
		s = sb.reverse().toString();
		return s;
	}
}

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

int main() {
  int h, n, a, total = 0;
  cin >> h >> n;
  rep(i, n) {
    cin >> a;
    total += a;
  }
  cout << (h <= total ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll n,a[5];
    cin>>n;
    rep(i,5) cin>>a[i];
    ll p = 0;
    rep(i,5) maxch(p,n/a[i]+(n%a[i]==0?0:1));
    cout<<p+4<<endl;
    return 0;
}

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

using ll = long long;

int n;
ll a[200005], b[200005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];

	sort(a, a + n);
	sort(b, b + n);

	if (n & 1) {
		cout << b[n / 2] - a[n / 2] + 1 << endl;
		return 0;
	}

	for (int i = 0; i < n; ++i) a[i] *= 2, b[i] *= 2;


	ll ma1 = a[n / 2 - 1], ma2 = a[n / 2];
	ll mb1 = b[n / 2 - 1], mb2 = b[n / 2];

	ll ki = (ma1 + ma2) / 2;
	ll ka = (mb1 + mb2) / 2;

	cout << ka - ki + 1 << endl;

	return 0;
}

Measured memory_bytes: 6740
# coding: utf-8
# Your code here!
s=input()

alpha=[chr(i+97) for i in range(26)]
ans=[]

for chara in alpha:
    temp=s
    while len(temp)>temp.count(chara):
        rna=""
        for i in range(len(temp)-1):
            if temp[i+1]==chara:
                rna+=(temp[i+1])
            elif temp[i]==chara:
                rna+=(temp[i])
            else:
                rna+=(temp[i+1])
        temp=rna
        #print(temp)
    ans.append(len(s)-len(temp))

print(min(ans))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<n-2;i++)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}







Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    m = N % 1000
    if m == 0:
        print(0)
    else:
        print(1000 - m)


if __name__ == '__main__':
    main()

Measured memory_bytes: 72772
#include<stdio.h>

int main(void){

float w;

while(scanf("%f",&w) != EOF){

if(w<=48.00){
printf("light fly\n");
}
else if(w>48.00 && w<=51.00){
printf("fly\n");
}
else if(w>51.00 && w<=54.00){
printf("bantam\n");
}
else if(w>54.00 && w<=57.00){
printf("feather\n");
}
else if(w>57.00 && w<=60.00){
printf("light\n");
}
else if(w>60.00 && w<=64.00){
printf("light welter\n");
}
else if(w>64.00 && w<=69.00){
printf("welter\n");
}
else if(w>69.00 && w<=75.00){
printf("light middle\n");
}
else if(w>75.00 && w<=81.00){
printf("middle\n");
}
else if(w>81.00 && w<=91.00){
printf("light heavy\n");
}
else if(w>91.00){
printf("heavy\n");
}
}
return 0;
}



Measured memory_bytes: 2044
#include<iostream>
#include<algorithm>
#include<vector>
typedef long long int ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;

int n, q;
int ans = 0;

int main() {
	cin >> n;
	vector<int> S(n);
	rep(i, 0, n)cin >> S[i];
	cin >> q;
	vector<int> T(q);
	rep(i, 0, q) {
		cin >> T[i];
		int left = 0;
		int right = n;
		int mid;
		while (left < right) {
			mid = (left + right) / 2;
			if (T[i] == S[mid]) {
				ans++;
				break;
			}
			if (T[i] > S[mid]) {
				left = mid + 1;
			}
			if (T[i] < S[mid]) {
				right = mid;
			}
		}
	}
	
	cout << ans << endl;

	return 0;
}


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

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

  rep(i, 3) {
    if (n.at(i) == '7') {
      cout << "Yes" << endl;
      return 0;
      }
    }
    cout << "No" << endl;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;







int main() {

	int n;
	cin >> n;
	VLL v(n);
	REP(i, n)cin >> v[i];
	VLL x = v;

	ll sum = 0;
	REP(i, n)sum += v[i];
	sum /= 2;
	FOR(i, 1, n) {
		sum -= v[i];
		i++;
	}
	VLL ans(n);
	ans[0] = sum;
	REP(i, n-1) {
		ans[i + 1] = v[i] - ans[i];
	}

	REP(i, n)cout << ans[i] * 2 << ' ';

	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;cin >> x;
	vector<int> a(4);
	for(int i = 3; i >= 0; i--){
		a.at(i) = x % 10;
		x /= 10;
	}
	rep(i,(1 << 3)){
		int sum = a.at(0);
		vector<char> c(3);
		rep(j,3){
			if((1 << j) & i){
				sum += a.at(j + 1);
				c.at(j) = '+';
			}
			else{
				sum -= a.at(j + 1);
				c.at(j) = '-';
			}
		}
		if(sum == 7){
			cout << a.at(0) << c.at(0) << a.at(1) << c.at(1) << a.at(2) << c.at(2) << a.at(3) << "=7" << endl;
			return 0;
		}
	}
}


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

struct treasure {
	int w;
	int v;
	void operator+=(treasure t){
		*this = *this + t;
	}
	treasure operator+(treasure t){
		treasure tt;
		tt.v = this->v + t.v;
		tt.w = this->w + t.w;
		return tt;
	}
};

struct treasure t[1000];
struct treasure dp[1001][1001];
int n;

treasure max(treasure a, treasure b){
	if(a.v == b.v){
		return a.w <= b.w ? a : b;
	}else{
		return a.v >= b.v ? a : b;
	}
}

treasure calc(int i, int w){
	if(dp[i][w].v >=0){ return dp[i][w]; }
	struct treasure res;
	if(i == n){
		res.v = 0;
		res.w = 0;
	}else if(w < t[i].w){
		res += calc(i+1, w);
	}else{
		res = max(calc(i+1, w), calc(i+1, w-t[i].w) + t[i]);
	}
	return dp[i][w] = res;
}

int main(void){
	int w, c=1;
	struct treasure res;
	while(true){
		scanf("%d", &w);
		if(w == 0){ break; }
		scanf("%d", &n);
		for(int i=0; i<n; ++i){
			scanf("%d,%d", &(t[i].v), &(t[i].w));
		}
		memset(dp, -1, sizeof(dp));

		res = calc(0, w);
		printf("Case %d:\n", c++);
		printf("%d\n", res.v);
		printf("%d\n", res.w);
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    string a, b;
    cin >> a >> b;
    int ok = 1;
    if (a == "D")
        ok ^= 1;
    if (b == "D")
        ok ^= 1;
    if (ok)
        cout << "H"
             << "\n";
    else
        cout << "D"
             << "\n";
    return 0;
}

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

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

  int k, x;
  cin >> k >> x;

  string ans;
  if (500 * k >= x) {
    ans = "Yes";
  } else {
    ans = "No";
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from bisect import bisect_left
def resolve():
    N = ir()
    a = lr()
    tr = [[] for _ in range(N)]
    for i in range(N-1):
        u, v = lr()
        tr[u-1].append(v-1)
        tr[v-1].append(u-1)
    INF = pow(10, 9)+1
    lis = [INF]*N
    lis[0] = a[0]
    ans = [0]*N
    ans[0] = 1
    def dfs(v, p=-1):
        for u in tr[v]:
            if u == p:
                continue
            idx = bisect_left(lis, a[u])
            prev = lis[idx]
            lis[idx] = a[u]
            ans[u] = bisect_left(lis, INF)
            dfs(u, v)
            lis[idx] = prev
    dfs(0)
    print(*ans, sep='\n')
resolve()

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a.at(i);
        a.at(i)--;
    }
    int ans = 0;
    rep(i,n) if (i == a.at(a.at(i))) ans++;
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

int main() {
  string s;
  cin >> s;

  int y = stoi(s.substr(0, 4));
  int m = stoi(s.substr(5, 2));
  int d = stoi(s.substr(8, 2));

  if (y <= 2019) {
    if (m <= 4) {
      if (d <= 30) {
        puts("Heisei");
        return 0;
      }
    }
  }
  puts("TBD");

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a[100000];
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	a[0]--;
	if(n==1)
	{
		cout<<"Yes";
		return 0;
	}
	for(int i=0;i<n-1;i++)
	{
		if(a[i]>a[i+1]){	
			cout<<"No";
			return 0;
		}
		if(a[i]<a[i+1]) a[i+1]--; 
	}
	cout<<"Yes";
	return 0;
}


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

typedef pair<string, pair<int, int>> dic;
dic dics[100];

int main() {
  int N;
  cin >> N;
  string s;
  int p;
  rep(i, N) {
    cin >> s;
    cin >> p;
    dics[i] = make_pair(s, make_pair(-p, i+1));
  }
  sort(dics, dics+N);
  rep(i, N) {
    cout << dics[i].second.second << endl;
  }
  return 0;
}



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

int main(int argc, char const *argv[])
{
	int a, b, c; cin >> a >> b >> c;
	cout << (a * b) / 2 << endl;
	return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<int> p(M);
    string S[M];
    int wa[100010] = {0};
    int ac[100010] = {0};
    int ans_ac = 0, ans_wa = 0;
    for(int i = 0; i < M; ++i) {
        cin >> p[i] >> S[i];
        if(S[i] == "WA") ++wa[p[i]];
        if(S[i] == "AC") {
            if(ac[p[i]] == 0) {
                ans_wa += wa[p[i]];
                ++ac[p[i]];
                ans_ac += ac[p[i]];
            }
        }
    }
    
    cout << ans_ac << " " << ans_wa << endl;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=50050;

char s[maxn];
int main(){
    int n;
    scanf("%d", &n);

    if (n < 1200)  puts("ABC");
    else if (n < 2800)  puts("ARC");
    else if (n < 1000000)  puts("AGC");
    return 0;
}


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

int main()
{
    int A, B, C, D, x, y;

    scanf("%d%d%d%d", &A, &B, &C, &D);

    if(A > D)
    {
       x = D*1;
    }
    else if(A + B > D)
    {
        x = A*1;
    }
    else
    {
        y = D - (A + B);
        x = A*1 + y*(-1);
    }

    printf("%d\n" , x);

    return 0;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005
int ALL[NUM],EACH[30][NUM];


int main(){

	for(int i = 0; i < NUM; i++){

		ALL[i] = 0;
		for(int k = 0; k < 30; k++){
			EACH[k][i] = 0;
		}
	}

	int N,C;
	scanf("%d %d",&N,&C);

	int left,right,channel;

	for(int loop = 0; loop < N; loop++){

		scanf("%d %d %d",&left,&right,&channel);

		channel--;

		EACH[channel][left] += 1;
		EACH[channel][right] -= 1;
	}

	for(int channel = 0; channel < C; channel++){

		//チェンネル毎の累積和
		for(int i = 1; i < NUM; i++){

			EACH[channel][i] += EACH[channel][i-1];
		}

		for(int i = NUM-1; i >= 1; i--){
			if(EACH[channel][i] == 0 && EACH[channel][i-1] == 1){

				EACH[channel][i] = 1; //末尾を1伸ばす
			}
		}
		for(int i = 0; i < NUM; i++){
			ALL[i] += EACH[channel][i];
		}
	}

	int ans = 1;

	for(int i = 1; i < NUM; i++){

		ans = max(ans,ALL[i]);
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 12416
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))

k=0
m=100000000000000
for i in range(1,n+1):
    b=a-t+h[i-1]*0.006
    if m>abs(b):
        m=abs(b)
        k=i


print(k)        
        

Measured memory_bytes: 9084
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int a,b,c,d;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b>>c>>d;
	while(1){
		c-=b;
		if(c<=0){
			cout<<"Yes"<<endl;
			return 0;
		}
		a-=d;
		if(a<=0){
			cout<<"No"<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3612
n = int(input())
al = list(map(int, input().split()))
r = range(len(al)-1)

c = 0
for i in r:
    a_prev = al[i]
    a_next = al[i+1]
    if a_prev > a_next:
        diff = a_prev - a_next
        c += a_prev - a_next
        al[i+1] += diff

print(c)


Measured memory_bytes: 32384
class PriorityQueue
    def initialize(arr)
        @size = arr.size
        @array = arr
        @array.unshift(nil)
        h = (@size / 2) | 0
        h.downto(1) do |i|
            maxHeapify(i)
        end
    end
    def getArray
        return @array[1..@size]
    end
    def maxHeapify(i)
        left = 2 * i
        right = 2 * i + 1
        largest = 0
        if left <= @size && @array[left] > @array[i]
            largest = left
        else
            largest = i
        end
        if right <= @size && @array[right] > @array[largest]
            largest = right
        end
        if largest != i
            @array[i], @array[largest] = @array[largest], @array[i]
            maxHeapify(largest)
        end
    end
    def pop
        return -(1<<29) if @size < 1
        maxv = @array[1]
        @array[1] = @array[@size]
        @size -= 1
        maxHeapify(1)
        maxv
    end
    def push(e)
        @size += 1
        i = @size
        @array[i] = -(1<<29)
        return if e < @array[i]
        @array[i] = e
        while i > 1 && @array[i/2] < @array[i]
            @array[i], @array[i/2] = @array[i/2], @array[i]
            i = i / 2
        end
    end
end

n, m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
pq = PriorityQueue.new(a)
m.times do |i|
    largest = pq.pop
    largest = largest / 2
    pq.push(largest)
end

print pq.getArray.inject(:+)

Measured memory_bytes: 10124
race1 = {}
for i in range(8):
    p, t = input().split()
    race1[int(p)] = float(t)
race2 = {}
for i in range(8):
    p, t = input().split()
    race2[int(p)] = float(t)
race3 = {}
for i in range(8):
    p, t = input().split()
    race3[int(p)] = float(t)
for p,t in sorted(race1.items(), key = lambda x: x[1])[:2]:
    print(p,race1.pop(p))
for p,t in sorted(race2.items(), key = lambda x: x[1])[:2]:
    print(p,race2.pop(p))
for p,t in sorted(race3.items(), key = lambda x: x[1])[:2]:
    print(p,race3.pop(p))
race1.update(race2)
race1.update(race3)
for p,t in sorted(race1.items(), key = lambda x: x[1])[:2]:
    print(p,race1.pop(p))


Measured memory_bytes: 5624
#include <cassert>
#include <cstdio>
#include <functional>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

constexpr int inf = 1e9+7;
int main() {
    int n; scanf("%d", &n);
    vector<vector<pair<int, int> > > g(n);
    repeat (i, n - 1) {
        int a, b, c; scanf("%d%d%d", &a, &b, &c); -- a; -- b;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
    vector<int> size(n);
    ll result = 0;
    int offset = inf;
    int centroid = -1;
    int min_centroid_weight = inf;
    function<void (int, int)> go = [&](int i, int parent) {
        size[i] = 1;
        int centroid_weight = 0;
        for (auto edge : g[i]) {
            int j, edge_weight; tie(j, edge_weight) = edge;
            if (j == parent) continue;
            go(j, i);
            size[i] += size[j];
            int s = min(size[j], n - size[j]);
            result += edge_weight * 2ll * s;
            if (2 * s == n) {
                offset = edge_weight;
            }
            setmax(centroid_weight, size[j]);
        }
        setmax(centroid_weight, n - size[i]);
        if (centroid_weight < min_centroid_weight) {
            min_centroid_weight = centroid_weight;
            centroid = i;
        }
    };
    go(0, -1);
    if (offset == inf) {
        for (auto edge : g[centroid]) {
            int edge_weight = edge.second;
            setmin(offset, edge_weight);
        }
    }
    result -= offset;
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
#define int long long

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

  int n,m; cin >> n >> m;
  cout << (m*1900+(n-m)*100) * pow(2,m) << endl;

  return 0;
}


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MOD = (int) 1e9 + 7;

const int MAXN = 50;

int n;

int a[MAXN * 2 + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= 2 * n - 1; ++i) a[i] = read<int>();
}

inline void solve()
{
	static int f[MAXN + 5][MAXN * 2 + 5][MAXN * 2 + 5];

	sort(a + 1, a + 2 * n);

	f[n][1][0] = 1;
	for(int i = n - 1; i >= 1; --i)
	{
		int pl = a[i] != a[i + 1], pr = a[2 * n - i - 1] != a[2 * n - i];
		for(int l = 0; l <= 2 * n - 1; ++l) for(int r = 0; l + r <= 2 * n - 1; ++r) if(f[i + 1][l][r])
		{
			for(int k = 1; k <= l + pl; ++k) (f[i][l + pl - k + 1][r + pr + (k > 1)] += f[i + 1][l][r]) %= MOD;
			for(int k = 1; k <= r + pr; ++k) (f[i][l + pl + 1][r + pr - k] += f[i + 1][l][r]) %= MOD;
		}
	}

	int ans = 0;
	for(int l = 0; l <= 2 * n - 1; ++l) for(int r = 0; l + r <= 2 * n - 1; ++r)
		(ans += f[1][l][r]) %= MOD;
	printf("%d\n", (ans + MOD) % MOD);
}

int main()
{

	input();
	solve();

	return 0;
}



Measured memory_bytes: 1408
n,k = (int(x) for x in input().split())
list = list(map(int, input().split()))
max=0
list2=[0]
for i in range(n):
	list2.append(list2[i]+list[i])
for i in range(n-k+1):
	if max < list2[i+k] - list2[i]:
		max=list2[i+k]-list2[i]
print((max+k)/2)

Measured memory_bytes: 25604
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int n,m;
int hako[11111];
int main(){
  cin>>n>>m;
  int a,b;
  vector<pii> p;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    p.pb(pii(a,b));
  }

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

  int l,r;
  l=p[0].first;
  r=p[0].second;
  int res=0;
  //printf(";;%d %d\n",l,r);
  for(int i=1;i<m;i++){
    if(p[i].first>=r){
      res++;
      l=p[i].first;
      r=p[i].second;
    }
    else{
      l=max(l,p[i].first);
      r=min(r,p[i].second);
    }
  }
  cout<<res+1<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 
int main() {
    int n = 0;
    cin >> n;
    vector<int> b(n+1);
    for (int i=1; i<n+1; i++) {
        cin >> b.at(i);
    }
    vector<int> ans;
    for (int i=n; i>=1; i--) {
        bool flag = false;
        for (int j=i; j>=1; j--) {
            if (j == b.at(j)) {
                ans.push_back(j);
                b.erase(b.begin() + j);
                flag = true;
                break;
            }
        }
        if (!flag) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    for (int x : ans) {
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
e,y=map(int,input().split())
ei=[0,1867,1911,1925,1988]
if e==0:
    if y>1988:
        print(f'H{y-1988}')
    elif y>1925:
        print(f'S{y-1925}')
    elif y>1911:
        print(f'T{y-1911}')
    else:
        print(f'M{y-1867}')
else:
    print(ei[e]+y)


Measured memory_bytes: 5612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] str = br.readLine().split(" ");
		int k = Integer.parseInt(str[0]);
		int s = Integer.parseInt(str[1]);
		int cnt = 0;

		int x = 0;
		int y = 0;
		int z = 0;
		for(x = k; x > -1; --x){
			int rest = s - x;
			if(rest > 2*k || rest < 0)
				continue;
			if(rest > k){
				cnt += -(rest - 2*k) + 1;
			}else{
				cnt += rest + 1;
			}
		}
		sb.append(cnt);
		System.out.println(sb);
	}
}

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

const int MAX = 100003;
int Map[26][MAX];

int main(){
	string s,t;
	cin>>s>>t;
	long long ans = 0;
	for(int i = 0; i < 26; i++)
              Map[i][s.length()] = -1;
	for(int i = s.length()-1 ; i >=0; i-- ){
		for(int j = 0; j < 26; j++){
			Map[j][i] = Map[j][i+1];
		}
		Map[s[i]-'a'][i] = i;
	}
 
	int flag = 0;
	int wz = 0;
	for(int i = 0; i < t.length(); i++){
		if(wz == 0 && Map[t[i]-'a'][wz] == -1){
			flag = 1;
			break;
		}
		else{
			if( Map[t[i]-'a'][wz] != -1 ){
				ans+=Map[t[i]-'a'][wz]-wz+1;
				wz = Map[t[i]-'a'][wz]+1;
			}
			else{
				ans+=s.length()-wz;
				wz = 0;
				i--;
			}
		}
	}
	if(flag)
		cout<<-1;
	else
		cout<<ans;
	return 0;
}

Measured memory_bytes: 10752
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N;
int main(){

  set<int> st;
  cin>>N;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(st.size()<11){
      st.insert(a);
    }
    else{
      st.erase(*(--st.end()));
      st.insert(a);
    }
  }
  vector<int> v=vector<int>(st.begin(),st.end());
  vector<ll> res;
  for(int i=0;i<(int)v.size();i++){
    for(int j=0;j<(int)v.size();j++){
      if(i==j)continue;
      string s1=IntToString(v[i]);
      string s2=IntToString(v[j]);
      string s=s1+s2;
      ll b=StringToInt<ll>(s);
      res.push_back(b);
    }
  }
  sort(res.begin(),res.end());
  cout<<res[2]<<endl;
  
  return 0;
}

Measured memory_bytes: 1252
#include<stdio.h>
int main(){
  long int A[300][300],B[300][300],n,i,j,k,t,x=0;
  scanf("%ld",&n);
  for(i=0;i<n;i++)for(j=0;j<n;j++){scanf("%ld",&A[i][j]);B[i][j]=A[i][j];}
  for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(B[i][j]>B[i][k]+B[k][j])B[i][j]=B[i][k]+B[k][j];
  for(i=0;i<n;i++)for(j=0;j<n;j++)if(A[i][j]!=B[i][j]){printf("-1");return 0;}
  for(i=0;i<n;i++)for(j=i+1;j<n;j++){t=1;for(k=0;k<n;k++)if(i!=k&&j!=k&&A[i][j]==A[i][k]+A[k][j])t=0;if(t)x+=A[i][j];}
  printf("%ld",x);
}


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

#ifndef LOCAL
#define fprintf if(false) fprintf
#endif
#define debug_int(x) fprintf(stderr, "%s = %d\n", #x, x)
#define debug_double(x) fprintf(stderr, "%s = %llf\n", #x, x)
#define debug_array(v,n) fprintf(stderr, "%s = [ ", #v); for(int i=0; i<n; i++) fprintf(stderr, "%d ", v[i]); fprintf(stderr, "]\n")
#define forr(i,start,end) for(int i=start; i<end; i++)
#define PI 3.14159265358979323846264338

using lli = long long int;
using ii = pair<int, int>;

const int MAXN = 100010;

int main() {
    int hl, ml; // a b
    int h, m;
    scanf("%d %d %d %d", &hl, &ml, &h, &m);

    double h_angle = h*30 + double(m)/2.0;
    double m_angle = 6*m;
    // printf("%.2lf, %.2lf\n", h_angle, m_angle);

    pair<double, double> hour = {sin(h_angle*PI/180.0)*hl, cos(h_angle*PI/180.0)*hl};
    pair<double, double> min = {sin(m_angle*PI/180.0)*ml, cos(m_angle*PI/180.0)*ml};
    // printf("%.2lf, %.2lf\n", hour.first, hour.second);
    printf("%.18lf\n", sqrt(pow(hour.first - min.first, 2) + pow(hour.second - min.second, 2)));
}


Measured memory_bytes: 4152
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

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

int main(){
    int n;
    cin >> n;
    vi c(n);
    vi v(n);
    for(auto && x:v)cin >> x;
    for(auto && x:c) cin >> x;
    int ret = 0;
    for(int i=0;i<n;i++){
        ret += max(v[i] - c[i], 0);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, x[MAXN], L, T;
int cur;
pair<int, int> a[MAXN];
int main(){
    int _;// scanf("%d", &_);
    _ = 1;
    for(int CA = 1; CA <= _; ++CA){
        scanf( "%d%d%d", &n, &L, &T );
        for(int i = 0; i < n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
        pair<int, int> tmp;
        sort(a, a + n);
        cur = lower_bound(a, a + n, tmp) - a;
        for( int i = 0 ; i < n ; i++ )
            if(a[i].second == 1 ){
                x[ i ] = ( a[i].first + T ) % L;
                cur += ( a[i].first + T ) / L;
            }
            else{
                x[ i ] = ( a[i].first - T ) % L;
                cur += ( a[i].first - T ) / L;
                if( x[ i ] < 0 ) x[ i ] += L, cur--;
            }
        cur = ( cur % n + n ) % n;
        sort( x, x + n );
        for(int i = cur; i < n; ++i)printf("%d\n", x[i]);
        for(int i = 0; i < cur; ++i)printf("%d\n", x[i]);
       // printf("%d\n", x[cur]);
    }
}


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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input();
		var n = p[0].ToLong();
		var k = p[1].ToLong();
		
		var ary = new long[100000+2];
		
		for(int i = 0; i < n; i++)
		{
			var q = Input();
			ary[q[0].ToLong()]+=q[1].ToLong();
		}
		long index=k;
		for(int i = 0; i < ary.Length; i++)
		{
			index -= ary[i];
			if(index <= 0)
			{
				Console.WriteLine(i);
				return;
			}
		}
	}
	

	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 int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

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)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



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

int main () {
    string s;
  	cin >> s;
    int count = 0;
    vector<char> vec_forward(s.size() / 2);
    for (int i = 0; i < s.size() / 2; i++)
    {
        vec_forward.at(i) = s.at(i);
    }
    vector<char> vec_backward(s.size() / 2);
    for (int i = 0; i < s.size() / 2; i++)
    {
        vec_backward.at(i) = s.at(s.size() - i -1);
    }

    for (int i = 0; i < s.size() / 2; i++)
    {
        if (vec_forward.at(i) == vec_backward.at(i))
        {
            continue;
        }

        else
        {
            count++;
        }
        
    }

    cout << count << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque


def kenkenpa(s, visited):
    res = []
    for v1 in e[s]:
        if visited[v1][1]:
            continue
        visited[v1][1] = True
        for v2 in e[v1]:
            if visited[v2][2]:
                continue
            visited[v2][2] = True
            for v3 in e[v2]:
                if visited[v3][0]:
                    continue
                visited[v3][0] = True
                res.append(v3)
    return res


N, M = map(int, input().split())
e = defaultdict(list)
for i in range(M):
    u, v = map(int, input().split())
    e[u].append(v)

S, T = map(int, input().split())
q = deque([[S, 0]])
visited = [[False]*3 for _ in range(N+1)]
visited[S][0] = True
ans = -1
while q:
    u, c = q.popleft()
    if u == T:
        ans = c
        break
    l = kenkenpa(u, visited)
    for v in l:
        q.append([v, c+1])
print(ans)


Measured memory_bytes: 40408
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn read_pair() -> (i64, i64) {
    let s = read_line();
    let mut it = s.split_whitespace().map(|s| s.parse().unwrap());
    let h = it.next().unwrap();
    let w = it.next().unwrap();
    (h, w)
}

fn main() {
    let (n, k) = read_pair();
    let ps: Vec<_> = (0..n).map(|_| read_pair()).collect();

    let mut ans = i64::max_value();

    let (mut xs, mut ys): (Vec<_>, Vec<_>) = ps.iter().cloned().unzip();
    xs.sort();
    ys.sort();

    for ix1 in 0..xs.len() {
        for ix2 in (ix1 + 1)..xs.len() {
            for iy1 in 0..ys.len() {
                for iy2 in (iy1 + 1)..ys.len() {
                    let x1 = xs[ix1];
                    let x2 = xs[ix2];
                    let y1 = ys[iy1];
                    let y2 = ys[iy2];

                    let cnt = ps.iter()
                        .filter(|&&(x, y)| x1 <= x && x <= x2 && y1 <= y && y <= y2)
                        .count();
                    // let mut cnt = 0;
                    // for &(x, y) in ps.iter() {
                    //     if x1 <= x && x <= x2 && y1 <= y && y <= y2 {
                    //         cnt += 1;
                    //         if cnt >= k {
                    //             break;
                    //         }
                    //     }
                    // }

                    if cnt >= k as usize {
                        ans = std::cmp::min(ans, (x2 - x1) * (y2 - y1));
                    }
                }
            }
        }
    }

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


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c <= b) {
    cout << "delicious" << endl;
  }
  if (c > b && c <= a+b) {
    cout << "safe" << endl;
  }
  if (c > a+b) {
    cout << "dangerous" << endl;
  }
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  S[K-1] = tolower(S[K-1]);
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
struct edge{int to,cost;};
vector<int> G[100005];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
std::vector<P> tree[100010];
ll i,j;

ll n;
ll a[100005]={1,3,5,7,8,9,10,13},b[100005],c[100005];
int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		cin>>b[i];
	}
	for(i=0;i<n;i++){
		cin>>c[i];
	}
	sort(a,a+n);
	sort(c,c+n);
	ll aa=0,cc=0;
	ll ans=0;
	for(i=0;i<n;i++){
		aa=lower_bound(a,a+n,b[i])-lower_bound(a,a+n,0);
		cc=upper_bound(c,c+n,b[i])-upper_bound(c,c+n,0);
		ans += aa*(n-cc);
		aa=cc=0;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 7296
n, m = map(int, raw_input().split())
red = []
blue = []

for i in range(n):
    row = raw_input()
    r = ['#']
    b = ['.']
    for j in range(1, m - 1):
        if row[j] == '#':
            r.append('#')
            b.append('#')
        else:
            if i % 2 == 0:
                r.append('#')
                b.append('.')
            else:
                r.append('.')
                b.append('#')
    r.append('.')
    b.append('#')
    red.append(''.join(r))
    blue.append(''.join(b))

for r in red:
    print(r)
for b in blue:
    print(b)


Measured memory_bytes: 3716
N = int(input())
H = list(map(int, input().split()))

ans = 'Yes'
for i in range(1, N):
  if H[N-i-1]-1 == H[N-i]:
    H[N-i-1] -= 1
  elif H[N-i-1]-1 > H[N-i]:
    ans = 'No'
    break
    
print(ans)

Measured memory_bytes: 20656