akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

long long cnt = 0; //for counting num of invensions

void merge(int *a, int left, int mid, int right) {

    int nL = mid - left;
    int nR = right - mid;

    int L[nL], R[nR];

    for(int i=0; i<nL; i++) {
        L[i] = a[left + i];
    }
    for(int i=0; i<nR; i++) {
        R[i] = a[mid + i];
    }
    

    int indexL = 0, indexR = 0;
    int k = left;
    while(k<right) {

        if( indexL>=nL ) { //in case that L[] has no element
            a[k] = R[indexR]; //this is not inversion
            indexR++;
        } else if( indexR>=nR ) { //in case that R[] has no element
            a[k] = L[indexL]; //this is not inversion
            indexL++;
        } else if( L[indexL] <= R[indexR] ) {
            a[k] = L[indexL]; //this is not inversion
            indexL++;
        } else if( L[indexL] > R[indexR] ) { //actually, this condition is not needed
            a[k] = R[indexR]; //this is inversion
            indexR++;
            cnt += nL - indexL; //num of inversion = num of elements remaining in L[]
        }
        
        k++;
    }

//    //display info. about this step
//    cout << "-----\n";
//    cout << "merge(" << left << ", " << mid << ", " << right <<")" << endl;
//
//    cout << "L" << " = "; for(int i=0; i<nL; i++) {cout << L[i] << " ";} cout << endl;
//    cout << "R" << " = "; for(int i=0; i<nR; i++) {cout << R[i] << " ";} cout << endl;
//    
//    cout << "cnt = " << cnt << endl;

    return;
}


void mergeSort(int *a, int left, int right) {

    if(left+1  <  right) {
        int mid = (left + right) / 2;

        mergeSort(a, left, mid);
        mergeSort(a, mid, right);

        merge(a, left, mid, right);

    }

    return;
}


