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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

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

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	--n; --m;
	printf("%d\n", n * m);
	return 0;
}

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

const int INF = 1001001001;
int dp[1005][10005];

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];

    rep(i,n+1) rep(j,h+1) dp[i][j] = INF;

    dp[0][0] = 0;

    rep(i,n) rep(j,h+1){
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        int nj = min(h, j + a[i]);
        dp[i+1][nj] = min(dp[i+1][nj], dp[i+1][j] + b[i]);
    }

    cout << dp[n][h] << endl;
}

Measured memory_bytes: 42672
/*ITP1_10_B:Triangle*/
#include <iostream>
#include <math.h>

using namespace std;

int main() {

    double a,b,c,C,S,L,h;

    cin >> a >> b >> C;

    C = C * M_PI / 180.0;
    h = b * sin(C);
    S = a * h / 2.0;
    double tmp = a*a + b*b - 2.0*a*b*cos(C);
    c = sqrt(tmp);
    L = a + b + c;

    cout << fixed;
    cout << S << endl;
    cout << L << endl;
    cout << h << endl;

    return 0;

}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;

int n, cnt, X, Y, Z;
long long sumy, sumz, ans, que[MAX_N], pre[MAX_N];
struct Triple {
    int x, y, z;
    
    Triple() {
    }
    Triple(int _x, int _y, int _z) :
        x(_x), y(_y), z(_z) {
    }
    
    bool operator <(const Triple &rhs) const {
        return x - y > rhs.x - rhs.y;
    }
} a[MAX_N];

int main() {
    scanf("%d%d%d", &X, &Y, &Z);
    n = X + Y + Z;
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i) {
        a[i].x -= a[i].z;
        a[i].y -= a[i].z;
        sumz += a[i].z;
    }
    for (int i = 1; i <= X; ++i) {
        que[cnt++] = -a[i].x;
        pre[X] += a[i].x;
    }
    make_heap(que, que + cnt);
    for (int i = X + 1; i <= n - Y; ++i) {
        que[cnt++] = -a[i].x;
        push_heap(que, que + cnt);
        pre[i] = pre[i - 1] + a[i].x + que[0];
        pop_heap(que, que + (cnt--));
    }
    cnt = 0;
    for (int i = n - Y + 1; i <= n; ++i) {
        que[cnt++] = -a[i].y;
        sumy += a[i].y;
    }
    make_heap(que, que + cnt);
    ans = sumy + pre[n - Y];
    for (int i = n - Y; i > X; --i) {
        que[cnt++] = -a[i].y;
        push_heap(que, que + cnt);
        sumy += a[i].y + que[0];
        ans = max(ans, sumy + pre[i - 1]);
        pop_heap(que, que + (cnt--));
    }
    printf("%lld\n", ans + sumz);
}

