akhauriyash/Code-Regression huggingface dataset:
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    ll n, k;
    cin >> n >> k;
    printf("%lld\n", min(n%k, k-(n%k)));
    return 0;
}



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

cnt = 0
for i in range(1, N):
    front = A[i - 1]
    back = A[i]

    if front > back:
        diff = front-back 
        cnt += diff
        A[i] = A[i] + diff

    # print(A)
print(cnt)

Measured memory_bytes: 32296
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	double a,b,c;
	int x;
	scanf("%lf %lf",&a,&b);
	c=(a+b)/2;
	x=int(c);
	if(c>=x+0.5) printf("%d\n",x+1);
	else printf("%d\n",x);
}

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

import itertools

N = int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

# 重複順列で自分の店の全パターンを出す
me_list = list(itertools.product([0, 1], repeat=10))

# 初期値は利益の最小値
me_p = -float("inf")
# 自分の店の全パターンループ
for i in range(len(me_list)):

    # 一度も営業しないパターンを除く
    if i == 0:
        continue

    tmp_p = 0
    # 他店の数でループ
    for j in range(N):

        cnt = 0
        # 月～金のAMPMループ
        for k in range(10):

            # 他店との営業重複カウント
            if me_list[i][k] == 1 and F[j][k] == 1:
                cnt += 1
        
        # 各店舗との重複数に応じた利益を合算していく
        tmp_p += P[j][cnt]

    # 合算した利益を現状の最高値と比較して置き換えていく
    me_p = max(me_p, tmp_p)   

print(me_p)

Measured memory_bytes: 3188
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if(s.find("YAKI") == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
string s;
cin>>s;
ll n=s.size();
string ans="";
for(ll i=0;i<n;i++)
{
    ans+='x';
}
cout<<ans<<endl;
return 0;
}


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

int main() {
    int h, w; cin >>h >>w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) cin >>s[i];

    string ret = "Yes";
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                if (i>0   && s[i-1][j]=='#') continue;
                if (i<h-1 && s[i+1][j]=='#') continue;
                if (j>0   && s[i][j-1]=='#') continue;
                if (j<w-1 && s[i][j+1]=='#') continue;

                ret = "No"; // 四方を探してだめならNoとなる
                break;
            }
        }
        if (ret == "No") break;
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    vector<bool> ok(n+1,false);
    ok[0]=true;
    for(int i=0;i<n;i++){
        if(!ok[i]) continue;
        if(i+5<=n&&s.substr(i,5)=="dream") ok[i+5]=true;
        if(i+7<=n&&s.substr(i,7)=="dreamer") ok[i+7]=true;
        if(i+5<=n&&s.substr(i,5)=="erase") ok[i+5]=true;
        if(i+6<=n&&s.substr(i,6)=="eraser") ok[i+6]=true;
    }
    if(ok[n]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int dp[100005];
int a[102];

void solve(){
    int N, K;   cin>>N>>K;
    forI(i, 1, N)   cin>>a[i-1];
    memset(dp, 0, sizeof dp);
    
    forI(i, 1, K){
        forI(j, 0, N-1){
            if(a[j] > i)    continue;
            if(dp[i - a[j]] == 0)
                dp[i] = 1;
        }
    }

    if(dp[K])    cout<<"First\n";
    else    cout<<"Second\n";
}

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

Measured memory_bytes: 4428
#include<iostream>
using namespace std;
#include<cstdio>       // k-D_tree. (k = 2)
#include<algorithm>

class Point
{
public:
    int id, x, y;
    Point(){};
    Point(int no, int pos_x, int pos_y) : id(no), x(pos_x), y(pos_y) {};
    void print(){ printf("%d\n", id); }
};

bool cmp_x(const Point &P1, const Point &P2){ return P1.x < P2.x; }
bool cmp_y(const Point &P1, const Point &P2){ return P1.y < P2.y; }
bool cmp_id(const Point &P1, const Point &P2){ return P1.id < P2.id; }

class node // nodes of 2-D_tree.
{
public:
    Point *mark;
    node *less, *more;
    int depth;   // parity of depth is important.
    node() : mark(NULL), less(NULL), more(NULL), depth(0) {};
    node(Point* pos, node* l, node* m, int d) : mark(pos), less(l), more(m), depth(d) {};
};

node* make_tree(Point S[], int left, int right, int d) // recursive construction of 2-D_tree.
{
    if(left > right){ return NULL; }
    if(left == right){
        node* leaf = new node;
        *leaf = node(&S[left], NULL, NULL, d);    // arrived at leaf.
        return leaf;
    }

	if(d & 1){
		sort(S + left, S + right + 1, cmp_x);
	}else{
        sort(S + left, S + right + 1, cmp_y);
	}

    int mid = (left + right) / 2;

    node* n = new node;   // make a new node.
    n->mark = &S[mid];
    n->depth = d;
    n->less = make_tree(S, left, mid - 1, d + 1);
    n->more = make_tree(S, mid + 1, right, d + 1);

    return n;
}

int cnt;

void find(Point S[], int sx, int tx, int sy, int ty, node* kd_n)
{
    if(kd_n == NULL) return;

    if(sx <= kd_n->mark->x && kd_n->mark->x <= tx && sy <= kd_n->mark->y && kd_n->mark->y <= ty){
        S[cnt] = *(kd_n->mark);
        cnt++;
    }
    int ax = kd_n->mark->x, ay = kd_n->mark->y, d = kd_n->depth;

    if(d & 1){
        if(sx <= ax) find(S, sx, tx, sy, ty, kd_n->less);
        if(ax <= tx) find(S, sx, tx, sy, ty, kd_n->more);
    }else{
        if(sy <= ay) find(S, sx, tx, sy, ty, kd_n->less);
        if(ay <= ty) find(S, sx, tx, sy, ty, kd_n->more);
    }
}

int main()
{
    int i, pos_x, pos_y, n;
    Point P[500000], Q[100];

    scanf("%d", &n);
    for(i = 0; i < n; i++){ scanf("%d %d", &pos_x, &pos_y); P[i] = Point(i, pos_x, pos_y); }
	
    node* root;
    root = make_tree(P, 0, n - 1, 0);  // make a 2-D_tree.

    int q, sx, tx, sy, ty;
    scanf("%d", &q);
    while(q){
        cnt = 0;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);      // input data.
        find(Q, sx, tx, sy, ty, root);   // counting.
        sort(Q, Q + cnt, cmp_id);
        for(i = 0; i < cnt; i++){ Q[i].print(); }  // print out.
        printf("\n");
        q--;
    };

    return 0;
}

