akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

class Program
{
    static int n;
    static int[] v;

    public static void Main(string[] args)
    {
        n = Input.NextInt();
        v = Input.LineInt();

        var d0 = SepBuket(0);
        var d1 = SepBuket(1);
        var dorderedbynum0 = d0.OrderBy(n => -n.Value).ToList();
        var dorderedbynum1 = d1.OrderBy(n => -n.Value).ToList();

        int min = int.MaxValue;
        min = Math.Min(min, NewMethod(dorderedbynum0, dorderedbynum1));
        min = Math.Min(min, NewMethod(dorderedbynum1, dorderedbynum0));

        Console.WriteLine(min);
    }

    private static int NewMethod(List<KeyValuePair<int, int>> dorderedbynum0, List<KeyValuePair<int, int>> dorderedbynum1)
    {
        int n_2 = v.Length / 2;
        int min = int.MaxValue;
        foreach (var do0 in dorderedbynum0)
        {
            if (do0.Key == 100000)
                continue;

            var nn = n_2 - do0.Value;
            if (nn > min)
                break;
            var okat1 = dorderedbynum1.FirstOrDefault(n => n.Key > do0.Key);
            if (default(KeyValuePair<int, int>).Equals(okat1))
            {
                min = Math.Min(min, nn + n_2);
            }
            else
            {
                min = Math.Min(min, nn + (n_2 - okat1.Value));
            }
        }

        return min;
    }

