akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;

int main() {
  string s;
  cin >> s;
  int a = INT_MAX, b = -1;
  rep(i,(int)s.size()) {
    if( s[i] == 'A' ) a = min(a,i);
    if( s[i] == 'Z' ) b = max(b,i);
  }
  cout << b - a + 1 << endl;
  return 0;
}


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

int main(){
  long long int A,B,K;
  cin>>A;
  cin>>B;
  cin>>K;
  if(K<A){
    A=A-K;
  }else if(K-A>B){
    A=0;
    B=0;
  }else{
    B=B-K+A;
    A=0;
  }
    cout<<A<<" "<<B;
}


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

int main(void)
{
    int dp[2][3],a[3],i,N;
    i=0; 
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
 
    scanf("%d",&N);
    while(N--)
    {
        scanf("%d%d%d",a,a+1,a+2);
        dp[1-i][0]=a[0]+max(dp[i][1],dp[i][2]);
        dp[1-i][1]=a[1]+max(dp[i][0],dp[i][2]);
        dp[1-i][2]=a[2]+max(dp[i][1],dp[i][0]);
        i=1-i;
    }
    printf("%d\n",max(max(dp[i][0],dp[i][1]),dp[i][2]));
    return 0;
}

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

using namespace std;

#define ll long long
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cmax(a,b)		a = max (a, b)
#define cmin(a,b)		a = min (a, b)

const int MAXN = 1e5 + 5;
const int oo = 0x3f3f3f3f;

int N, L, T, a[MAXN], t[MAXN], st = 0;

int main(){
	scanf("%d%d%d", &N, &L, &T);
	up (i, 0, N - 1) scanf("%d%d", &a[i], &t[i]);
	up (i, 0, N - 1) {
		if (t[i] == 1) {
			int cnt = (T + a[i]) / L;
			a[i] = (a[i] + T) % L;
			if (a[i] == 0) cnt -= (cnt > 0);
			st = (st + cnt) % N;
		}else {
			int cnt = (L - a[i] + T) / L;
			a[i] = (a[i] + L - (T % L)) % L; 
			if (a[i] == 0) cnt -= (cnt > 0);
			st = (st + N - (cnt % N)) % N;
		}
	}
	sort(a, a + N);
	int cur = st;
	up (i, 1, N) printf("%d\n", a[(cur++) % N]);
	return 0;
}


Measured memory_bytes: 1920
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
    
    public void DFS() {
        int time = 1;
        int[] discovered = new int[totalVertex];
        int[] finished = new int[totalVertex];

        for (int i = 0; i < totalVertex; i++) {
            if (discovered[i] == 0) {
                time = DFSHelper(i, time, discovered, finished) + 1;
            }
        }

        for (int i = 0; i < totalVertex; i++) {
            System.out.println((i + 1) + " " + discovered[i] + " " + finished[i]);
        }
    }

    public int DFSHelper(int vertex, int timestamp, int[] discovered, int[] finished) {
        discovered[vertex] = timestamp;

        LinkedList<Integer> neighbors = adjList.get(vertex);
        for (Integer n : neighbors) {
            if (discovered[n] == 0) {
                timestamp = DFSHelper(n, ++timestamp, discovered, finished);
            }
        }

        finished[vertex] = timestamp + 1;
        return finished[vertex];
    }
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
        g.DFS();
	}
}