Measured memory_bytes: 29732
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;

int main(){
  int x, a, b;
  cin >> x >> a >> b;

  int day = -a + b;
  if(day <= 0) cout << "delicious" << endl;
  else if(day > 0 && day <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}


Measured memory_bytes: 3524
import java.util.*;
import java.lang.*;

public class Main {

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

		String str = s.nextLine();

		if(str.charAt(2)==str.charAt(3) && str.charAt(4)==str.charAt(5)){
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
	}

 }


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

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        long X = scanner.nextLong();
        Map<Long, Pair> map = new HashMap<>();
        for (long i = -600; i <= 600; i++) {
            long ii = i * i * i * i * i;
            for (long j = -600; j <= 600; j++) {
                map.put(ii - j * j * j * j * j, new Pair(i, j));
            }
        }
        Pair pair = map.getOrDefault(X, new Pair(-9999, -9999));
        if(pair.a == -9999) throw new RuntimeException("aaa");
        System.out.println(pair.a);
        System.out.println(pair.b);
    }

    class Pair {
        long a;
        long b;

        Pair(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }
}

Measured memory_bytes: 141348
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
// #define MULTIPLE_TESTS 1

int n;
vector<ll> arr;
void readArray() {
    arr.resize(n);
    for (auto &a: arr) {
        cin >> a;
    }
}

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << a*b << endl;
}