    private static Dictionary<int, int> SepBuket(int start)
    {
        var dic0 = new Dictionary<int, int>();
        for (int i = start; i < v.Length; i += 2)
        {
            if (!dic0.ContainsKey(v[i]))
                dic0[v[i]] = 0;
            dic0[v[i]]++;
        }
        return dic0;
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

int main(){
    int x,y;
    cin >> x >> y;

    if(y<x*2){
        cout << "No";
    }else if(y>x*4){
        cout << "No";
    }else{
        if(y&1){
            cout << "No";
        }else{
            cout << "Yes";
        }
    }
    return 0;
}

Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<memory.h>
#include<ctime>
#include<cstdio>

using namespace std;

int main()
{
	int n;
	cin>>n;
	cout<<n*800-int(n/15)*200<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;lint K;
    cin >> N >> K;
    VEC(lint) X(N);
    READVEC(X);
    const int MAX_BIT = 40;

    lint ret = 0;
    bool lesser = false;
    FORD(bit, MAX_BIT - 1, -1) {
        int ones = 0, zeros = 0;
        for(lint x : X)
            if (x & (1LL << bit))
                ones++;
            else
                zeros++;

        if (lesser) {
            ret += max(ones, zeros) * (1LL << bit);
        } else {
            if (ones >= zeros) {
                if (K & (1LL << bit))
                    lesser = true;
                ret += ones * (1LL << bit);
            } else {
                if (K & (1LL << bit)) {
                    ret += zeros * (1LL << bit);
                } else {
                    ret += ones * (1LL << bit);
                }
            }
        }
    }

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


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define fr(i,a,b) for(register int i=a;i<=b;i++)
#define N 100010
using namespace std;
int a[N];
int main(){
	int n,m = 0,ans = 0;
	cin>>n;
	fr(i,1,n)cin>>a[i];
	fr(i,1,n)
		if(a[i] <= a[i - 1])m++;
		else {ans = max(ans,m);m = 1;}
	ans = max(ans,m);
	cout<<ans - 1;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define size(s) s.size()
#define mod 1000000007
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	string s,t,u;
	int a,b;
	cin>>s>>t>>a>>b>>u;
	if(u==s)a--;
	else b--;
	cout<<a<<" "<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int a, b;
	cin >> a >> b;
	yorn(a == b);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N;cin>>N;
    vector<int> P(N+1);
    int cnt = 0;
    rep(i,1,N+1) cin>>P[i];
    rep(i,1,N+1){
        if(P[i]==i){
            ++cnt;
            ++i;
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		long A=sc.nextLong();
		long B=sc.nextLong();
		for(long v=1;v<=100000;++v) {
			if(v*8/100==A&&v*10/100==B) {
				System.out.println(v);
				return;
			}
		}
		System.out.println(-1);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define IO() assert(freopen("in.in", "rt", stdin)),assert(freopen("out.out", "wt", stdout))
#define FastIO() ios::sync_with_stdio(false);
#define debug(x) cout << __LINE__ << ": " << #x << " = " << (x) << endl

typedef long long ll;
const ll MOD=1e9+7;
const int N = 1e7+9, M = 1e5+9, OO = 0x3f3f3f3f;
const double EPS = 1e-10;

// inline int readi(){int n;scanf("%d", &n);return n;}
// inline ll readll(){ll n;scanf("%lld", &n);return n;}
// inline char readc(){char c;scanf("%c ", &c);return c;}
// inline double readd(){double n;scanf("%lf", &n);return n;}
inline bool dCMP(const long double& a, const long double& b){return fabsl(a-b)<EPS;}
pair<int,int> arr[N];
int main()
{
	#ifdef _LOCAL_DEFINE
	IO();
	#endif
	int n;
	int sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;++i) scanf("%d%d",&arr[i].second,&arr[i].first);
	sort(arr,arr+n);
	for(int i=0;i<n;++i)
	{
		sum+=arr[i].second;
		if(sum<=arr[i].first) continue;
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1792
n,m=gets.split.map(&:to_i)
as=n.times.map{gets.chomp}
bs=m.times.map{gets.chomp}
(n-m+1).times do |i|
  (n-m+1).times do |j|
    check=true
    m.times do |k|
      check=false if as[j+k][i..i+m-1]!=bs[k]
    end
    if check
      puts "Yes"
      exit
    end
  end
end
puts "No"


Measured memory_bytes: 1916
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long m = sc.nextInt();
        long lcm = lcm(n, m);
        Map<Long, Character> map = new HashMap<>();
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();

        long dn = lcm/n;
        long dm = lcm/m;
        for(long i=0; i<n; i++) {
            map.put(i*dn, s[(int)i]);
        }
        for(long i=0; i<m; i++) {
            if(map.containsKey(i*dm)) {
                if(map.get(i*dm).charValue() != t[(int)i]) {
                    System.out.println("-1");
                    return;
                }
            }
        }
        System.out.println(lcm);

    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

}


Measured memory_bytes: 33056
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        long N=gl();

        for (long h=1; h<=3500; h++) {
        	for (long n=1; n<=3500; n++) {
            	long l=1;
            	long r=3500;
            	while(r-l>1) {
            		long w=(l+r)/2;
            		long wl=4*h*n*w;
            		long wr=N*(n*w+h*w+h*n);
            		if(wl==wr) {
            			System.out.println(h + " " + n + " " + w);
            			return;
            		} else if(wl<wr) {
            			l=w;
            		} else {
            			r=w;
            		}

            	}
            }
        }

        //System.out.println(ans);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 39404
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int A;
	cin >> A;

	int kotae = 10000 - A;

	while (kotae >= 1000) kotae -= 1000;

	co(kotae);





	Would you please return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = scan.nextInt();
        for (int i = k; i < n; i++) {
            if (a[i] > a[i - k]) System.out.println("Yes");
            else System.out.println("No");
        }
    }
}


Measured memory_bytes: 60332
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

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

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<int> x(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;

		x.at(a - 1)++;
		x.at(b - 1)++;
	}
	
	for (int i = 0; i < n; i++)
	{
		println(x.at(i));
	}
}


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double a = 0;
		double ans = 0;
		for(int i = 0;i < n;i++) {
			a = sc.nextDouble();
			ans += 1 / a;
		}
		ans = 1/ans;
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

int main(int argc, char* argv[]) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  /* */
  std::string s;
  std::cin >> s;

  for (int i = 0; i < s.length() - 1; ++i) {
    if (s[i] == s[i + 1]) {
      std::printf("%d %d\n", i + 1, i + 2);  std::exit(EXIT_SUCCESS);
    }
  }

  for (int i = 0; i < s.length() - 2; ++i) {
    if (s[i] == s[i + 2]) {
      std::printf("%d %d\n", i + 1, i + 3);  std::exit(EXIT_SUCCESS);
    }
  }
  std::printf("-1 -1\n");
  /* */

  return EXIT_SUCCESS;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=100010;
int main(){
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	int q,n,i,j,a[N],b[N],c[N],m,p;
	cin>>q;
	cin>>n>>m>>p;
	a[0]=max(m,p); b[0]=max(n,p); c[0]=max(m,n);
	for(i=1;i<q;++i){
		cin>>n>>m>>p;
		a[i]=max(b[i-1],c[i-1])+n;
		b[i]=max(a[i-1],c[i-1])+m;
		c[i]=max(b[i-1],a[i-1])+p;
	}
	cout<<max(max(a[q-1],b[q-1]),c[q-1]);
}


Measured memory_bytes: 1408
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N - 1 + M)]

import sys
sys.setrecursionlimit(100000)

from collections import defaultdict

vs = defaultdict(set)

for a, b in AB:
    vs[b].add(a)

cache = {}

def calc(n):
    if n in cache:
        return cache[n]
    max_distance = 0
    max_distance_parent = 0
    for m in vs[n]:
        d = calc(m)[0]
        if max_distance < d + 1:
            max_distance = d + 1
            max_distance_parent = m
    result = max_distance, max_distance_parent
    cache[n] = result
    return result

for i in range(1, N + 1):
    print(calc(i)[1])


Measured memory_bytes: 183896
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		FScanner fs=new FScanner();
		//Scanner sc=new Scanner(System.in);
		
