akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc, out);

		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out) {
		String s = sc.next();
		
		for(int i = 0; i < s.length(); i+=2) {
			out.print(s.charAt(i));
		}
	}
	
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22228
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int n_4 = 0;
	int n_2 = 0;
	int n_1 = 0;

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

		if (a % 4 == 0) {
			n_4++;
		} else if (a % 2 == 0) {
			n_2++;
		} else {
			n_1++;
		}
	}

	if (n_2 > 0) {
		n_1++;
	}

	bool ok = n_4 + 1 >= n_1;
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<pair<long long,long long>> B;
	for(int i=0;i<N;i++){
		int x,y;
		cin >> x >> y;
		B.push_back(make_pair(x,y));
	}
	sort(B.begin(),B.end());
	map<pair<long long,long long>,int> m;
	vector<pair<long long,long long>> exist;
	
	for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){
		long long dx=B[j].first-B[i].first;
		long long dy=B[j].second-B[i].second;
		if(dx==0 && dy==0)continue;
		if(m[make_pair(dx,dy)]==0)exist.push_back(make_pair(dx,dy));
		m[make_pair(dx,dy)]++;
	}
	
	int ma=0;
	for(auto p:exist){
		ma=max(ma,m.at(p));
	}
	cout << N-ma << endl;
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> compress(vector<T> v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	return v;
}