int main(void) {
    int N;
    cin >> N;

    int a[N];
    for(int i=0; i<N; i++) {
        cin >> a[i];
    }

//    //display a[] before sorting
//    cout << "a[] = ";
//    for(int i=0; i<N; i++) {
//        cout << a[i] << " ";
//    }
//    cout << endl;

    //merge sort a[]
    mergeSort(a, 0, N);

//    //display a[] after sorting
//    cout << "a[] = ";
//    for(int i=0; i<N; i++) {
//        cout << a[i] << " ";
//    }
//    cout << endl;
    

//    cout << "Num of inversions = ";
    cout << cnt << endl;
    
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


#define double long double
const double EPS=1e-8;

int N,L;

signed main(){
    cin>>N>>L;

    deque<pair<double,double>>deq;
    double T=0.0,V=0.0;
    rep(i,N){
        int t,v;
        cin>>t>>v;

        while(V>L-v){
            double tmp=min(V-L+v,deq.front().se);
            T*=V;
            T-=deq.front().fi*tmp;
            V-=tmp;
            T/=V;
            deq.front().se-=tmp;
            if(deq.front().se<EPS)deq.pop_front();
        }

        deq.push_back({t,v});
        T*=V;
        T+=v*t;
        V+=v;
        T/=V;

        while(deq.size()>=2&&deq[deq.size()-2].fi>=deq[deq.size()-1].fi){
            auto p=deq.back();
            deq.pop_back();
            auto q=deq.back();
            deq.pop_back();
            deq.push_back(pair<double,double>((p.fi*p.se+q.fi*q.se)/(p.se+q.se),p.se+q.se));
        }


        printf("%.20Lf\n",T);
    }
    return 0;
}


Measured memory_bytes: 31796
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

cc = [0] + c
sm = b[0]
for i in range(1, n):
    sm += b[i]
    if a[i]==(a[i-1]+1):
        sm += cc[a[i]-1]
print(sm)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define lli unsigned long long int
#include<bits/stdc++.h>
int main(){
  lli a,b,k;
  cin>>a>>b>>k;
  if(k>=a+b){
    cout<<"0"<<" "<<"0";
  }
  else{
    if(k<=a){
      a=a-k;
    }
    else{
      b=b-(k-a);
      a=0;
    }
    cout<<a<<" "<<b;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
ll D = 1000000007;

ll factor(ll n){
  if(n==1) return 1;
  else return (n*factor(n-1))%D;
}

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

  int t[N];

  for(int i=0;i<N;i++){
    cin >> t[i];
  }

  ll ans = 0;
  for(int i=1;i<N;i++){
    ans += min(T, t[i]-t[i-1]);
  }
  
  ans += T;

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

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

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

using namespace std;

int main(){
	int n, c, d[31][31], map[502][502], ans;

	cin >> n >> c;
	vector<int> z(c), o(c), t(c);

	REP(j,c){
		REP(k,c) cin >> d[j][k];
	}
	REP(j,n){
		REP(k,n){ 
			cin >> map[j][k];
			map[j][k]--;
		}
	}

	REP(j,n){
		REP(k,n){
			REP(i,c){
				if ((j+k)%3==0) z[i] += d[map[j][k]][i];
				else if ((j+k)%3==1) o[i] += d[map[j][k]][i];
				else t[i] += d[map[j][k]][i];
			}
		}
	}

//	cout << "po" << endl;

	ans = z[0] + o[1] + t[2];
	REP(j,c){
		REP(k,c){
			REP(l,c){
				if ((j-l)*(k-l)*(j-k)!=0){
					// printf("z[%d]+o[%d]+t[%d]=%d\n", j, k, l,z[j]+o[k]+t[l]);
					ans = min(ans, z[j]+o[k]+t[l]);
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}





Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws InterruptedException {
        Scanner scanner = new Scanner(System.in);
        String in = scanner.nextLine();
        String[] all = new String[] {
                "dreamer",
                "eraser",
                "dream",
                "erase"
        };

        int prev = 0;
        int next = 0;
        for (int i = 0; i < in.length(); ) {
            boolean found = false;
            for (int j = next; j < all.length; j++) {
                String target = all[j];
                int index = in.indexOf(target, i);
                if (index == i) {
                    i += target.length();
                    found = true;
                    prev = j;
                    next = 0;
                    break;
                }
            }
            if (!found) {
                if (next == 3) {
                    System.out.println("NO");
                    return;
                } else if (prev != -1) {
                    i -= all[prev].length();
                    if (prev == 3) {
                        System.out.println("NO");
                        return;
                    }
                    next = prev + 1;
                } else {
                    System.out.println("NO");
                    return;
                }
            }
        }

        System.out.println("YES");
    }
}


Measured memory_bytes: 13764
import itertools
H,W,K=map(int,input().split())
c=[list(input()) for i in range(H)]
s=[[0 for j in range(W)] for i in range(H)]
ans=0
for X in itertools.product(range(2),repeat=H):
    for Y in itertools.product(range(2),repeat=W):
        for i in range(H):
            for j in range(W):
                if c[i][j]=="#":
                    s[i][j]=1
                else:
                    s[i][j]=0
        for i in range(H):
            for j in range(W):
                if X[i]==1 or Y[j]==1:
                    s[i][j]=0
        tmp=0
        for i in range(H):
            for j in range(W):
                if s[i][j]==1:
                    tmp+=1
        if tmp==K:
            ans+=1
print(ans)



Measured memory_bytes: 68716
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=998244353
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m,k=map(int,input().split())

# MOD combination
def cmb(n, r, mod=998244353):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**5*2+100
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans=m*pow(m-1,n-1,mod)
ans%=mod
# print(ans)
for i in range(k):
    tmp=cmb(n-1,i+1)*m*pow(m-1,n-(i+2),mod)
    # print(cmb(n-1,i+1),m,pow(m-1,n-(i+1),mod))
    # print(tmp)
    tmp%=mod
    ans+=tmp
    ans%=mod
    # print(ans,tmp)
print(ans)

Measured memory_bytes: 113508
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int c[] = {0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1};
	int cc[] = {0, 1, 2, 3, 4, 5, 4, 3, 2, 1};
string s;
int n;
int dp[10001000][2];
int solve(int ind, int carry)
{
	if(ind == 0)
	{
		int cur = s[0] - '0';
		cur += carry;
		// if(cur == 10)
		// 	return 0;
		// return min(c[cur], 1 + c[10 - cur]);
		return min(cur, 1 + (10-cur));
	}
	if(dp[ind][carry] != -1)
		return dp[ind][carry];
	int ans = 0;
	int cur = s[ind] - '0';
	cur += carry;
	ans = min(solve(ind-1, 0) + 1 + (10 - cur), min(solve(ind-1, 0) + cur, solve(ind-1, 1) + (10-cur)));
	return dp[ind][carry] = ans;
}


int32_t main() 
{
	
	memset(dp, -1, sizeof dp);
	cin >> s;
	n = s.length();	

	
	// if(s.length() == 1)
	// {
	// 	cout << c[s[0]-'0'] << endl;
	// 	return 0;
	// }
	// int ans = 0;
	// for(int i=0; i<s.length(); i++)
	// {
	// 	ans += cc[s[i]-'0'];
	// }
	// cout << ans << endl;
	
	cout << solve(n-1, 0) << endl;
	return 0;
}

Measured memory_bytes: 220164
import java.util.*;
import java.util.Collections;
import java.util.ArrayList;

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

        int N = sc.nextInt();
        int ans = 0;
        ArrayList<Integer> list = new ArrayList<Integer>();

        for(int i=0; i<N; i++){
            list.add(sc.nextInt());
        }

        Collections.sort(list);

        if(list.get(N/2)!=list.get(N/2-1)){
            for(int i=list.get(N/2-1)+1; i<=list.get(N/2); i++){
                ans += 1;
            }
            System.out.println(ans);
        }
        else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 57668
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) ( ((a) + ((b) - 1) ) / b)

typedef long long int lli;

int main(void) {
	int N;
	scanf("%d", &N);
	int t = 0;
	int x = 0;
	int y = 0;
	for (int i = 0; i < N; i++) {
		int it, ix, iy;
		scanf("%d%d%d", &it, &ix, &iy);
		int dx = abs(x - ix), dy = abs(y - iy);

		if ((it - t)%2 != (dx+dy)%2 || dx + dy > it - t) {
			printf("No\n");
			return 0;
		}
		t = it; x = ix; y = iy;
	}

	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	int n; std::cin >> n;
	std::vector<std::vector<int>> nodes(200000);
	for (auto i = 0; i < n; ++i) {
		int x, y; std::cin >> x >> y; --x; --y;
		nodes[x * 2].push_back(y * 2 + 1);
		nodes[y * 2 + 1].push_back(x * 2);
	}
	std::stack<int> stack;
	std::vector<bool> is_visit(200000, false);
	long long int result = -n;
	for (auto i = 0; i < nodes.size(); ++i) if (!is_visit[i]) {
		long long int odd = 0, even = 0;
		stack.push(i);
		is_visit[i] = true;
		while (!stack.empty()) {
			const auto top = stack.top(); stack.pop();
			if (top % 2 == 1) ++odd;
			else ++even;
			for (const auto next : nodes[top]) if (!is_visit[next]) {
				is_visit[next] = true;
				stack.push(next);
			}
		}
		result += odd * even;
	}
	std::cout << result << std::endl;
}


Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

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

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll>div = divisor(m);
    ll ans = 0;
    for(int i = 0 ; i < div.size() ; i++){
        if(n <= m / div[i])ans = div[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// =====================================================
//   File    :   main.cpp
//   Author  :   eezyl
//   Synopsis:   codeforces/atcoder template
//   Address :
//   Date    :   2020/08/28
// =====================================================
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<vi> vvi;

#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) { return b ? "true" : "false"; }
str ts(vector<bool> v) { str res; F0R(i,sz(v)) res += char('0'+v[i]); return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res; F0R(i,SZ) res += char('0'+b[i]); return res; }

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))

const ll MOD = 1e9+7; // 998244353;
const int MX = 1e6+1;

int tree[1];

int sum(int k) {
    int a = 0;
    while (k >= 1) {
        a += tree[k];
        k -= k&-k;
    }
    return a;
}

void add(int k, int x) {
    while (k <= MX) {
        tree[k] += x;
        k += k&-k;
    }
}

void solve() {
    int D, T, S;
    cin >> D >> T >> S;
    if (T*S >= D)
        cout << "Yes\n";
    else
        cout << "No\n";
}


int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define LOCAL
#ifdef LOCAL
freopen("data.in", "r", stdin);
while (!feof(stdin)) {
#endif // LOCAL

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

#ifdef LOCAL
}
printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);
#endif // LOCAL
    return 0;
}


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

using namespace std;

int main()
{
	int n, total=0;
	int b[100];

	cin >> n;

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

	if (n == 2) {
		total = b[0] * 2;
	}
	else {
		total += b[n - 2];
		for (int i = n - 3; 0 <= i; i--) {
			if (b[i] <= b[i+1]) {
				total += b[i];
			}
			else if (b[i] > b[i + 1]) {
				total += b[i + 1];
			}
		}
		total += b[0];
	}
	
	cout << total << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string a,b;
    cin>>a>>b;
    int ans=-1; // 0=a , 1=draw , 2=b
    if(a.length()>b.length())
        ans=0;
    else if(a.length()<b.length())
        ans=2;
    else{
        ans=1;
        for(int i=0;i<a.length();i++){
            if(b[i]>a[i]){
                ans=2;
                break;
            }
            else if(a[i]>b[i]){
                ans=0;
                break;
            }
        }
    }
    if(ans==0){
        cout<<"GREATER"<<endl;
    }
    else if(ans==1){
        cout<<"EQUAL"<<endl;
    }
    else{
        cout<<"LESS"<<endl;
    }
    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#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(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int N; cin >> N&&N;) {
		string s; cin >> s;
		vector<int> a(N, 0);
		int f = 0;
		rep(i, 0, s.size()) {
			if (s[i] == 'M') {
				a[i % N]++;
			}
			else if (s[i] == 'S') {
				a[i % N]++;
				f += a[i % N];
				a[i % N] = 0;
			}
			else {
				a[i % N]++;
				a[i % N] += f;
				f = 0;
			}
		}
		sort(all(a));
		rep(i, 0, N)cout << a[i] << " ";
		cout << f << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)

int N, M;
int P[100000], Y[100000];
vector<int> yd[100001];

int main(){

    cin >> N >> M;
    rep(i, M) cin >> P[i] >> Y[i], yd[P[i]].push_back(Y[i]);
    rep(i, N) sort(yd[i+1].begin(), yd[i+1].end());
    rep(i, M) cout << setfill('0') << right << setw(12) << ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin()) + 1 << endl;
    return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll n, m, z = 0;
    cin >> n >> m;
    for (ll i = m; i <= n + 1; i++) {
        //[0,i-1]~[n-i+1,n]
        z = (z + (n + n - i + 1) * i / 2 - (0 + i - 1) * i / 2 + 1) % mod;
    }
    cout << z;
}


Measured memory_bytes: 3640
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]

    def roll(self, c):
        if c in ['N', 'S']:
            if c == 'N':
                self.y.append(self.y.pop(0))
            elif c == 'S':
                self.y.insert(0, self.y.pop())
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
        else:
            if c == 'E':
                self.x.insert(0, self.x.pop())
            elif c == 'W':
                self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]

    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]