		int n=fs.readInt();
		boolean slv=false;
		for(int i=0; i<=25; i++){
			for(int j=0; j<=14; j++){
				if((i*4+j*7)==n){
					slv=true;
				}
			}
		}
		System.out.println((slv==true)? "Yes": "No");
		
	}
	
	

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static class FScanner{
		Scanner sc;
		FScanner() throws FileNotFoundException{
			sc=new Scanner(System.in);
		}
		boolean hasNextLine(){
			boolean has=true;
			if(!sc.hasNextLine()){
				has=false;
			}
			return has;
		}
		int readInt(){
			int i=Integer.parseInt(sc.nextLine());
			return i;
		}
		int[] readIntL(){
			String[] buf=sc.nextLine().split(" ");
			int[] num=new int[buf.length];
			for(int i=0; i<buf.length; i++){
				num[i]=Integer.parseInt(buf[i]);
			}
			return num;
		}
		String[] readStringL(){
			String[] s=sc.nextLine().split("");
			return s;
		}
	}
}


Measured memory_bytes: 23764
INF = 1000000007

D, G = map(int, input().split())

p = []
c = []

for i in range(D):
    pi, ci = map(int, input().split())
    p.append(pi)
    c.append(ci)


def main():
    ans = INF

    # 2 ** D - 1 まで
    for b in range(2 ** D):
        num = 0
        pnt = 0

        # コンプリートしない MAX
        x = None

        # 得点が高い方から
        for i in range(D - 1, -1, -1):
            if b >> i & 1:
                num += p[i]
                # コンプリートする
                pnt += c[i] + 100 * (i + 1) * p[i]

            elif not x:
                x = i

        # コンプリート オール
        if x is None:
            ans = min(ans, num)
            continue

        flg = True

        for i in range(p[x]):
            if G <= pnt:
                break

            pnt += 100 * (x + 1)
            num += 1

            # コンプリートした
            # 無効
            if i == p[x] - 1:
                flg = False

        if not flg:
            continue

        ans = min(ans, num)

    print(ans)
    return


main()


Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
void stack(int);
void calc(int);
int pop();
int cnt=0;
int st[200]={0};
int main(){
  char t[10];
  int st1;
  int st2;
  while(scanf("%s",t)!=EOF){
    if(t[0]=='+')calc(pop()+pop());
    else if(t[0]=='-'){
      st1=pop();
      st2=pop();
      calc(st2-st1);
    }
    else if(t[0]=='*')calc(pop()*pop());
    else stack(atoi(t));
  }
  printf("%d\n",st[0]);
  return 0;
}
void stack(int l){
  st[cnt++]=l;
}
int pop(){
  return st[--cnt];
}
void calc (int l){
  st[cnt++]=l;
}



Measured memory_bytes: 2144
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#define ls id<<1
#define rs id<<1|1
using namespace std;
typedef long long ll;
int n,k;
const int N=100050;
const ll mod=1e9+7;
ll ans=1;
struct edge{
	int v,nxt;
}e[N<<1];
int col[N];
int dep[N];
int head[N],ecnt;
ll a[N];
int f[N],son[N];
void ad(int u,int v){
	e[++ecnt].v=v;
	e[ecnt].nxt=head[u];
	head[u]=ecnt;
}

void dfs1(int u,int fa){
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].v;
		if(v==fa)continue;
		f[v]=u;
		son[u]++;
		dep[v]=dep[u]+1;
		dfs1(v,u);
	}
}
void dfs2(int u,int fa,ll val){
	int t=son[u],nv=k;t--;
	a[u]=val;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].v;
		if(v==fa)continue;
		if(dep[v]<=1){
			dfs2(v,u,--nv);
		}
		else{
			dfs2(v,u,k-2-t);
			t--;
		}
	}
}