Measured memory_bytes: 27996
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k;
    cin >> k;
    
    queue<ll> q;
    rep(i, 9) q.push(i+1);
    ll ans;
    while (!q.empty()) {
        ll v = q.front();
        q.pop();

        if (--k == 0) {
            ans = v;
            break;
        }
        int last = v%10;
        for (int i = max(last-1, 0); i <= min(last+1, 9); ++i) {
            ll nv = v * 10 + i;
            q.push(nv);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
/* author   : mpily :-()
title : Competing.cpp
time :Sun Apr 26 15:01:19 2020

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int s,w;
	cin >> s >> w;
	if(w >= s)
		cout << "unsafe\n";
	else cout << "safe\n";

	return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node* prev, * next;
};

Node* nil;
Node* listSearch(int key) {
	Node* cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node*)malloc(sizeof(Node));
	nil->prev = nil;
	nil->next = nil;
}

void printList() {
	Node* cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil) break;
		if (isf++ > 0)printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node* t) {
	if (t == nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node* x = (Node*)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') { insert(key); np++; size++; }
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F')deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}

	printList();

	return 0;
}


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

using namespace std;

#define MAX 100001
#define MOD 1000000007
typedef long long ll;

int bit[MAX], N;

int sum(int i)
{
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x)
{
    while (i <= N) {
        bit[i] += x;
        i += i & -i;
    }
}

int main()
{
    ll fact[MAX];    
    fact[0] = 1;
    for (int i = 1; i < MAX; i++) {
        fact[i] = ((ll)i * fact[i-1]) % MOD;
    }
    
    int R, s, t;
    while (cin >> N, N) {
        cin >> R;
        vector<ll> v(N);
        for (int i = 0; i < N; i++) {
            v[i] = i + 1;
        }
        for (int i = 0; i < R; i++) {
            cin >> s >> t;
            s--; t--;
            swap(v[s], v[t]);
        }

        memset(bit, 0, sizeof(bit));
        
        ll res = 0;
        for (int i = N-1; i >= 0; i--) {
            add(v[i], 1);
            res += fact[(N - i - 1)] * sum(v[i]-1);
            res %= MOD;
        }
        cout << res << endl;
    }       
    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <set>
using namespace std;
#define MAX_V 100
#define INF 1<<30

int N, M;
int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];
bool Vused[MAX_V][MAX_V];

int prim(){
	for(int i=0;i<N;i++){
		mincost[i]=INF;
		used[i] = false;
	}
	mincost[0] = 0;
	int res = 0;

	while(true){
		int v = -1;
		for(int u=0;u<N;u++){
			if(!used[u] && (v==-1 || mincost[u] < mincost[v])) v=u;
		}
		if(v == -1) break;
		used[v] = true;
		if(mincost[v] >= INF) return INF;
		res += mincost[v];
		for(int u=0;u<N;u++){
			if(mincost[u] > cost[v][u]){
				mincost[u] = cost[v][u];
			}
		}
	}
	return res;
}


main(){
	int i,j;
	while(cin >> N, N){
		for(i=0;i<N;i++){
			for(j=0;j<N;j++){
				cost[i][j] = INF;
				Vused[i][j] = false;
			}
		}
		cin >> M;
		for(i=0;i<M;i++){
			int a,b,c;
			char x;
			cin >> a >> x >> b >> x >> c;
			cost[a][b] = cost[b][a] = c/100-1;
		}
		cout << prim() << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
import java.util.*;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static class Pair {
		int id, value;

		Pair(int id, int value) {
			this.id = id;
			this.value = value;
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		List<Pair> A = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			A.add(new Pair(i, Integer.parseInt(tokens[i])));
		}
		Collections.sort(A, new Comparator<Pair>() {
			@Override
			public int compare(Pair o1, Pair o2) {
				return Integer.compare(o1.value, o2.value);
			}
		});
		for (int i = 0; i < N; ++i) {
			System.out.print((A.get(i).id + 1) + " ");
		}
		System.out.println("");
	}
}


Measured memory_bytes: 50976
using System; 
using System.Text; 
using System.Collections.Generic;
using System.Linq; 
using E = System.Linq.Enumerable; 
 
class Program { 
     const long beki = 1000000007;
     static void Main(string[] args) {
     //入力を受け取る 
     int[] NQ = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
     int N =　NQ[0];
     int Q =　NQ[1];
     
     var S = Console.ReadLine();
     var ACamount = new int[N+1];
     
     for(int i = 0; i < N-1 ;i++){
         if(S[i] == 'A' && S[i+1] == 'C'){
             ACamount[i+1] = ACamount[i]+1;
         }else{
             ACamount[i+1] = ACamount[i];
         }
     }
     for(int i = 0; i < Q ;i++){
         int[] lr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
         int l = lr[0];
         int r = lr[1];
         Console.WriteLine(ACamount[r-1]-ACamount[l-1]);
     }
     
       }
      
     }

Measured memory_bytes: 18492
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T& container, typename T::key_type& key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法


int main(void) {
	string S;
	cin >> S;
	bool bad = false;
	for (int i = 1; i < S.size(); i++) {
		if (S[i - 1] == S[i]) bad = true;
	}
	cout << (bad ? "Bad" : "Good") << endl;
	return 0;
}



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

#define rep(i, a, n) for(int i=(a);i<(n);++i)
#define per(i, a, n) for(int i=(a);i>(n);--i)
#define pb emplace_back
#define mp make_pair
#define lowbit(x) (x & -x)

typedef long long LL;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int M = 45;
const int N = 2e5 + 10;
int n;
char s[100];

void decode(int &c2, int &c5, int &m){
	int len = strlen(s);
	LL a, b;
	bool flag = 0;
	rep(i, 0, len){
		if(s[i] == '.'){
			sscanf(s, "%lld.%lld", &a, &b);
			flag = 1;
			m = len - i - 1;
			break;
		}
	}
	if(!flag){
		sscanf(s, "%lld", &a);
		b = 0;
		m = 0;
	}

	rep(i, 0, m)	a = a * 10;
	a = a + b;

	c2=0, c5=0;

	while(a % 2 == 0){
		a >>= 1;
		++c2;
	}
	while(a % 5 == 0){
		a /= 5;
		++c5;
	}

	int c = min(c2, c5);
	m -= c;
	c2 -= c;
	c5 -= c;
}

unordered_map<int, int> MP0, O, MP2[M], MP5[M];

int main(){
	scanf("%d", &n);

	int c2, c5, lft;

	LL ans = 0, ans1 = 0;

	rep(i, 0, n){
		scanf("%s", s);
		decode(c2, c5, lft);
		
		if(c2 > 0){
			MP2[c2][lft]++;
			O[lft]++;
		} else if(c5 > 0){
			MP5[c5][lft]++;
			O[lft]++;
		} else {
			MP0[lft]++;
		}
		if(lft <= 0)	ans1--;
	}

	for(auto it : MP0){
		for(auto it1 : MP0){
			if(it.first + it1.first <= 0)	ans1 += 1LL * it.second * it1.second;
		}
	}
	
	for(auto it : MP0){
		for(auto it1 : O){
			if(it.first + it1.first <= 0)	ans += 1LL * it.second * it1.second;
		}
	}

	rep(i, 0, M){
		for(auto it : MP2[i]){
			rep(j, 0, M){
				for(auto it1 : MP2[j]){
					if(it.first + it1.first <= 0){
						ans1 += 1LL * it.second * it1.second;
					}
				}
				for(auto it1 : MP5[j]){
					if(it.first + it1.first - min(i, j) <= 0){
						ans += 1LL * it.second * it1.second;
					}
				}
			}
		}

		for(auto it : MP5[i]){
			rep(j, 0, M){
				for(auto it1 : MP5[j]){
					if(it.first + it1.first<= 0){
						ans1 += 1LL * it.second * it1.second;
					}
				}
			}
		}
	}


	printf("%lld\n", ans + ans1 / 2);

	return 0;
}


Measured memory_bytes: 3720
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, M): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    fn bis<P: Fn(i64) -> bool>(ok: i64, ng: i64, p: P) -> i64 {
        let mid = (ok + ng) / 2;
        if (ok - ng).abs() == 1 {
            ok
        } else if p(mid) {
            bis(mid, ng, p)
        } else {
            bis(ok, mid, p)
        }
    }

    let B = {
        let mut B = A.clone();
        B.sort();
        B.reverse();
        B
    };
    let mut acc = vec![0];
    for i in 0..N {
        let s = acc[i] + B[i];
        acc.push(s);
    }
    let f = |m| {
        (0..N).fold((0, 0), |(c, s), i| {
            if 2 * B[i] < m {
                (c, s)
            } else {
                let i = i as i64;
                let j = bis(i, N as i64, |k| {
                    k == i - 1 || B[i as usize] + B[k as usize] >= m
                });
                if j == i - 1 {
                    (c, s)
                } else {
                    let q = j - i;
                    (
                        c as i64 + 2 * q + 1,
                        s + 2 * q * B[i as usize] + 2 * (acc[(j + 1) as usize] - acc[i as usize]),
                    )
                }
            }
        })
    };
    const INF: i64 = 1e12 as i64;
    let L = bis(1, INF, |m| {
        let (c, _) = f(m);
        c >= M as i64
    });
    let (c, s) = f(L);
    let ans = s - (c - M as i64) * L;

    println!("{}", ans);
}


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

const long long mod = 1000000007;

long long mod_pow(long long x, long long n) {
	if (n == 0) return 1;
	long long res = mod_pow(x * x % mod, n / 2);
	if (n % 2) res = res * x % mod;
	return res;
}

int main() {
	long long m, n;
	cin >> m >> n;
	cout << mod_pow(m, n) % mod << endl;
}


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

void solve_test() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d)) << '\n';
}

int32_t main() {
	int T; 
	// cin >> T;
	T = 1;
	while (T--)
		solve_test();

	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <list>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <cstdio>
#include <queue>
#include <unordered_set>

using namespace std;

#define rank roman_kaban


int main()
{
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    string t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i <= min(s.size(), t.size()); i++){
        bool ok = true;
        for(int j = 0; j < i; j++){
            if(t[j] != s[ s.size() - i + j]) ok = false;
        }
        if(ok) ans = i;
    }
    cout << s.size() + t.size() - ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

	int n = scan.nextInt();
	int[] d = new int[n];
	int max = 0;
	int count = 0;

	for(int i = 0; i < n; i++){
	    d[i] = scan.nextInt();
	}

	for(int i = 0; i < n-1; i++){
	    for(int j = i+1; j < n; j++){
		if(d[i] > d[j]){
		    int tmp = d[i];
		    d[i] = d[j];
		    d[j] = tmp;
		}
	    }
	}

	for(int i = 0; i < n; i++){
	    if(max < d[i]){
		max = d[i];
		count++;
	    }
	}

	System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 100000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int n, i, cnt[4] = {0};
    string s;
    cin >> n;
    for (i = 0; i < n; ++i) {
        cin >> s;
        if (s == "AC") {
            cnt[0]++;
        } else if (s == "WA") {
            cnt[1]++;
        } else if (s == "TLE") {
            cnt[2]++;
        } else {
            cnt[3]++;
        }
    }
    cout << "AC x " << cnt[0] << "\n";
    cout << "WA x " << cnt[1] << "\n";
    cout << "TLE x " << cnt[2] << "\n";
    cout << "RE x " << cnt[3] << "\n";

    return 0;
}

Measured memory_bytes: 3224
K = int(input())

idx = 0
l = list(range(1, 10))

while len(l) < K:
    m = l[idx]
    for i in (-1, 0, 1):
        n = (m % 10) + i
        if n in {-1, 10}:
            continue
        tmp = int(str(m) + str(n))
        l.append(tmp)
    idx = idx + 1

print(l[K-1])

Measured memory_bytes: 7072
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,k,flag=0,ma=0,mi=0x3f3f3f3f;
	char s[200005];
	scanf("%s",&s);
	n=strlen(s);
	for(i=0;i<n;i++)
	{
		if(s[i]=='?')
		s[i]='D';
	}
	printf("%s",s);
} 

Measured memory_bytes: 3908
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    S,T=input().split()
    ans=[None]*(2*n)

    for i in range(n):
        ans[2*i]=S[i]
        ans[2*i+1]=T[i]

    print(''.join(ans))
resolve()

Measured memory_bytes: 38384
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll cul(ll a,ll b,ll x){
    ll l=0,r=b+1;
    while(r-l>1){
        ll m=l+(r-l)/2;
        if(m*x>a || m>b || (b-m)/x>a-(m*x)){r=m;}
        else{l=m;}
    }
    return l;
}

//1-indexed
string cul(ll a,ll b,ll c,ll d){
    string ret;
    ll x=(a+b)/(b+1);
    if(a==b || x==1){
        for(ll i=c;i<=d;i++){ret.push_back(i&1?'A':'B');}
        return ret;
    }
    ll L=cul(a,b,x),R=cul(b,a,x);
    for(ll i=c;i<=d;i++){
        if(i<=L*(x+1)){
            ret.push_back(i%(x+1)?'A':'B');
        }
        else if(a+b-i+1<=R*(x+1)){
            ret.push_back((a+b-i+1)%(x+1)?'B':'A');
        }
        else{
            ll I=i-(x+1)*L;
            ll A=a-L*x-R;
            ll B=b-L-R*x;
            //cout<<i<<" "<<L<<" "<<R<<" "<<A<<" "<<B<<endl;
            ret.push_back(I<=A?'A':'B');
        }
    }
    return ret;
}


int main(){
    ll q;
    cin>>q;
    while(q--){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        string ans;
        if(a>b){
            ans=cul(a,b,c,d);
        }
        else{
            ans=cul(b,a,a+b-d+1,a+b-c+1);
            reverse(ans.begin(),ans.end());
            for(auto &I:ans){I=(I=='A'?'B':'A');}
        }
        cout<<ans<<endl;
    }
    
    
    return 0;
}


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

using namespace std;

struct odd : public unary_function<int, bool> { bool operator () (int x) const { return (x % 2) != 0; } };
void dis(int *Array, int N) { for(int i = 0; i < N; ++i) {std::cout.width(1); std::cout << Array[i];} std::cout << std::endl;}
signed fac(int n){return (n==1 || n==0) ? 1: n * fac(n - 1);}
bool V(char x) {return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'); } 
template<typename T, typename U> inline signed  amin(T &x, U y) { if(y < x) x = y; return x;}
template<typename T, typename U> inline signed  amax(T &x, U y) { if(x < y) x = y; return x;}
//signed m(){long long T, pp,p,ppp, ct, nn, xx; cin >> p; cin.ignore(); for(int k=0;k<n;k++){for(int l=0;l<(k+1);l++){cin>>a[k][l];}}
#define inn freopen("input.txt", "r", stdin) 
#define outt freopen("output.txt", "w",stdout)
#define all(cont) cont.begin(), cont.end()
#define ll          long long
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)

ll n,E,E1,D=0,c,m,D1,k=0,arr[1000],a,b,d,e,f,flag=0,max2=0,l=0;

vector<int>fi,fi1;
string s;
std::vector<int>::iterator low1, low2;
//set <char> se;

int main () {
double max1=0,st;
cin>>n>>k;
for(int i=0; i<n; i++)
{
    cin>>a;
    fi.push_back(a);
}
sort(fi.begin(),fi.end());

for(int i=0; i<fi.size(); i++)
{
    if(fi[i]>=k)
    {
        D++;
    }
}
cout<<D<<"\n";
    


}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int X, Y, A, B, C;
priority_queue <Pli> que;

int main(){
  cin >> X >> Y >> A >> B >> C;

  for (int i = 0; i < A; i++){
    ll P; cin >> P; que.push({P, 0});
  }
  for (int i = 0; i < B; i++){
    ll Q; cin >> Q; que.push({Q, 1});
  }
  for (int i = 0; i < C; i++){
    ll R; cin >> R; que.push({R, 2});
  }

  ll ans = 0;
  int R = 0, G = 0, T = 0;
  while (R+G+T < X+Y){
    Pli Q = que.top(); que.pop();

    if (Q.se == 0 && R < X){
      ans += Q.fi; R++;
    }
    if (Q.se == 1 && G < Y){
      ans += Q.fi; G++;
    }
    if (Q.se == 2){
      ans += Q.fi; T++;
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define forI(n) for(ll i = 0 ; i<n ; i++) 
#define forD(an) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a[3][3];
  	for(ll i=0;i<3;++i) for(ll j=0;j<3;++j) cin>>a[i][j];
  
  	ll n;
  	cin>>n;
  	while(n--) {
    	ll t; cin>>t;
      	for(ll i=0;i<3;++i) for(ll j=0;j<3;++j) if(a[i][j]==t) a[i][j] = -1;
    }
  	if( (a[0][0]==-1 && a[0][1]==-1 && a[0][2]==-1) || (a[1][0]==-1 && a[1][1]==-1 && a[1][2]==-1) || (a[2][0]==-1 && a[2][1]==-1 && a[2][2]==-1) || (a[0][0]==-1 && a[1][0]==-1 && a[2][0]==-1) || (a[0][1]==-1 && a[1][1]==-1 && a[2][1]==-1) || (a[0][2]==-1 && a[1][2]==-1 && a[2][2]==-1) || (a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1) || (a[0][2]==-1 && a[1][1]==-1 && a[2][0]==-1) ) cout <<"Yes";
	else cout <<"No";	
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

const int MAXS = 100005;
const int MOD = 1000000007;

char s[MAXS];

int main() {
    scanf("%s", s);
    int n = strlen(s);

    static int f[2][4];
    int curr = 0, last = 1;

    f[curr][0] = 1;
    for (int i = 0; i < n; i++) {
        curr ^= 1;
        last ^= 1;

        for (int j = 0; j < 4; j++) f[curr][j] = f[last][j];
        if (s[i] == '?') for (int j = 0; j < 4; j++) {
            int temp = f[last][j] * 2;
            temp >= MOD ? temp -= MOD : 0;
            f[curr][j] += temp;
            f[curr][j] >= MOD ? f[curr][j] -= MOD : 0;
        }

        if (s[i] == 'A' || s[i] == '?') {
            f[curr][1] += f[last][0];
            f[curr][1] >= MOD ? f[curr][1] -= MOD : 0;
        }
        if (s[i] == 'B' || s[i] == '?') {
            f[curr][2] += f[last][1];
            f[curr][2] >= MOD ? f[curr][2] -= MOD : 0;
        }
        if (s[i] == 'C' || s[i] == '?') {
            f[curr][3] += f[last][2];
            f[curr][3] >= MOD ? f[curr][3] -= MOD : 0;
        }
    }

    printf("%d\n", f[curr][3]);
    
    return 0;
}

Measured memory_bytes: 256
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
MOD = 10**9 + 7
_sum = 0
for i in range(k,n+2):
    _sum += ((n + (n-i+1)) * i // 2) - ((i-1) * i) // 2 + 1
    _sum %= MOD
print(_sum)

Measured memory_bytes: 63692
s = input()
n = len(s)
ans = 0
p = 0
n_s1 = 1
n_s2 = 1
while p<n:
  if s[p:p+n_s1]==s[p+n_s1:p+n_s1+n_s2]:
    n_s2 += 1
    if p+n_s1+n_s2>n:
      ans += 1
      break
  else:
    p += n_s2
    n_s1 = n_s2
    ans += 1
    n_s2 = 1
print(ans)

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

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

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int ans = 0;
    for (int i = 0; i < n-1; ++i) {
        if(v[i] < v[i+1]) ans++;
    }
    cout << ans << "\n";
    return 0;
}


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

typedef long long i64;

struct LazySegment
{
	vector<i64> node;
	vector<i64> lazy;
	vector<bool> lazyFlag;
	int n;


	i64 init = 0;

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

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

	LazySegment(const vector<i64>& vec)
	{
		int sz = vec.size();

		n = 1;
		while(n < sz) n <<= 1;

		node.resize(2 * n - 1,init);
		lazy.resize(2 * n - 1,0);
		lazyFlag.resize(2 * n - 1,false);

		for(int i = 0;i < sz;i++)
		{
			node[n - 1 + i] = vec[i];
		}

		for(int i = n - 2;i >= 0;i--)
		{
			node[i] = node[left(i)] + node[right(i)];
		}
	}

	void eval(int k,int l,int r)
	{
		if(lazyFlag[k])
		{
			node[k] = node[k] + lazy[k];

			if(r - l > 1)
			{
				lazy[left(k)] += lazy[k] / 2;
				lazy[right(k)] += lazy[k] / 2;
				lazyFlag[left(k)] = true;
				lazyFlag[right(k)] = true;
			}

			lazyFlag[k] = false;

			lazy[k] = 0;
		}
	}

	void add_inter(int a,int b,i64 x,int k = 0,int l = 0,int r = -1)
	{
		if(r < 0) r = n;

		eval(k,l,r);

		if(b <= l || r <= a) return ;

		if(a <= l && r <= b)
		{
			lazy[k] += (r - l) * x;
			lazyFlag[k] = true;
			eval(k,l,r);
		}

		else
		{
			add_inter(a,b,x,left(k),l,(l + r) / 2);
			add_inter(a,b,x,right(k),(l + r) / 2,r);
			node[k] = node[left(k)] + node[right(k)];
		}
	}

	i64 get_inter(int a,int b,int k = 0,int l = 0,int r = -1)
	{
		if(r < 0) r = n;

		eval(k,l,r);
		if(b <= l || r <= a) return init;

		if(a <= l && r <= b) return node[k];

		i64 lv = get_inter(a,b,left(k),l , (l + r) / 2);
		i64 rv = get_inter(a,b,right(k),(l + r) / 2 , r);

		return lv + rv;
	}
};

int main()
{
	int n;
	int q;

	cin >> n >> q;

	LazySegment seg(vector<i64>(n,0));

	for(int i= 0;i < q;i++)
	{
		int query;
		cin >> query;

		if(query == 0)
		{
			int a,b;
			i64 x;
			cin >> a >> b >> x;

			a--;
			b--;
			seg.add_inter(a,b + 1,x);
		}
		else
		{
			int a;
			int b;
			cin >> a >> b;
			a--;
			b--;

			cout << seg.get_inter(a,b + 1) << endl;

		}
	}
	return 0;
}



Measured memory_bytes: 7860
#include <iostream>

using namespace std;

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

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

char field[55][55];

int main() {
    int H, W;
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            cin >> field[i][j];
        }
    }

    rep(i, H) {
        rep(j, W) {
            if (field[i][j] == '#')continue;
            int cou = 0;

            for (int a = 0; a < 8; a++) {
                int nx = j + dx[a];
                int ny = i + dy[a];
                if (field[ny][nx] == '#') {
                    cou++;
                }
                if (a == 7) {
                    field[i][j] = '0' + (char)cou;
                }
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            cout << field[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
from sys import stdin

x = int(stdin.readline().rstrip())

counter = 0
for i in range(2000000):
    if x - 500 >= 0:
        x = x - 500
        counter += 1000
    else:
        break
for i in range(102):
    if x - 5 >= 0:
        x = x - 5
        counter += 5
    else:
        break

print(counter)

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

using namespace std;
typedef long long ll;
#define MP make_pair

int main(void) {
    int n,m,ans=0;

    cin>>n>>m;


    if(m!=0)ans+=m*(m-1)/2;
    if(n!=0)ans+=n*(n-1)/2;



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

Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int, input().split())), )
j = 1
if A[0] == 0:
    print(0)
    exit()
for i in A:
    j = i * j
    if j > 10**18:
        print(-1)
        exit()
if j > 10**18:
    print(-1)
else:
    print(j)

Measured memory_bytes: 21652
abcd = list(input())
a,b,c,d = int(abcd[0]),int(abcd[1]),int(abcd[2]),int(abcd[3]),
if (a+b+c+d)==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'='+'7')
elif (a+b+c-d)==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'='+'7')
elif (a+b-c+d)==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'='+'7')
elif (a-b+c+d)==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'='+'7')
elif (a+b-c-d)==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'='+'7')
elif (a-b-c+d)==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'='+'7')
elif (a-b+c-d)==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'='+'7')
elif (a-b-c-d)==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'='+'7')

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll n, a, b; cin>>n>>a>>b;

    if(!(a + b - 1 <= n && n <= a * b)){
        cout << -1 << endl;
        return 0;
    }

    vector<int> ans(n);
    for(int i=0; i<b; i++){
        ans[i] = b - i;
    }

    if(a == 1){
        for(int i=0; i<n; i++){
            cout << ans[i] << " \n"[i == n-1];
        }
        return 0;
    }

    int index = b;

    int cnt = (n - b) / (a - 1);
    int rem = (n - b) % (a - 1);

    int pre = b;
    for(int i=index; i<n;){
        int curcnt = cnt + (rem-- > 0);
        int num = pre + curcnt;
        int cur = num;

        for(int j=i; j<i+curcnt; j++){
            ans[j] = num--;
        }

        i += curcnt;
        pre = cur;
    }

    for(int i=0; i<n; i++){
        cout << ans[i] << " \n"[i == n-1];
    }

    return 0;
}

Measured memory_bytes: 3328
s = []
h = []
c = []
d = []
num = int(input())
for num1 in range(num):
    a,b = input().split(" ")
    b = int(b)
    if a == "S":
        s.append(b)
    elif a == "H":
        h.append(b)
    elif a == "D":
        d.append(b)
    else:
        c.append(b)
s.sort()
h.sort()
c.sort()
d.sort()
for num2 in range(1,14):
    if num2 in s:
        continue
    else:
        print("S " + str(num2))
        continue
for num3 in range(1,14):
    if num3 in h:
        continue
    else:
        print("H " + str(num3))
        continue
for num4 in range(1,14):
    if num4 in c:
        continue
    else:
        print("C " + str(num4))
        continue
for num5 in range(1,14):
    if num5 in d:
        continue
    else:
        print("D " + str(num5))
        continue


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const long long INF = 1LL << 60;
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}

signed _main(){
  int N,P; cin >> N >> P;
  bool flag=false;
  rep(i,N){
    int a; cin >> a;
    if(a%2==1) flag=true;
  }
  if(flag){
    int ans=1;
    rep(i,N-1){
      ans*=2;
    }
    cout << ans << endl;
    return 0;
  }
  else{
    if(P==0){
      int ans=1;
      rep(i,N){
        ans*=2;
      }
      cout << ans << endl;
      return 0;
    }
    else{
      cout << 0 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int k, a, b; cin >> k >> a >> b;
    repf(i,a,b+1) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int n;
vector<int> dat;

//inputします
void input() {
	cin >> n;
	dat.resize(100050);
	ff(i, 0, n) {
		int a;
		cin >> a;
		dat[a]++;
	}
}

//ライブラリ置き場



//main
int main() {
    input();
	int ans = 0;
	ff(i, 1, 100000) {
		int pre = dat[i - 1] + dat[i] + dat[i + 1];
		if (ans < pre)ans = pre;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[3];

        a[0] = sc.nextInt();
        a[1] = sc.nextInt();
        a[2] = sc.nextInt();

        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }

        int res = Integer.MAX_VALUE;
        OUTER: for (int i = 0; i < (1 << (2 * n)); i++) {

            int[] len = new int[4];
            int[] num = new int[4];

            for (int j = 0; j < n; j++) {
                int ind = (i >> (2 * j)) % 4;
                len[ind] += l[j];
                num[ind]++;
            }

            int mp = 0;
            for (int j = 0; j < 3; j++) {
                if(num[j] == 0) continue OUTER;
                mp += (num[j] - 1) * 10;
                mp += Math.abs(a[j] - len[j]);
            }
            res = Math.min(res, mp);

        }
        System.out.println(res);

    }

}

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

int d,k;
string b;
int n;
vector<char> v;
int dp[10000][10000][2];
int solve(int i,int cnt,int f)
{
	if(i==n)
	{
		if(cnt==k)
		{
			return 1;
		}
		return 0;
	}
	if(cnt>k)
	{
		return 0;
	}
	if(dp[i][cnt][f]!=-1)
	{
		return dp[i][cnt][f];
	}
	int limit=9;
	if(!f)
	{
		limit=v[i]-'0';
	}
			int ans=0;
	for(int digit=0;digit<=limit;digit++)
	{
			int new_cnt=cnt;
			int new_flag=f;
		if(digit>0)
		{
			new_cnt++;
		}
		if(f==0 && digit<limit)
		{
			new_flag=1;
		}
		if(new_cnt<=k)
		ans+=solve(i+1,new_cnt,new_flag);
	}

	return dp[i][cnt][f]=ans;
}
int main()
{
	cin>>b>>k;
	for(int i=0;i<b.size();i++)
	{
		v.push_back(b[i]);
	}
//	reverse(v.begin(),v.end());
	n=v.size();
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,0,0);
}

Measured memory_bytes: 781568
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, W;
    std::cin >> N >> W;

    struct Bag {
        int64_t weight;
        int64_t value;
    };

    std::vector<Bag> B;
    int64_t W0;
    for (decltype(N) i = 0; i < N; ++i) {
        Bag t;
        std::cin >> t.weight >> t.value;
        if (i == 0) {
            W0 = t.weight -1;
        }
        B.push_back(t);
        B.back().weight -= W0;
    }

    #include <boost/multi_array.hpp>

    boost::multi_array<int64_t, 3> memo(boost::extents[101][101][5*100]);
    std::fill(memo.data(), memo.data() + memo.num_elements(), -1);

    auto f = [&memo,W0, N, W, &B](auto F, int64_t i, int64_t s, int64_t w) -> int64_t {

        if (memo[i][s][w] != -1) {
            return memo[i][s][w];
        }
        if (i == N) {
            return 0;
        }

        if (w + B[i].weight <= W - (s+1)*W0) {
            memo[i][s][w] = std::max(F(F, i+1, s+1, w+B[i].weight) + B[i].value, F(F, i+1, s, w));
        }
        else {
            memo[i][s][w] = F(F, i+1, s, w);
        }
        return memo[i][s][w];
    };

    auto val = f(f, 0, 0, 0);

    std::cout << val << std::endl;

    return 0;
}


Measured memory_bytes: 40064
/*
 * 
 * Author: Pranav Bansal
 * 
*/
#include<bits/stdc++.h>

#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define V(x) vector<x>
#define P(x,y) pair<x,y>
#define UMP(x,y) unordered_map<x,y>
#define MP(x,y) map<x,y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define inf 1e18
#define endl "\n"
#define coutd(n) cout << fixed << setprecision(n)
#define watch(x) cout<<#x<<" = "<<x<<endl;
typedef double db;
typedef long double ld;	
const int mod = 1000000007;

using namespace std;

bool check(ld arr[],int n){
	rep(i,0,n)
		if(arr[i] == 0)
			return true;
	return false;
}

int32_t main(){
    fast
    	
	//int t;
	//cin>>t;
	//rep(_,0,t){
		
	//}
	int n;
	cin>>n;
	ld arr[n];
	rep(i,0,n)
		cin>>arr[i];
		
	if(check(arr,n)){
		cout<<0;
		return 0;
	}
	
	ld pro = 1;
	rep(i,0,n){
		pro*=arr[i];
		if(pro > 1e18){
			pro = -1;
			break;
		}
	}
	
	coutd(0)<<pro;
    return 0;
}


Measured memory_bytes: 5368
#include"bits/stdc++.h"
using namespace std;

int main() {
    int64_t W, H;
    cin >> W >> H;
    vector<int64_t> p(W), q(H);
    for (int64_t i = 0; i < W; i++) {
        cin >> p[i];
    }
    for (int64_t i = 0; i < H; i++) {
        cin >> q[i];
    }

    //行,列ごちゃまぜで小さい順に取りたい
    struct Element {
        int64_t value, row_or_col;
        bool operator<(const Element& rhs) const {
            return value < rhs.value;
        }
        bool operator>(const Element& rhs) const {
            return value > rhs.value;
        }
    };

    priority_queue<Element, vector<Element>, greater<Element>> pq;
    for (int64_t i = 0; i < W; i++) {
        pq.push({ p[i], 0 });
    }
    for (int64_t i = 0; i < H; i++) {
        pq.push({ q[i], 1 });
    }

    int64_t row_line_num = 0, col_line_num = 0, ans = 0;
    while (!pq.empty()) {
        Element e = pq.top();
        pq.pop();
        if (e.row_or_col == 0) {
            ans += e.value * (H + 1 - row_line_num);
            col_line_num++;
        } else {
            ans += e.value * (W + 1 - col_line_num);
            row_line_num++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8048
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int main(int argc, char *argv[]) {
	while (true) {
		int n;
		cin >> n;
		if (!n) {
			break;
		}
		int z[16];
		int cost[16][16];
		for (int i = 0; i < n; ++i) {
			cin >> z[i];
			for (int j = 0; j < n; ++j) {
				cin >> cost[i][j];
			}
		}
		int dp[1 << 16];
		memset(dp, 0x3f, sizeof(dp));
		dp[0] = 0;
		int m = 1 << n;
		for (int b = 0; b < m; ++b) {
			for (int i = 0; i < n; ++i) {
				if (!(b & (1 << i))) {
					int c = z[i];
					for (int j = 0; j < n; ++j) {
						if (b & (1 << j)) {
							c = min(c, cost[i][j]);
						}
					}
					dp[b | (1 << i)] = min(dp[b | (1 << i)], dp[b] + c);
				}
			}
		}
		cout << dp[m - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3344
#include<iostream>
using namespace std;
int a[100000];
int n;
int Partition(int p,int r){
    int i=p-1,j;
    for(int j=p;j<r-1;j++){
        if(a[j]<=a[r-1]){
            i++;
            swap(a[i],a[j]);
        }
    }
    swap(a[r-1],a[i+1]);
    return i+1;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int m=Partition(0,n);
    for(int i=0;i<m;i++)
        cout<<a[i]<<" ";
    cout<<'['<<a[m]<<']'<<" ";
    for(int i=m+1;i<n-1;i++)
        cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
    return 0;
}



Measured memory_bytes: 3392
#アルゴリズム
def solve(i, s):
    global n_list
    global sum_list
    
    if i < len(n_list):
        sum_list.add(s + n_list[i])
        solve(i + 1, s + n_list[i])
        solve(i + 1, s)

#初期値
n = int(input())
n_list = list(map(int, input().split()))
sum_list = set()

#合計値の計算
solve(0, 0)

#判定値
q = int(input())
q_list = list(map(int, input().split()))

#結果表示
for i in range(q):
    if q_list[i] in sum_list:
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5664
/*  ex9_1
    kosaq   */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>//strlenを使用するため
#define SIZE 11

typedef struct{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;//構造体を定義

void initialize_stack(stack *stk);
void push(stack *stk, char elem);
char pop(stack *stk);//プロトタイプ宣言

int main(void){
    char input[SIZE];//入力のために配列を定義
    stack sentence;//構造体を定義
    scanf("%s", input);//0,1,Bからなる配列を入力
    initialize_stack(&sentence);//スタックの初期化

    for(int i = 0; i < strlen(input); i++){
        if(input[i] == '0'){
            push(&sentence, '0');
        }
        else if(input[i] == '1'){
            push(&sentence, '1');
        }
        //0,1のときはスタックにデータを追加
        else if(input[i] == 'B' && sentence.count > 0){
            pop(&sentence);//Bのときであり、かつ文字がまだあるとき（count>0）はデータを取り出し
        }
    }
    
    for(int i = 0; i < sentence.count; i++){
        printf("%c", sentence.data[SIZE - i - 1]);//答えの配列を出力
    }
    printf("\n");
    return 0;

}

//スタックの初期化
void initialize_stack(stack *stk){
    stk -> count = 0;
    stk -> size = SIZE;
    stk -> top = &(stk -> data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk -> count >= stk -> size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk -> top--;
        *(stk -> top) = elem;
        stk -> count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk -> count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk -> top);
        stk -> top++;
        stk -> count--;
        return latest;
    }
}

Measured memory_bytes: 1600