p = [ int(n) for n in input().split()]
s = input()

dice = Dice(p)

for c in s:
    dice.roll(c)
print(dice.num(1))



Measured memory_bytes: 5612
//2013/11/25(Mon)

#include <iostream>
using namespace std;

int main()
{
	int m,n;

	bool ham[1000001];
    for(int i=0; i<=1000000; i++)
        ham[i] = false;
 
    for(int i=1; i<=1000000; i*=2)
        for(int j=i; j<=1000000; j*=3)
            for(int k=j; k<=1000000; k*=5)
                ham[k] = true;
 
    while(true){
		  int cnt = 0;

			cin >> m;
        if(m==0)
            break;
			cin >> n;
 
        for(int i=m; i<=n; i++)
            if(ham[i] == true)
                cnt++;
 
        cout << cnt << endl;
    }
 
    return 0;
}

Measured memory_bytes: 2136
#include<iostream>

using namespace std;

long long layer[51];

void fill_layer(long long n){
    layer[0] = 1;
    for(int i=1;i<=n;i++){
        layer[i] = layer[i-1]*2 + 3;
    }
}

long long solve(long long n, long long x){
    if(n==0){
        return 1;
    }
    else if(x==1)return 0;
    else if(x<=1+layer[n-1]){
        return solve(n-1, x-1);
    }
    else if(x==2+layer[n-1]){
        return 1+solve(n-1, layer[n-1]);
    }
    else if(x<=2+2*layer[n-1]){
        return 1+solve(n-1, layer[n-1])+solve(n-1, x-2-layer[n-1]);
    }
    else{
        return 1+solve(n-1, layer[n-1])*2;
    }
}