int main(){
	cin>>n>>k;
	for(int i=1;i<n;++i){
		int x,y;
		cin>>x>>y;
		ad(x,y),ad(y,x);
	}
	dfs1(1,0);
	dfs2(1,0,k);
	for(int i=1;i<=n;++i){
		ans*=a[i];
		ans%=mod;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int A,B,m;
  cin>>A>>B>>m;
  int ans=INF;
  vi a(A),b(B);
  rep(i,A) cin>>a[i];
  rep(i,B) cin>>b[i];
  vi x(m),y(m),c(m);
  rep(i,m) cin>>x[i]>>y[i]>>c[i];
  int am=INF,bm=INF;
  rep(i,A) chmin(am,a[i]);
  rep(i,B) chmin(bm,b[i]);
  ans=am+bm;
  rep(i,m){
    chmin(ans,a[x[i]-1]+b[y[i]-1]-c[i]);
  }

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




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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int H, W;
  char S[50][50];
  cin >> H >> W;
  for (int i = 0; i < H; i++)
    for (int k = 0; k < W; k++)
      cin >> S[i][k];

  for (int i = 0; i < H; i++) {
    for (int k = 0; k < W; k++) {
      int count = 0;
      if (S[i][k] == '#') {
        printf("#");
        continue;
      }
      // 左
      if (k != 0 && S[i][k - 1] == '#') count++;
      // 上
      if (i != 0 && S[i - 1][k] == '#') count++;
      // 右
      if (k != W - 1 && S[i][k + 1] == '#') count++;
      // 下
      if (i != H - 1 && S[i + 1][k] == '#') count++;

      // 左上
      if (k != 0 && i != 0 && S[i - 1][k - 1] == '#') count++;
      // 左下
      if (k != 0 && i != H - 1 &&  S[i + 1][k - 1] == '#') count++;
      // 右上
      if (k != W - 1 && i != 0 && S[i - 1][k + 1] == '#') count++;
      // 右下
      if (k != W - 1 && i != H - 1 && S[i + 1][k + 1] == '#') count++;
      printf("%d", count);
    }
    printf("\n");
  }
}


Measured memory_bytes: 760
#include<iostream>
#include<set>
using namespace std;struct P{int x,y,z;};bool operator<(P a,P b){return a.x!=b.x?a.x<b.x:(a.y!=b.y?a.y<b.y:a.z<b.z);}main(){for(int n,h,a,b,i;cin>>n>>h,n;){set<P>x;for(string c;h-->0;i=0)for(cin>>c>>a>>b;i++<n;){P p={a,i,b};if(c=="xy")swap(p.y,p.z);if(c=="yz")swap(p.x,p.y);x.insert(p);}cout<<n*n*n-x.size()<<endl;}}

Measured memory_bytes: 2336
s = gets.to_i

a = [0, s]

for i in 2..10**6 do
  tmp =
    if a[i-1]%2 == 0
      a[i-1]/2
    else
      3*a[i-1]+1
    end

  if a.include?(tmp)
    puts i
    exit
  else
    a[i] = tmp
  end
end


Measured memory_bytes: 1788
#include <iostream>
using namespace std; 
int a,b,c,d;
int main(){
  cin>>a>>b>>c>>d;
   
    if (a+b>c+d) cout << "Left\n"; 
    else if (a+b==c+d)  cout << "Balanced\n"; 
    else cout << "Right\n"; 
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
#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++)
#define _GLIBCXX_DEBUG 
 int main(){
     int a,b,c;
     cin>>a>>b>>c;
     vector<int> vec(b);
     rep1(i,b){
         int moda=a%b;
         moda*=i;
         moda%=b;
         vec[i-1]=moda;
     }
     bool judge =false;
     rep(i,b){
         if(vec[i]==c) judge=true;
         else continue;
     }
     if(judge) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;

 }

Measured memory_bytes: 3576
N, M = list(map(int,input().split()))
a = []
for i in range(M):
    a.append(list(map(int,input().split())))
a = sorted(a, key=lambda x: x[1])
bridges = []

for i in range(M): 
    flag = 1
    for bridge in bridges:
        if a[i][0] <= bridge and bridge < a[i][1]:
            flag = 0
            break 
    if flag:	bridges.append(a[i][1] - 1)   
print(len(bridges))

Measured memory_bytes: 65624
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    cin >> N;
    
    int MAX = 0;
    int MIN = INT32_MAX;
    int A[110];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if(MAX < A[i]) MAX = A[i];
        if(MIN > A[i]) MIN = A[i];
    }
    
    cout << MAX - MIN << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

  int count = 0 ;
  for ( int i = a ; i <= b ; ++i ) {
    if ( c % i )
      continue ;
    ++count ;
  }

  std::cout << count << std::endl ;

  return 0 ;
}

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


