akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;

const int LEN = 100005;
int head, tail;
vector<pair<string, int>> ling_buf(LEN);

void Enqueue(string s, int n)
{
    ling_buf[tail] = make_pair(s, n);
    tail = (tail+1) % LEN;
}
pair<string, int> Dequeue(void)
{
    pair<string, int> x = ling_buf[head];
    head = (head+1) % LEN;
    return x;
}

int main()
{
    int n, q;
    cin >> n >> q;
    rep(i,n){
        string name;
        int time;
        cin >> name >> time;
        ling_buf[i] = make_pair(name, time);
    }
    head = 0; tail = n;

    int p_time = 0;
    while(tail != head){
        pair<string, int> p = Dequeue();
        int q_time = min(p.second, q);
        p_time += q_time;
        if (p.second - q_time == 0) cout << p.first << " " << p_time << endl;
        else Enqueue(p.first, p.second - q_time);
    }
    return 0;
}


Measured memory_bytes: 6812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3620
n = int(input())
k = int(input())
x = list(input().split())
x = [ int(i) for i in x ]

sum = 0
for i in range(n):
	a = x[i] * 2
	b = (k - x[i]) * 2
	if a < b:
		sum += a
	else:
		sum += b

print(sum)

Measured memory_bytes: 3060
n = int(input())
li = list(map(int, input().split()))
new_li = sorted(li)
ans = (new_li[0] + new_li[1]) / 2
i = 2
for l in range(n - 2):
    ans = (ans + new_li[i]) / 2
    i += 1
print(str(ans))


Measured memory_bytes: 38384
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		for (long num = 1; num <= X / 100; ++num) {
			long res = X - num * 100;
			if (res <= 5 * num) {
				System.out.println(1);
				return;
			}
		}
		System.out.println(0);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int [] a = new int[n];
        Map<Integer, Integer> numberTimes = new HashMap<>();
        long totalWays = 0;
        for (int i = 0; i < n; ++i) {
            a[i] = scanner.nextInt();
            int times = numberTimes.getOrDefault(a[i], 0);
            numberTimes.put(a[i], times + 1);
        }
        for (Map.Entry<Integer, Integer> numberTime: numberTimes.entrySet()) {
            long currentTimes = numberTime.getValue();
            long currentWays = currentTimes * (currentTimes - 1) / 2;
            totalWays += currentWays;
        }
        for (int i = 0; i < n; ++i) {
            int currentNumber = a[i];
            int currentTimes = numberTimes.get(currentNumber);
            long newWays = totalWays - currentTimes * (currentTimes - 1) / 2 +
                    (currentTimes - 1) * (currentTimes - 2) / 2;
            System.out.println(newWays);
        }
    }
}


Measured memory_bytes: 98852
# include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846

void solve()
{
        int n, a, b; cin >> n >> a >> b;
        string s; cin >> s;
        int o = 0;
        int ca = 0, cb = 0;
        int all = 0;
        for(int i = 0; i < n; ++i)
        {
                if(s[i] == 'a')
                {
                        //all++;
                        if(all < a + b)
                        {
                                all++;
                                cout << "Yes" << endl;
                        }
                        else cout << "No" << endl;
                }
                else if(s[i] == 'b')
                {
                        cb++;
                        if(cb <= b && all < a + b) 
                        {
                                all++;
                                cout << "Yes" << endl;
                        }
                        else cout << "No" << endl;
                }
                else cout << "No" << endl;
        }
}
 
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        solve();
}