int main(){
    long long n, x;
    cin >> n >> x;
    fill_layer(n);
    cout << solve(n, x) << endl;
}

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

using namespace std;

struct comp {
  double re, im;

  comp(double x = 0, double y = 0) : re(x), im(y) {}

  comp operator+(const comp& a) { return comp(re + a.re, im + a.im); }
  comp operator-(const comp& a) { return comp(re - a.re, im - a.im); }
  comp operator*(const comp& a) { return comp(re * a.re - im * a.im, re * a.im + im * a.re); }
};

const double pi = acos(-1);

void fft(vector<comp>& x) {
  int n = x.size();
  for (int i = 1, k = 0; i < n; ++i) {
    for (int bit = n >> 1; (k ^= bit) < bit; bit >>= 1) {}
    if (i < k) {
      swap(x[i], x[k]);
    }
  }
  for (int k = 1; k < n; k <<= 1) {
    comp wlen(cos(pi / k), sin(pi / k));
    for (int i = 0; i < n; i += (k << 1)) {
      comp w(1);
      for (int j = 0; j < k; ++j) {
        comp tmp = w * x[i + j + k];
        x[i + j + k] = x[i + j] - tmp;
        x[i + j] = x[i + j] + tmp;
        w = w * wlen;
      }
    }
  }
}

template<class T> vector<T> mul(vector<T>& a, vector<T>& b) {
  int n = max(a.size(), b.size());
  int lg = 31 - __builtin_clz(n);
  n = 1 << (lg + 1 + (n != (1 << lg)));
  vector<comp> fa(n), fb(n);
  for (int i = 0; i < a.size(); ++i) {
    fa[i] = a[i];
  } for (int i = 0; i < b.size(); ++i) {
    fb[i] = b[i];
  }
  fft(fa);
  if (a == b) {
    fb = fa;
  } else {
    fft(fb);
  }
  for (int i = 0; i < n; ++i) {
    fa[i] = fa[i] * fb[i];
  }
  fft(fa);
  reverse(fa.begin() + 1, fa.end());
  vector<T> c(n);
  for (int i = 0; i < n; ++i) {
    c[i] = (T)(fa[i].re / n + (fa[i].re > 0 ? 0.5 : -0.5));
  }
  return c;
}