int main() {
    FAST_IO;
    int t = 1;
    #ifdef MULTIPLE_TESTS
    cin >> t;
    #endif

    while (t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3624
package main
import ("fmt"
	"bufio"
	"os"
	"strconv"
	"strings"
)

func main(){
	var n, m, c, anAll int
	fmt.Scanf("%d %d %d",&n, &m, &c)
	sc :=bufio.NewScanner(os.Stdin)
	var b []int
	sc.Scan()
	instr:=strings.Split(sc.Text()," ")
	for _,j:=range instr{
		jint,_:=strconv.Atoi(j)
		b=append(b,jint)
	} 
	for i:=0;i<n;i++{
		sc.Scan()
		instr:=strings.Split(sc.Text()," ")
		var a []int
		for _,j:=range instr{
			jint,_:=strconv.Atoi(j)
                	a=append(a,jint)
        	}
		var an int
		for k,j:=range a{
			an += j*b[k]
		}
		an+=c
		if an>0{
			anAll++
		}
	}
	fmt.Println(anAll)
}


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

int main(){
	LL n,k;
	cin>>n>>k;
	LL ar[n+2];
	for(LL i=1;i<=n;i++) {
		cin>>ar[i];
	}
	ar[n+1]=1000000007;
	ar[0]=1000000007;
	LL sum=0;
		LL kecil=1000000007;
		for(LL i=k;i<=n;i++){
			kecil=min(kecil,min(abs(ar[i-k+1]),abs(ar[i]))+abs(ar[i]-ar[i-k+1]));
		}
		sum=kecil;
	cout<<sum<<endl;
}


Measured memory_bytes: 1024
n=int(input())
a=[int(i) for i in input().split()]
a.sort()

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

l=make_divisors(a[0])
l2=make_divisors(a[1])
le=len(l)
le2=len(l2)         
an=[0]*le
an2=[0]*le2
for i in range(n):
    for j in range(le):
        if a[i]%l[j]==0:
            an[j]+=1
    for j in range(le2):
        if a[i]%l2[j]==0:
            an2[j]+=1
ans=1
ans2=1
for i in range(le):
    if an[i]>=n-1:
        ans=max(ans,l[i])
for i in range(le2):
    if an2[i]>=n-1:
        ans2=max(ans2,l2[i])

print(max(ans,ans2))

Measured memory_bytes: 63984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;

// aoj DSL_1_A
public class Main {

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

		int n = sc.nextInt();
		int q = sc.nextInt();

		UnionFind uf = new UnionFind(n);

		for (int i = 0; i < q; i++) {
			int com = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();

			if (com == 0) {
				uf.unite(x, y);
			} else {
				if (uf.same(x, y)) {
					pr.println(1);
				} else {
					pr.println(0);
				}
			}
		}

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class UnionFind {
		int n;
		// cnt : ??°?????????????????°
		int cnt;
		// parent[x] : 0???n-1 ?????´??????????´?x???root????´?
		//           : -1???-n ?????´?????????????????????root????´????
		//                            -parent[x]??§x??????????????????????´???°
		int[] parent;

		UnionFind(int n) {
			this.n = n;
			cnt = n;
			parent = new int[n];
			Arrays.fill(parent, -1);
		}

		// x???root????±???????
		int find(int x) {
			if (parent[x] < 0) {
				return x;
			} else {
				return parent[x] = find(parent[x]);
			}
		}

		// x??¨y???????????????????±?????????????
		boolean same(int x, int y) {
			return find(x) == find(y);
		}

		// x??¨y????±????????????????????????????
		void unite(int x, int y) {
			x = find(x);
			y = find(y);
			if (x == y) {
				return;
			}

			cnt--;
			// ????´???°?????§???????????????root?????????(Quick Find Weighted?)
			if (parent[x] > parent[y]) {
				parent[y] += parent[x];
				parent[x] = y;
			} else {
				parent[x] += parent[y];
				parent[y] = x;
			}

			return;
		}

		// ????´?x??????????????????????´???°
		int count(int x) {
			return -parent[find(x)];
		}

		// ??°?????????????????°
		int count() {
			return cnt;
		}
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

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

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}

Measured memory_bytes: 64856
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int count=0;
	if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3]))
	count=1;
	if(count)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
//	main();
}

Measured memory_bytes: 256
#include <bits/stdc++.h> // {{{
// clang-format off
#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define pb emplace_back
#define em emplace
#define fi first
#define se second
#define USE1(...) template <typename __VA_ARGS__> inline
#define USE2(T, ...) USE1(T, typename __VA_ARGS__)
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
 