Measured memory_bytes: 848
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,n;
  while(1){
    cin >> n;
    int pm,pe,pj;
    if(n == 0) break;
    for(i=0;i<n;i++){
      cin >> pm >> pe >> pj;
      if(pm == 100 || pe == 100 || pj == 100 || (pm + pe)/2 >= 90 || (pm + pe + pj)/3 >= 80) cout << "A" << endl;
      else if((pm + pe + pj)/3 >= 70 || (pm + pe + pj)/3 >= 50 && (pm >= 80 || pe >= 80)) cout << "B" << endl;
      else cout << "C" << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 0
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
B = set(A)
if len(A) == len(B):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 26612
def otosi(n,y):
  ans=None
  for i in range(n+1):
    ii=0
    while n-i>=ii:
      if i*10000+ii*5000+(n-i-ii)*1000==y:
        ans=str(i)+" "+str(ii)+" "+str(n-i-ii)
        return ans
      else:
        ii+=1
  else:
    ans="-1 -1 -1"
    return ans
n,y=map(int,input().split())
print(otosi(n,y))

Measured memory_bytes: 38640
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 
int main(){
    int n, m ;
    cin >> n >> m ;
    map<int, int> mp ;
    rep(i, m){
        int s, c ;
        cin >> s >> c ;
        if(mp.count(s)){
            if(mp[s] != c){
                cout << - 1 << endl ;
                return 0 ;
            }
        }
        if(s == 1){
            if(c == 0 && n != 1){
                cout << -1 << endl ;
                return  0;
            }
        }
        mp[s] = c ;
    }
    vector<int> ans (n) ;
    for(int i = 1; i <= n ; i++){
        ans[i - 1] = mp[i] ;
    }
    if(ans[0] == 0){
        if(n != 1){
            ans[0] = 1 ;
        }
    }
    rep(i, n){
        cout << ans[i] ;
    }
    cout << endl ;
    return 0 ;
} 

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

int main() {
	int n,m,i,j,k,ans,cur;
	cin >> n >> m;
	vector<int> a(n);
	cur=0;
	for(i=0; i<n; i++){
		cin >> a[i];
		cur+=a[i];
	}
	sort(a.begin(),a.end());
	if(a[n-m]*4*m<cur){
		cout << "No" << endl;
	}else{
		cout << "Yes" <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll magic(ll a)
{
  ll k=a%4;
  if(a%4==1) return 1;
  if(a%4==2) return a+1;
  if(a%4==0) return a;
  return 0;
}
int main()
{
  ll a,b;
  cin>>a>>b;
  cout<<(magic(a-1)^magic(b));//Important to put brackets around cout<<(-----) else error
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * https://abc060.contest.atcoder.jp/tasks/arc073_a
 */
public class Main {
	 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int T = sc.nextInt();
		int[] t = new int[N];
		for(int i=0; i<N; i++){
			t[i] = sc.nextInt();
		}
		sc.close();
		
		int ans = 0;
		for(int i=1; i<N; i++){
			ans += Math.min(t[i]-t[i-1], T);
		}
		ans += T;
 
		System.out.println(ans);
 
	}
 
}

Measured memory_bytes: 61948
from bisect import bisect_left as bs
def solve():
  while True:
    d = int(input())
    if not d: break
    n = int(input())
    m = int(input())
    d_lst = [int(input()) for _ in range(n - 1)]
    d_lst.extend([0,d])
    d_lst.sort()
    ans = 0
    for _ in range(m):
      k = int(input())
      ind = bs(d_lst,k)
      ans += min(abs(k - d_lst[ind]), abs(k - d_lst[ind - 1]))
    print(ans)
solve()


Measured memory_bytes: 10232
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
char S[N];
int n;
int main() {
	scanf("%s",S+1); n=strlen(S+1);
	int tot=0;
	for(int i=1;i<=n;++i)
		tot+=S[i]=='1';
	int x=0,y=0;
	ll res=0;
	for(int i=1;i<=n;++i) {
		if(S[i]=='0') ++x;
		else {
			int j=i; while(j+1<=n&&S[j+1]=='1') ++j;
			if(j-i+1&1) {
				if(!(x+y&1)) res+=(x+1>>1);
				else res+=(x>>1);
				res+=(n-tot)-x;
				y^=1;
			}
			res+=1ll*(j-i+1>>1)*(n-tot);
			i=j;
		}
	}
	if(tot&1) res+=(tot+1>>1),tot--;
	for(int i=tot;i;i-=2) res+=i;
	printf("%lld",res);
	return 0;
}

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

int main() {
  char S;
  cin >> S;
  

  
    if(S=='a'||S=='i'||S=='u'||S=='e'||S=='o'){cout << "vowel" << endl;}
    else{cout << "consonant" << endl;}
 
  
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
using namespace std;

ll gcd(ll a, ll b){
	ll q = max(a, b);
	ll r = min(a, b);
	while (r){
		ll t = q;
		q = r;
		r = t % r;
	} return q;
}

int main(){
	ll n,g; cin >> n;
	vl a(n), b(n), vte(n), etv(n); cin >> a[0];
	g = a[0];
	vte[0] = a[0];
	for (ll i = 1; i < n; ++i){
		cin >> a[i];
		g = gcd(g, a[i]);
		vte[i] = g;
	}g = a[n - 1];
	etv[0] = a[n - 1];
	for (ll i = 1; i < n; ++i){
		g = gcd(g, a[n - 1 - i]);
		etv[i] = g;
	}

	ll ans = g;
	for (ll i = 0; i < n ; ++i){
		if (i == 0) ans = max(ans, etv[n - 2]);
		else if (i == n - 1) ans = max(ans, vte[n - 2]);
		else ans = max(ans, gcd(vte[i - 1], etv[n - 2 - i]));
	}cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define max_heap priority_queue<int>
#define min_heap priority_queue<int,vector<int>,greater<int>>
using ll = long long;
#define int long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define inp_arr(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define out_arr(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";
#define deb(n) cerr << #n << " = " << n << "\n";
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
ll mypower(ll x,ll n,ll c){
    if(n == 0)
        return 1;
    ll temp = mypower(x,n/2,c)%c;
    if(n%2)
        return (n<0)? (1/x)*temp*temp%c: ((x*temp)%c)*temp%c;
    else
        return temp*temp%c;
}
bool codejam = 0;

bool check(ll mid, vector<int> a,ll k){
	ll ans = 0;
	for(int i=0;i<a.size();i++){
		if(a[i]>mid){
			ans += a[i]/mid;
		}
	}
	return ans<= k;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	ll n;
	ll k;
	cin>>n>>k;
	vector<int> a(n);
	inp_arr(a,n);
	ll low = 0;
	ll high = *max_element(all(a));
	while(low<high){
		ll mid = low+(high-low)/2;
		if(mid and check(mid,a,k))
			high = mid;
		else
			low = mid+1;
	}
	cout<<low<<endl;
	return 0;
}


Measured memory_bytes: 6336
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, y;
  cin >> n >> y;
  bool flag = true;
  bool flag_roop = false;
  rep(i, n+1) {
    rep(j, n+1) {
      int zan = y - 1000*i - 5000*j;
      if (zan >= 0) {
        if (zan%10000 == 0) {
          if (zan/10000+i+j == n) {
            cout << zan / 10000 << " " << j << " " << i << endl;
            flag = false;
            flag_roop = true;
            break;
          }
        }
      }
    }
    if (flag_roop) {
      break;
    }
  }
  if (flag) {
    cout << "-1 -1 -1" << endl;
  }
}


Measured memory_bytes: 3588
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;

public class Main {
	
	MyScanner sc;
	PrintWriter writer;

	public void solve() {
		while(true) {
			int n = sc.nextInt();
			if (n == 0) {
				return;
			}
			Map<Character, Character> map = new HashMap<Character, Character>(n);
			for (int i = 0; i < n; i++) {
				map.put(sc.nextChar(), sc.nextChar());
			}
			StringBuilder sb = new StringBuilder();
			int m = sc.nextInt();
			for (int i = 0; i < m; i++) {
				char c = sc.nextChar();
				if (map.containsKey(c)) {
					sb.append(map.get(c));
				} else {
					sb.append(c);
				}
			}
			writer.println(sb);
		}
	}

	public Main() {
		sc = new MyScanner(System.in);
		writer = new PrintWriter(System.out);
	}

	public static void main(String[] args) {
		Main m = new Main();
		m.solve();
		m.writer.flush();
	}

	class MyScanner {
		InputStream is;
		private byte[] buffer = new byte[1024];
		private int bufferPointer = 0;
		private int bufferLength = 0;

		MyScanner(InputStream is) {
			this.is = is;
		}

		private int readByte() {
			if (bufferLength == -1) {
				throw new InputMismatchException();
			}
			if (bufferPointer >= bufferLength) {
				bufferPointer = 0;
				try {
					bufferLength = is.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (bufferLength <= -1) {
					return -1;
				}
			}
			return buffer[bufferPointer++];
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (isChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		
		char nextChar() {
			int b = skip();
			return (char) b;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			int num = 0;
			int b;
			boolean negative = false;
			while ((b = readByte()) != -1 && !isDigit(b) && b != '-')
				;
			if (b == '-') {
				negative = true;
				b = readByte();
			}
			while (true) {
				if (isDigit(b)) {
					num = num * 10 + (b - '0');
				} else {
					return negative ? -num : num;
				}
				b = readByte();
			}
		}

		int[] nextIntArray(int length) {
			int[] array = new int[length];
			for (int i = 0; i < length; i++) {
				array[i] = sc.nextInt();
			}
			return array;
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean negative = false;
			while ((b = readByte()) != -1 && !isDigit(b) && b != '-')
				;
			if (b == '-') {
				negative = true;
				b = readByte();
			}
			while (true) {
				if (isDigit(b)) {
					num = num * 10 + (b - '0');
				} else {
					return negative ? -num : num;
				}
				b = readByte();
			}
		}

		// from '!' to '~'
		private boolean isChar(int b) {
			return b >= 33 && b <= 126;
		}

		private boolean isDigit(int b) {
			return b >= '0' && b <= '9';
		}

		private int skip() {
			int b;
			while ((b = readByte()) != -1 && !isChar(b))
				;
			return b;
		}

	}
}

Measured memory_bytes: 33964
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        sc.close();
        if(a > k){
            System.out.println(k);
        }else if(a + b > k){
            System.out.println(a);
        }else{
            System.out.println(2 * a - k + b);
        }
    }
}

Measured memory_bytes: 35828
#include <bits/stdc++.h>
using namespace std;
int a[103],n,ans=0;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];sort(a,a+n);
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)for(int k=j+1;k<n;k++)
		if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]+a[j]>a[k]) ans++;
	cout<<ans;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int a[4];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    rep(i, 0, 4) cin >> a[i];
    int l = a[0] + a[1], r = a[2] + a[3];
    if (l == r) cout << "Balanced" << endl;
    else if (l < r) cout << "Right" << endl;
    else cout << "Left" << endl;
    return 0;
}



Measured memory_bytes: 256
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
pl=[]
nl=0
ans=0
su=0
for a,b in zip(al,bl):
    su+=a-b
    if a>=b:
        pl.append(a-b) 
    else:nl+=a-b;ans+=1
if su<0:print(-1);exit()
pl.sort()


while nl<0:
    nl+=pl.pop()
    ans+=1
print(ans)

Measured memory_bytes: 18356
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

int main()
{
    int n,k,cnt=0;
    cin>>n>>k;
    while(n)
    {
        n/=k;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

unordered_map<ll, int> mp;
int N;
const int MAX_N = (int) 1e5;

void solve() {
    int ans = 0;
    EACH(m, mp) if (m.second % 2 != 0) ans++;
    cout << ans << endl;
}

int main() {
    cin >> N;
    ll temp;
    REP(i, N) {
        cin >> temp;
        mp[temp]++;
    }
    solve();
    return 0;
}

Measured memory_bytes: 4388
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String num1 = in.next();
		String num2 = in.next();
		Main com = new Main();
		int result = com.Compare(num1, num2);
		String display = "";
		if (result == -1) {
			display = "LESS";
		}else if (result == 1) {
			display = "GREATER";
		} else {
			display = "EQUAL";
		}
		System.out.println(display);
	}
	
	private int Compare(String num1, String num2) {
		// TODO Auto-generated method stub
		int len1 = num1.length();
		int len2 = num2.length();
		if (len1 < len2) {
			return -1;
		}else if (len1 > len2) {
			return 1;
		}else {
			int i = 0;
			while (i < len1) {
				if (num1.charAt(i) > num2.charAt(i)) {
					return 1;
				}else if(num1.charAt(i) < num2.charAt(i)){
					return -1;
				}
				i++;
			}
		}
		return 0;
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  ans = n * (n-1)/2 + m * (m-1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif

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

    string S; cin >> S;
    int SL = S.size();
    string T; cin >> T;
    int TL = T.size();

    if (SL<TL) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    string ans = "UNRESTORABLE";
    for(int i=SL-1; i>=0; i--) {
        bool match = true;
        for(int j=0; j<TL; j++) {
            if (i-j<0 || (S[i-j]!='?' && S[i-j]!=T[TL-1-j])){
                match = false;
                break;
            }
        }
        if (match) {
            // atcoderabc
            int b = i - TL + 1;
            ans = S.substr(0, b) + T + S.substr(b + TL);
            for(int k=0; k<ans.size(); k++) {
                if (ans[k] == '?') ans[k] = 'a';
            }
            break;
        }
    }    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
int main(){
  vector<vector<ll>> a(3, vector<ll>(3,0));
  rep(i,3)rep(j,3){
    ll ta; cin >> ta; a[i][j]=ta;
  }
  ll n; cin >> n;
  vector<vector<ll>> b(a);
  map<ll,ll> r,c;
  ll x1=0,x2=0;
  rep(t,n){
    ll tb; cin >> tb;
    rep(i,3)rep(j,3){
      if(b[i][j]==tb){
        b[i][j]=-1;
        r[i]++;
        c[j]++;
        if(i==j){x1++;x2++;}
        if(abs(i-j)==2)x2++;
      }
    }
  }
  string ans = no;
  if(x1>=3||x2>=3) ans=yes;
  rep(i,3){
    if(r[i]>=3||c[i]>=3) ans=yes;
  }
  cout << ans;
  return 0;
}
// 1 2 3 4 5 6 7 8 9


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

using namespace std;

long long n, ans = 0;
int main()
{
    cin >> n;
    int help = n % 3;
    for(long long i = 1; i < n; i++)
        ans += (n - 1) / i;
    cout << ans;     
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
	int a, b;
	cin >> a >> b;
	if ((a < 0 && b > 0) || (a == 0 || b == 0)) {
		cout << "Zero" << endl;
	}
	else if (a > 0) {
		cout << "Positive" << endl;
	}
	else {
		if ((a - b) % 2 == 0)
		{
			cout << "Negative" << endl;
		}
		else {
			cout << "Positive" << endl;
		}
		
	}
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
const int  maxn=100+50;
char s[maxn];
int main ()
{
	int k;
  	cin>>s;
	cin>>k;
	int i;
	for ( i=0;i<k;++i)
	   {
	   	 if (s[i]=='1') continue;
	   	 else
	   	   {
	   	   	cout<<s[i]<<"\n";
	   	   	break;
		   }
	   }
	if (i==k)
	  cout<<"1"<<"\n"; 
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,x;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<40)	a=40;
	if(b<40)	b=40;
	if(c<40)	c=40;
	if(d<40)	d=40;
	if(e<40)	e=40;
	x=a+b+c+d+e;
	x=x/5;
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    for(ll i=0;i<k;i++)ans+=a[i];
    cout<<ans<<"\n";
}


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

using namespace std;

typedef long long ll;
typedef pair <ll,ll> pll;

int main()
{
    set <pll> st;

    ll C = 0;               /// constant sum
    ll Cnt1 = 0, Sum1 = 0;  /// less or equal
    ll Cnt2 = 0, Sum2 = 0;  /// greater

    ll q;  cin >> q;

    pll x;

    ll T, a, b;    scanf("%lld%lld%lld", &T, &a, &b);

    st.insert(pll(a, 0));
    x = pll(a, 0);
    Cnt1++;
    Sum1 += a;
    C += b;

    for(ll i = 1; i < q; i++)
    {
        scanf("%lld", &T);

        if(T == 1)
        {
            scanf("%lld%lld", &a, &b);

            pll p = pll(a, i);

            st.insert(p);

            if(p <= x)  Cnt1++, Sum1 += a;
            else        Cnt2++, Sum2 += a;

            set <pll> :: iterator it = st.lower_bound(x);

            while(Cnt2 > Cnt1 - 1)
            {
                it++;

                Cnt2--;
                Sum2 -= (*it).first;

                Cnt1++;
                Sum1 += (*it).first;
            }

            while(Cnt1 - 1 > Cnt2)
            {
                Cnt1--;
                Sum1 -= (*it).first;

                Cnt2++;
                Sum2 += (*it).first;

                it--;
            }

            x = *it;
            C += b;
        }

        else
        {
            ll Ans = x.first * Cnt1 - Sum1 - x.first * Cnt2 + Sum2;

            printf("%lld %lld\n", x.first, Ans + C);
        }
    }
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N = 100100;
int A[MAX_N], N;

ll min_to_center() 
{
    ll res = 0;
    ll left = A[0], right = A[0];
    int i = 1, j = N-1;
    while(j - i > 0) {
        res += abs(left - A[j]);
        left = A[j];
        --j;
        if(j - i <= 0) break;
        res += abs(right - A[j]);
        right = A[j];
        --j;
        if(j - i <= 0) break;
        res += abs(left - A[i]);
        left = A[i];
        ++i;
        if(j - i <= 0) break;
        res += abs(right - A[i]);
        right = A[i];
        ++i;
        if(j - i <= 0) break;
    }
    res += max(abs(left - A[i]), abs(right - A[i]));
    return res;
}

ll max_to_center() 
{
    ll res = 0;
    ll left = A[N-1], right = A[N-1];
    int i = 0, j = N-2;
    while(j - i > 0) {
        res += abs(left - A[i]);
        left = A[i];
        ++i;
        if(j - i <= 0) break;
        res += abs(right - A[i]);
        right = A[i];
        ++i;
        if(j - i <= 0) break;
        res += abs(left - A[j]);
        left = A[j];
        --j;
        if(j - i <= 0) break;
        res += abs(right - A[j]);
        right = A[j];
        --j;
        if(j - i <= 0) break;
    }
    res += max(abs(left - A[i]), abs(right - A[i]));
    return res;
}

int main()
{
    scanf("%d", &N);
    for(int i = 0; i < N; ++i) scanf("%d", &A[i]);

    sort(A, A + N);
    ll res = max(max_to_center(), min_to_center());
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    long long ans=0;
    for (int i = 1;i*i <=n; i++) {
        ans=i*i;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=1e5+10;
LL t,n,m,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

LL K,S;

LL check(LL a,LL b,LL c){
	LL i,j,k,l;
	if(a==b&&a==c)return 1;
	if(a==b&&a!=c)return 3;
	if(a!=b&&b==c)return 3;
	return 6;
}

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0;
	cin>>K>>S;
	repu(i,0,K){
		repu(j,i,K){
			k=S-i-j;
			if(k<j)break;
			if(k>=j&&k<=K)ans+=check(i,j,k);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  ll n,m;
  cin>>n>>m;
  cout<<abs((n-2)*(m-2))<<endl;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<bitset>
#include<vector>
const int N=1000000;
int main()
{
	std::bitset<N>p;
	std::vector<int>v,A,B;
	int i,j,a,b;
	for(i=2;i<N;++i)if(!p[i])for(v.push_back(i),j=i*2;j<N;j+=i)p[j]=1;
	while(scanf("%d%d",&a,&b),a)
	{
		A.clear(),B.clear();
		for(i=0;i<v.size();++i)
		{
			if(a%v[i]==0)A.push_back(v[i]);
			if(b%v[i]==0)B.push_back(v[i]);
		}
		for(a=A.back(),i=0;i<A.size()-1;++i)a-=A[i];
		for(b=B.back(),i=0;i<B.size()-1;++i)b-=B[i];
		puts(a>b?"a":"b");
	}
	return 0;
}

Measured memory_bytes: 1340
#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{
    char s[99];
    gets(s);
    int n=strlen(s)-1;
    int f1=0;
    for(int i=0;i<=n/2;i++){
        if(s[i]!=s[n-i]){
            f1++;
            printf("No");
            return 0;
        }
    }
    int f2=0;
    for(int i=0;i<=(n-1)/2;i++){
        if(s[i]!=s[(n-1)/2-i]){
            f2++;
            printf("No");
            return 0;
        }
    }
    int f3=0;
    for(int i=(n+3)/2;i<=n;i++){
        if(s[i]!=s[n-i]){
            f3++;
            printf("No");
            return 0;
        }
    }
    if(f1==0 && f2==0 && f3==0) printf("Yes");
    else printf("No");

    return 0;
}

Measured memory_bytes: 1628
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
using namespace std;
signed main(){
    vector<int>dp(51,1LL),dp2(51,1LL);
    int n,x; cin >> n >> x;
    for(int i = 1; i < dp.size();++i){
        dp[i] = dp[i-1] + dp[i-1] + 3;
        dp2[i] = dp2[i-1] + dp2[i-1] + 1;
    }
    function<int(int,int)>cal = [&](int i,int x) -> int{
        if(i == 0){ return x > 0;}
        return (x >= dp[i-1] + 2 ? dp2[i-1] + 1 + cal(i-1,x-dp[i-1]-2) : cal(i-1,x-1));
    };
    cout << cal(n,x) << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	ll a, b; cin >> a >> b;
	ll c = __gcd(a, b);
	vector<ll> div;
	for(int i = 2; (ll)i * i <= c; i++) if(c % i == 0){
		div.pb(i);
		while(c % i == 0) c /= i;
	}
	if(c > 1) div.pb(c);
	cout << 1 + div.size() << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		long[] a = new long[n];

		for (int i = 0; i < n ;  i++) {
			a[i] = scan.nextLong();
			if(a[i] == 0) {				//入力された数値が0なら"0"を出力
				System.out.print(0);
				return;					//プログラム終了
			}
		}
		
		long ans = a[0];
		for(int i = 1; i < n; i++) {
			if(a[i] <= (1000000000000000000L / ans)) {
				ans *= a[i];
			}
			else {
				System.out.print(-1);
				return;
			}
		}
		
		System.out.print(ans);
		
	}

}


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

int a[100][100], b[100];
int main() {
	int n, m; cin >> n >> m;
	rep(i, n)rep(j, m)cin >> a[i][j];
	rep(i, m)cin >> b[i];
	rep(i, n) {
		int sum = 0;
		rep(j, m)sum += a[i][j] * b[j];
		cout << sum << endl;
	}
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[100];
  cin>>n;
  cin>>a[0];
  int m=a[0],cn=1;
  for(int i=1;i<n;i++){
    cin>>a[i];
    if(m<=a[i]){
      cn++;
      m=a[i];
    }
  }
  cout<<cn<<endl;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int a, b;
  cin >> a >> b;
  cout << (max(a, b) > 8 ? ":(" : "Yay!") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #include<boost/multiprecision/cpp_int.hpp>
// using boost ::multiprecision::cpp_int;
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/

int main()
{
    boost;
    ll n,w;
    cin>>n>>w;
    ll a[n+1],b[n+1];
    b[0]=0;
    for(ll i=1;i<=n;i++)
    cin>>a[i]>>b[i];
    ll total_value = 0 ;
    for(auto &x: b)
    total_value+=x;
    ll dp[n+1][total_value+1]; // mininmum weight we can get when total value is j
    // memset(dp,1000000000,sizeof dp);
    dp[0][0] = 0;
    for(ll i=1;i<=total_value;i++)
    {
        dp[0][i] = 10000000000000;
        // dp[0][i]=0;

    }
    for(ll i=1;i<=n;i++)
    {
        dp[i][0]=0;
    }
    // cout<<dp[0][0]<<"\n";
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=total_value;j++)
        {
            if(b[i] > j )
            {
                dp[i][j] = dp[i-1][j];
            }
            else 
            dp[i][j] = min(dp[i-1][j], a[i] + dp[i-1][j-b[i]]);
            // cout<<dp[i][j]<<" ";
        }
        // cout<<"\n";.
    }
    
    for(ll i=1;i<=total_value;i++)
    {
        if(dp[n][i]  <= w)
        {
            ans = max(ans,i);
        }
    }
    cout<<ans<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}
/* AnsHuman_7 || Anshuman Gaur */

Measured memory_bytes: 79232
N = int(input())
A = [int(x) for x in input().split()]


i = 0
min_val = float("inf")
res = 0
while i < N:
    if A[i] <= min_val:
        res += 1
    min_val = min(min_val, A[i])
    i += 1

print(res)


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

long long const inf = 1e18;
int const mxn = 4e2+10;

 
 
long long l[mxn],par[mxn],dp[mxn][mxn];


int main(){
	int n;
	cin>>n;
	for (int i = 1;i<=n;i++)
		cin>>l[i];
	par[1]=l[1];
	for (int i = 1;i<=n;i++)
		par[i] = par[i-1] + l[i];
		
	for (int i =0;i<mxn;i++)
		for (int j =0;j<mxn;j++)	
			dp[i][j]=1e18;
			
	for (int i = 1;i<=n;i++)
		dp[i][i]=0;
		
		
		
		
	for (int t = 1;t<=n;t++){
		
		for (long long  i =1 ;i+t<=n;i++){
			
			long long  k  = i + t;
			
			for (long long  j = i;j<=k;j++){
				
				dp[i][k] = min(dp[i][k], dp[i][j]+dp[j+1][k]+par[k]-par[i-1]);
				
			}
		}
	}
	cout<<dp[1][n];
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
	while(1){
		int i,h[5],a=0,b=0,c=0;
		cin>>h[0];
		if(h[0]==0)break;
		cin>>h[1]>>h[2]>>h[3]>>h[4];
		for(i=0;i<5;i++){
			if(h[i]==1){
				a++;
			}else if(h[i]==2){
				b++;
			}else{
				c++;
			}
		}
		if((a!=0&&b!=0&&c!=0)||(a==5||b==5||c==5)){
			for(i=0;i<5;i++){
				cout<<'3'<<endl;
			}
		}else if(a==0){
			for(i=0;i<5;i++){
				if(h[i]==2){
					cout<<'1'<<endl;
				}else{
					cout<<'2'<<endl;
				}
			}
		}else if(b==0){
			for(i=0;i<5;i++){
				if(h[i]==3){
					cout<<'1'<<endl;
				}else{
					cout<<'2'<<endl;
				}
			}
		}else{
			for(i=0;i<5;i++){
				if(h[i]==1){
					cout<<'1'<<endl;
				}else{
					cout<<'2'<<endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int deg[110];

int solve() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  int mx = 0;
  for(int i = 0; i < n; i++) {
    int a; cin >> a;
    deg[a]++;
    mx = max(mx, a);
  }
  int dia = mx + 1;
  int mi, center, need;
  if(dia % 2) {
    mi = (dia + 1) / 2;
    center = dia / 2;
    need = 1;
  } else {
    mi = dia / 2 + 1;
    center = dia / 2;
    need = 2;
  }
  for(int i = 1; i <= mx; i++) {
    if(center == i) {
      if(deg[i] != need) return 0;
    } else if((i < mi && deg[i] >= 1) || (i >= mi && deg[i] < 2)) {
      return 0;
    }
  }
  return 1;
}

int main() {
  cout << (solve() ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<P> p(N);
  REP(i, N) {
    int a, b;
    cin >> a >> b;
    p[i] = P(b, a);
  }
  bool ok = true;
  sort(all(p));
  int t = 0;
  REP(i, N) {
    t += p[i].second;
    if(p[i].first < t) {
      ok = false;
      break;
    }
  }
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3456
#include <cstdio>
#include <cstdlib>

int main(){
    int A1,A2,A3;
    scanf("%d%d%d",&A1,&A2,&A3);
    int t[3];
    t[0] = abs(A1 - A2);
    t[1] = abs(A2 - A3);
    t[2] = abs(A3 - A1);
    int maxt = t[0];
    for(int i = 1; i < 3; i++){
        if(maxt < t[i]){
            maxt = t[i];
        }
    }
    printf("%d\n",t[0] + t[1] + t[2] - maxt);

    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=310;
int n,x,tot,b[N][N],f[N][N];
main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) scanf("%d",&f[i][j]);
	for (int k=1;k<=n;++k)
		for (int i=1;i<=n;++i)
			for (int j=1;j<=n;++j)
			if (f[i][j]>f[i][k]+f[k][j]) return puts("-1"),0;
			else if (i!=k&&k!=j&&f[i][j]==f[i][k]+f[k][j]) b[i][j]=1;
	long long ans=0;
	for (int i=1;i<=n;++i) for (int j=i+1;j<=n;++j) ans+=f[i][j]*(1-b[i][j]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF =ll(1e18) +5;
ll N,M,X;
vector<ll> C;
vector<vector<ll>> A;
ll ans;
vector<bool> used;

void dfs(int t){
    // cerr <<"t="<<t << endl;
    if(t==N){
        ll sum =0;
        ll power[M] = {};
        for(int i=0;i<N;i++){
            if(used[i] == false){
                continue;
            }
            sum += C[i];
            for(int j=0;j<M;j++){
                power[j] += A[i][j];
            }
        }
        for(int i=0;i<M;i++){
            if(power[i] <X){
                return;
            }
        }
        ans = min(ans,sum);
        return;
    }
    dfs(t+1);
    used[t] = true;
    dfs(t+1);
    used[t] = false;

}


int main(){
    cin >> N >>M >>X;
    C.resize(N);
    A.resize(N);
    used.resize(N,false);
    ans =INF;
    for(int i=0;i<N;i++){
        cin >> C[i];
        for(int j=0;j<M;j++){
            ll a;
            cin >> a;
            A[i].push_back(a);
        }
    }
    // cerr <<"temp" << endl;
    dfs(0);
    if(ans  ==INF){
        cout <<-1 <<endl;
        return 0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i)
        cout << "x";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
#define int long long

signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  int v[n];
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v, v + n, greater<int>());
  int sum = 0;
  double ans = 0;
  int ansp = 0;
  for (int i = 0; i < a; i++) {
    sum += v[i];
  }
  ans = (double)sum / a;
  printf("%.8f\n", ans);
  int pascal[n + 1][n + 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      pascal[i][j] = 0;
    }
  }
  pascal[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (j == 0) pascal[i][j] = pascal[i - 1][j];
      else pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
    }
  }
  if (v[0] == v[a - 1]) {
    int count = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] == v[0]) count++;
    }
    int res = 0;
    for (int i = a; i <= b; i++) {
      if (count < i) break;
      res += pascal[count][i];
    }
    cout << res << endl;
  } else {
    int x = 0, y = 0;
    for (int i = 0; i < a; i++) {
      if (v[i] == v[a - 1]) {
        x++;
        y++;
      }
    }
    for (int i = a; i < n; i++) {
      if (v[i] == v[a - 1]) {
        x++;
      }
    }
    cout << pascal[x][y] << endl;
  }
  /*
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cout << pascal[i][j] << " ";
    }
    cout << endl;
  }
  */
  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  vector<int> cnt(2);
  for (auto &c : s) cnt[c-'0']++;
  cout << min(cnt[0], cnt[1]) * 2<< '\n';
  return 0;
}

Measured memory_bytes: 512