const int P = 2e5 + 3;
int p[P];
int ord[P];

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

  p[0] = 1;
  for (int i = 1; i < P; ++i) p[i] = p[i - 1] * 2 % P;
  for (int i = 0; i < P - 1; ++i) ord[p[i]] = i;
  //for (int i = 1; i < 10; ++i) cout << ord[i] << endl;
  vector<long long> cnt(P);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i]) ++cnt[ord[a[i]]];
  }
  cnt = mul(cnt, cnt);
  long long ans = 0;
  for (int i = 0; i < P - 1; ++i) ans += 1ll * p[i] * (cnt[i] + cnt[i + P - 1]);
  for (int i = 0; i < n; ++i) {
    ans -= 1ll * a[i] * a[i] % P;
  }
  cout << ans / 2;

  return 0;
}


Measured memory_bytes: 28912
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	long A[N + 1];
	long B[N];



	for (int i = 0; i < N + 1; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	long counter = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 2; j++) {
			if (B[i] >= A[j + i]) {
				B[i] -= A[j + i];
				counter += A[j + i];
				A[j + i] = 0;
			}
			else {
				counter += B[i];
				A[j + i] -= B[i];
				B[i] = 0;
			}
		}
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 1792
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    int n, m;
    cin >> n >> m;
    bool data[n][n];
    rep(i, n)
    {
        rep(j, n)
        {
            data[i][j] = false;
        }
    }
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        data[a][b] = true;
        data[b][a] = true;
    }

    int ans = 0;
    rep(i, n)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (data[i][j])
            {
                data[i][j] = false;
                data[j][i] = false;
                bool seen[n];
                fill(seen, seen + n, false);
                queue<int> q;
                q.push(0);
                while (q.size())
                {
                    int tmp = q.front();
                    q.pop();
                    seen[tmp] = true;
                    rep(k, n)
                    {
                        if (data[tmp][k] == true && seen[k] == false)
                        {
                            q.push(k);
                        }
                    }
                }
                data[i][j] = true;
                data[j][i] = true;
                bool is_good = true;
                rep(k, n)
                {
                    if (!seen[k])
                    {
                        is_good = false;
                        break;
                    }
                }
                if (!is_good)
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>

#include <cstdio>
#include <cstring>
#include <cmath>

#define taskname "a"

using namespace std;

long long q, h, s, d, n;

int main() {
  cin >> q >> h >> s >> d >> n;

  h = min(h, 2 * q);
  s = min(s, 2 * h);
  d = min(d, 2 * s);

  cout << (n / 2) * d + (n % 2) * s;

  return 0;
}


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

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

    if(N == 'A') cout << 'T' << endl;
    else if(N == 'T') cout << 'A' << endl;
    else if(N == 'C') cout << 'G' << endl;
    else if(N == 'G') cout << 'C' << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[12]{1,6,36,216,1296,1296*6,1296*36,9,81,729,729*9,729*81};cin>>n;int dp[100010];
	for(int i=0;i<100010;i++) dp[i]=i;
	sort(a,a+10);
	for(int i=0;i<100010;i++){
		for(int j=0;j<12;j++){
			if(i>=a[j]) dp[i]=min(dp[i],dp[i-a[j]]+1);
		}
	}
	cout<<dp[n]<<endl;
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}
 
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 400010;
const int B = 200001;

vi g[maxn];
bool ex[maxn], vis[maxn];
int cnt[2];

void dfs(int v, int d) {
	cnt[d]++;
	vis[v] = true;

	for (int to : g[v]) {
		if (!vis[to]) {
			dfs(to, d ^ 1);
		}
	}
}

int main() {
	int N; cin >> N;
	vector<pii> vec(N);

	rep(i, N) {
		int a, b; cin >> a >> b;
		vec[i] = mp(a, b);
		g[a].pb(b + B);
		g[b + B].pb(a);
		ex[a] = ex[b + B] = true;
	}

	ll ans = 0;
	for (int i = 0; i < maxn; ++i) {
		if (ex[i] && !vis[i]) {
			cnt[0] = cnt[1] = 0;
			dfs(i, 0);
			ans += (ll)cnt[0] * cnt[1];
		}
	}

	cout << ans - N << endl;

	return 0;
}