using ll = long long;
template<typename T> using vec = std::vector<T>;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE2(T=int,V=vec<T>)V reserved(int n){V v;v.reserve(n);return v;}
USE1(T=int)vec<T>in(int n){auto v=reserved<T>(n);rep(i,n)v.pb(in<T>());return v;}
USE2(T,U=std::pair<T,int>)vec<U>enume(const vec<T>&x,int s=0){int N=x.size();auto v=reserved<U>(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE2(T,U)void prif(bool b,T t,U f){if(b)pr(t);else pr(f);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(20);
    std::cout.setf(std::ios::fixed);
  }
} iosetup; //}}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  int N = in();
  auto B = ndvec(0, N, 26);
  rep(i, N) {
    for (char c : in<string>()) {
      B[i][c - 'a']++;
    }
  }
  rep(i, 26) {
    int mini = inf;
    rep(j, N) {
      chmin(mini, B[j][i]);
    }
    rep(j, mini) {
      cout << (char)('a' + i);
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main()
{
    ll n,ans = 0;
    cin >> n;
    vector<ll> time(n);
    vector<string> name(n);
    string s;
    rep0(i, n)cin >> name[i] >> time[i];
    cin >> s;
    bool f = false;
    rep0(i, n){
        if(f)ans += time[i];
        if(s == name[i])f = true;
    }
    pf(ans)
    return 0;
}



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


#define INF 1000000000000

int pow(int n,int k){
  int q=1;
  for(int i=0;i<k;i++){
    q*=n;
  }
  return q;
}

signed main()
 {
  int n;
  cin>>n;
  if(n==0){cout<<'0';exit(0);}
  vector<int>ans(0);
  for(int i=35; i>=0; i--){
    if(i%2==0){
      int k=i/2+1;
      if((pow(4,k-1)-1)/3<n&&n<=(pow(4,k)-1)/3){
        ans.push_back(1);
        n-=pow(4,k-1);
      }
      else{
        ans.push_back(0);
      }
    }
    if(i%2==1){
      int k=(i+1)/2;
      if((1-pow(4,k))*2/3<=n&&n<(1-pow(4,k))*2/3+2*pow(4,k-1)){
        ans.push_back(1);
        n-=pow(4,k-1)*2*(-1);
      }
      else{
        ans.push_back(0);
      }
    }
  }
  int l=0;
  rep(i,40){
    if(ans[i]==0&&ans[i+1]!=0){l=i+1;break;}
  }
  for(int i=l;i<ans.size();i++){
    cout<<ans[i];
  }
 }


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

vector<vector<int>> defeated;
vector<int> height;
void dfs(int node)
{
    height[node] = 0;

    int n = defeated[node].size();
    vector<int> tmp;
    rep(i, n)
    {
        int child = defeated[node][i];
        dfs(child);
        tmp.push_back(height[child]);
    }
    sort(tmp.begin(), tmp.end());

    rep(i, n)
    {
        height[node] = max((int64_t)height[node], tmp[i] + n - i);
    }
}

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

    defeated.resize(n);
    height.resize(n);
    rep(i, n - 1)
    {
        int a;
        cin >> a;
        defeated[a - 1].push_back(i + 1);
    }

    dfs(0);
    cout << height[0] << endl;

    return 0;
}

Measured memory_bytes: 17024
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>

using namespace std;

struct edge {
    int t, w;

    bool operator<(const edge &other) const { return w < other.w; }

    bool operator>(const edge &other) const { return w > other.w; }
};

int main() {
    int V, E;
    cin >> V >> E;

    unordered_set<int> visited;
    unordered_map<int, vector<edge>> G;

    for (int i = 0; i < E; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        G[s].push_back({t, w});
        G[t].push_back({s, w});
    }

    int ans = 0;
    priority_queue<
            edge,
            vector<edge>,
            greater<>> pq;

    pq.push(edge{0, 0});

    while (!pq.empty()) {

        edge s = pq.top();
        pq.pop();

        if (visited.find(s.t) != visited.end())
            continue;

        ans += s.w;
        visited.insert(s.t);

        for (edge e : G[s.t]) {
            if (visited.find(e.t) == visited.end()) {
                pq.push(e);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 7564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    ll L,R,d;
    cin>>L>>R>>d;
    cout<<R/d-(L-1)/d<<endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt();

		System.out.println(possible(a) ? "Possible" : "Impossible");
		sc.close();
	}
	
	static boolean possible(int[] a) {
		int N = a.length;
		Arrays.sort(a);
		
		int min = a[0];
		int max = a[N-1];
		if(max<min*2-1 || min*2<max)
			return false;
		
		int[] cnt = new int[min*2+1];
		for(int i=0; i<N; i++)
			cnt[a[i]]++;
		
		for(int i=min; i<=max; i++) {
			if(i==min) {
				if(max==min*2) {
					if(cnt[i]!=1)
						return false;
				} else {
					if(cnt[i]!=2)
						return false;
				}
			} else {
				if(cnt[i]<2)
					return false;
			}
		}
		
		return true;
	}
}


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

using namespace std;

int main(void){
    int N,L;
    cin>>N>>L;
    int sum=(L+L+N-1)*N/2;
    if(L>=0){
        cout<<sum-L<<endl;
    }else if((L+N-1)<=0){
        cout<<sum-(L+N-1)<<endl;
    }else{
        cout<<sum<<endl;
    }
    return 0;
}


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

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

    vector<int> su(N);

    rep(i,K){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            --a;
            ++su[a];
        }
    }

    int ans = 0;
    rep(i, N) {
        if(su[i]==0)
            ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
require 'pp'

n = gets.chomp!.to_i
a_n = gets.chomp!.split(" ").map(&:to_i)

count = 0
find = 1

a_n.each do |a|
    if a == find
        count += 1
        find += 1
    end
end

if count == 0
    puts -1
else
    puts n - count
end


Measured memory_bytes: 16988
#include <stdio.h>
#include <math.h>
 
#define PI (M_PI)
 
int main(void) {
    double a, b, c;
    double s, l, h;
 
    scanf("%lf %lf %lf", &a, &b, &c);
    s = a*b*sin(c*PI/180.0)/2.0;
    l = a + b + sqrt(a*a + b*b - 2.0*a*b*cos(c*PI/180.0));
    h = s*2.0/a;
    printf("%.4f\n%.4f\n%.4f\n", s, l, h);
 
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
fx(3){
	string s;
	cin>>s;
	cout<<s.at(x);
}
cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    while(n-- > 0) {
        vector<int> edge;
        for(int i = 0; i < 3; i++) {
            int e;
            cin >> e;
            edge.push_back(e);
        }
        sort(edge.begin(), edge.end(), greater<int>());
        if((edge[0] * edge[0]) == (edge[1] * edge[1] + edge[2] * edge[2])) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    cin >> A;
    YESNO(accumulate(ALL(A), 0LL) < H, "No", "Yes");
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const int MM = 2e5+5;

int n, a[MM];
ll cnt[MM], tot;

int main(){
    scan(n);
    for(int i = 1; i <= n; i++){
        scan(a[i]);
        tot += cnt[a[i]]++;
    }
    for(int i = 1; i <= n; i++){
        tot += cnt[a[i-1]]++;
        tot -= --cnt[a[i]];
        print(tot);
    }
    
    
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}

const int N = 1035;
int a[N][N];
int b[N][N];

int main()
{
	startTime = (double)clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	for (int len = 1; 2 * len < N; len <<= 1) {
		for (int i = 0; i < len; i++)
			for (int j = 0; j < len; j++) {
				a[i][len + j] = a[len + i][len + j] = a[i][j];
				a[len + i][j] = a[i][j] ^ 1;
			}
	}
	
	int n, m;
	scanf("%d%d", &n, &m);
	n = 1 << n;
	m = 1 << m;
	for (int i = 0; i < n; i += min(n, m))
		for (int j = 0; j < m; j += min(n, m))
			for (int x = 0; x < min(n, m); x++)
				for (int y = 0; y < min(n, m); y++)
					b[i + x][j + y] = a[x][y];

	for (int i = 1; i < n; i++) {
		for (int j = 1; j < m; j++)
			printf("%d", a[i][j] ^ a[i - 1][j] ^ a[i][j - 1] ^ a[i - 1][j - 1]);
		printf("\n");
	}

	return 0;
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	auto e = vector<vector<int>>(n + 1);
	auto ab = vector<pair<int, int>>(m);
	for(auto i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
		ab[i] = make_pair(a, b);
	}
	int ans = 0;
	for(auto i = 0; i < m; ++i){
		auto q = queue<int>();
		auto v = vector<bool>(n + 1);
		q.push(ab[i].second);
		int d = 0;
		bool closed = false;
		while(!q.empty()){
			int r = q.size();
			for(auto j = 0; j < r; ++j){
				int c = q.front();
				q.pop();
				if(v[c]) continue;
				if(c == ab[i].first){
					closed = true;
					break;
				}
				v[c] = true;
				for(auto k = 0; k < (int)e[c].size(); ++k){
					int next = e[c][k];
					if(!v[next] && (d > 0 || next != ab[i].first)) q.push(next);
				}
			}
			if(closed) break;
			++d;
		}
		if(!closed) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int x,y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++){
        if(2*i + 4*(x-i) == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <queue>
#include <algorithm>
const int MAX = 2e5 + 10;
using namespace std;

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

	long long a[MAX];

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

	for(int i=n-2;i>=0;i--) {
		if(a[i] <= a[i+1]) continue;

		if(a[i] - a[i+1] >= 2) {
			cout << "No" ; return 0;
		}

		a[i]--;
	}

	cout<<"Yes";	
}

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

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  char c;
  bool flag1 = true;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    mp[s]++;
    if (i > 0) {
      if (s.at(0) != c) flag1 = false;
    }
    c = s.at(s.size() - 1);
  }

  bool flag2 = true;
  for (auto x : mp) {
    if (x.second >= 2) flag2 = false;
  }
  if (flag1 && flag2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <cctype>
#include <algorithm>
using namespace std;
int main(void){
    int a , b , c , d ;
    cin >> a >> b >> c >> d ;
    int s1 , s2 ;
    s1 = a * b ;
    s2 = c * d ;

    if(s1 <= s2 ){
        cout << s2 << endl;
    }else{
        cout << s1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------
int divi[1001];

int main(void) {
  int n;
  cin >> n;
  arr(a,n);
  sortall(a);
  uniqueall(a);
  prt(a.size()-((a.size()+1)%2));

}


Measured memory_bytes: 768
n, m = gets.chomp.split.map(&:to_i)
pt = Array.new(m + 1, 0)
cnt = 0
while ln = gets
  a = ln.chomp.split.map(&:to_i)
  for i in 1..a[0]
    pt[a[i]] += 1
  end
end
for i in 1..m
  if pt[i] == n
    cnt += 1
  end
end
puts cnt
   

Measured memory_bytes: 1788
/* ITP1_2_D */

import java.io.*;
import java.util.*;

public class Main {
  public static void main (String[] args) throws java.lang.Exception {
    // 入力された値をゲット
   Scanner sc = new Scanner(System.in);

   int W = sc.nextInt();  // 1個目をWにセット
   int H = sc.nextInt();  // 1個目をHにセット
   int x = sc.nextInt();  // 1個目をxにセット
   int y = sc.nextInt();  // 1個目をyにセット
   int r = sc.nextInt();  // 1個目をrにセット

   if( ((x + r) <= W) && ((y + r) <= H) && ((x - r) >= 0) && ((y - r) >= 0) ) {
       System.out.println("Yes");
   } else {
       System.out.println("No");
   }
 }
}



Measured memory_bytes: 26256
n = int(input())
A = sorted(list(map(int, input().split())))
c = 1
sumA = sum(A)
for i in range(n-1, 0, -1):
  sumA -= A[i]
  if sumA*2 >= A[i]:
    c += 1
  else:
    print(c)
    exit()
print(n)  

Measured memory_bytes: 14228
from heapq import heappush, heappop, heapify

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
# print(p)
# print(q)
# print(r)

ar = p[:x]
ag = q[:y]
heapify(ar)
heapify(ag)

for i in range(c):
    if r[i] > ar[0] and r[i] > ag[0]:
        if ar[0] < ag[0]:
            heappop(ar)
            heappush(ar, r[i])
        else:
            heappop(ag)
            heappush(ag, r[i])
    elif r[i] <= ar[0] and r[i] > ag[0]:
        heappop(ag)
        heappush(ag, r[i])
    elif r[i] > ar[0] and r[i] <= ag[0]:
        heappop(ar)
        heappush(ar, r[i])
    else:
        # r[i] <= ar[0] and r[i] <= ag[0]
        break

# print(ar)
# print(ag)
ans = sum(ar) + sum(ag)
print(ans)


Measured memory_bytes: 110120
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n,a,x[55];
    long long d[55][55][2550]={0};
    cin>>n>>a;
    for(int i=0;i<n;i++) cin>>x[i];
    d[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            for(int k=0;k<=2550;k++){
                d[i+1][j][k]+=d[i][j][k];
                d[i+1][j+1][k+x[i]]+=d[i][j][k];
            }
        }
    }
    long long ans=0;
    for(int i=1;i<=n;i++) ans+=d[n][i][i*a];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 60544
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;


signed main()
{
    int n;cin>>n;
    --n;
    std::vector<int> inp(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>inp[i];
    }
    int ans=0;
    for(int i=1;i<n;++i)
    {
        ans+=(min(inp[i],inp[i-1]));
    }
    ans+=inp[0];
    ans+=inp[n-1];
    cout<<ans;
}

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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD   = 1e9 + 7;
const double PI = acos(-1.0);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int INF   = 1e18;

#define fastio            ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define f first
#define s second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define spc " "
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

void solve(){

    int n, m, k;
    cin >> n >> m >> k;
    vi a(n);
    rep(i, n){
        cin >> a[i];
    }
    vi b(m);
    rep(i, m){
        cin >> b[i];
    }
    int ans = 0;

    vi prefa(n + 1, 0);
    rep(i, n){
        prefa[i + 1] = a[i] + prefa[i];
    }
    vi prefb(m + 1, 0);
    rep(i, m){
        prefb[i + 1] = b[i] + prefb[i];
    }

    rep(i, n + 1){
        if(prefa[i] > k){
            break;
        }
        int need = k - prefa[i];
        int idx = upper_bound(all(prefb), need) - prefb.begin() - 1;
        ans = max(ans, i + idx);
    }

    cout << ans << endl;




}

signed main(){
    fastio;

    solve();

    return 0;
}


Measured memory_bytes: 9484
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

string T1[10];
string T2[10];
int p, q;

void solve() {
	vector<int> ind(p);
	for(int i = 0; i < p; i++) {
		int cnt = 0;
		while(T1[i][cnt] == '.') cnt++;
		ind[i] = cnt;
	}

	vector<int> ans(q, -2);
	for(int R = 1; R <= 20; R++) {
		for(int C = 1; C <= 20; C++) {
			for(int S = 1; S <= 20; S++) {
				int r = 0, c = 0, s = 0;
				bool flag = true;
				for(int i = 0; i < p; i++) {
					int sum = R * r + C * c + S * s;
					if(ind[i] != sum) {
						flag = false;
						break;
					}
					for(char x : T1[i]) {
						if(x == '(') r++;
						if(x == ')') r--;
						if(x == '{') c++;
						if(x == '}') c--;
						if(x == '[') s++;
						if(x == ']') s--;
					}
				}
				if(!flag) continue;

				r = c = s = 0;
				for(int i = 0; i < q; i++) {
					int sum = R * r + C * c + S * s;
					if(ans[i] == -2) {
						ans[i] = sum;
					}
					else if(ans[i] != sum) {
						ans[i] = -1;
					}
					for(char x : T2[i]) {
						if(x == '(') r++;
						if(x == ')') r--;
						if(x == '{') c++;
						if(x == '}') c--;
						if(x == '[') s++;
						if(x == ']') s--;
					}
				}
			}
		}
	}

	for(int i = 0; i < q; i++) {
		cout << ans[i];
		if(i != q - 1) cout << " ";
	}
	cout << endl;
}

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


	while(cin >> p >> q, p | q) {
		for(int i = 0; i < p; i++) {
			cin >> T1[i];
		}
		for(int i = 0; i < q; i++) {
			cin >> T2[i];
		}

		solve();
	}
}

Measured memory_bytes: 3180
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;

int main(){
  int a,b,c,x; cin >> a >> b >> c >> x;
  int xx = x/50;
  int cnt=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(10*i+2*j+k == xx) cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 3 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 
    
    int n;
    cin>>n;
    vl v(n);
    vl a(n) , b(n);


    rep(n){
        int x;
        cin>>x;

        a[i] = x;
    }

    rep(n){
        int x;
        cin>>x;
        b[i] = x;
    }

    rep(n){
        v[i] = a[i] - b[i];
    }

    sort(all(v), greater<bint>());

    bint sum = 0;

    int i=0; 
    while(v[i]>0 and i<n){
        sum+=v[i];
        ++i;
    }
    cout<<max(sum , 0ll)<<endl;

    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("bin","r",stdin);
    freopen("bout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int H,W;
    int i,j,k,count;

    int a[100][2];

    for(count=0;;count++){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0){
            break;
        }

        a[count][0]=H;
        a[count][1]=W;
    }

    for(i=0;i<count;i++){
        /* 長方形 */
        for(j=0;j<a[i][0];j++){
            /* 横一列 */
            for(k=0;k<a[i][1];k++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2604