signed main(){
    int x, y; cin >> x >> y;
	cout << __gcd(x,y) << endl;
}


Measured memory_bytes: 3092
let (tbl : (string, unit) Hashtbl.t) = Hashtbl.create 1000000

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if Hashtbl.mem tbl s then "yes" else "no")
    | [_; s] -> Hashtbl.add tbl s ()
    | _ -> assert false
  done

Measured memory_bytes: 43848
n, m, x, y = map(int, raw_input().split())
arrx = map(int, raw_input().split())
arry = map(int, raw_input().split())
arrx.append(x)
arry.append(y)
if max(arrx)+1 > min(arry):
    print "War"
else:
    print "No War"

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b){
    cout<<c<<'\n';
  }
  else if(a==c){
    cout<<b<<'\n';
  }
  else if(b==c){
    cout<<a<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3556
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,c=0,d=0,min,x,i;
  int *b;
  scanf("%d",&a);
  b=(int *)malloc(sizeof(int) * a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  while(c<a-1){
    min=b[c];
    for(i=a-1;i>c;i--){
      if(b[i-1]>b[i]){x=b[i];b[i]=b[i-1];b[i-1]=x;d++;}
    }
  c++;
  }
  for(i=0;i<a;i++){
  printf("%d",b[i]);
  if(i!=a-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",d);
  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	double ans=0,mi=10000000;
	double n,t,a;
	cin >> n>>t>>a;
	for(int i = 0; i < n; ++i) {
		double h,m;
		cin >> h;
		m = abs(a - (t - h * 0.006));
		if(m < mi) {
			ans = i;
		}
		mi = min(mi, m);
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 256
import numpy as np

n, s = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

U = 3010
count = 0
F = np.zeros(U + 1, np.int64)
for a in A:
    F[0] += 1
    F[a:] += F[:-a].copy()
    F %= MOD
    count += F[s]

count %= MOD
print(count)

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

int main(){
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;

    double dist;
    dist = sqrt(pow(x1-x2,2)+pow(y1-y2,2));

    printf("%8lf",dist);

    return 0;
}



Measured memory_bytes: 3292
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

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

    vector<int> p(n);
    vector<double> lp(n);
    rep(i,n){
        cin>>p[i];
        lp[i]=(double)(((1+p[i])*p[i])/2)/p[i];
        //cout<<lp[i]<<endl;
    }
    double maxdice=0;
    double sum=0;
    rep(i,n){
        if(i<k){
            sum+=lp[i];
        }else{
            sum-=lp[i-k];
            sum+=lp[i];
        }
        maxdice=max(maxdice,sum);
    }
    cout<<fixed<<setprecision(6)<<maxdice<<endl;
    return 0;
}

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

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

int A[2010];

int main() {
    int N, X, Y; cin >> N >> X >> Y;

    for(int i = 1; i < N + 1; i++){
        for(int j = i + 1; j < N + 1; j++){
            int a = 1 + abs(Y - i) + abs(X - j);
            int b = 1 + abs(X - i) + abs(Y - j);
            A[min({j - i, a, b})]++;
        }
    }
    rep1(i,N) cout << A[i] << endl;
}


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

int main(){
    int a, b, k, i;
    cin >> a >> b >> k;
    for(i=0; i<k; i++){
        if(a+i <= b){
            cout << a+i << '\n';
        }
    }
    for(i=k-1; i>=0; i--){
        if(a+k <= b-i){
            cout << b-i << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 256
// MOHIT KUMAR
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pin;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
void change(ll&a , ll b) {a = max(a, b);}
#define ff(i, a, b) for ( ll i=a; i<(b); i++)
#define ffd(i, a, b) for ( ll i=a; i<= b; i++)
#define fr(i, a, b) for ( ll i = (b)-1; i >= a; i--)
#define ffr(i, a, b) for ( ll i = b ; i >= a; i--)
#define vl vector < ll >
#define vp vector < pl >
#define endl "\n"
#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const ld pi = acos(-1) ;
const ll maxn = 105 ;
const int mod = 1e9 + 7 ;
const ll INF = 1e18 ;
const int MX = 2000000001 ; // check the limits, dummy

int main() {
  ios_base::sync_with_stdio(0) , cin.tie(0);
  ll t, q, n, a, b, c, d, k, l, m, r,  x = 0, y = 0, z = 0 , sum = 0, ans = 0, temp = 0, res = 0 ;
  string s ;
  cin >> n ;
  ans =  1 ^ n  ;
  cout << ans ;

}

Measured memory_bytes: 3644
import java.util.*;

class Main{
  Scanner sc = new Scanner(System.in);
  
  public static void main(String[] args) {
    
    new Main().run();
    
  }
  
  void run() {
    int n = sc.nextInt();
    System.out.print( (n + 1) / 2 );
  }
  
}
  


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  string s;
  cin>>s;
  int n=s.size();

  int a=0;
  int b=0;
  int c=0;
  rep(i,n){
    if(s[i]=='a')a++;
    if(s[i]=='b')b++;
    if(s[i]=='c')c++;
  }

  vector<int> p={a,b,c};
  sort(all(p));

  if(n%3==0){
    if(a>n/3 || b>n/3 || c>n/3) {
      cout << "NO" << endl;
      return 0;
    }
  }
  if(n%3==1){
    if(p[0]>n/3 || p[1]>n/3 || p[2]>n/3+1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  if(n%3==2){
    if(p[0]>n/3 || p[1]>n/3+1 || p[2]>n/3+1) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] H = new int[N];
        int[] A = new int[M];
        int[] B = new int[M];
        int[] highlow = new int[N]; // 0==high, 1==low

        for(int i=0; i<N; i++){
            H[i] = sc.nextInt();
        }
  
        // input
        for(int i=0; i<M; i++){
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
            // dicide highlow
            if(H[A[i]-1] > H[B[i]-1]){
                highlow[B[i]-1] = 1;
            }else if(H[A[i]-1] < H[B[i]-1]){
                highlow[A[i]-1] = 1;
            }else{
                highlow[A[i]-1] = 1;
                highlow[B[i]-1] = 1;
            }
        }

        // logic
        int count = 0;
        for(int i=0; i<N; i++){
            if(highlow[i] == 0){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 51508
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair

using namespace std;

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

int s[1<<20];
int size;

// k人目の状態をseg-treeで管理
// ノードは区間内の生存者の合計を保持
void init(int n){
	size = 1;
	while(size < n){
		size *= 2;
	}
	memset(s, 0, sizeof(int)*size*2);
}

// k番目にaを加算
void add(int k, int a){
	k += size-1;
	s[k] += a;
	while(k > 0){
		k = (k-1)/2;
		s[k]+=a;
	}
}

// 生存者のn番目の位置を探す
int query(int n, int k, int l, int r){
	if(s[k] < n || s[k] == 0) return -1;
	if(r - l == 1){
		return k-(size-1);
	}
	int chl = k*2+1, chr = k*2+2;
	int ret = query(n, chl, l, (l+r)/2);
	if(ret != -1) return ret;
	return query(n-s[chl], chr, (l+r)/2, r);
}


int main(){
	int q, lim;
	while(cin >> q >> lim, q|lim){
		init(q);
		map<int, int> idmap;
		vector<int> v;
		int idx = 0;
		rep(i, q){
			int type, x;
			cin >> type >> x;
			int pos;
			switch(type){
			case 0:
				v.push_back(x);
				idmap[x] = idx;
				add(idx++, 1);
				// 生存者がlim人を超えたら一番左を殺す
				if(s[0] > lim){
					add(query(1, 0, 0, size), -1);
				}
				break;
			case 1:
				add(query(x, 0, 0, size), -1);
				break;
			case 2:
				pos = query(x, 0, 0, size);
				cout << v[pos] << endl;
				break;
			case 3:
				add(idmap[x], -1);
				break;
			}
		}
		cout << "end" << endl;
    }

	return 0;
}

Measured memory_bytes: 25488
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i]>a[j]:
            x+=1
y = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            y += 1

ans = x*k + y*k*(k-1)//2
print(ans%(10**9+7))

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

namespace A
{
    class Program
    {
        /// <summary>
        ///   The main entry point for the application
        /// </summary>
        [STAThread]
        public static void Main(string[] args)
        {
            string str = Console.ReadLine();
            long n = long.Parse(str);
            Console.Write("{0}", n * (n - 1) / 2);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,e) for(int i = a;i < e;++i)
using LL = long long;

struct TopologicalSort {
	vector<vector<int>> E; TopologicalSort(int N) { E.resize(N); }
	void add_edge(int a, int b) { E[a].push_back(b); }
	bool visit(int v, vector<int>& order, vector<int>& color) {
		color[v] = 1;
		for (int u : E[v]) {
			if (color[u] == 2) continue; if (color[u] == 1) return false;
			if (!visit(u, order, color)) return false;
		} order.push_back(v); color[v] = 2; return true;
	}
	bool sort(vector<int> &order) {
		int n = E.size(); vector<int> color(n);
		for (int u = 0; u < n; u++) if (!color[u] && !visit(u, order, color)) return false;
		reverse(order.begin(), order.end()); return true;
	}
};
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
vector<int> E[1000*500];
int dp[1000 * 500];
int main() {
	int N;
	cin >> N;
	// 閉路検出+DAGの最長パス
	using PII = pair<int, int>;
	int c = 0;
	map<PII, int>id; {
		FOR(i, 0, N) {
			FOR(j, i + 1, N) {
				id[PII(i, j)] = c++;
			}
		}
	}
	TopologicalSort G(c);
	FOR(i, 0, N) {
		vector<int>b(N - 1);
		FOR(j, 0, N - 1) {
			cin >> b[j];
			b[j]--;
		}
		FOR(j, 0, N - 2) {
			int from = id[i < b[j] ? PII(i, b[j]) : PII(b[j], i)];
			int to = id[i < b[j + 1] ? PII(i, b[j + 1]) : PII(b[j + 1], i)];
			G.add_edge(from, to);
			E[from].push_back(to);
		}
	}
	vector<int>ord;
	bool ok = G.sort(ord);
	if (!ok) {
		cout << "-1" << endl;
		return 0;
	}
	else {
		fore(cu, ord) fore(to, E[cu]) chmax(dp[to], dp[cu] + 1);
		int ans = 0;
		rep(i, 0, c) chmax(ans, dp[i]);
		cout << ans + 1 << endl;
	}

}





Measured memory_bytes: 90236
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

bool solve(){
    int x, y, z;
    cin >> x >> y >> z;
    if(!x) return 0;
    vector<int> v(x);
    for (auto &&i : v) scanf("%d", &i);
    vector<pair<int, int>> event(y+1);
    for (int i = 0; i < z; ++i) {
        int n, e, a;
        cin >> n >> e >> a;
        event[n] = {e, a};
    }
    auto dp = make_v(y+1, z*100+1, 0.0);
    int mx = 0;
    dp[0][0] = 1.0;
    for (int i = 0; i < y; ++i) {
        int maxx = mx;
        for (int j = 0; j <= mx; ++j) {
            for (int k = 0; k < x; ++k) {
                int ii = min(y, i+v[k]), jj = j;
                if(event[ii].first == 1){
                    ii = min(y, ii+event[ii].second);
                }else if(event[ii].first == 2){
                    jj += event[ii].second;
                    maxx = max(maxx, jj);
                }else if(event[ii].first == 3){
                    jj = max(0, jj-event[ii].second);
                }
                dp[ii][jj] += dp[i][j]/x;
            }
        }
        mx = maxx;
    }
    double ans = 0;
    for (int i = 0; i <= mx; ++i) {
        ans += i*dp.back()[i];
    }
    printf("%.0lf\n", floor(ans));
    return 1;
}

int main() {
    while(solve());
    return 0;
}


Measured memory_bytes: 5044
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
def sub(x):
    s = [(1,a[0])]
    for i in range(1,n):
#         print(s)
        l = a[i-1]
        if l<a[i]:
            s.append((1,a[i]-l))
        else:
            while s:
                k,v = s[-1]
                if l-v<=a[i]:
                    s[-1] = (k,v-(l-a[i]))
                    if s[-1][1]==0:
                        s.pop()
                    break
                else:
                    s.pop()
                    l -= v
            if s[-1][0]<x:
                k,v = s.pop()
                if v>=2:
                    s.append((k,v-1))
                s.append((k+1,1))
            else:
                if len(s)<2:
                    ans = False
                    break
                item = s.pop()
                k,v = s.pop()
                if v>=2:
                    s.append((k,v-1))
                    s.append((k+1,1))
                else:
                    if len(s)>=1 and s[-1][0]==k+1:
                        tmp = s.pop()
                        s.append((tmp[0], tmp[1]+1))
                    else:
                        s.append((k+1, v))
                s.append((1,item[1]))
        if len(s)>=2 and s[-1][0]==s[-2][0]:
            k,v1 = s.pop()
            k,v2 = s.pop()
            s.append((k, v1+v2))
    else:
        ans = True
    return ans
l = 0
r = n+1
while l<r-1:
    m = (l+r)//2
    if sub(m):
        r = m
    else:
        l = m
print(r)

Measured memory_bytes: 103768
n = gets.to_i
arr = gets.split.map(&:to_i)
ans = []
max = arr.index(arr.max_by(&:abs))
# maxが正なら左から、負なら右から
(n - 1).times do |i|
  if arr[max] > 0
    2.times do
      a = arr[i]
      b = arr[i + 1]
      if a > b
        arr[i + 1] += arr[max]
        ans << "#{max + 1} #{i + 2}"
      end
      max = arr[max] > arr[i + 1] ? max : i + 1
    end
  else
    2.times do
      a = arr[-i - 1]
      b = arr[-i - 2]
      if a < b
        arr[-i - 2] += arr[max]
        ans << "#{max + 1} #{n - i - 1}"
      end
      max = arr[max] < arr[-i - 2] ? max : n - i - 2
    end
  end
end
puts ans.count
puts ans


Measured memory_bytes: 3836
n=int(input())

value=0
cost=0

v=list(map(int, input().split()))
c=list(map(int, input().split()))

for i in range(n):
    if v[i]>c[i]:
        value=value+v[i]
        cost=cost+c[i]

total=value-cost

print(total)

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

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 998244353;
const ll MAX = 3e3+23;
const ll inf = 1e18+7;


int main(){
  fastio;
  ll a,b,ans=0;
  cin>>a>>b;
  f(i,1,1500){
    if((i*8)/100==a && (i*10)/100 == b){ans=i;break;}
  }
  if(ans) cout<<ans<<"\n";
  else cout<<"-1\n";
  return 0; 
}

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

int main() {
  int array[5]={}, flag = -1;
  for(int i = 0; i < 6; i++) {
    int num;
    cin >> num;
    array[num]++;
  }
  for(int i = 1; i <= 4; i++) {
    if(array[i] == 3) {
      cout << "NO" << endl;
      flag++;
      break;
    }
  }
  if(flag == -1) {
    cout << "YES" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
#include <iterator>

#define along long(x) x.begin(), x.end()
#define MOD 998244353
const unsigned long long M = 1000000007;
const long double PI = 3.141592653589793236L;

typedef long long ll;
typedef long double ld;
#define MAX 50
using namespace std;
void solve(){
    int n;
    cin>> n;
    string arr[n];
    int ac=0;
    int tle=0;
    int wa=0;
    int re=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    for(int i=0;i<n;i++){
        if(arr[i]=="AC")ac++;
        if(arr[i]=="TLE")tle++;
        if(arr[i]=="RE")re++;
        if(arr[i]=="WA")wa++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
   int t=1;
   //cin>>t;
   while(t--){
       solve();
   }
}

Measured memory_bytes: 6784
// https://atcoder.jp/contests/abc116/tasks/abc116_d
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

template <int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod)
            x -= mod;
    }
    ModInt &operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0)
            x += mod;
        return *this;
    }
    ModInt &operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt &operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
    friend ostream &operator<<(ostream &s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream &operator>>(istream &s, ModInt<mod> &a) {
        s >> a.x;
        return s;
    }
};
using mint = ModInt<(int)1e9 + 7>;

mint dp[101][8];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    // フィボナッチ数列
    vector<ll> fib(10);
    fib[0] = 1;
    fib[1] = 1;
    FOR(i, 2, 10) fib[i] = fib[i - 1] + fib[i - 2];
    dp[0][0] = 1;
    REP(i, h) REP(j, w) {
        if (j >= 1) {
            dp[i + 1][j - 1] += dp[i][j] * (fib[j - 1] * fib[w - j - 1]);
        }
        if (j <= w - 2) {
            dp[i + 1][j + 1] += dp[i][j] * (fib[j] * fib[w - j - 2]);
        }
        dp[i + 1][j] += dp[i][j] * (fib[j] * fib[w - j - 1]);
    }
    cout << dp[h][k - 1] << endl;

    return 0;
}


Measured memory_bytes: 256