Measured memory_bytes: 15872
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
            int n = Integer.parseInt(reader.readLine());
            int i = 0;
            int[][] a = new int[12][10];
            for(int j = 0; j<12;j++){
                for(int k = 0; k<10;k++){
                    a[j][k] = 0;
                }
            } 
            while(i < n){
                String line = reader.readLine();
                String[] str = line.split(" ");
                int b = Integer.parseInt(str[0]);
                int f = Integer.parseInt(str[1]);
                int r = Integer.parseInt(str[2]);
                int v = Integer.parseInt(str[3]);

                a[(b - 1) * 3 + f -1][r - 1] += v;
                i++;
            }

            for(int j = 0; j<12; j++){
                for(int k = 0; k< 10; k++){
                    System.out.print(" " + a[j][k]);
                }
                System.out.println();
                if(j%3 == 2 && j != 11){
                    for(int l = 0; l < 20;l++){
                        System.out.print("#");
                    }
                    System.out.println();
                }
            }
        }catch(IOException e){
        
        }
    }
}


Measured memory_bytes: 24780
N,D=map(int,input().split())
X=[]
for _ in range(N):
    X.append(list(map(int,input().split())))

arr=[]
for i in range(N):
    for j in range(N):
        if i < j:
            dist_l=[]
            for d in range(D):
                dist_l.append((X[i][d]-X[j][d])**2)
            arr.append(sum(dist_l)**(1/2))

print(sum(list(map(lambda x: x%1==0,arr))))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int pos[222222],n,len,num,cur,j;
char s[222222],ans[222222],ch;
bool used[28];
int main()
{
	scanf("%s",s);
	n=strlen(s);
	pos[0]=n;
	len=1;
	for (int i=n-1;i>=0;i--)
	{
		if (!used[s[i]-'a'])
		{
			used[s[i]-'a']=1;
			num++;
		}
		if (num==26) 
		{
			pos[len]=i;
			len++;
			memset(used,0,sizeof(used));
			num=0;
		}		
	}
	memset(used,0,sizeof(used));
	for (int i=0;i<pos[len-1];i++)
	{
		used[s[i]-'a']=1;
	}
	for (int i=0;i<26;i++)
	{
		if (!used[i])
		{
			ans[0]=i+'a';
			cur=1;
			break;
		}
	}
	ch=ans[0];
	for (int i=len-1;i>=1;i--)
	{
		for (j=pos[i];j<pos[i-1];j++)
		{
			if (s[j]==ch) break;
		}
		memset(used,0,sizeof(used));
		j++;
		for (;j<pos[i-1];j++)
		{
			used[s[j]-'a']=1;
		}
		for (int k=0;k<26;k++)
		{
			if (!used[k])
			{
				ans[cur++]=k+'a';
				ch=k+'a';
				break;
			}
		}
	}
	ans[cur]='\0';
	printf("%s\n",ans);
	return 0;
}

Measured memory_bytes: 512
(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
 
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
 
src.append(last_row)
 
 
for rc in range(r + 1):
    print(' '.join([str(a) for a in src[rc]]))

Measured memory_bytes: 7760
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    long long N;
    string S;
    cin >> N >> S;

    // long long N_rb;
    // long long N_aw;

    // N_aw = 0;
    // for(long long i = 0; i < N; i++){
    //     if(S[i] == '#'){
    //         N_aw += 1;
    //     }
    // }


    // N_rb = 0;
    // bool first_b = false;
    // for(long long i = 0; i < N; i++){
    //     if(S[i] == '#'){
    //         first_b = true;
    //     }
    //     if(S[i] == '.' && first_b){
    //         N_rb += 1;
    //     }
    // }    
    
    vector<long long> N_w(N+1);
    N_w[0] = 0;

    for(long long i = 0; i < N ;i++){
        if(S[i] == '.'){
            N_w[i+1] = N_w[i] + 1;
        }else{
            N_w[i+1] = N_w[i];
        }
    }

    // for(int i = 0; i < N+1; i ++){
    //     cout << N_w[i] << endl;
    // }

    vector<long long> ans_sep(N+1);

    for(long long i = 0; i < N + 1; i++){
        ans_sep[i] = (i - N_w[i]) + (N_w[N] - N_w[i]);
    }

    cout << *min_element(ans_sep.begin(), ans_sep.end()) << endl;

    return 0;
}


Measured memory_bytes: 3732
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    
    int number = N%(2*D+1);
    if(number==0){
        System.out.println(N/(2*D+1));
    } else{
        System.out.println(N/(2*D+1)+1);
    }

  }
}

Measured memory_bytes: 22868
#include <stdio.h>