Measured memory_bytes: 2176
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
typedef long long ll;
using namespace std;
long long n,k,cnt;
int main(){
	cin>>n>>k;
	for (int i=1;i<=int(n);i++){
		cnt+=ll(n/i*max(0ll,i-k));
		if (n%i!=0) cnt+=ll(max(0ll,n%i-ll(max(k,1ll))+1));
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

bool ch[100010];
int main() {
	ll n,m,t[100010];
	cin>>n>>m;
	for(ll i=0;i<n;i++){
		cin>>t[i];
	}
	for(ll i=0;i<n;i++){
		ch[i]=true;
	}
	for(ll i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		if(t[x]<=t[y]){
			ch[x]=false;
		}
		if(t[y]<=t[x]){
			ch[y]=false;
		}
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
		if(ch[i]){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 4500
#include <iostream>
#include <cstring>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void){
    int l, b = 1, cnt = 0;
    vector<int> u, v, w;
    cin >> l;
    
    while (b <= l) {
        b *= 2;  cnt++;
    }
    for (int i = 1; i <= cnt - 1; i++) {
        u.push_back(i);  v.push_back(i + 1);  w.push_back(pow(2, i - 1));
        u.push_back(i);  v.push_back(i + 1);  w.push_back(0);
    }
    l -= b / 2;
    int n = cnt, k = b / 2;
    
    while (l != 0) {
        cnt = 0;
        b = 1;
        while (b <= l) {
            b *= 2;  cnt++;
        }
        u.push_back(cnt);  v.push_back(n);  w.push_back(k);
        k += b / 2;
        l -= b / 2;
    }
    
    
    cout << n << " " << u.size() << endl;
    for (int i = 0; i < u.size(); i++) cout << u[i] << " " << v[i] << " " << w[i] << endl;
}


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

int main(){
  int n;
  cin >> n;
  int a,s[13]={},h[13]={},c[13]={},d[13]={};
  char b;
  for(int i=0;i<n;i++){
    cin >> b >> a;
    if(b=='S')s[a-1]=1;
    else if(b=='H')h[a-1]=2;
    else if(b=='C')c[a-1]=2;
    else if(b=='D')d[a-1]=3;
  }
  for(int i=0;i<13;i++){
    if(!(s[i]>0))cout << "S" << " " << i+1  << endl;
  }
  for(int i=0;i<13;i++){
    if(!(h[i]>0))cout << "H" << " " << i+1 << endl;
  }
  for(int i=0;i<13;i++){
    if(!(c[i]>0))cout << "C" << " " << i+1 << endl;
  }
  for(int i=0;i<13;i++){
    if(!(d[i]>0))cout << "D" << " " << i+1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3080
# -*- coding: utf-8 -*-

a = list(input())
dic = {}
for x in a:
    dic.setdefault(x, 0)
    dic[x] += 1
if (len(dic) == 2):
    if(dic[a[0]]==2):
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

int main(){
int n,m;
cin >> n >> m;
int a[m];
ll sum = 0;
rep(i,m) {
    cin >> a[i];
    sum += a[i];
}
  if(n-sum < 0){
    cout << -1 << endl;
    return 0;
  }
cout << n-sum << endl;
}



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

int main () {
	int x; cin >> x;
	for (int i = 1; i <= 50000; ++i) {
		if (int(double(i)*1.08) == x) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int A, B, C;
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  if ((A==B && B!=C) || (A==C && C!=B) || (B==C && A!=B)){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


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

int main() {
	long long n, k;
	cin >> n >> k;
	map<int, long long> mp;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		mp[a] += b;
	}
	int ans;
	for (auto e : mp) {
		if (e.second >= k) {
          ans = e.first;
          break;
        }
		else k -= e.second;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile("\\s");
      int[] arrayS = delim
        .splitAsStream(line)
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 179784
#include <stdio.h>

int main(void)
{
	int n;
	int A, B;
	int playerA = 0, playerB = 0;
	int i = 0;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		while (i < n){
			scanf("%d %d", &A, &B);
			if (A == B){
				playerA += A;
				playerB += B;
			}
			else if (A > B){
				playerA += A + B;
			}
			else {
				playerB += A + B;
			}
			i++;
		}
		printf("%d %d\n", playerA, playerB);
		i = 0;
		playerA = 0;
		playerB = 0;
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int sh, sm, th, tm, k; cin >> sh >> sm >> th >> tm >> k;
    int time = 60 * th + tm - 60 * sh - sm;
    cout << time - k << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdlib>
#include <cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
#include <bits/stdc++.h>
using namespace std;


int main()
{      
    int n, k;
    cin >> n >> k;
    vector<int> p(n, 0);
    
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    
    sort(p.begin(), p.end());
    
    int sum = 0;
    for(int i=0; i<k; i++){
        sum += p[i];
    }
    cout << sum << endl;
}


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

int main()
{
    int year, month, day;
  	char c1, c2;
    cin >> year >> c1 >> month >> c2 >> day;
    if(month <= 4)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>


using namespace std;


template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}


#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(container).begin(), (container).end()

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif



int main()
{
	inp(long long, n, x, m);
	
	if (n == 1) { otp(x); return 0; }
	if (x == 0) { otp(0); return 0; }
	if (x == 1) { otp(n); return 0; }
	
	long long s = x;
	vector<int> a;
	decltype(a)::iterator it;
	a.push_back(x);
	for (int i = 1; i < n; i++) {
		x *= x;
		x %= m;
		if (x == 0) break;
		if (x == 1) { s += n - i; break; }
		if ((it = find(a.begin(), a.end(), x)) != a.end()) {
			int d = distance(it, a.end());
			s += (n - i) / d * accumulate(it, a.end(), 0ll);
			s += accumulate(it, it + (n - i) % d, 0ll);
			break;
		}
		a.push_back(x);
		s += x;
	}
	
	otp(s);
	
	return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>


using namespace std;

const int N_MAX = 1000000;

int how_many_compared = 0;

void print_vector(vector<int> v){
  for(int i=0; i<v.size(); i++){
    cout << v[i];
    if(i!=v.size()-1) cout << " ";
    else cout << endl;
  }
}

vector<int> merge(vector<int> arr1, vector<int> arr2){
  int ix_1 = 0;
  int ix_2 = 0;
  vector<int> new_arr;
  //cout << "arr1: " << endl;
  //print_vector(arr1);

  //cout << "arr2: " << endl;
  //print_vector(arr2);
    
  while(ix_1 < arr1.size() && ix_2 < arr2.size()){
    //cout << "ix_1: " << ix_1 << ", arr1.size(): " << arr1.size() << ", arr2.size(): "<< arr2.size()<< endl;
    if(arr1[ix_1] < arr2[ix_2]){
      new_arr.push_back(arr1[ix_1]);
      ix_1++;
    }
    else{
      new_arr.push_back(arr2[ix_2]);
      ix_2++;
    }
    how_many_compared++;
  }
  //cout << "new_arr: " << endl;
  //print_vector(new_arr);
  if(ix_1 == arr1.size()){
    for(int i=ix_2;i<arr2.size();i++) new_arr.push_back(arr2[i]);
    how_many_compared += arr2.size() - ix_2;
  }
  if(ix_2 == arr2.size()){
    for(int i=ix_1;i<arr1.size();i++) new_arr.push_back(arr1[i]);
    how_many_compared += arr1.size() - ix_1;
  }
  //cout << "new_arr: " << endl;
  //print_vector(new_arr);
  return new_arr;
}

vector<int> mergesort(vector<int> arr){
  
  // return merged vector
  // if only one elem, return itself
  if(arr.size()<=1) return arr;
  
  int mid_ix = arr.size()/2;
  // cout << "mid_ix: " << mid_ix << ", arr.size(): "<< arr.size() << endl;
  vector<int> l_arr(arr.begin(), arr.begin()+mid_ix);
  vector<int> r_arr(arr.begin()+mid_ix, arr.begin()+arr.size());
  //print_vector(l_arr);
  //print_vector(r_arr);
  vector<int> left_arr = mergesort(l_arr);
  vector<int> right_arr = mergesort(r_arr);
  return merge(left_arr, right_arr);
}


int main(){
  int n;
  cin >> n;
  vector<int> v;
  for(int i=0;i<n; i++){
    int tmp;
    scanf("%d", &tmp);
    v.push_back(tmp);
  }
  print_vector(mergesort(v));
  cout << how_many_compared << endl;
  return 0;
  
}



Measured memory_bytes: 18476
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define f(i,a,b) for(long long i=a;i<b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define tc long long test;cin>>test;while(test--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define output(a,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define endl "\n"
#define mem(a) memset(a,-1,sizeof(a))
#define ll long long

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

        ll flag=0,c=0;
        tc{
            ll p,q;
            cin>>p>>q;

            if(p==q){
                c++;
                if(c>=3){
                    cout<<"Yes"<<endl;
                    flag=1;
                    break;
                }
            }
            else c=0;
        }
        if(flag==0) cout<<"No"<<endl;

    return 0; 
}










Measured memory_bytes: 3620
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100005
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define mp make_pair
#define ff first
#define ss second

int n,m,tot;
int p[maxn],now[maxn],pre[maxn*2],son[maxn*2];

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

void add(int a,int b){son[++tot]=b,pre[tot]=now[a],now[a]=tot;}
void link(int a,int b){add(a,b),add(b,a);}

int top,stack[maxn];
bool vis[maxn],app[maxn];

void dfs(int x){
	vis[x]=app[x]=1; stack[++top]=x;
	for (int p=now[x];p;p=pre[p])
		if (!vis[son[p]]) dfs(son[p]);
}

int main(){
	n=read(),m=read();
	for (int i=1;i<=n;i++) p[i]=read();
	for (int i=1,x,y;i<=m;i++) x=read(),y=read(),link(x,y);
	int ans=0;
	for (int i=1;i<=n;i++)
		if (!vis[i]){
			dfs(i);
			for (int j=1;j<=top;j++)
				ans+=app[p[stack[j]]];
			while (top) app[stack[top--]]=0;
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main()
{
      int n;
      cin>>n;
      int a[n];
      set<int> s;
      for(int i=0;i<n;i++)
      {
        cin>>a[i];
        s.insert(a[i]);
      }
      if(s.size()==n)
      cout<<"YES"<<endl;
      else
      {
        cout<<"NO"<<endl;
      }
     return 0; 
}

Measured memory_bytes: 10368
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
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 fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
const ll INF = 1e9 + 10 ;
const ll N = 110 ; 
int main(){
    fastio
    ll n , k ; 
    cin >> n >> k ; 
    vector<ll> v(n) ; 
    priority_queue<ll> q ;
    for(ll i = 0; i < n; i++){
        cin >> v[i] ; 
        q.push(v[i]);
    }
    while(k){
        ll top = q.top() ; q.pop() ; 
        q.push(top/2);
        k--;
    }
    ll ans = 0 ; 
    while(not q.empty()){
        ans += q.top() ; q.pop();
        
    }
    cout << ans << endl;
    return 0 ;
}







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

int main(){
  int64_t n,b=0,c=0,d,e;
  cin >> n;
  vector<int64_t> a(n);
  for(int64_t i=0; i<n; i++){
    cin >> a[i];
    b += a[i];
  }
  for(int64_t i=0; i<n; i++){
    c += a[i];
    if(c>(double)b/(double)2){
      e = b - c + a[i];
      break;
    }
  }
  if(abs(2*c-b)>abs(2*e-b)) cout << abs(2*e-b) << endl;
  else cout << abs(2*c-b) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
const int mod=1e9+7;
int r1,c1,r2,c2,fac[2000010],inv[2000010],tot;
#define inc(x,y) x+=y,x>=mod?x-=mod:0
#define dec(x,y) x-=y,x<0?x+=mod:0
inline int kuai(int p,int q,int mod) {int tot=1;for(;q;p=(ll)p*p%mod,q>>=1) if(q&1) tot=(ll)tot*p%mod;return tot;}
inline int C(int x,int y) {
	if(x<y||x<0||y<0) return 0;
	return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
	read(r1),read(c1),read(r2),read(c2),fac[0]=1;
	for(res i=1;i<=2000009;++i) fac[i]=(ll)fac[i-1]*i%mod;
	inv[2000009]=kuai(fac[2000009],mod-2,mod);
	for(res i=2000008;~i;--i) inv[i]=(ll)inv[i+1]*(i+1)%mod;
	for(res i=r1;i<=r2;++i) inc(tot,C(i+c2+1,c2)),dec(tot,C(i+c1,c1-1));
	print(tot,'\n');
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 15872
#include <iostream>
int main()
{
    unsigned long long A,B,C,D;
    unsigned long long i,r,x;
    scanf("%llu %llu %llu %llu",&A,&B,&C,&D);
    unsigned long long s=B-A+1;
    A--;
    s-=B/C-A/C;
    s-=B/D-A/D;
    if(C<D)
    {
        unsigned long long temp=C;
        C=D;
        D=temp;
    }
    x=C*D;
    r=C%D;
    while(r!=0)
    {
        C=D;
        D=r;
        r=C%D;
    }
    x=x/D;
    s+=B/x-A/x;
    printf("%llu",s);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
def F(n):
    count = 0
    for i in range(1,n+1):
        if n % i == 0:
            count += 1
    return count

ans = 0

for i in range(1, n+1, 2):
    if F (i) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define F first
#define s second
#define int long long		
int x[214514];
double y[214514];
string z[214514];
int sum[214514];
signed main(){
	ic(n)
	int ans=0;
	int anssaidai=0;
	rep(0,i,n)cin>>x[i];
	rep(0,i,n)if(x[i]<x[i+1])sum[i]=1;
	rep(0,i,n-1){
		if(sum[i]==0)ans++;
		else ans=0;			
		if(ans>anssaidai)anssaidai=ans;
	}
	c(anssaidai)
}		

Measured memory_bytes: 5504
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc051

{
    public class Program
    {
        public static void Main(string[] args)
        {
            

            string[]str = Console.ReadLine().Split(' ');
            int k =  Convert.ToInt32(str[0]);
            int s = Convert.ToInt32(str[1]);

            int x, y, z = 0;

            int cnt = 0;

            for(x = 0; x <= k; x++)
            {
                for(y = 0; y <= k; y++)
                {
                    z = s - (x + y);

                    if (z>=0 &&z<=k)
                    {
                        cnt++;
                    }
                }
            }

            Console.WriteLine(cnt);
        }
    }
}

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

int main(){
  string s,t;
  cin >> s >> t;
  
  int a,b;
  cin >> a >> b;
  
  string u;
  cin >> u;
  
  if(u==s)
    a=a-1;
  else
    b=b-1;
  
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
n,m=[int(i) for i in input().split()]
p=[[0 for i in range(2)] for j in range(m)]

a=[0 for i in range(n+1)]
b=[0 for i in range(n+1)]

for i in range(m):
  p[i]=[int(i) for i in input().split()]

for i in range(m):  
  
  if p[i][0]==1:
    a[p[i][1]]+=1
    
  elif p[i][1]==n:
    a[p[i][0]]+=1
   
    
if max(a)>=2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
      

Measured memory_bytes: 42560
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int len,i,score=0,p=0;
//g->rock  p->paper  p=rock-paper>=0
int main()
{gets(s);
len=strlen(s);
 for(i=0;i<len;i++)
  if(s[i]=='g')
  {if(p<1) p++;
   else {p--; score++;} 
  }
  else{
  if(p<1) {p++; score--;}
  else p--;
  }
 cout<<score; 
 return 0;
}

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

int n;
int A[2010];

int bs(int x, int s, int e){
     int start=s, end=e, result=-1;
     while(start<=end){
          int mid=start+(end-start)/2;
          if(A[mid]>=x){
               result=mid;
               end=mid-1;
          }
          else start=mid+1;
     }
     if(result==-1) return e-s+1;
     else return result-s;
}


int main(){
     cin>>n;
     for(int i=0;i<n;i++)cin>>A[i];
     sort(A, A+n);
     int ans=0;
     for(int i=0;i<n;i++){
          for(int j=i+1;j<n;j++){
               int temp=A[i]+A[j];
               ans+=bs(temp, j+1, n-1);
          }
     }
    cout<<ans;
}

Measured memory_bytes: 256
def partition(A, l, r):
    i = l - 1
    for j in range(l, r):
        if A[j] <= A[r]:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1
n = int(input())
arr = list(map(int, input().split()))
idx = partition(arr, 0, n - 1)
print(*(arr[0:idx] + ['[' + str(arr[idx]) + ']'] + arr[idx + 1:]))


Measured memory_bytes: 16384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct Combination {
	vector<int64_t> fact, rfact;
	Combination(int sz) : fact(sz + 1), rfact(sz + 1) {
		fact[0] = 1;
		for(int i = 1; i < fact.size(); i++){
			fact[i] = fact[i - 1] * i % mod;
		}
		rfact[sz] = inv(fact[sz]);
		for(int i = sz - 1; i >= 0; i--){
			rfact[i] = rfact[i + 1] * (i + 1) % mod;
		}
	}
	int64_t inv(int x) const {
		return pow(x, mod - 2);
	}
	int64_t pow(int64_t x, int64_t n) const {
		int64_t ret = 1;
		while(n > 0){
			if(n & 1) (ret *= x) %= mod;
			(x *= x) %= mod;
			n >>= 1;
		}
		return (ret);
	}
	int64_t P(int n, int r) const {
		if(r < 0 || n < r) return (0);
		return (fact[n] * rfact[n - r] % mod);
	}

	int64_t C(int p, int q) const {
		if(q < 0 || p < q) return (0);
		return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
	}

	int64_t H(int n, int r) const {
		if(n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	Combination c(500000);
	int ans = c.C(2 * n - 1, n - 1);
	if(k >= n - 1){
		cout << ans << endl;
		return 0;
	}
	for(int i = k + 1; i <= n - 1; i++){
		int tmp = c.C(n, i) * c.C(n - 1, n - 1 - i) % mod;
		ans = (ans - tmp + mod) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8064
import math
import collections


def main():
    #infile = open("compprog.txt")
    #n, a, b = [int(x) for x in infile.readline().split()]
    #nums = [int(x) for x in infile.readline().split()]
    n, a, b = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    nums.sort(reverse=True)
    hml = how_many_largest(nums)
    if hml <= a:
        hml_less(n, a, b, nums, hml)
    elif a < hml < b:
        hml_between(n, a, b, nums, hml)
    else:
        hml_between(n, a, b, nums, b)
    #infile.close()


def hml_less(n, a, b, nums, hml):
    highest = []
    for idx in range(a):
        highest.append(nums[idx])
    mean = sum(highest) / len(highest)
    in_cnt = dict(collections.Counter(highest))
    full_cnt = dict(collections.Counter(nums))
    ways = num_combs(full_cnt[highest[-1]], in_cnt[highest[-1]])
    print(mean)
    print(ways)


def hml_between(n, a, b, nums, hml):
    print(float(nums[0])) # mean
    cnt = dict(collections.Counter(nums))[nums[0]]
    ways = 0
    for i in range(hml, a - 1, -1):
        ways += num_combs(cnt, i)
    print(ways)


def how_many_largest(lst):
    res = 1
    idx = 1
    while idx < len(lst) and lst[idx - 1] == lst[idx]:
        res += 1
        idx += 1
    return res


def num_combs(n, k):
    return math.factorial(n) // (math.factorial(n - k) * math.factorial(k))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include<stdio.h> 
        int main(void) {
     

          int x,a,b;
          scanf("%d %d %d",&x,&a,&b);

          if(b <= a){
              printf("delicious");
          }else if((b-a) <= x ){
              printf("safe");
          }else{
              printf("dangerous");
          }
        }

Measured memory_bytes: 128
(args => {
  const [A,B,H,M] = args.trim().split(' ').map(parseFloat);
  const theta = ( (H+M/60)/12.0 - M/60.0 ) * Math.PI * 2.0;
  const CC = A*A + B*B - 2.0*A*B*Math.cos(theta);
  console.log((Math.sqrt(CC)).toString());
})(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29748
import sys


fin = sys.stdin.readline
N = int(fin())
work_list = [[int(elem) for elem in fin().split()] for _ in range(N)]
assert len(work_list[0]) == 2


work_list.sort(key=lambda x: (x[1], x[0]))
cur_past_time = 0

for load, limit in work_list:
    if load + cur_past_time > limit:
        print("No")
        exit(0)
    cur_past_time += load
print("Yes")


Measured memory_bytes: 86236
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ffor for(;;)
#define ub upper_bound
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
 
typedef long long ll;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    string s;
    std::cin >> s;
    int n=s.size();
    int c=0;
    int ans=0;
    rep(i,n){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')c++;
        else{
            ans=max(ans,c);c=0;
        }
    }
    ans=max(ans,c);
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 5100000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  ll N;
  cin>>N;
  vector<pair<ll,int>> C(N);
  for(int i=0;i<N;i++){
    cin>>C.at(i).first;
    C.at(i).second=i;
  }
  sort(C.begin(),C.end());
  ll ans=0;
  vector<ll> res(N+2,1);
  for(int i=0;i<N+1;i++){
    res.at(i+1)=2*res.at(i)%MOD;
  }
  ll pat=res.at(N);
  for(ll i=0;i<N-1;i++){
    ans+=(C.at(i).first*pat%MOD)*((((N-i-1)*res.at(N-i-2)+res.at(N-i-1))%MOD)*res.at(i)%MOD)%MOD;
    ans%=MOD;
  }
  ans+=(C.at(N-1).first*pat%MOD)*res.at(N-1)%MOD;
  ans%=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 4992
cur = []

def recur(n):
    if n > 10 ** 10:
        return
    cur.append(n)
    for i in range(10):
        if abs(n % 10 - i) <= 1:
            recur(10 * n + i)

for i in range(1, 10):
    recur(i)
cur.sort()
n = int(input())
print((cur[n - 1]))

Measured memory_bytes: 12776
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin>>n;
  int l=0,ans=1;
  cin>>l;
  REP(i,1,n){
    int k;
    cin>>k;
    if(k<=l){
      ans++;
      l=k;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  int64_t p,v,p1,v1,p2,v2,t;
  cin >> p1 >> v1 >> p2 >> v2 >> t;
  p=abs(p2-p1);
  if(v1<=v2) {
    cout << "NO" << endl;
    return 0;
  }
  v=v1-v2;
  if ( p<=v*t ) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3612
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int A,B,K;
    cin>>A>>B>>K;
    int c=min(A,B);
    while(K){
        if(A%c==0&&B%c==0)K--;
        c--;
    }
    cout<<c+1<<endl;
}


Measured memory_bytes: 3612
n = gets.to_i 
map = Hash.new(0)
max = 0
n.times do
  s = gets.chomp!
  map[s] += 1
  if max < map[s]
    max = map[s]
  end
end

arr = []
map.each do |s, count|
  next if count < max
  
  arr << s
end

arr.sort!.each do |e|
  puts e
end


Measured memory_bytes: 33128
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, T, *AB = map(int, read().split())
    D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

    D.sort()

    dp = [0] * T
    ans = 0

    for i, (a, b) in enumerate(D[:-1]):
        for t in range(T - 1, a - 1, -1):
            if dp[t] < dp[t - a] + b:
                dp[t] = dp[t - a] + b
        if ans < dp[T - 1] + D[i + 1][1]:
            ans = dp[T - 1] + D[i + 1][1]

    print(ans)
    return


if __name__ == '__main__':
    main()


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

d = {}
for i in range(n):
  s, p = input().split()
  d[s] = d.get(s, []) + [[i+1, int(p)]]

for key in sorted(list(d.keys())):
  for i in sorted(d[key], key = lambda x: x[1], reverse=True):
    print(i[0])

Measured memory_bytes: 3060
#!/usr/bin/env ruby

if __FILE__ == $0 then
	r, c = gets.split.map(&:to_i)

	bottom = [0]*c
	r.times do
		s = gets.chomp
		n = s.split.map(&:to_i)
		puts '%s %d' % [s, n.sum]
		c.times do |j|
			bottom[j] += n[j]
		end
	end
	puts '%s %d' % [bottom.map(&:to_s).join(' '), bottom.sum]
end



Measured memory_bytes: 7036
def expr():
    global cur
    while cur < len(S):
        cur += 1 # '('
        if clause():
            return 1
        cur += 2 # ')|'
    return 0

def clause():
    R = []
    global cur
    R.append(literal())
    cur += 1 # '&'
    R.append(literal())
    cur += 1 # '&'
    R.append(literal())
    return check(R)

def literal():
    global cur
    if S[cur] == '~':
        r = S[cur:cur+2]
        cur += 2 # '~a'
    else:
        r = S[cur]
        cur += 1 # 'a'
    return r

def check(R):
    for l0 in R:
        if len(l0) == 1:
            for l1 in R:
                if len(l1) == 2 and l1[1] == l0:
                    return 0
    return 1


ans = []
while 1:
    S = input()
    if S == '#':
        break
    cur = 0
    ans.append('yes' if expr() else 'no')
print(*ans, sep='\n')



Measured memory_bytes: 5716
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var x int
	fmt.Fscan(r, &x)

	t := 0
	sum := 0
	for sum < x {
		t++
		sum = t * (t + 1) / 2
	}
	fmt.Println(t)
}


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

int main() {
    int N, K;
    cin >> N >> K;

    vector<int> D(K);
    for(int i = 0; i < K; i++) cin >> D.at(i);

    int digit, temp;
    bool check = false;

    N--;

    while(!check){
        N++;
        check = true;
        temp = N;

        while(temp != 0){
            digit = temp % 10;
            for(int i = 0; i < K; i++){
                if(digit == D.at(i)) check = false;
            }
            temp /= 10;
        }
    }

    cout << N << endl;
}


Measured memory_bytes: 3628
N = int(input())
A = list(map(int,input().split()))

left = A[0]
right = sum(A)-A[0]

s = abs(left-right)

for i in range(1,N-1):
    left += A[i]
    right -= A[i]
    s = min(s,abs(left-right))

print(s)

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

using namespace std;

using ll = long long;

bool judge(vector<string>& ans, int A, int B) {
    int H = ans.size();
    int W = ans[0].size();
    for (int i = 0; i < H; i++) {
        int cnt = 0;
        for (int j = 0; j < W; j++) {
            cnt += ans[i][j] - '0';
        }
        cnt = min(cnt, W - cnt);
        if (cnt != A) return false;
    }

    for (int j = 0; j < W; j++) {
        int cnt = 0;
        for (int i = 0; i < H; i++) {
            cnt += ans[i][j] - '0';
        }
        cnt = min(cnt, H - cnt);
        if (cnt != B) return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    vector< string > ans(H, string(W, '0'));
    if (H == 2 * B) {
        if (B * W == A * H) {
            string s1 = string(A, '1') + string(A, '0');
            string s2 = string(A, '0') + string(A, '1');
            for (int i = 0; i < B; i++) {
                ans[i] = s1;
            }

            for (int i = B; i < H; i++) {
                ans[i] = s2;
            }
        } else {
            cout << "No\n";
            return 0;
        }
    } else {
        int hoge = H - 2 * B;
        int bar = -1;
        int ai = -1;
        for (int i = 0; i <= H; i++) {
            int anum = A * i + (W - A) * (H - i);
            if (anum < B * W) continue;
            int foo = anum - B * W;
            if (foo % hoge != 0) continue;
            int next_bar = W - foo / hoge;
            if (next_bar < 0 || next_bar > W) continue;
            bar = next_bar;
            ai = i;
            break;
        }

        if (bar == -1) {
            cout << "No\n";
            return 0;
        }

        //cerr << bar << " " << ai << endl;
        vector<int> rest(H, W - A);
        for (int i = 0; i < ai; i++) {
            rest[i] = A;
        }

        for (int j = 0; j < bar; j++) {
            int cnt = 0;
            for (int i = 0; i < H; i++) {
                if (cnt == B) break;
                if (rest[i] > 0) {
                    ans[i][j] = '1';
                    rest[i]--;
                    cnt++;
                }
            }
        }

        for (int j = bar; j < W; j++) {
            int cnt = 0;
            for (int i = 0; i < H; i++) {
                if (cnt == H - B) break;
                if (rest[i] > 0) {
                    ans[i][j] = '1';
                    rest[i]--;
                    cnt++;
                }
            }
        }
    }
    assert(judge(ans, A, B)); 
    for (int i = 0; i < H; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 2304
import sys
INF = 10**18

if __name__ == "__main__":
    n = int(input())
    h = list(map(int,input().split()))
    dp = [INF]*(n)
    dp[0] = 0
    for i in range(1,n):
        d1 = abs(h[i] - h[i-1])
        d2 = INF
        if i>=2:
            d2 = abs(h[i] - h[i-2])
        dp[i] = min(d1+dp[i-1],d2+dp[i-2])
    print(dp[-1])

Measured memory_bytes: 13976
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define SZ (1<<18)
map<int,int> t[SZ];
int L,E[SZ];
void addW(char*c,int l,int W){
	if(!L)t->clear(),L=1,*E=0;
    int u(0);
    F(l)if(t[u].count(c[i]))u=t[u][c[i]];
        else t[u][c[i]]=L,E[u=L++]=0,t[u].clear();
    E[u]=W;
}
vector<ll> o;
char s[1<<17];
ll l,X;
int N;
void dfs(int u,int d){
    if(E[u])return;
    if(t[u].size()^2)o.PB(l-d);//+/-1
    for(auto&h:t[u])dfs(h.bb,d+1);
}
ll nim(ll u){
    int I=0;
    while(!(u&1ll<<I))++I;
    return 1ll<<I;
}
int main(void){
    scanf("%d%lld",&N,&l);
    F(N)scanf("%s",s),addW(s,strlen(s),1);
    dfs(0,0),sort(o.begin(),o.end());
//    for(auto&h:o)D(h)
    for(auto&h:o)X^=nim(h);
    puts(X?"Alice":"Bob");
    return 0;
}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    string s;
    cin>>s;
    ll k;
    cin>>k;
    
    for(int i=0;i<k;i++){
         if(s[i]!='1'){
               cout<<s[i]<<endl;
               return 0;
         }
        if(i+1==s.size()){
            break;
        }
    }
    cout<<1<<endl;
     
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i,a,n,t,trump[5][14]={};
    char c,mark[]="SHCD";

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

        scanf("%*c%c %d",&c,&t);
        for(a=0;a<4;a++){
            if(mark[a]==c){
                trump[a][t-1]=1;
            }
        }
    }
    
    for(i=0;i<4;i++){
        for(a=0;a<13;a++){
            if(trump[i][a]!=1){
                printf("%c %d\n",mark[i],a+1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2112
program main
	implicit none
	integer N, i
	integer(8) S, Sall, ans
	integer(8), allocatable :: a(:)
	read(*, *) N
	allocate(a(1: N))
	read(*, *) a(1: N)
	Sall = sum(a)
	S    = Sall
	ans  = 2d14
	do i = 1, N-1
		S   = S - a(i)
		ans = min(ans ,abs((Sall - S) - S))
	end do
	write(*, *) ans
end program main

Measured memory_bytes: 2304
#include<stdio.h>

int main()
{
	int i,j,a[4],b[4],hit=0,blow=0;
	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF | scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3])!=EOF)
	{
		for(i=0;i<4;i++)
		{
			if(a[i]==b[i])
				hit++;
		}
		
		for(i=0;i<4;i++)
		{
			for(j=0;j<4;j++)
			{
				if(a[i]==b[j])
					blow++;
			}
		}
		blow = blow -hit;
		printf("%d %d\n",hit,blow);
		blow = hit = 0;
	}
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int, input().split())) # taberu order
b = list(map(int, input().split())) # get
c = list(map(int, input().split())) # renzoku
 
ans = 0
for i in range(n):
  po = a[i]
  ans += b[po-1]
 
for i in range(n-1):
  if(a[i] + 1 == a[i+1] ):
    ans += c[a[i]-1]
    
print(ans)

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


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll a, b, q , in;
vector<ll> s, t;

int main() {
	cin >> a >> b >> q;
	s.push_back((ll)-INF * 100); REPO(i, a) { cin >> in; s.push_back(in); } s.push_back((ll)INF * 100);
	t.push_back((ll)-INF * 100); REPO(i, b) { cin >> in; t.push_back(in); } t.push_back((ll)INF * 100);
	REP(i, q) {
		ll x, ss[2], tt[2], ans = INF64; cin >> x;
		REP(j, 2)ss[j] = lower_bound(ALL(s), x) - s.begin() - j;
		REP(j, 2)tt[j] = lower_bound(ALL(t), x) - t.begin() - j;
		REP(j, 2) {
			REP(k, 2) {
				ans = min(ans, min(abs(x - s[ss[j]]), abs(x - t[tt[k]])) + abs(s[ss[j]] - t[tt[k]]));
			}
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 3060
using System;

class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split(' ');
        var a = int.Parse(ab[0]);
        var b = int.Parse(ab[1]);

        if (a <= 8 && b <= 8) Console.WriteLine("Yay!");
        else Console.WriteLine(":(");
    }
}


Measured memory_bytes: 13140
n,k = map(int,input().split())
s = input()
 
if s[k-1] == "A":
  s=s[0:k-1]+"a"+s[k:n]
elif s[k-1] == "B":
  s=s[0:k-1]+"b"+s[k:n]
else:
  s=s[0:k-1]+"c"+s[k:n]
print(s)

Measured memory_bytes: 3060
#include <stdio.h>

/*

?????????

2????????´??° a ??¨ b ?????????????????§?????\?????????????¨??????????????????°??????????????????????????????:

a ?? b : d (??´??°)
a ?? b ????????? : r (??´??°)
a ?? b : f (???????°???°?????°)
Input
1??????2????????´??° a, b ????????????????????????

Output
d, r, f ???1??????????????§????????£???1??????????????????????????????f??????????????????0.00001??\????????????????????£????????????????????¨????????????
*/

int main( )
{
	int a, b, d, r;
	double f;

	scanf( "%d %d", &a, &b );

	d = a / b;

	r = a % b;

	f = ( double ) a / ( double ) b;

	printf( "%d %d %f\n", d, r, f );

	return 0;
}

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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}



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

    if(K<=A){
        ans=K;
    }else if(K<=A+B){
        ans=A;
    }else{
        ans= A - (K-A-B);
    }

        cout << ans << endl;

 
    return 0;

}

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

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

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    string s; cin>>s;
    int n=s.size();
    for(char cha='a'; cha<='z'; cha++){
        bool f=true;
        for(int i=0; i<n; i++){
            if(s[i] == cha) f=false;
        }

        if(f){
            cout << cha << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512