akhauriyash/Code-Regression huggingface dataset:
(defun calc-next-rest (a b rest)
  (let ((a- (if (> a rest) (- a rest) 0)))
    (if (> b a-) (- b a-) 0)))

(defun calc-killed (a b rest)
  (let ((b+ (+ b rest)))
    (min a b+)))

(defun attack (la lb rest ret)
  (if (null la)
      ret
      (let ((a (car la))
            (b (car lb)))
        (attack (cdr la)
                (cdr lb)
                (calc-next-rest a b rest)
                (+ ret (calc-killed a b rest))))))

(defun main ()
  (let* ((n (read))
         (la (loop :repeat (1+ n)
                   :for a = (read)
                   :collect a))
         (lb (append (loop :repeat n
                           :for b = (read)
                           :collect b)
                     '(0))))
    (format t "~A~%" (attack la lb 0 0))))

(main)


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

int left(int);
int right(int);
void maxHeapify(int *, int);
void buildMaxHeap(int *);

int n;

int main(){
        int *A;
        int i;

        scanf("%d", &n);
        A = malloc(n * sizeof(int));

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

        buildMaxHeap(A);

        for(i = 0 ; i < n ;i++){
                printf(" %d", A[i]);
        }
        printf("\n");

        return 0;
}

int left(int i){
        return i * 2 + 1;
}

int right(int i){
        return i * 2 + 2;
}

void maxHeapify(int *A, int i){
        int l, r, largest, buf;
        l = left(i);
        r = right(i);
        if(l < n && A[l] > A[i])
                largest = l;
        else
                largest = i;
        if(r < n && A[r] > A[largest])
                largest = r;

        if(largest != i){
                buf = A[i];
                A[i] = A[largest];
                A[largest] = buf;
                maxHeapify(A, largest);
        }
}

void buildMaxHeap(int *A){
        int i;
        for(i = n/2 ; i >= 0 ; i--){
                maxHeapify(A, i);
        }
}



Measured memory_bytes: 3684
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<int, int> PP;

double EPS = 1e-10;

double add(double a, double b){
	if(abs(a + b) < EPS * (abs(a) + abs(b))){
		return 0;
	}
	return a + b;
}

struct P{
	double x, y;
	P(){}
	P(double x, double y) : x(x), y(y){}
	P operator + (P p){
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p){
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d){
		return P(x * d, y * d);
	}
	double dot(P p){
		return add(x * p.x, y * p.y);
	}
	double det(P p){
		return add(x * p.y, -y * p.x);
	}
};

// x -> y の順で比較
bool cmp_x(const P& p, const P& q){
	if(p.x != q.x){
		return p.x < q.x;
	}
	return p.y < q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps, ps + n, cmp_x);
	int k = 0; // 凸包の頂点数
	vector<P> qs(n * 2); // 構築中の凸包
	
	// 上側凸包の作成
	for(int i = 0; i < n; i++){
		while(k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0){
			k--;
		}
		qs[k++] = ps[i];
	}
	
	// 下側凸包の作成
	for(int i = n - 2, t = k; i >= 0; i--){
		while(k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0){
			k--;
		}
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

int N;
P ps[1000];
P ps_b[1000];

int main(){
	
	cin >> N;
	
	map<PP, double> m;
	
	for(int i = 0; i < N; i++){
		cin >> ps[i].x >> ps[i].y;
		ps_b[i].x = ps[i].x;
		ps_b[i].y = ps[i].y;
		PP p;
		p.first = ps[i].x;
		p.second = ps[i].y;
		m[p] = 0;
	}
	
	vector<P> qs = convex_hull(ps, N);
	qs.push_back(qs[0]);
	qs.push_back(qs[1]);
	
	vector<P> norm;
	
	for(int i = 0; i < qs.size() - 1; i++){
		P p;
		p.x = qs[i + 1].y - qs[i].y;
		p.y = -(qs[i + 1].x - qs[i].x);
		norm.push_back(p);
		//cout << atan2(p.y, p.x) << endl;
		//cout << qs[i].x << " " << qs[i].y << endl;
	}
	
	for(int i = 0; i < norm.size() - 1; i++){
		double ret = (atan2(norm[i + 1].y, norm[i + 1].x) - atan2(norm[i].y, norm[i].x)) / M_PI / 2;
		if(ret > 1){
			ret -= 1;
		}
		if(ret < 0){
			ret += 1;
		}
		PP p;
		p.first = qs[i + 1].x;
		p.second = qs[i + 1].y;
		m[p] = ret;
		//cout << ret << endl;
		//cout << p.first << " " << p.second << endl;
	}
	
	for(int i = 0; i < N; i++){
		PP p;
		p.first = ps_b[i].x;
		p.second = ps_b[i].y;
		printf("%.20f\n", m[p]);
	}
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  // ここにプログラムを追記
  int current_rate, goal_rate, expected_rate = 0;
  scanf("%d\n %d\n", &current_rate, &goal_rate);

  expected_rate = 2 * goal_rate - current_rate;
  cout << expected_rate << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

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

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int main( int argc, char * argv[] ){
  int n; cin >> n; 
  vi v(n); input(v);
  int tot = 0;
  forall(i,0,n){
    forall(j,i+1,n){
      tot += v[i] * v[j];
    }
  }
  cout << tot << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[2];
	while (cin >> a[0] >> a[1])
	{
		if (a[0] == 0 && a[1] == 0)
		{
			break;
		}
		sort(a, a + 2);
		cout << a[0] << " " << a[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,a,b,ans=0,rem,count;
    cin>>n>>a>>b;
    if(a!=0){
    count=n/(a+b);
    ans=a*count;
    rem=n%(a+b);
    if(rem<a)
    ans=ans+rem;
    else
    ans=ans+a;
    cout<<ans;
    }
    else
    cout<<"0";
}


Measured memory_bytes: 3596
N,M, *V = map(int, open(0).read().split())
P = V[0::2]
Y = V[1::2]

table = dict()

for i in range(len(P)):
  if(P[i] in table):
    table[P[i]].append(Y[i])
  else:
    table[P[i]] = []
    table[P[i]].append(Y[i])

for key in table.keys():
  table[key] = sorted(table[key])

sr_table = dict()

for key in table.keys():
  sr_table[key] = dict()
  for i in range(len(table[key])):
    sr_table[key][table[key][i]] = i+1

for i in range(len(P)):
  order = sr_table[P[i]][Y[i]]
  pre  = '{:0=6}'.format(P[i])
  post = '{:0=6}'.format(order)
  print(str(pre) + str(post))

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

using namespace std;

long cnt[26];

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string str;
	cin>>str;
	
	long long ans = 1;
	for(long i = 0; i < str.size(); i++){
		ans = ans + i - cnt[str[i]-'a'];
		cnt[str[i]-'a']++;
	}
	
	cout<<ans;	
	return 0;
}

Measured memory_bytes: 720
from typing import List


def partition(A: List[int], p: int, r: int) -> int:
    """パーティション

    A[p, ..., r]を、A[p, ..., q-1]とA[q+1, ..., r]二分割する。
    A[p, ..., q-1]の各要素は A[q]以下とする。
    A[q+1, ..., r]の各要素は A[q]より大きくする。

    Args:
        A (List[int]): 分割対象のリスト
        p (int): 分割対象のリストの先頭のインデックス
        r (int): 分割対象のリストの最後のインデックス

    Returns:
        int: q
    """
    tmp = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= tmp:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


n = int(input())
A = [int(i) for i in input().split()]
q = partition(A, 0, n - 1)
result = [str(A[i]) if i != q else '[' + str(A[i]) + ']' for i in range(len(A))]
print(' '.join(result))



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

int		main(void)
{
	int n;
	string s;

	cin >> n;
	cin >> s;
	int x = 0, ans = 0;

	for (int i = 0; i < n; i++)
	{
		s[i] == 'I' ? x++ : x--;
		ans < x ? ans = x : 0;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
from itertools import product

N = input()
l = len(N)
a = int(N[0])
b = int(N[-1])

if l == 1:
    print(l)
    exit()
elif l == 2:
    print(9 + min(a, b) ** 2 * 2)
    exit()

N = N[1:-1]
table = [[0] * 10 for _ in range(10)]
for i in range(1, 10):
    table[i][i] = 1

for i, j in product(range(1, 10), repeat=2):
    table[i][j] += sum(10 ** (l - i) for i in range(3, l + 1))
    if i < a:
        table[i][j] += 10 ** (l - 2)
    elif i == a:
        if b < j:
            table[i][j] += sum((int(N[-i - 1])) * 10 ** i for i in range(l - 2))
        else:
            table[i][j] += sum((int(N[-i - 1])) * 10 ** i for i in range(l - 2)) + 1

answer = 0
for i, j in product(range(1, 10), repeat=2):
    answer += table[i][j] * table[j][i]
    # print(i, j, table[i][j], table[j][i])

print(answer)


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<998244353>;
template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; cin >> N >> M;
	num val = pow(num(M+1), N) * pow(num(N+1), M);
	num ans = val;
	for (int i = 1; i <= min(N, M); i++) {
		val *= N - i + 1;
		val *= M - i + 1;
		val /= i;
		val /= M+1;
		val /= N+1;
		val *= -1;
		ans += val;
	}
	cout << ans << '\n';

	return 0;
}


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

int main(){
	int a,b,s,o;
	while(scanf("%d %d", &a, &b) != EOF){
		s = a + b;
		o = 0;
		while(s != 0){
			s /= 10;
			o++;
		}
		printf("%d\n", o);
	}

	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int i = 0, ans = 0;
  while(i<n) {
    int cc = a[i], f = 0;
    while(i<n && a[i] == cc) {f++; i++;}
    ans += f%2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	double R;
	cin >> R;
	double ans = 2*R*M_PI;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3788
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int inv(int x) {return qpow(x,maxd-2);}

	int C(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	int math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=inv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;

int n,m,a[2020][2020];

void solve(int l1,int r1,int l2,int r2)
{
	if ((l1==l2) && (r1==r2)) {a[l1][r1]=1;return;}
	int midl=(l1+l2)>>1,midr=(r1+r2)>>1;
	a[midl][midr]=1;
	solve(l1,r1,midl-1,midr-1);
	solve(l1,midr+1,midl-1,r2);
	solve(midl+1,r1,l2,midr-1);
	solve(midl+1,midr+1,l2,r2);
}

int main()
{
	n=read();m=read();
	int mx=max(n,m);
	solve(1,1,(1<<mx)-1,(1<<mx)-1);
	rep(i,1,(1<<n)-1) 
	{
		rep(j,1,(1<<m)-1) putchar('0'+a[i][j]);
		puts("");
	}
	return 0;
}



Measured memory_bytes: 11520
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int result = 0;
		
		int count = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'A' || s.charAt(i) == 'C' || s.charAt(i) == 'G' || s.charAt(i) == 'T') {
				count++;
				if(result < count) {
					result = count;
				}
			}else {
				count = 0;
			}
		}
		System.out.println(result);
		sc.close();
	}

}


Measured memory_bytes: 23124
n = int(input())
s = input()
ans = 0
for i in range(0,10):
  for j in range(0,10):
    left = s.find(str(i))
    right = s.rfind(str(j))
    if left<0 or right <= left:
      continue
    for k in range(0,10):
      ans += int(str(k) in s[left+1:right])
print(ans)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	int n; cin >> n;
	vint l(n);
	rep(i, n) cin >> l[i];
	sort(ALL(l));

	int ans = 0;
	rep(i, n-2){
		rep2(j, i+1, n-1){
			rep2(k, j+1, n){
				if(l[i] + l[j] > l[k]) ans++;
				else break;
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;
  vector <int> P(N);
  rep(i,N) cin >> P[i];
  int ans = 0;
  int curMin = 1e9;  //今までのmin
  rep(i,N){
    curMin = min(curMin, P[i]);
    if (P[i] == curMin) ans ++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4008
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll k,cnt;
string s;
int main()
{
	cin>>s>>k;
	for (int i=0;i<s.size() && s[i]=='1';i++) cnt++; 
	if (cnt>0)
	{
		if (k>cnt) cout<<s[cnt];
		else cout<<1;
	}
	else cout<<s[0];
    return 0;
}

Measured memory_bytes: 256
// Problem : B - Nice Shopping
// Contest : AtCoder - Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020
// URL : https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

void solve(){
    int A,B,C;
    cin>>A>>B>>C;
    vi a(A+1), b(B+1);
    int mna = inf, mnb = inf, mn;
    for(int i=1;i<=A;i++) cin>>a[i], mna = min(mna, a[i]);
    for(int i=1;i<=B;i++) cin>>b[i], mnb = min(mnb, b[i]);
    mn = mna + mnb;
    for(int i=0;i<C;i++){
        int x,y,c;
        cin>>x>>y>>c;
        mn = min(mn, a[x]+b[y]-c);
    }
    cout<<mn<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int t;
    //cin>>t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
using namespace std;
int main(void){
    int D, G; cin >> D >> G;
    vector<int> p(D);
    vector<int> c(D);
    vector<int> sum(D, 0);
    int i = 0;
    int answer = pow(10,9);
    while(i < D){
        cin >> p[i];
        cin >> c[i];
        i++;
    }
    i = 0;
    while(i <  (1 << D)) {
        int sum = 0;
        int count = 0;
        int bit = D;
        while (bit >= 0 && sum < G) {
            int k = 0;
            if (1 & (i >> bit)) {
                while(k < p[bit] && sum < G) {
                    sum += (bit+1) * 100;
                    count++;
                    k++;
                }
                if (k == p[bit]) {
                    sum += c[bit];
                }
            }
            bit--;
        }
        if (sum >= G) {
            answer = min(answer, count);
        }
        i++;
    }
    cout << answer << endl;
}


Measured memory_bytes: 3604
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int W = sc.nextInt();   
   int H = sc.nextInt();
   int N = sc.nextInt();
   int[] x = new int[N];
   int[] y = new int[N];
   int[] a = new int[N];
   for(int i=0;i<N;i++)
   {
     x[i] = sc.nextInt();
     y[i] = sc.nextInt();
     a[i] = sc.nextInt();
   }
   int xmax=W;
   int xmin=0;
   int ymax=H;
   int ymin=0;
   for(int i=0;i<N;i++)
   {
     if(a[i]==1)
     {
       if(xmin<x[i]) xmin=x[i];
     }
     if(a[i]==2)
     {
       if(xmax>x[i]) xmax=x[i];
     } 
     if(a[i]==3)
     {
       if(ymin<y[i]) ymin=y[i];
     }
     if(a[i]==4)
     {
       if(ymax>y[i]) ymax=y[i];
     }
   }
   int ans =0;
   if(xmax>xmin&&ymax>ymin) ans = (xmax-xmin)*(ymax-ymin);
   System.out.println(ans);
 }
}

Measured memory_bytes: 22868
//  RAKSHIT KADAM

 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 3
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning check the size of arrays!!!
// NUMERIC DEFINITIONS :
    #define INF 1000000000000000005
    #define inf 1000000004
    #define MOD  1000000007
    #define mod 998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll ter; cin>> ter; while(ter--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}

int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500003;
//ll fact[10005];
//ll modIN[1000005];
//void facto()
//{
//    ll lim =1000005;fact[0]=1;
//    for(ll i=1;i<lim;i++)
//    {
//        fact[i]=(fact[i-1]*i)%MOD;
//    }
//    modIN[n]=modInverse(fact[n],MOD);
//    for(ll i=n-1;i>=1;i--)
//    {
//        modIN[i] = (modIN[i+1]*(i+1))%MOD;
//    }
//}
//ll ncr(ll a,ll b)
//{
//    ll ret = 0;
//    ret = fact[a]*(modIN[b]);
//    ret%=MOD;
//    ret*=modIN[a-b];
//    ret%=MOD;
//    return ret;
//}

void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans =-INF;
    
    
        ans=max(ans,d*b);
    
    
    
        ans=max(ans,a*c);
    
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    cout<<ans<<endl;
}
signed main(){
   Need_for_speed(activated);
//
//    satisfy
//    {
// solve();
//    }
    
  
    solve();

    
    
    return 0;
}


Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cstdio>
using namespace std;
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
int main()
{
	fast();
	string s;
	int x = 0, y = 0;
	map<char, int> mp;

	cin >> s;
	for (int i = 0;i < s.size()-1;i++)
	{
		if (s[i] == s[i + 1])
			x++;
		else
		{
			y = x;
			x = 0;
		}
	}
	if (x >= 2 || y >= 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  if(A+B > C+D) cout <<"Left" <<endl;
    else if(A+B < C+D) cout<<"Right"<<endl;
  		else cout <<"Balanced"<<endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int type[111111];
vint G[111111];
int dep[111111];
int val[111111];

void dfs(int v,int p,int d,int b){
    dep[v]=d;
    val[v]=b;
    for(auto u:G[v]){
        if(u==p)continue;
        int bb=0;
        for(int i=0;i<4;i++){
            int o=i>>(type[u]&1)&1;
            if(type[u]/2==0){
                bb|=((b>>i&1)|o)<<i;
            }
            else if(type[u]/2==1){
                bb|=((b>>i&1)&o)<<i;
            }
            else{
                bb|=((b>>i&1)^o)<<i;
            }
        }
        dfs(u,v,d+1,bb);
    }
}

int dfs2(int v,int p,vint &q){
    if(G[v].size()==(p!=-1)){
        int res=0;
        for(int i=1;i<4;i++){
            res+=(1<<q[i-1])*(val[v]>>i&1);
        }
        return res;
    }

    int res;
    if(dep[v]&1)res=INT_MAX;
    else res=INT_MIN;
    for(auto u:G[v]){
        if(u==p)continue;
        if(dep[v]&1)chmin(res,dfs2(u,v,q));
        else chmax(res,dfs2(u,v,q));
    }
    return res;
}

signed main(){
    cin>>N>>M;
    for(int i=1;i<N;i++){
        string s;
        cin>>s;
        if(s[3]=='|')type[i]=0;
        else if(s[3]=='&')type[i]=1;
        else type[i]=2;
        if(s[4]=='X')type[i]=type[i]*2;
        else type[i]=type[i]*2+1;
    }
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        G[a].pb(b);G[b].pb(a);
    }


    dfs(0,-1,0,0);
    vector<int>q(3);rep(i,3)q[i]=i;
    map<vint,int>lis;
    do{
        lis[q]=dfs2(0,-1,q);
    }while(next_permutation(all(q)));

    while(M--){
        int x,y;
        cin>>x>>y;
        int xx=(x<<3)+5;
        int yy=(y<<3)+6;

        bool ex[4]={};
        int cur=2;
        for(int i=20;i>=0;i--){
            int o=(xx>>i&1)+(yy>>i&1)*2;
            if(o==0)continue;
            if(ex[o])continue;
            ex[o]=1;
            q[o-1]=cur--;
        }

        int latte=lis[q];
        int ans=0;
        for(int i=15;i>=0;i--){
            ans<<=1;
            int o=(x>>i&1)+(y>>i&1)*2;
            if(o)ans+=latte>>(q[o-1])&1;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 19012
#include <stdio.h>
int a[110],cnt;
int main(){
  int i,n;
  scanf("%d",&n);
  for(i=1;i<=n;++i){
    scanf("%d",a+i);
    if(a[i]==a[i-1])++cnt,a[i]=-1;
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int INF = 1e9;
vector<int> a, dp, ans;
vector<int> g[200005];

void dfs(int u, int p = -1){
  int i = lower_bound(dp.begin(),dp.end(),a[u]) - dp.begin();
  int temp = dp[i];
  dp[i] = a[u];
  ans[u] = p==-1 ? i : max(i,ans[p]);
  for(int v : g[u]) if(v!=p) dfs(v,u);
  dp[i] = temp;
}

int main() {
  int n;
  cin >> n;
  a = vector<int>(n);
  rep(i,n) cin >> a[i];
  rep(i,n-1){
    int u,v;
    cin >> u >> v;
    --u; --v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }

  dp = vector<int>(n+2, INF);
  dp[0] = -INF;
  ans = vector<int>(n);

  dfs(0);
  rep(i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 30776
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

ll Q[4];
ll dfs(ll n){
    if(n==0) return 0LL;
    ll res=Q[0]*n;
    if(n>=2) res=min(res,dfs(n-(n/2)*2)+Q[1]*(n/2));
    if(n>=4) res=min(res,dfs(n-(n/4)*4)+Q[2]*(n/4));
    if(n>=8) res=min(res,dfs(n-(n/8)*8)+Q[3]*(n/8));
    return res;
}
int main(){
    REP(i,4) cin>>Q[i];
    ll N;cin>>N;
    N*=4;
    cout<<dfs(N)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int n; cin >>n;
    vector<int> a(n); REP(i,n) cin >> a[i];
    sort(a.begin(), a.end());

    int ans = 1;

    if (n % 2 == 0) {

        for (int i = 0; i < n/2; i++) {
            if (a[2*i] != 2*i+1 || a[2*i+1] != 2*i+1) {
                cout << 0 << endl;
                return 0;
            } else {
                ans *= 2;
                ans %= MOD;
            } 
        }

    } else {

        if (a[0] != 0) {
            cout << 0 << endl;
            return 0;
        } 

        for (int i = 0; i < n/2; i++) {
            if (a[2*i+1] != 2*(i+1) || a[2*i+2] != 2*(i+1)) {
                cout << 0 << endl;
                return 0;
            } else {
                ans *= 2;
                ans %= MOD;
            } 
        }

    } 
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
 
int main(){
  int N;
  cin>>N;
  int V[100];
  int C[100];
  rep1(i,N){
    cin>>V[i];
  }
  rep1(i,N){
    cin>>C[i];
  }
  
  int count=0;
  rep1(i,N){
    if(V[i]-C[i]>0){
      count+=V[i]-C[i];
    }
    else continue;
  }
  
  cout<<count<<endl;
}
    
    

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

int main() {
    int n;cin>>n;
    repd(i,1,10){
        repd(j,1,10){
            if(i*j==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> N;
  rep(i,0,N){
    cin >> D;
    if(i%2==0&&D&1)num++;
  }
  Out(num);
}

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

using namespace std;

int main()
{
    long long int z,n,x,a[100009],b[100009];
    scanf("%I64d%I64d",&n,&x);
    for(int i=0;i<n;i++){
        scanf("%I64d",&a[i]);
        b[i]=abs(a[i]-x);
    }
    sort(b,b+n);
    z=b[0];
    for (int i=1; i<n; i++) {
        z=__gcd(z,b[i]);
    }
    printf("%I64d",z);

    return 0;
}


Measured memory_bytes: 1792
using System;

namespace ABC109_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var W = new string[N];

            var c = true;
            W[0] = Console.ReadLine();
            var lw = W[0][W[0].Length - 1];

            for (int i = 1; i < N; i++)
            {
                W[i] = Console.ReadLine();
                if (W[i][0] != lw)
                {
                    c = false;
                }
                lw = W[i][W[i].Length - 1];
                for (int j = 0; j < i - 1; j++)
                {
                    if (W[i] == W[j])
                    {
                        c = false;
                    }
                }
            }

            Console.WriteLine(c ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
N = int(input())

if N % 2 == 0:
    tab = [None] * 32
    pow5 = 10
    for s_tab in range(1, 32):
        if pow5 > N:
            tab[s_tab] = 0
            break
        else:
            tab[s_tab] = N // pow5
            pow5 *= 5
    #
    # print("#", tab)
    ans = 0
    cnt = 0
    for j in range(s_tab):
        i = s_tab - j
        #
        cnt_tmp = tab[i] - cnt
        ans += i * cnt_tmp
        cnt += cnt_tmp
    #
    print(ans)
else:
    print(0)

Measured memory_bytes: 3064
import java.util.*;
public class Main{

  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      
      System.out.println( n % digitSum(n) == 0 ? "Yes" : "No");
  }

  private static int digitSum(int n) {
      int sum = 0;
      while(n > 0) {
          sum += n % 10;
          n /= 10;
      }
      return sum;
  }
}



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


int main(){
    long long L,R,mL,mR;
    int ans = 0;
    int min = 2019;
    cin >> L >> R;
    if(R-L >= 2019){
        min = 0;
    }
    mL = L%2019;
    mR = (R%2019);
    if(mL >= mR){
        mR += 2019;
        min = 0;
    }
    
    for(int i = mL; i <= mR-1; i++){
        for(int j = i+1; j <= mR; j++){
            if(((i*j)%2019) < min  ){
                min = ((i*j)%2019);
            }
        }
    }
   

   

  
    cout << min <<"\n";
    
    
    return 0;
}

Measured memory_bytes: 256
/*
https://beta.atcoder.jp/contests/abc085/tasks
*/
#include<iostream>
using namespace std;

main(){
  int n,y;
  bool flag=false;
  int i,j,k;
  cin>>n>>y;
  for(i=0;i<=n;i++){
    for(j=0;j<=n-i;j++){
      for(k=0;k<=n-i-j;k++){
        if(y==i*10000+5000*j+1000*k&& i+j+k==n){
          flag=true; break;
        }
      }
      if(flag) break;
    }
    if(flag) break;
  }
  if(flag)
    cout<<i<<" "<<j<<" "<<k<<"\n";
  else
    cout<<-1<<" "<<-1<<" "<<-1<<"\n";
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll N, K;
vector<ll> G[101010];
vector<ll> val(101010, 0);
ll res;

ll kera(ll kosu, ll era){
	ll re = 1;
	REP(i, era){
		re *= (kosu-i);
		re %= mod;
	}
	return re;
}

void dfs(ll now, ll par){
	if(par == -1){
		res *= kera(K-1, G[now].size());
		res %= mod;
	}else{
		res *= kera(K-2, G[now].size()-1);
		res %= mod;
	}
	REP(i, G[now].size()){
		if(G[now][i] == par) continue;
		dfs(G[now][i], now);
	}
	return;
}

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

    cin >> N >> K;
    res = K;
    REP(i, N-1){
    	ll a, b;
    	cin >> a >> b;
    	a--, b--;
    	G[a].push_back(b);
    	G[b].push_back(a);
    }
    dfs(0, -1);
    cout << res << endl;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,del=0;
	long long ans=0;
	int tmp;
	int pos[20];
	memset(pos,0,sizeof(pos));
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ans+=i;
		cin>>tmp;
		int j=0;
		while(tmp)
		{	
			if(tmp&1)
			{
				if(pos[j]>0)
				{
					del=max(del,pos[j]);
				}
				pos[j]=i;
			}
			tmp>>=1;
			j++;
		 } 
		 ans-=del;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i, a, b)  for(int i = a; i <= b; ++i)
#define Ford(i, a, b) for(int i = a; i >= b; --i)
#define FileName      "test"
#define ll            long long
#define ld            long double
#define ull           unsigned long long
#define pb            push_back
#define X             first
#define Y             second
//#define Karma

using namespace std;

template <typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-')
            sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 1e6 + 7;
const int M = 1e5 + 7;
const ld pi = 3.1415926535897;

int n, m, t, a[N], idm, idt;
vector<pii> res;

void Enter()
{
    cin >> n;
    m = INT_MIN;
    t = INT_MAX;
    For(i, 1, n)
    {
        cin >> a[i];
        if(m < a[i]) m = a[i], idm = i;
        if(t > a[i]) t = a[i], idt = i;
    }
}

void Solve()
{
    if(abs(t) > abs(m) && t <= 0 && m >= 0)
    {
        For(i, 1, n)
        {
            if(a[i] > 0)
            {
                a[i] += t;
                res.pb({idt, i});
            }
        }
        t = -1;
    }
    else if(abs(t) <= abs(m) && t <= 0 && m >= 0)
    {
        For(i, 1, n)
        {
            if(a[i] < 0)
            {
                a[i] += m;
                res.pb({idm, i});
            }
        }
        t = 1;
    }
    if(t < 0) Ford(i, n, 2) res.pb({i, i - 1});
    else For(i, 1, n - 1) res.pb({i, i + 1});
    t = m = 1;
    cout << res.size() << '\n';
    for(pii v: res) cout << v.X << ' ' << v.Y << '\n';
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


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

int main() {
	int N = 0;
	int M = 0;
	int a[10000] = { 0 };
	int b[10000] = { 0 };
	int n = 0;
	cin >> N;
	a[0] = N / 100;
	a[1] = N % 100 / 10;
	a[2] = N % 100 % 10;
	for (int i = 0; i < 3; i++) {
		if (a[i] == 1) {
			n++;
		}
	}
	

	cout << n;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
  string s;
  cin >> s;
  char before = s[0];
  int cnt = 0;
  int itr = 0;
  int l = s.length() / 2;
  int r = s.length() / 2;
  if(s.length() % 2 == 0){
    l--;
  }

  int ans = s.length() / 2;
  int num = s[l];
  for(int i = 0; i < s.length(); ++i){
    if(s[l] != s[r] || s[l] != num) break;
    ans++;
    l--;
    r++;
  }

  cout << ans << endl;
}


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

using namespace std;

int main()
{
  int n;
  cin >> n;
  map<int, int, greater<int>> a;
  for (int i = 0; i < n; i++)
  {
    int t;
    cin >> t;
    a[t]++;
  }
  int ans = 0;
  for (pair<int, int> i : a)
  {
    if (i.second < 1)
      continue;
    int bit = 1;
    while (bit < i.first)
      bit *= 2;
    if (bit == i.first)
      ans += i.second / 2;
    int c = min(i.second, a[bit - i.first]);
    ans += c;
    a[bit - i.first] -= c;
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll mx = max(a, max(b,c));
    if(mx == a+b+c-mx) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<functional>
typedef long long ll;
#define INF 99999999
int main() {
	int n = 0, f = 0;	
	ll ans = 0, p, q;
	std::cin >> n;
	std::vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		std::cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		std::cin >> c[i];
	}
	//必ずソート(昇順)をすること
	std::sort(a.begin(), a.end());
	std::sort(b.begin(), b.end());
	std::sort(c.begin(), c.end());
	//イテレータはコンテナの要素を枚挙するために使う
	std::vector<int>::iterator it_u, it_l;
	for (int i = 0; i < n; i++) {
		//uは～より大きい、lは～以上の要素が現れたとき、”その要素”を出す
		//begin() end()は実はイテレータを受け取るものだった！
		it_u = std::upper_bound(c.begin(), c.end(), b[i]);
		it_l = std::lower_bound(a.begin(), a.end(), b[i]);
		//イテレータはイテレータどうしの計算しかできない
		p = n - (it_u - c.begin());//it_u以上ならOK
		q = (it_l - a.begin());//it_l未満ならOK
		ans += p*q;
	}
	std::cout << ans << std::endl;
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int m[100][100];

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> c;
    rep(i, n) rep(j, a[i]) c.push_back(i + 1);

    int k = 0;
    rep(i, h)
    {
        bool flag = (i % 2 == 0 ? 0 : 1);
        int j = (flag == 0 ? 0 : w - 1);
        int cnt = 0;
        while (cnt < w)
        {
            m[i][j] = c[k];
            flag == 0 ? j++ : j--;
            k++;
            cnt++;
        }
    }

    rep(i, h) rep(j, w) j != w - 1 ? cout << m[i][j] << " " : OP(m[i][j]);

    return 0;
}

Measured memory_bytes: 512
import java.util.*;

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

        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int x2 = sc.nextInt();
        int y2 = sc.nextInt();

        int a = x2 - x1;
        int b = y2 - y1;

        int x3 = x2 - b;
        int y3 = y2 + a;

        int x4 = x3 - a;
        int y4 = y3 - b;

        System.out.print(x3 + " ");
        System.out.print(y3 + " ");
        System.out.print(x4 + " ");
        System.out.println(y4);

    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>

using namespace std;

int main() {
	int N;
	string s;
	string t;

	cin >> N;
	cin >> s >> t;

	for (int i = 0; i < N; ++i){
		cout << s[i] << t[i];
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int m,n;
  cin>>m>>n;
  vector<int> p(m);
  REP(i,m)cin>>p[i];
  sort(begin(p),end(p),greater<int>());
  vector<int> s(m+1);
  partial_sum(begin(p),end(p),begin(s)+1);
  vector<int> c(n),e(n);
  REP(i,n)cin>>c[i]>>e[i];
  vector<vector<int>> dp(n+1,vector<int>(m+1,1000000000));
  dp[0][0] = 0;
  REP(i,n) {
    multiset<int> st;
    REP(j,m+1) {
      dp[i+1][j] = dp[i][j];
      st.insert(dp[i][j]);
      if (j > c[i]) {
        auto itr = st.lower_bound(dp[i][j-c[i]-1]);
        st.erase(itr);
      }
      dp[i+1][j] = min(*begin(st) + e[i], dp[i+1][j]);
    }
  }
  int mxc = 0;
  REP(i,m+1) {
    mxc = max(mxc, s[i] - dp[n][i]);
  }
  cout<<mxc<<endl;
  return 0;
}

Measured memory_bytes: 21324
package main

import "fmt"

func main() {
	var n, k int

	fmt.Scanf("%d %d", &n, &k)

	var nums = make([]int, n)
	var s = make([]interface{}, n)
	for i := range nums {
		s[i] = &nums[i]
	}
	fmt.Scanln(s...)

	fmt.Println(logic(nums, k))
}

func logic(nums []int, k int) int {
	ans := []int{}
	for _, n := range nums {
		if n >= k {
			ans = append(ans, n)
		}
	}

	return len(ans)
}

Measured memory_bytes: 5248