int main(void){
  int i,n,a[100];
  scanf("%d",&n);
  
  for(i=0;i<n;i++) 
    scanf("%d",&a[i]);

  for(i=1;i<=n;i++){
    printf("%d",a[n-i]);
    if(i==n)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main() {
    long A,B,C,r;

    scanf("%ld %ld %ld",&A,&B,&C);

    if(A+B>=C-1) {
        r=B+C;
    }
    else {
        r=A+B+1+B;
    }

    printf("%ld\n",r);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

const int MOD = 1000000007;

using namespace std;



int main(){

    int m,d,month=1,day,count=0;
    cin >> m >> d;

    while(month<m+1){
        day=0;
        while(day<d){
            day++;
            if(day/10<2 || day%10<2)continue;
            if((day/10)*(day%10)==month){
                count++;
            }
        }
        month++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(int A,int B)
{
    for(int i=1;i<=1000;i++)
    {
        if((i*8)/100==A &&i/10==B)
        {
            cout<<i<<endl;
            return;
        }
    }
    cout<<"-1"<<endl;
}
int main()
{
    int a,b;
    cin>>a>>b;
    solve(a,b);
    return 0;
}

Measured memory_bytes: 256
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

const MOD: usize = 998244353;

fn main() {
   input! {
      n:usize,s:usize,
      mut a:[usize;n]
   }
   let mut dp = vec![vec![0; s + 1]; n + 1];
   dp[0][0] = 1;
   for i in 0..n {
      for j in 0..=s {
         dp[i + 1][j] += 2 * dp[i][j];
         dp[i + 1][j] %= MOD;
         if a[i] + j > s {
            continue;
         }
         dp[i + 1][a[i] + j] += dp[i][j];
         dp[i + 1][a[i] + j] %= MOD;
      }
   }
   println!("{}", dp[n][s]);
}


Measured memory_bytes: 72488
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            if (a > b)
                out.println(a - 1);
            else
                out.println(a);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 21460
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(); //Nドル
        boolean[] f = new boolean[N+1];
        f[0] = true;
        for (int i = 0; i < N; i++)
            if (f[i] && i + 4 <= N)
                f[i + 4] = true;
        for (int i = 0; i < N; i++)
            if (f[i] && i + 7 <= N)
                f[i + 7] = true;
        if(f[N])
            System.out.println("Yes");
        else
            System.out.println("No");
        sc.close();
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector <int>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

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

    int n; cin >> n;
    int q[n][2];
    REP(i, n) {
        cin >> q[i][0] >> q[i][1];
    }


    vi nums;
    REP(i, 8) {
        nums.push_back(i);
    }

    do {
        bool flag = true;
        REP(i, n) {
            if (nums[q[i][0]] != q[i][1]) flag = false;
        }
        if (!flag) continue;
        REP(i, 7) {
            if (!flag) break;
            FOR(j, i+1, 8) {
                if (abs(i - j) == abs(nums[i] - nums[j])) {
                    flag = false;
                    break;
                }
            }
        }
        if (flag) {
            REP(i, 8) {
                REP(j, 8) {
                    if (j == nums[i]) {
                        cout << 'Q';
                    } else {
                        cout << '.';
                    }
                }
                cout << "\n";
            }
            break;
        }
    } while (next_permutation(nums.begin(), nums.end()));
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    vector<ll> dp(n + 1), cnt(2019);
    vector<ll> t(n + 1);
    t[0] = 1;
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1] = dp[i] * 10;
        dp[i + 1] += s[i] - '0';
        dp[i + 1] %= 2019;
        t[i + 1] = t[i] * 10 % 2019;
    }
    for (int i = 0; i < n + 1; i++) {
        dp[i] *= t[n - i];
        dp[i] %= 2019;
        cnt[dp[i]]++;
    }
    ll ans = 0;
    for (int i = 0; i < 2019; i++) {
        if (cnt[i]) debug(i, cnt[i]);
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    debug(cnt[0]);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 6720
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define PER(i,n,a) for(ll i=n;i>a;i--)
#define REP1(i,a,n) for(ll i=a;i<=n;i++)
#define forit(it,x) for(auto it=(x).begin();it!=(x).end();++it)
#define ull unsigned long long int
#define ld long double
#define prec(n) fixed<<setprecision(n)
#define test ll t; cin>>t; while(t--)
#define re return 0
#define pb push_back
#define PI 3.1415926535897932384626
#define MOD (ll)1000000007
#define fi first
#define se second
#define eb emplace_back
#define vll vector<ll>
#define vi  vector<int>
#define mpll map<ll,ll>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
const ll MAXI = (ll)1e9+7;
int countFreq(string &pat, string &txt) 
{ 
    int M = pat.length(); 
    int N = txt.length(); 
    int res = 0; 
    
    /* A loop to slide pat[] one by one */
    for (int i = 0; i <= N - M; i++) 
    {  
        /* For current index i, check for  
           pattern match */
        int j; 
        for (j = 0; j < M; j++) 
            if (txt[i+j] != pat[j]) 
                break; 
   
        // if pat[0...M-1] = txt[i, i+1, ...i+M-1] 
        if (j == M)   
        { 
           res++; 
           j = 0; 
        } 
    } 
    return res; 
} 
int main(){
    IOS;
//    test{
        int n;
        cin>>n;
        string txt,pat;
        cin>>txt;
        pat="ABC";
        cout<<countFreq(pat,txt)<<"\n";
//    }
re;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll m=1;
    bool a=false;
  	bool b=false;
    for(ll i=0; i<N; i++){
        cin >> A.at(i);
        if(A.at(i)==0) a=true;
    }
    for(ll i=0; i<N; i++){
        ll c = 1000000000000000000/m+1;
        if(A.at(i)>=c){
          b=true;
          break;
        }
        m = m*A.at(i);
      	if(m>1000000000000000000) break;
    }
    if(a){
        cout << 0 << endl;
    }else if(b || m > 1000000000000000000){
        cout << -1 << endl;
    }else{
        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N;
    string S;
    cin >> N >> S;
    map<char, vint> cnt;
    cnt['R'].resize(N + 1);
    cnt['G'].resize(N + 1);
    cnt['B'].resize(N + 1);
    for (int i = 0; i < N; i++)
    {
        for (auto c : {'R', 'G', 'B'})
        {
            if (S[i] == c)
            {
                /*  if (i > 0)
                    cnt[c][i] = cnt[c][i - 1] + 1;
                else
                    cnt[c][i] = 1;*/
                cnt[c][i + 1] = cnt[c][i] + 1;
            }
            else
            {
                /*  if (i > 0)
                    cnt[c][i] = cnt[c][i - 1];
                else
                {
                    cnt[c][i] = 0;
                }*/
                cnt[c][i + 1] = cnt[c][i];
            }
        }

        /*        int r=0,g=0,b=0;
        if(S[i]=='R')
        r=1;
        if(S[i]=='G')
        g=1;
        if(S[i]=='B')
        b=1;
        if(i>0)
        {
        cntR[i]=cntR[i-1]+r;
        cntG[i]=cntG[i-1]+g;
        cntB[i]=cntB[i-1]+b;
        }
        else
        {
            cntR[i]=r;
            cntG[i]=g;
            cntB[i]=b;
        }
        */
    }
    ll ans = 0;
    for (int i = 0; i < N - 1; i++)
    {
        for (int j = i + 1; j < N - 1; j++)
        {
            if (S[i] == S[j])
                continue;

            set<char> s = {'R', 'G', 'B'};
            s.erase(S[i]);
            s.erase(S[j]);

            char res = *s.begin();
            int minus = 0, k = 2 * j - i;
            if (k < N and S[k] == res)
                minus = 1;
            ans += max(0, cnt[res].back() - cnt[res][j] - minus);
        }
    }
    cout << ans;
    return 0;
}

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

int gcd(int a, int b) {
	if (a < b) 
		return gcd(b, a);
	else if (b != 0)
		return gcd(b, a % b);
	else
		return a;
}

int main (void) {
	cin.tie(0);
	cin.sync_with_stdio(false);
	int a, b, k;
	cin >> a >> b >> k;
	int aa = gcd(a, b), times = 0, num;
	for (int i = aa; i >= 1; i --) {
		if (aa % i == 0) 
			times ++;
		if (times == k) {
			num = i;
			break;
		}
	}
	cout << num << '\n';
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll calc_size(int level) {
	return (1LL << (2 + level)) - 3LL;
}

ll calc_patty(int level) {
	return (1LL << (1 + level)) - 1LL;
}

ll solve(int level, ll x) {
	if (level == 0 && x == 1) return 1LL;
	--x;
	if (x == 0) return 0LL;
	ll sz = calc_size(level - 1);
	if (x <= sz) 
		return solve(level - 1, x);
	ll res = calc_patty(level - 1);
	x -= sz;
	if (x == 0) return res;
	res++; --x;
	if (x == 0) return res;
	res += solve(level - 1, min(sz, x));
	return res;
}

int main() {
	int N; ll X;
	cin >> N >> X;
	cout << solve(N, X) << endl;
	return 0;
}

Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]
A, B, C = inpl()
A, B, C = max(A, B, C), A+B+C -max(A, B, C) -min(A, B, C), min(A, B, C)
if (B-C)%2 == 0:
    print((2*A -B -C)//2)
else:
    print((2*A -B -C +3)//2)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
  while (1) {
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i < j && j < k && i + j + k == x) {
            ans++;
          }
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}


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

double Re(double a)
{ return 1/a;}

int main()
{
  int n,i;
  double sum=0,*a;

  scanf("%d",&n );
  a = calloc(n,sizeof(double));

  for(i=0; i<n; i++)
  {
    scanf("%lf",&a[i]);
    sum += Re(a[i]);
  }

  printf("%lf", Re(sum));

  free(a);
  return 0;
}


Measured memory_bytes: 1728