template<typename T>
int index(const vector<T> &v, T i) { return lower_bound(v.begin(), v.end(), i) - v.begin(); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int n; cin >> n&&n;) {
		vector<string> v(n);
		vector<char> c;
		rep(i, 0, n) {
			cin >> v[i];
			reverse(all(v[i]));
			rep(j, 0, v[i].size()) {
				if (v[i][j] >= '0'&&v[i][j] <= '9')continue;
				c.push_back(v[i][j]);
			}
			c.insert(c.end(), v[i].begin(), v[i].end());
		}
		vector<char> zip = compress(c);
		dump(zip);

		int mp[128];
		memset(mp, -1, sizeof(mp));
		rep(i, 0, 10)
			mp[i + '0'] = i;

		bool head[128];
		memset(head, 0, sizeof(head));
		rep(i, 0, n) {
			if (v[i].size() > 1) {
				head[v[i].back()] = true;
			}
		}

		char used[10];
		memset(used, 0, sizeof(used));
		function<int(int, int)> dfs = [&](int idx, int num) {
			int add = 0;
			rep(i, 0, 10) {
				int digit = add;
				add = 0;
				bool flag = false;
				rep(j, 0, n - 1) {
					if (v[j].size() <= i)continue;
					if (mp[v[j][i]] == -1) {
						flag = true;
						break;
					}
					digit += mp[v[j][i]];
				}
				if (flag)
					break;
				add += digit / 10;
				digit %= 10;
				if (v[n - 1].size() > i) {
					if (mp[v[n - 1][i]] == -1)
						break;
					if (digit != mp[v[n - 1][i]])
						return 0;
				}
				else {
					if (digit > 0 || add > 0)
						return 0;
					else
						break;
				}
			}
			if (zip.size() > idx + 1) {
				int ret = 0;
				rep(i, 0, 10) {
					if (used[i])continue;
					if (i == 0 && head[zip[idx + 1]])continue;
					used[i] = zip[idx + 1];
					mp[zip[idx + 1]] = i;
					ret += dfs(idx + 1, i);
					mp[zip[idx + 1]] = -1;
					used[i] = 0;
				}
				return ret;
			}
			else {
				return 1;
			}
		};
		int ans = 0;
		rep(i, 0, 10) {
			if (used[i])continue;
			if (i == 0 && head[zip[0]])continue;
			used[i] = zip[0];
			mp[zip[0]] = i;
			ans += dfs(0, i);
			mp[zip[0]] = -1;
			used[i] = 0;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int X, t;
    cin >> X >> t;
    cout <<  max(0,X-t) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF 2000000
int n;
int p[100];
int m[100][100];

int main(){
    int i;
    int t;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d %d", &p[i], &t);
    }
    p[n]=t;
    MatrixChainOrder();
    printf("%d\n", m[1][n]);
    return 0;
}
void MatrixChainOrder(){
    int i;
    int l;
    int a;
    int b;
    int c;
    for(i=1; i<=n; i++) m[i][i]=0;
    for(l=2; l<=n; l++){
        for(i=1; i<=n-l+1; i++){
            a=i+l-1;
            m[i][a]=INF;
            for(b=i; b<=a-1; b++){
            c=m[i][b]+m[b+1][a]+p[i-1]*p[b]*p[a];
            if(m[i][a]>c) m[i][a]=c;
            }
        }
    }
}

Measured memory_bytes: 636
def main():
    q, h, s, d = map(int, input().split())
    n = int(input())
    x = min(4*q, 2*h, s)
    y = min(2*x, d)
    ans = n//2*y
    if n%2 == 1:
        ans += x
    print(ans)

if __name__ == "__main__":
    main()

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

long long f(long long x){
  if(x == -1) return 0;

  long long a = (x + 1)/ 2;
    
  return (x & 0b1 ? 0 : x) ^ (a % 2 == 1);
}

int main(){
  long long a, b;

  cin >> a >> b;

  cout << (f(b) ^ f(a-1)) << endl;
}


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

using namespace std;

int main(){
long long n=0,ans=0,mx=0,x=0;
cin>>n;
cin>>x;
n--;
mx=x;
while(n--){
cin>>x;
if(x<mx){ans+=mx-x;x=mx;}
mx=max(mx,x);
}
cout<<ans;

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

vector<ll> divisor(ll n) {
  vector<ll> res;
  for(ll i=1;i*i<=n;i++) {
    if(n%i==0) {
      res.push_back(i);
      if(i!=n/i) {
        res.push_back(n/i);
      }
    }
  }
  return res;
}

int main() {
  ll n,k;
  cin >> n >> k;
  vec a(n);
  ll sum=0;
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    sum+=a[i];
  }
  sort(a.rbegin(),a.rend());
  vec div=divisor(sum);
  ll ans=1;
  for(ll i:div) {
    if(i==1) continue;
    ll tmp=0;
    ll cnt=0;
    vec aa(n);
    for(ll j=0;j<n;j++) {
      aa[j]=a[j]%i;
      tmp+=aa[j];
    }
    sort(aa.rbegin(),aa.rend());
    for(ll j=0;j<n;j++) {
      tmp-=i;
      cnt+=(i-aa[j]);
      if(tmp<=0) break;
    }
    if(cnt<=k) {
      ans=max(ans,i);
    }
  }
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int n, m; cin >> n >> m;
    if (n == 0) return;
    pqdesc<pair<int, int>> q;
    rep(i, n) {
      int d, p; cin >> d >> p;
      q.emplace(p, d);
    }
    i64 ans = 0;
    while (!q.empty()) {
      int p, d;
      tie(p, d) = q.top(), q.pop();
      if (m >= d) m -= d;
      else {
        d -= m;
        ans += (i64) d * p;
        m = 0;
      }
    }
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3140
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=1e5+10;
LL A[L];
int main() {
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	sort(A,A+N);
	LL ret=0;
	if(N%2){
		LL s=0;
		for(int i=0;i<N;i++){
			if(i==N/2||i==N/2-1){
				s-=A[i];
			}
			else if(i<N/2){
				s-=2*A[i];
			}
			else{
				s+=2*A[i];
			}
		}
		ret=s;
		s=0;
		for(int i=0;i<N;i++){
			if(i==N/2||i==N/2+1){
				s+=A[i];
			}
			else if(i<N/2){
				s-=2*A[i];
			}
			else{
				s+=2*A[i];
			}
		}
		ret=max(ret,s);
	}
	else{
		LL s=0;
		for(int i=0;i<N;i++){
			if(i==(N-1)/2){
				cerr << "a" << endl;
				s-=A[i];
			}
			else if(i==(N-1)/2+1){
				cerr << "b" << endl;
				s+=A[i];
			}
			else if(i<(N-1)/2){
				cerr << "c" << endl;
				s-=2*A[i];
			}
			else{
				cerr << "d" << endl;
				s+=2*A[i];
			}
			cerr << s << endl;
		}
		ret=s;
	}
	cout << ret << endl;

	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,cnt = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q;
    cin >> q;
    vector<int> b(q);
    for(int i = 0; i < q; i++){
        cin >> b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
     for(int i = 0; i < q; i++){
         for(int j = 0; j < n; j++){
             if(b[i] == a[j] && a[j] != a[j + 1]){
                 cnt++;
             }
         }
     }  
    cout << cnt << endl;
}


Measured memory_bytes: 3196
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[] a = new String[h];
        for(int i = 0; i<h;i++){
            a[i] = sc.next();
        }

        boolean[] row = new boolean[h];
        Arrays.fill(row,false);
        boolean[] col = new boolean[w];
        Arrays.fill(row,false);

        for(int i =0;i<h;i++){
            for(int j =0;j<w;j++){
                if(a[i].charAt(j)=='#'){
                    row[i] = true;
                    col[j] = true;
                }
            }
        }

        for(int i =0;i<h;i++){
            if(row[i]){
                for(int j = 0;j<w;j++){
                    if(col[j]){
                        System.out.print(a[i].charAt(j));
                    }
                }
                System.out.println();
            }
        }

    }
}


Measured memory_bytes: 25020
// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
	do {\
		std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
		debug_impl(__VA_ARGS__);\
		std::cerr << std::noboolalpha;\
	} while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
	{ for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
	for (auto it = v.begin(); it != v.end(); it++)
		{os << (it != v.begin() ? "," : "") << *it;}
	return os << "}";
}

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::vector<int> a(n); std::cin>>a;

	int k = 0, l = 0;
	for (int x : a) {
		if (x % 4 == 0) {
			k++;
		} else if (x % 2 == 0) {
			l++;
		}
	}
	bool ans = 2 * k + std::max(l,1) >= n;
	std::cout << (ans ? "Yes" : "No") << std::endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

struct Node {
    int key;
    struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

void insert(int k){
    struct Node *y = NIL;
    struct Node *x = root;
    struct Node *z;

    z = (struct Node *)malloc(sizeof(struct Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x!= NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        } else{
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL){
        root = z;
    } else{
        if( z->key < y->key){
            y->left = z;
        } else{
            y->right = z;
        }
    }

}

void inorder(struct Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(struct Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, i, x;
    char com[10];
    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s", com);
        if(com[0] == 'i'){
            scanf("%d", &x);
            insert(x);
        } else if(com[0] == 'p'){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 25168
#include <stdio.h>

int ReadValue() {
    int n; 
    scanf("%d",&n);
    return n;
}
void ReadArray(int A[],int N) {
    int i; 
    for (i=0; i<N; i++) {
        scanf("%d",&A[i]);
    } 
}
void Display(int A[],int N) {
    int i;
    for (i=0; i<N; i++) {
        if (i>0) {
            printf(" ");
        }
        printf("%d",A[i]);
    }
    printf("\n"); 
}
void InsertionSort(int A[],int N) {
    int i;
    for (i=0; i<N; i++) {
        int v=A[i];
        int j=i-1;
        while (i>=0&&A[j]>v) {
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        Display(A,N);
    }
}
int main() {
    int N=ReadValue();
    int A[N]; ReadArray(A,N);
    InsertionSort(A,N);
    return 0;
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

char maze[25][25];

int BFS(int a,int b)
{
	int dis[25][25]={},g=-1;
	queue<pair<int, int>>Q;
	pair<int,int>f=make_pair(a,b);
	int dx[4]={ 0, 1,  0, -1},dy[4]={ 1, 0, -1,  0};
	dis[a][b]=1;		
	Q.push(make_pair(f.first,f.second));//始点をqueueにぶっこむ
	while(!Q.empty())//queueが空になるまで
	{
		f=make_pair(Q.front().first,Q.front().second);//queueの先頭を参照
		Q.pop();//queueの先頭を削除
		for(int i=0;i<4;i++)//参照した頂点の周りを探索
		{
			if(!dis[f.first+dx[i]][f.second+dy[i]]&&maze[f.first+dx[i]][f.second+dy[i]]!='#')
			{
				dis[f.first+dx[i]][f.second+dy[i]]=dis[f.first][f.second]+1;//周りの数字を変えていく
				Q.push(make_pair(f.first+dx[i],f.second+dy[i]));//queueにぶっこむ
				g=max(g,dis[f.first+dx[i]][f.second+dy[i]]);
			}
		}
	}
	return g-1;
}


int main()	
{
	int n,m,ans=-1;
	cin>>n>>m;
	for(int i=0;i<=n+1;i++)
	{
		for(int j=0;j<=m+1;j++)
		{
			if(i==0||j==0||i==n+1||j==m+1)maze[i][j]='#';
			else cin>>maze[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(maze[i][j]!='#')ans=max(ans,BFS(i,j));
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

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

using namespace std;
using lint=long long;

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

	vector<lint> sum(n+1);
	rep(i,n){
		int a; scanf("%d",&a);
		sum[i+1]=sum[i]+a;
	}

	map<lint,int> f;
	rep(i,n+1) ++f[sum[i]];

	lint ans=0;
	rep(i,n){
		ans+=--f[sum[i]];
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define endl '\n';
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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 (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
    A[i]--;
  }
  int ans = 0;
  for(int i=0; i<N; i++){
    if(A[A[i]] == i) ans++;
  }
  cout << ans/2 << endl;
  return 0;
}

Measured memory_bytes: 640
n = int(input())
def is_p(k):
  for i in range(2,int(k**0.5)+1):
    if k%i == 0:
      return False
  return True
p = []
for i in range(2,n+1):
  if is_p(i):
    p.append(i)
l = len(p)
q =[0]*l
for i in range(2,n+1):
  for j in range(l):
    if i == 1:
      break
    while i%p[j] == 0:
      q[j] += 1
      i /= p[j]
c = 0
for qi in q:
  if qi >= 74:
    c += 1
o2 = 0
o4 = 0
o14 = 0
o24 = 0
for qi in q:
  if qi >= 24:
    o24 += 1
  elif qi >= 14:
    o14 += 1
  elif qi >= 4:
    o4 += 1
  elif qi >= 2:
    o2 += 1
c += o24*(o2+o4+o14+o24-1)
c += (o14+o24)*(o4+o14+o24-1)
c += (o2+o4+o14+o24-2)*(o4+o14+o24)*(o4+o14+o24-1)//2  
print(c)

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

using namespace std;

struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;

  Bipartite_Matching(int n)
  {
    timestamp = 0;
    graph.resize(n);
    alive.assign(n, 1);
    used.assign(n, 0);
    match.assign(n, -1);
  }

  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  bool dfs(int v)
  {
    used[v] = timestamp;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(alive[u] == 0) continue;
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }

  int bipartite_matching()
  {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return (ret);
  }
};

void solve()
{
  int X, Y, E;
  cin >> X >> Y >> E;
  Bipartite_Matching graph(X + Y);
  for(int i = 0; i < E; i++) {
    int a, b;
    cin >> a >> b;
    graph.add_edge(a, b + X);
  }
  cout << graph.bipartite_matching() << endl;
}

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

Measured memory_bytes: 3280
import sys
import math,bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,OrderedDict
def I(): return int(sys.stdin.readline())
def neo(): return map(int, sys.stdin.readline().split())
def Neo(): return list(map(int, sys.stdin.readline().split()))
mod = 10**9+7
fact = [1]+[0]*(10**4)
for i in range(1,10**4):
    fact[i] = (i*fact[i-1])%mod
N = I()
if N < 3:
    print(0)
    exit()
r = 1
Ans = 0
while N-r*3 >= 0:
    n = N-3*r
    Ans += (fact[n+r-1]*pow(fact[n],mod-2,mod)*pow(fact[r-1],mod-2,mod))%mod
    Ans = Ans%mod
    r += 1
print(Ans%mod)


Measured memory_bytes: 9820
import java.math.*;
import java.util.*;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			String s = sc.next();
			int n = s.length();
			String sa = s.substring(0, (n-1)/2);
			String sb = s.substring((n+1)/2);
			
			if(isPalindrome(s)) {
				if(isPalindrome(sa)) {
					if(isPalindrome(sb)) {
						System.out.println("Yes");
					}else {
						System.out.println("No");
					}
					
					
				}
				else {
					System.out.println("No");
				}
			}else {
				System.out.println("No");
			}
			
			
			
			
			
		}
		
		static boolean isPalindrome (String s) {
			int n = s.length();
			for (int i=0; i<n/2; i++) {
				if (s.charAt(i)!=s.charAt(n-i-1)) {return false;}
			}
			return true;
		}

	}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
const int mod=1000000007;
int main(){
    ll n,m;
    cin>>n>>m;
    ll ans=0;
    if(m<=2*n) ans=m/2;
    else{
        ans+=n;
        m=max(m-2*n,0ll);
        ans+=m/4;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
ll INF = 1000000000000 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

void Dijkstra(vector<vector<pll>> &g,vll &cnt,ll n,queue<ll> &q){
	for(int i=0;i<g.at(n).size();i++){
		if(cnt.at(g.at(n).at(i).first)>cnt.at(n)+g.at(n).at(i).second){
			q.push(g.at(n).at(i).first) ;
			cnt.at(g.at(n).at(i).first) = cnt.at(n)+g.at(n).at(i).second ;
		}
	}
	if(q.empty()) return ;
	ll sub = q.front() ;
	q.pop() ;
	Dijkstra(g,cnt,sub,q) ;
}

int main(){
	ll v,e,r ;
	cin >> v >> e >> r ;
	queue<ll> q ;
	vector<vector<pll>> g(v,vector<pll>(0)) ;
	for(int i=0;i<e;i++){
		ll s,t,d ;
		cin >> s >> t >> d ;
		g.at(s).push_back(make_pair(t,d)) ;
	}
	vll cnt(v,INF) ;
	cnt.at(r) = 0 ;
	Dijkstra(g,cnt,r,q) ;
	for(int i=0;i<v;i++){
		if(cnt.at(i)==INF) cout << "INF" << endl ;
		else cout << cnt.at(i) << endl ;
	}
}



Measured memory_bytes: 18156
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct{
	char s[32];
	char p[1001];
} Dic;

int compare_Dic(const void *a, const void *b)
{
    return (int)strcmp(((Dic*)a)->s, ((Dic*)b)->s);
}


int main(int argc, char *argv[]){
	int i,j,n;
	char b[32], t[10000];
	Dic d[100],*p;
	memset(d, 0, sizeof(d));
	for(i=0;i<100;i++){
		scanf("%s ",b);
		scanf("%d ",&n);
		for(p=d;*p->s && strcmp(p->s, b);p++);
		strcpy(p->s,b);
		p->p[n]=1;
	}
	qsort(&d, 100, sizeof(Dic), compare_Dic);
	for(p=d;p<=&d[99];p++){
		if(!p->s[0]) continue;
		printf("%s\n", p->s);
		for(t[0]=0,i=1;i<1001;i++) if(p->p[i]) sprintf(&t[strlen(t)], "%d ", i);
		t[strlen(t)-1]=0;
		printf("%s\n", t);
	}
    return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	int n;
	cin >> n;
	vector<int>v(n);
	rep(i, n) {
		cin >> v[i];
	}
	double ans = 0;


	sort(All(v));
	reverse(All(v));
	ans += v.back();
	v.pop_back();
	ans += v.back();
	v.pop_back();
	ans /= 2;
	while (!v.empty()) {
		ans += v.back();
		v.pop_back();
		ans /= 2;
	}

	c(ans);
	ed;
	return 0;
}


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

int main(){
int A, B;
cin >> A >> B;
if (A - 1 > B) {
    cout << A + A - 1 << endl;
} else if (B - 1 > A) {
    cout << B + B - 1 << endl;
} else {
    cout << A + B << endl;
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    int p;
    cin>>p;
    int k;
    if(p%1000) k=p/1000+1;
    else k=p/1000;
    cout<<k*1000-p<<endl;
    return 0;
}


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

int main(){
  int n;
  while(std::cin >> n, n){
    int length[n];
    string s;
    for (int i = 0; i < n; i++) {
      std::cin >> s;
      length[i] = s.length();
    }
    vector<int> correct = {5, 7, 5, 7, 7};
    for (int i = 0; i < n; i++) {
      int tmp = 0, pos = 0;
      for (int j = i; j < n; j++) {
        tmp += length[j];
        if(tmp == correct[pos])pos++, tmp = 0;
        if(pos == correct.size()){
          std::cout << i + 1 << std::endl;
          i = j = 1e9;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3144
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;
using llong = long long;
const int MOD=1000000007;


int main(int argc, char**argv){
    int a, b, k;
    cin >> a >> b >> k;
    int counter = 0;
    for (int i = max(a, b); i >= 1; i--){
        if (a%i == 0 && b%i == 0){
           counter++;
        }
        if (counter == k){
            cout << i << endl;
            break;
        }
    }

    return 0;
}













Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,T b){if(b<a){a=b;return 1;} return 0;}

int dx[4] = {0,0,-1,1};
int dy[4] = {1,-1,0,0};
string rlud = "RLUD";


// run : ctrl + c 
signed main(){

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

    int n;
    cin>>n;
    if(n<=2){
        cout << 0 << endl;
        return 0;
    }
    int p[n+3]={};
    for(int i=2;i*i<=n+2;i++){
        if(p[i]) continue;
        for(int j=i+i;j<=n+2;j+=i){
            p[j] = 1;
        }
    }
    int ans = 0;
    for(int i=3;i<=n;i++){
        if(p[i]==0 && p[i+2]==0)ans++;
    }
    cout << ans*2 << endl;
    
    
}


Measured memory_bytes: 42288
n = int(input())
s = input()

r, g, b = 0, 0, 0
for si in s:
    if si == "R":
        r += 1
    elif si == "G":
        g += 1
    else:
        b += 1
        
ans = r * g * b

d = 0
for i in range(n-2):
    for j in range(i, n-1):
        k = j + j - i
        if k < n and s[i] != s[j] and s[k] not in (s[i], s[j]):
            d += 1
        
print(ans - d)

Measured memory_bytes: 68176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define sf scanf
#define pf printf
#define pb push_back
#define F first
#define S second

int main()
{
    BOOST

    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        long double a,b;
        cin>>a>>b;
        cout<<(long long)(a*b)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int dp[100001];
struct Node
{
    int data;
    Node* next;
}*ver2[100001];
int Longestpath(int vertex)
{int res;
    if(dp[vertex]!=-1)
        res=dp[vertex];
    else if(ver2[vertex]==NULL)
        res=0;
    else
    {
        int max=0;
        Node* p=ver2[vertex];
        while(p!=NULL)
        {
            if(max<Longestpath(p->data))
            {
                max=Longestpath(p->data);
            }
            p=p->next;
        }
        res=1+max;
    }
    dp[vertex]=res;
    return res;
}

void push(int data,int pos)
{
    Node* p=ver2[pos];
    if(p!=NULL)
    while(p->next!=NULL)
            p=p->next;
    Node* t=new Node;
    t->data=data;
    t->next=NULL;

    if(p==NULL)
        {
            p=t;
            ver2[pos]=p;
        }
    else
        p->next=t;

}
int main()
{   int n,m;
    cin>>n>>m;
    int i,j,k,l;
    for(i=0;i<=n;i++)
        {
            ver2[i]=NULL;
        }
    for(i=0;i<m;i++)
    {
        cin>>k>>l;
        push(k,l);
    }
    for(i=0;i<=n;i++)
        dp[i]=-1;
    int max=0;
    for(i=1;i<=n;i++)
    {   Longestpath(i);
        if(max<dp[i])
        max=dp[i];
    }
    cout<<max;
    return 0;
}


Measured memory_bytes: 7552
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := 7
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	k := aa[1]
	fmt.Fprintln(writer, k+max(calc(aa[0], aa[3], aa[4]), calc(aa[0]-1, aa[3]-1, aa[4]-1)+3))

}
func calc(i, j, l int) int {
	if i < 0 || j < 0 || l < 0 {
		return -3
	}
	return (i>>1 + j>>1 + l>>1) << 1
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	return -min(-a, -b)
}


Measured memory_bytes: 1824
n,l=map(int, input().split())
a=list(map(int, input().split()))
ans=-1
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        ans=i+1
        break
if ans==-1:print('Impossible')
else:
    print('Possible')
    for i in range(1,ans):print(i)
    for i in range(n-1,i,-1):print(i)

Measured memory_bytes: 14060
from collections import defaultdict, deque
N, X, Y = map(int, input().split())
G = defaultdict(list)
for i in range(1, N):
    G[i].append(i+1)
    G[i+1].append(i)
#print(G)

G[X].append(Y)
G[Y].append(X)

#print(G)

d = [0] * N

for i in range(1, N+1):
    q = deque()
    q.append(i)
    visit = [-1]*N
    visit[i-1] = 0
    while q:
        p = q.popleft()
        for next_p in G[p]:
            if visit[next_p-1] == -1:
                visit[next_p-1] = visit[p-1] + 1
                q.append(next_p)

    for l in range(N):
        d[visit[l]] += 1

for k in range(1, N):
    print(d[k]//2)


Measured memory_bytes: 48220
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)

int main(){
    int N;
    lint L;
    cin >> N >> L;
    vector<pair<lint, int>> koma(N);
    rep(i, N){
        cin >> koma[i].first >> koma[i].second;
    }
    sort(all(koma));
    lint L_sum[N + 2], R_sum[N + 2]; // 左埋め、右埋め
    L_sum[0] = R_sum[N + 1] = 0;
    rep(i, N){
        if(koma[i].second == 0){ // 左向き
            L_sum[i + 1] = L_sum[i] - (i + 1 - koma[i].first);
        }else{ // 右向き
            L_sum[i + 1] = L_sum[i] + (i + 1 - koma[i].first);
        }
    }
    repr(i, N){
        if(koma[i].second == 0){ // 左向き
            R_sum[i + 1] = R_sum[i + 2] - (L - N + i + 1 - koma[i].first);
        }else{ // 右向き
            R_sum[i + 1] = R_sum[i + 2] + (L - N + i + 1 - koma[i].first);
        }
    }
    lint ans = 0;
    rep(i, N + 1){
        ans = max(ans, L_sum[i] + R_sum[i + 1]);
    }
    /*rep(i, N + 1){
        cout << L_sum[i] << " " << R_sum[i + 1] << endl;
    }*/
    cout << ans << endl;
}





Measured memory_bytes: 5988
// file creato da gio il 2020-03-31 21:23:51.245102

#include <bits/stdc++.h>
#define FAST 

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

pair<int,char> arr[300000];

int main(){
	//freopen("output","w",stdout);
	//freopen("input","r",stdin);
#ifdef FAST
	ios::sync_with_stdio(0);
  	cin.tie(0);
#endif

	int X,Y,A,B,C;
	cin >>X>>Y>>A>>B>>C;
	for(int i=0;i<A;i++){
		cin >>arr[i].F;
		arr[i].S=0;
	}
	for(int i=0;i<B;i++){
		cin >>arr[A+i].F;
		arr[A+i].S=1;	
	}
	for(int i=0;i<C;i++){
		cin >>arr[A+B+i].F;
		arr[A+B+i].S=2;
	}

	sort(arr,arr+A+B+C);
	int a=0,b=0,c=0;
	long long sum=0;
	for(int i=A+B+C-1;(a+b+c)<(X+Y)&&i>=0;i--){
		if(arr[i].S==0&&a<X){
			a++;
			sum+=arr[i].F;
		}else if(arr[i].S==1&&b<Y){
			b++;
			sum+=arr[i].F;
		}else if(arr[i].S==2){
			c++;
			sum+=arr[i].F;
		}
	}
	cout <<sum;
}

Measured memory_bytes: 2560
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

// ------------------ ベクター合計 ------------------ //

int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}


int main(void) {

	int N, K, Q; cin >> N >> K >> Q;
	vector<int> cnt(N, 0);
	rep(i, Q) {
		int x;
		cin >> x;
		cnt[x - 1]++;
	}

	rep(i, N) {
		if (K - (Q - cnt[i]) > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[100005],sum[100005];
int main(){
	cin>>n;
	for(int i=0;i<=n;++i){
		cin>>a[i];
		sum[i]=a[i];
	}
	for(int i=n-1;i>=0;--i){
		sum[i]+=sum[i+1];
	}
	ll val=1,ans=0;
	for(int i=0;i<=n;++i){
		if(val<a[i]){
			cout<<"-1\n";
			return 0;
		}
		ans+=val;
		val-=a[i];
		val*=2;
		val=min(val,sum[i+1]);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 5184
#include<iostream>
#include<string.h>
#include<algorithm>
#define P 1000000007
using namespace std;
int main(){
	int n,i,j;
	cin>>n;
	char domino[2][n];
	long long int dp[n];
	for(i=0;i<2;i++){
		for(j=0;j<n;j++){
			cin>>domino[i][j];
		}
	}
	
	for(j=0;j<n;j++){
		if(domino[0][j]==domino[1][j]){
			if(j==0){
				dp[0]=3;
			}
			else{
				if(domino[0][j-1]==domino[1][j-1]){
				dp[j]=(dp[j-1]*2)%P;
				}
				else{
				dp[j]=dp[j-1];
				}
			}
		}
		else{
			if(j==0){
				dp[1]=6;
				j++;
			}
			else{
				if(domino[0][j-1]==domino[1][j-1]){
					dp[j+1]=(dp[j-1]*2)%P;
				}
				else{
					dp[j+1]=(dp[j-1]*3)%P;
				}
				j++;
			}
		}
	}

cout<<dp[n-1];
}
			
			

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

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int k = 0, s = 0;
    cin >> k >> s;

    int ans = 0;
    for(int i = 0; i <= k; i++) {
        for(int j = 0; j <= k; j++) {
            if(i + j <= s && (s - (i + j) <= k)) ans++; 
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3632
import math
n = int(input())
lr = [None]*100000
rmax = 0
for i in range(n):
    lr[i]= list(map(int,input().split()))
    if lr[i][1] > rmax:
        rmax = lr[i][1]

p = [1]*(rmax+1)
p[0]=0
p[1]=0
        

for j in range(2,int(math.sqrt(rmax)+1)):
    if p[j] == 0:
        continue
    for i in range(2,rmax+1):
        if i!=j and i%j == 0:
            p[i] = 0
for i in range(rmax, 1,-2):
    if p[int((i+1)/2)] == 0:
        p[i] = 0
p[2] = 0
for i in range(2,rmax):
    p[i+1] += p[i]  

for i in range(n):
    print(p[lr[i][1]] - p[lr[i][0]-1])
    

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define rep(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    int A, B;
    cin >> A >> B;

    if (A == 1) A = 14;
    if (B == 1) B = 14;
    string ans = "Draw";
    if (A > B) {
        ans = "Alice";
    } else if (B > A) {
        ans = "Bob";
    }

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

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

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

const int MAXN = 200 * 1000 + 10;
int ind[MAXN], dp[MAXN];

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
	{
		int p;
		cin >> p;
		p --;
		ind[p] = i;
	}

	dp[n - 1] = 1;
	int ans = 1;
	for (int i = n - 1; i --; )
	{
		dp[i] = (ind[i] < ind[i + 1]) * dp[i + 1] + 1;
		smax(ans, dp[i]);
	}

	cout << n - ans << endl;
	

	return 0;
}






Measured memory_bytes: 3328
N = int(input())
S = input()

rgb2num = {"R":0, "G":1, "B":2}
num2rgb = {0:"R", 1:"G", 2:"B"}

RGB = [[0, 0, 0] for _ in range(N)]
S = S[::-1]
for i, s in enumerate(S):
    for j in range(3):
        RGB[i][j] = RGB[i - 1][j]
    RGB[i][rgb2num[s]] += 1
RGB = RGB[::-1]
S = S[::-1]
#print(RGB)
#print(S)

answer = 0
for m in range(1, N - 1):
    for l in range(m - 1, -1, -1):
        #print(m, l)
        if S[m] != S[l]:
            #print(S[m], S[l], m + 1, (3 - rgb2num[S[m]] - rgb2num[S[l]]))
            answer += RGB[m + 1][(3 - rgb2num[S[m]] - rgb2num[S[l]])]
            if 2 * m - l < N and S[2 * m - l] == num2rgb[3 - rgb2num[S[m]] - rgb2num[S[l]]]:
                answer -= 1
print(answer)

Measured memory_bytes: 69280
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static char[] s;
    static long[] mCum;
    static long[] cCum;
    static long[] cum;
    static int n;
    static int q;
    static int[] k;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        s = sc.next().toCharArray();
        q = sc.nextInt();
        k = new int[q];
        for (int i = 0; i < q; i++) {
            k[i] = sc.nextInt();
        }
        mCum = new long[n + 1];
        for (int i = 0; i < n; i++) {
            mCum[i + 1] = mCum[i] + (s[i] == 'M' ? 1 : 0);
        }
        cCum = new long[n+1];
        for (int i = 0; i < n; i++) {
            cCum[i+1] = cCum[i] + (s[i] == 'C' ? 1 : 0);
        }
        cum = new long[n+1];
        for (int i = 0; i < n; i++) {
            cum[i+1] = cum[i] + (s[i] == 'C' ? mCum[i] : 0);
        }

        List<Integer> left = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (s[i] == 'D') {
                left.add(i);
            }
        }
        for (int j = 0; j < k.length; j++) {
            long ret = 0;
            for(Integer i : left) {
                int right = Math.min(i+k[j], n);
                ret += cum[right] - cum[i] - (cCum[right] - cCum[i]) * mCum[i];
            }
            System.out.println(ret);
        }

    }
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		int[] l = new int[N];
		
		for(int i = 0; i < N; i++) {
			l[i] = sc.nextInt();
		}
		
		Arrays.sort(l);
		
		int sum = 0;
		
		for(int i = N - 1; i >= N - K; i--) {
			sum += l[i];
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 23252
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ESumEqualsXor solver = new ESumEqualsXor();
        solver.solve(1, in, out);
        out.close();
    }

    static class ESumEqualsXor {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int n = s.length();
            ModInt[] safe = new ModInt[n];
            ModInt[] giri = new ModInt[n];

            safe[0] = new ModInt(1);
            giri[0] = new ModInt(2);

            for (int i = 1; i < n; i++) {
                if (s.charAt(i) == '0') {
                    safe[i] = safe[i - 1].mul(3);
                    giri[i] = giri[i - 1];
                } else {
                    safe[i] = safe[i - 1].mul(3).add(giri[i - 1]);
                    giri[i] = giri[i - 1].mul(2);
                }
            }

            out.println(safe[n - 1].add(giri[n - 1]).getVal());


        }

    }

    static class ModInt {
        int val;
        int MOD = (int) 1e9 + 7;

        public ModInt(long i) {
            this.val = (int) ((i + MOD) % MOD);
        }

        public ModInt mul(long l) {
            return new ModInt(this.val * l);
        }

        public ModInt add(ModInt m) {
            return new ModInt(this.val + m.getVal());
        }

        public int getVal() {
            return val;
        }

    }
}



Measured memory_bytes: 32276