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

int cnt[1000001] = {};

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        bool f = false;
        for(int j = 1; j*j <= a[i]; j++){
            if(a[i]%j)  continue;
            int x = j;
            if(cnt[x] > (x==a[i]))    f = true;
            x = a[i]/j;
            if(cnt[x] > (x==a[i]))    f = true;
        }
        if(!f)  ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8104
N=int(input())
A=list(map(int,input().split()))
a,b,c=0,0,0
ans=1
mod=10**9+7
for i in A:
    ans=ans*[a,b,c].count(i)%mod
    if i==a: a+=1
    elif i==b: b+=1
    elif i==c: c+=1
print(ans)

Measured memory_bytes: 14092
#include <iostream>
#include <string>
#include <stack>

using namespace std;
typedef long long ll;

const int MOD = 1000000007;
int powmod[1000001];

struct Result {
	int numVars, numPats;
};

enum {
	EXPR_FIRST,
	EXPR_SECOND,
	EXPR,
	TERM_FIRST,
	TERM_SECOND,
	TERM,
	FACTOR,
	FACTOR_NEG,
	FACTOR_BRACE,
	VAR
};

int main(){
	powmod[0] = 1;
	for(int i = 1; i <= 1000000; ++i){
		powmod[i] = (powmod[i - 1] << 1) % MOD;
	}
	string s;
	cin >> s;
	stack<Result> rstack;
	stack<int> sstack;
	sstack.push(EXPR_FIRST);
	int p = 0;
	while(!sstack.empty()){
		int type = sstack.top();
		sstack.pop();
		if(type == EXPR_FIRST){
			sstack.push(EXPR_SECOND);
			sstack.push(TERM_FIRST);
		}else if(type == EXPR_SECOND){
			if(s[p] == '|'){
				++p;
				sstack.push(EXPR);
				sstack.push(TERM_FIRST);
			}
		}else if(type == EXPR){
			Result q = rstack.top();
			rstack.pop();
			Result &r = rstack.top();
			int nr = powmod[r.numVars] - r.numPats;
			if(nr < 0){ nr += MOD; }
			int nq = powmod[q.numVars] - q.numPats;
			if(nq < 0){ nq += MOD; }
			ll pat0 = ((ll)r.numPats * q.numPats) % MOD;
			ll pat1 = ((ll)nr * q.numPats) % MOD;
			ll pat2 = ((ll)nq * r.numPats) % MOD;
			r.numPats = (pat0 + pat1 + pat2) % MOD;
			r.numVars += q.numVars;
			if(s[p] == '|'){
				++p;
				sstack.push(EXPR);
				sstack.push(TERM_FIRST);
			}
		}else if(type == TERM_FIRST){
			sstack.push(TERM_SECOND);
			sstack.push(FACTOR);
		}else if(type == TERM_SECOND){
			if(s[p] == '&'){
				++p;
				sstack.push(TERM);
				sstack.push(FACTOR);
			}
		}else if(type == TERM){
			Result q = rstack.top();
			rstack.pop();
			Result &r = rstack.top();
			r.numPats = ((ll)r.numPats * q.numPats) % MOD;
			r.numVars += q.numVars;
			if(s[p] == '&'){
				++p;
				sstack.push(TERM);
				sstack.push(FACTOR);
			}
		}else if(type == FACTOR){
			if(s[p] == '~'){
				++p;
				sstack.push(FACTOR_NEG);
				sstack.push(FACTOR);
			}else if(s[p] == '('){
				++p;
				sstack.push(FACTOR_BRACE);
				sstack.push(EXPR_FIRST);
			}else{
				sstack.push(VAR);
			}
		}else if(type == FACTOR_NEG){
			Result &r = rstack.top();
			r.numPats = powmod[r.numVars] - r.numPats;
			if(r.numPats < 0){ r.numPats += MOD; }
		}else if(type == FACTOR_BRACE){
			++p;
		}else if(type == VAR){
			++p;
			while(isdigit(s[p])){ ++p; }
			Result r;
			r.numVars = r.numPats = 1;
			rstack.push(r);
		}
	}
	cout << rstack.top().numPats << endl;
	return 0;
}

Measured memory_bytes: 9532
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
dd=defaultdict(lambda:0)
mina,maxa=0,10**5
for aa in a:
  mina=min(mina,aa)
  maxa=max(maxa,aa)
  dd[aa]+=1
maxsum=0
for i in range(mina, maxa-1):
  maxsum=max(maxsum, dd[i]+dd[i+1]+dd[i+2])
print(maxsum)

Measured memory_bytes: 23592
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout<<((a + b + c >= 22) ? "bust" : "win");
	
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

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

Measured memory_bytes: 256
def solve(writer):
    N, A, B, C = map(int, input().split())
    variables = {
        'A': A,
        'B': B,
        'C': C
    }

    queries = (list(input()) for _ in range(N))

    buffer = list()

    for i in range(N):

        if not buffer:
            t1, t2 = next(queries)
        else:
            b = buffer.pop()
            if b == 'pass':
                continue
            else:
                t1, t2 = list(b)

        v1 = variables[t1]
        v2 = variables[t2]

        if v1 == v2 == 0:
            return False

        elif v1 == v2 == 1:
            if i == N-1:
                writer.append(t1)
                return True

            nt1, nt2 = next(queries)
            if len({t1, t2, nt1, nt2}) == 2:
                buffer.append('pass')
                writer.append(t1)
                writer.append(t2)
                continue

            if t1 in {nt1, nt2}:
                variables[t1] += 1
                variables[t2] -= 1
                writer.append(t1)
            else:
                variables[t1] -= 1
                variables[t2] += 1
                writer.append(t2)

            buffer.append(''.join([nt1, nt2]))

        elif v1 > v2:
            variables[t1] -= 1
            variables[t2] += 1
            writer.append(t2)
        elif v2 > v1:
            variables[t1] += 1
            variables[t2] -= 1
            writer.append(t1)
        else:
            variables[t1] += 1
            variables[t2] -= 1
            writer.append(t1)

    return True


def main():
    writer = list()
    ok = solve(writer)
    if ok:
        print('Yes')
        for w in writer:
            print(w)
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9692
#include "bits/stdc++.h"
using namespace std;
int main()
{
		int n,x,y;
		cin>>n>>x>>y;
		vector<vector<int> >  g(n+1);

		g[x].push_back(y);
		g[y].push_back(x);

		for(int i=1;i<n;i++)
		{
			g[i].push_back(i+1);
			g[i+1].push_back(i);
		}

		vector<vector<int> > mat(n+1,vector<int>(n+1));

		function<void(int)> bfs=[&](int x)
		{
			vector<bool> vis(n+1);
			vis[x]=1;
			queue<pair<int,int> > q;

			q.push({x,0});

			while(!q.empty())
			{
				pair<int,int> t=q.front();

				q.pop();

				int nd=t.first;
				int dis=t.second;

				for(auto i:g[nd])
				{
					if(vis[i])
						continue;
					q.push({i,dis+1});
					mat[x][i]=dis+1;
					vis[i]=1;
				}

			}

		};


		for(int i=1;i<=n;i++)
		{
			bfs(i);
		}

		// for(int i=1;i<=n;i++)
		// {
		// 	for(int j=1;j<=n;j++)
		// 	{
		// 		cout<<mat[i][j]<<" ";
		// 	}
		// 	cout<<endl;
		// }


		map<int,int> mp;


	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{

			mp[mat[i][j]]++;
		}	
	}

	for(int i=1;i<n;i++)
	{
		cout<<mp[i]/2<<endl;
	}


	return 0;
}

Measured memory_bytes: 19528
#include <bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=0;



void solve(){
	int s,w;
	cin>>s>>w;
	if(w>=s)cout<<"unsafe";
	else cout<<"safe";
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 3612
import sys
def az14():
    while True:
        xs = raw_input().split()
        H,W = int(xs[0]),int(xs[1]) 
        if H==0 and W==0 : break
        for i in range(0,H):
            for j in range (0,W):
                if i%2 == 0:
                    if j%2 == 0:
                        sys.stdout.write("#"),
                    else:
                        sys.stdout.write("."),
                else :
                    if j%2 == 0:
                        sys.stdout.write("."),
                    else:
                        sys.stdout.write("#"),
            print
        print

az14()

Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;


struct Solver{
    int n, m;
    vector<double> prob_use;
    vector<double> prob_use_sum;
    vector<int> val;

    Solver(int n_, int m_, vector<int> val_) : 
        n(n_), m(m_), prob_use(m + 1, 0.0), prob_use_sum(m + 2, 0.0), val(val_) {
        prob_use[0] = 1.0;
        for(int i = 0; i < m; i++){
            vector<double> next(m + 1, 0.0);
            for(int j = 0; j <= i; j++){
                next[j] += prob_use[j] * 2.0 / 3.0;
                next[j + 1] += prob_use[j] * 1.0 / 3.0;
            }
            prob_use.swap(next);
        }
        for(int i = 0; i <= m; i++){
            prob_use_sum[i + 1] = prob_use_sum[i] + prob_use[i];
        }
    }

    map<int, double> memo;
    double calc(int x, int win_point, int lose_point){
        if(memo.count(x)) return memo[x];
        double& res = memo[x];
        res = 0.0;

        double dp[2][4] = {}; // win, lose
        dp[0][0] = 1.0;
        for(int i = 0; i < n; i++) {
            double next[2][4] = {};
            int e = (x + val[i] - 1) / val[i];
            if(e > m+1) e = m+1;
            // [0, e) -> win
            // [e, inf) -> lose
            double win = prob_use_sum[e];
            double lose = 1.0 - win;

            for(int j = 0; j <= 1; j++) {
                for(int k = 0; k <= 3; k++) {
                    // win
                    int nj = min(1, j + 1);
                    next[nj][k] += win * dp[j][k];

                    // lose
                    int nk = min(3, k + 1);
                    next[j][nk] += lose * dp[j][k];
                }
            }
            memcpy(dp, next, sizeof(dp));
        }
        double get_p = 0.0;
        double lost_p = 0.0;
        for(int i = 0; i <= 1; i++) {
            for(int j = 0; j <= 3; j++) {
                bool get = j <= 2;
                bool lost = i == 0;
                assert(dp[i][j] == 0 || !get || !lost);
                if(get) get_p += dp[i][j];
                if(lost) lost_p += dp[i][j];
            }
        }

        return res = get_p * win_point - lost_p * lose_point;
    }
};

int main(){
    int n, m;
    while(cin >> n >> m){
        n--;
        int vi, da, vo;
        cin >> vi >> da >> vo;

        vector<vector<int>> val(3, vector<int>(n));
        REP(i, n) REP(j, 3) cin >> val[j][i];

        vector<Solver> solvers;
        REP(i, 3){
            solvers.push_back(Solver(n, m, val[i]));
        }

        double ans = -1e16;
        for(int x = 0; x <= m; x++){
            for(int y = 0; x + y <= m; y++){
                int z = m - x - y;
                double pos = 0;
                pos += solvers[0].calc(x * vi, 5, 1);
                pos += solvers[1].calc(y * da, 3, 1);
                pos += solvers[2].calc(z * vo, 2, 1);
                ans = max(ans, pos);
            }
        }
        printf("%.12f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1704
package main

import "fmt"

func main() {
	var A, B, C, X, Y int
	fmt.Scan(&A, &B, &C, &X, &Y)
	x := X*A + Y*B
	m := Max(X, Y) * 2 * C
	min := Min(X, Y)
	w := (X-min)*A + (Y-min)*B + min*2*C
	fmt.Println(Min(Min(x, m), w))

}
func Max(a, b int) int {
	if b > a {
		return b
	}
	return a
}
func Min(a, b int) int {
	if b < a {
		return b
	}
	return a
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MOD 1000000007
#define MAXN 100000
/*
Two numbers a and b will fulfill a + b = a XOR b if every a AND b is 0.
a AND b is 0 means that there is no bit position where both bit a and bit b is 1.

Hence the problem is solvable with digit dp.
*/

LL p2[MAXN + 3], p3[MAXN + 3];

//how many pairs of a and b such that a + b <= s and a AND b is 0
LL f(string s) {
    int n = (int) s.length();

    LL result = 0;
    int cntOneInPrefix = 0;

    for (int i = 0; i < n; i++) {
        if (s[i] == '0')
            continue;
        else {
            result = (result + (p2[cntOneInPrefix] * p3[n - i - 1])%MOD)%MOD;
            cntOneInPrefix += 1;
        }
    }

    return result;
}

int main() {
    p2[0] = p3[0] = 1;
    for (int i = 1; i <= MAXN; i++) {
        p2[i] = (p2[i - 1] * 2)%MOD;
        p3[i] = (p3[i - 1] * 3)%MOD;
    }

    string s;
    cin >> s;

    LL answer = f(s);

    int cntOne = 0;
    for (int i = 0; i < (int) s.length(); i++) {
        cntOne += (s[i] == '1');
    }

    answer = (answer + p2[cntOne])%MOD;

    cout << answer << endl;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String str = "CODEFESTIVAL2016";
		int cnt = 0;
		for(int i=0; i<s.length(); i++){
			if(s.charAt(i)!=str.charAt(i)) cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 10192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {

        //[m , n]
        static int[,] minHaba = new int[0,0];
        //haba of (hon n1) ~ (hon n2)
        static int[,] honHabaSum = new int[0,0];


        public static void dp() {
            int n  =minHaba.GetLength(1);
            int m = minHaba.GetLength(0);
            for (int i = 0; i < n; i++) {
                minHaba[0, i] = honHabaSum[0,i];
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    //Console.Write(honHabaSum[i, j] + ",");
                } //Console.WriteLine("honHabaSum. fin");
            }
            //dan suu
            for (int i = 1; i < m; i++) {
                //ireru hon no kazu
                for (int j = 0; j < n; j++) {
                    if (j == 0) { minHaba[i, j] = honHabaSum[0, 0]; continue; }
                    int haba = int.MaxValue;
                    //saigedann ni nann kann ijou wo ireruka
                    for (int k = j; k > 0; k--) {
                        haba = Math.Min(haba, Math.Max(honHabaSum[k, j], minHaba[i - 1, k - 1]));
                        //Console.WriteLine(i+","+j+","+k+".  "+haba);
                    }
                    minHaba[i, j] = haba;

                }
            }//
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    //Console.Write(minHaba[i, j] + ",");
                } //Console.WriteLine("minHaba. fin");
            }
        }


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //if (line.Equals("0")) { break; }
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int m = ints[0], n = ints[1];
                if (m == 0) { break; }
                minHaba = new int[m, n];
                honHabaSum = new int[n, n];
                int[] honW = new int[n];
                for (int i = 0; i < n; i++) {
                    honW[i] = int.Parse(Console.ReadLine()); 
                }

                for (int i = 0; i < n; i++) {
                    for (int j = i; j < n; j++) {
                        if (i == j) { honHabaSum[i, j] = honW[i]; }
                        else {
                            honHabaSum[i, j] = honHabaSum[i,j-1]+honW[j];
                        }
                    }
                }
                //sum stored.

                dp();

                Console.WriteLine(minHaba[m-1,n-1]);
            }
        }

        
    }



    
}

Measured memory_bytes: 12228
from collections import Counter
N,M = (int(T) for T in input().split())
def FindParent(X):
    if Parent[X]==X:
        return X
    else:
        Parent[X] = FindParent(Parent[X])
        return Parent[X]

def IsSameParent(X,Y):
    return FindParent(X)==FindParent(Y)

def UniteParent(X,Y):
    X = FindParent(X)
    Y = FindParent(Y)
    if X==Y:
        return 0
    if Rank[X]<Rank[Y]:
        Parent[X] = Y
    else:
        Parent[Y] = X
        if Rank[X]==Rank[Y]:
            Rank[X] += 1
Parent = [I for I in range(N+1)]
Rank = [0]*(N+1)
for TM in range(0,M):
    A,B = (int(T) for T in input().split())
    UniteParent(A,B)
for TN in range(1,N+1):
    FindParent(TN)
print(Counter(Parent[1:]).most_common()[0][1])

Measured memory_bytes: 44664
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  int ans = inf;
  
  rep(i,n)if(i+k-1<n){
    if(0<=a[i]){ ans = min(ans,a[i+k-1]); continue; }
    if(a[i+k-1]<=0){ ans = min(ans,-a[i]); continue; }
    ans = min(ans,max(-a[i],a[i+k-1])+2*min(-a[i],a[i+k-1]));
  }

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

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
  if(N<=999) cout<<"ABC";
  else cout<<"ABD";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define M 1000000007
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define rep(i,s,e) for(int i=s;i<e;i++)
#define drep(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
int s;
void fun(ll* arr,ll &tot){
    for(int i=1;i<s;i++){
        arr[i]+=arr[i-1];
        if(arr[i]==0){
            tot+=1;
            arr[i]=-arr[i-1]/abs(arr[i-1]);
        }
        else if( arr[i]/abs(arr[i])== arr[i-1]/abs(arr[i-1])){
            tot+=abs(arr[i])+1;
            arr[i]=- arr[i]/abs(arr[i]);
        }
    }
}
ll n[N],p[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin>>s;
    for(int i=0;i<s;i++){
        cin>>p[i];
        n[i]=p[i];
    }
    ll nt=0,pt=0;
    if(p[0]==0){
        p[0]=1;
        n[0]=-1;
        nt=1,pt=1;
    }
    if(p[0]<0){
        pt= abs(p[0])+1;
        p[0]=1;
    }
    if(n[0]>0){
        nt=n[0]+1;
        n[0]=-1;
    }
    fun(p,pt);
    fun(n,nt);
    cout<<min(pt,nt)<<endl;
    /*


    ll tot =0;
    if(x==0&&y>0){
       tot=1;
       x=-1;
    }
    else if(x==0&&y<0){
        tot=1;
        x=1;
    }
    else{
        y+=x;
        if(y==0){
            tot+=1;
            x=-x/abs(x);
      }
      if(x>0&&y<0||x<0&&y>0){
           x=y;
       }
       else if(x/abs(x)==y/abs(y)){
           if(abs(y)<abs(x))
                tot+=abs(y)+1;
           
            x=-x/abs(x);
       }
    }
    for(int i=2;i<n;i++){
        cin>>y;
        y+=x;
        if(y==0){
            tot+=1;
            x=-x/abs(x);
            continue;
        }
        if(x>0&&y<0||x<0&&y>0){
           x=y;
        }
        else if(x/abs(x)==y/abs(y)){
            tot+=abs(y)+1;
            x=-x/abs(x);
        }
    }
    cout<<tot<<endl;
    */
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  if(a>b) swap(a,b);
  while(b--){
    ans += a;
    if(b==0) break;
    ans *= 10;
  }
  cout << ans << endl;
}


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

int main(){
  int N, K, x, y, z, a = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    cin >> x;
    y = x * 2;
    z = abs(K - x) * 2;
    if(y < z){
      a += y;
    }
    else{
      a += z;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
// typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

#define LEN 100005

struct P{
  char name[100];
  int t;
};

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int main() {
  int elaps = 0, c;
  int q;
  P u;
  scanf("%d %d", &n, &q);

  for (int i = 1; i <= n; ++i) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1, tail = n + 1;

  while (head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0) enqueue(u);
    else printf("%s %d\n", u.name, elaps);
  }

  return 0;
}



Measured memory_bytes: 13304
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int a,b;
  for(int i=0;i<7;i++){
    scanf("%d%d",&a,&b);
    cout << a-b << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
using namespace std;
#define MAX 100000

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

int main(){
    int H, i, A[MAX+1];

    cin >> H;
    for (i=1; i<=H; i++){
        cin >> A[i];
    }

    for (i=1; i<=H; i++){
        cout << "node " << i << ": key = " << A[i] << ", ";
        if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
        if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
        if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}

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

class Card {
  String suit;
  int value;
  int storedNo;

  public Card( String suit, int value, int storedNo ) {
    this.suit  = suit;
    this.value = value;
    this.storedNo = storedNo;
  }
  public Card( Card card ) {
    this(card.suit, card.value, card.storedNo);
  }

  @Override
  public String toString() {
    return suit + String.valueOf(value);
  }
}

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      Card[][] cards = new Card[2][n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        cards[0][i] = new Card(
          line[i].substring(0, 1),
          Integer.parseInt(line[i].substring(1)),
          i );
        cards[1][i] = new Card(cards[0][i]);
      }

      bubbleSort(cards[0], n);
      dispIntArray(cards[0]);
      System.out.println(isStableSorted(cards[0], n) ? "Stable" : "Not stable");
      selectionSort(cards[1], n);
      dispIntArray(cards[1]);
      System.out.println(isStableSorted(cards[1], n) ? "Stable" : "Not stable");
    }
  }

  static int bubbleSort(Card[] a, int n) {
    int count=0;
    Card t;

    for(int i=0,f=1; f==1 || i<n; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j].value < a[j-1].value) {
          t = a[j]; a[j] = a[j-1]; a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  }

  static int selectionSort(Card a[], int n) {
    int count = 0;
    Card t;

    for(int i=0,min; i<n-1; i++ ) {
      min = i;
      for(int j=i+1; j<n; j++ ) {
        if( a[min].value > a[j].value) min = j;
      }
      if( min != i ) {
        t = a[i]; a[i] = a[min]; a[min] = t;
        count++;
      }
    }

    return count;
  }

  static boolean isStableSorted(Card[] sorted, int n) {
    boolean ret = true;

    for (int i=0, max=n-1; i < max; i++) {
      if( sorted[i].value == sorted[i+1].value
        && sorted[i].storedNo > sorted[i+1].storedNo )
        ret = false;
    }

    return ret;
  }

  public static void dispIntArray(Card[] a) {
    StringBuilder s = new StringBuilder();

    for (Card c : a) { s.append(c.toString()).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    set<string> S;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        if(S.find(s)==S.end()){
            S.insert(s);
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 19216
N = int(input())
A = [int(input()) for i in range(5)] #A[i]:amount of people able to be carried at once from i to i+1
B = [0] * 6 #B[i]:amount of people at i now 
cnt = 0

#max people able to be transported in m minutes
P = [0] * 9
B[0] = 10**15
for m in range(9):
    for i in range(5,0,-1):
        B[i] += min(A[i-1],B[i-1])
        B[i-1] -= min(A[i-1],B[i-1])
        
    P[m] = B[5]
    cnt += 1
#print(P)
x = N // P[-1]
y = N % P[-1]
if y == 0:
    print(5*x+4)
    exit(0)
for j in range(7,2,-1):
    if P[j]<y:
        time = 5 * x + j + 2
        print(time)
        exit(0)
        


Measured memory_bytes: 9160
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
 string s;
 ll n;
 cin >>n;
 cin >>s;
 ll k=s.size();
 ll w=0,e=0;
 for(ll i=0;i<k;i++){
   if(s[i]=='W') w++;
   else e++;
 }
 //左のwest右のeast
 ll cnt,ww=0,ee=0;
 if(s[0]=='W') ee+=e,cnt=ee;
 else ee+=(e-1),cnt=ee;
 ll ans=ww+ee;
 for(ll i=0;i<k-1;i++){
   if(s[i]=='W') {
     ww++;
     if(s[i+1]=='E') ee--;
   }
   else{
     if(s[i+1]=='E') ee--;

   }
   cnt=ww+ee;
   ans=min(ans,cnt);
 }
 cout <<ans<<endl;
}


Measured memory_bytes: 900
// ABC099_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M;
    cin >> N >> M;
    
    // calculation
    ll diff = M-N, sm = 0;
    REP(i, diff) sm += i+1;
    cout << sm - M << "\n";
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a=[0]+a
for i in range(1,n+1):
    a[i]+=a[i-1]
#print(a)
dic={}
for i in a:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
ans=0
for i in dic.values():
    #print(i)
    ans+=i*(i-1)//2
print(ans)

Measured memory_bytes: 36372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n; cin>>n;
    vector<long double> x(n);
    vector<string> c(n);
    rep(i,0,n) cin>>x[i]>>c[i];
    long double sum=0;
    rep(i,0,n){
        if(c[i]=="JPY") sum+=x[i];
        else sum+=x[i]*380000;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s,t,ans="";
 cin>>s>>t;
 if (s.size()<t.size()) {
  cout<<"UNRESTORABLE";
  return 0;
 }
 for (int i=0;i<=s.size()-t.size();i++){
  string s1=s;
  int k=i,j=0;
  while (j<t.size()){
   if (s1[k]=='?') s1[k]=t[j];
   else if (s[k]!=t[j]) break;
   j++;
   k++;
  }
  if (j==t.size()){
   for (int l=0;l<s1.size();l++){
    if (s1[l]=='?') s1[l]='a';
   }
   if (ans=="") ans=s1;
   else ans=min(s1,ans);
  }
 }
 if (ans=="") cout<<"UNRESTORABLE";
 else cout<<ans;
 return 0;
} 

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N,i,n,cnt,max_cnt,ans=1;
inline void solve(){
  IN(N);
  DW(i,N,1){
    n=i;
    cnt=0;
    while(n%2==0){
      n/=2;
      cnt++;
    }
    if(max_cnt<cnt){
      max_cnt=cnt;
      ans=i;
    }
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  vector<int> data(5);
  for(int i = 0; i < 5; i++)cin >> data.at(i);
  int k;
  cin >> k;
  if(data.at(4) - data.at(0) > k)cout << ":(" << endl;
  else cout << "Yay!" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <queue>
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;
}

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

int main(){
  int n;
  cin >> n;
  std::vector<int> a(n);
  rep(i, n){
    cin >> a.at(i);
  }
  std::map<int, int> mp;
  rep(i, n){
    mp[a.at(i)] = i + 1;
  }
  for(int i = 1; i <= n; i++){
    std::cout << mp.at(i) << " ";
  }
  cout << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<char> s(n);
  rep(i, n) cin >> s[i];

  vector<int> wsum(n + 1, 0), esum(n + 1, 0);
  rep(i, n + 1) {
    if (s[i] == 'W') {
      wsum[i] = wsum[i-1]+1;
      esum[i] = esum[i-1];
    }
    else {
      esum[i] = esum[i-1]+1;
      wsum[i] = wsum[i-1];
    }
  }
  int ans = 1e9;
  rep(i, n) {
    int cnt = 0;
    if (i == 0) cnt += esum[n-1] - esum[0];
    else if (i == n-1) cnt += wsum[n-2];
    else cnt += wsum[i-1] + esum[n-1] - esum[i];
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2944
S = input()
N = len(S)
cost1 = 0
cost2 = 0
for i in range(N):
    if i % 2 == 0:
        if S[i] == "0":
            cost1 += 1
        else:
            cost2 += 1
    else:
        if S[i] == "1":
            cost1 += 1
        else:
            cost2 += 1

if cost1 < cost2:
    print(cost1)
else:
    print(cost2)


Measured memory_bytes: 3188
n,m = map(int,input().split())
k = 0
alist = []
while k < n :
  a = list(map(int,input().split()))
  alist.append(a)
  k += 1
#
if n == 1 :
  print(len(alist[0])-1)
else:
  for blist in alist :
    b = blist[0]
    blist.remove(b)
#
  anslist = []
  ans = 0
  i_roop = len(alist[0])
  while i_roop >= 0 :
    if i_roop == 0 :
      break
    else:
      c = min(alist[0])
      for j in range(1,n) :
        if c in alist[j] :
          anslist.append("OK")
          if j == n-1 :
            if len(anslist) == n-1 :
              ans += 1
        else:
          if j == n-1 :
            if len(anslist) == n-1 :
              ans += 1
          break
      alist[0].remove(c)
    anslist = []
    i_roop += -1

if n != 1 :
  print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
ll N, A, B, C, D;
ll width = 6;
unordered_map<ll, ll> dp;

ll rec(ll now){
    if (dp.count(now)) return dp[now];
    if (now == 0) return 0;
    ll ret = INF;
    if (INF / D > now) ret = D * now;
    for (ll i = now - width; i < now + width - 3; i++){
        if (i < 0) continue;
        ll d = abs(now - i);
        if ((i % 2) == 0 && i / 2 != now) chmin(ret, rec(i / 2) + A + d * D);
        if ((i % 3) == 0 && i / 3 != now) chmin(ret, rec(i / 3) + B + d * D);
        if ((i % 5) == 0 && i / 5 != now) chmin(ret, rec(i / 5) + C + d * D);
    }
    // pt(now);
    dp[now] = ret;
    return ret;
}

void solve(){
    cin >> N >> A >> B >> C >> D;
    dp.clear();
    pt(rec(N));
}



int main(){
    ll T; cin >> T;
    while(T--){
        solve();
    }
}

Measured memory_bytes: 5084
#include <stdio.h>
int a, b, c, k, x;
int main() {
	scanf("%d%d%d%d", &a, &b, &c, &k);
	while (a >= b) {
		x++;
		b *= 2;
	}
	while (b >= c) {
		x++;
		c *= 2;
	}
	if (x <= k)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 1660
/*
 * Created by Dipta Das on 26-06-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

int INF = 1e9 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n;
    cin >> n;
    vector<int> height(n);
    for (int &i : height) cin >> i;
    vector<int> dp (n, INF);

    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j : {i+1, i+2}) {
            if (j < n) {
                dp[j] = min (dp[j], dp[i] + abs(height[i] - height[j]));
            }
        }
    }

    cout << dp[n-1] << endl;
    


    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std; typedef long long ll; typedef unsigned long long ull; const int mod = 1e9 + 7;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
//#define int ll

int n, k, h[100001], dp[100001][4], a[100001], b[100001], c[100001];

signed main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	memset(dp, 0, sizeof dp);
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 1; i <= n; i++)
	{
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b[i];
		dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]) + c[i];
	}
	cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end()))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int N;
    cin >> N;
    vint V(N + 1), W(N + 1);
    reps(i, N) { cin >> V[i] >> W[i]; }
    int m = min(bit(12), N + 1);
    vector<vpint> WV(m);
    for (int i = 1; i < m; i++) {
        vint Vc, Wc;
        int v = i;
        while (v > 0) { Vc.push_back(V[v]), Wc.push_back(W[v]), v >>= 1; }
        rep(j, bit(Vc.size())) {
            int Vcc = 0, Wcc = 0;
            rep(k, Vc.size()) { if (j & bit(k)) { Vcc += Vc[k], Wcc += Wc[k]; }}
            WV[i].push_back({Wcc, Vcc});
        }
        sort(all(WV[i]));
        for (int j = 1; j < WV[i].size(); j++) { chmax(WV[i][j].second, WV[i][j - 1].second); }
    }
    int Q;
    cin >> Q;
    rep(i, Q) {
        int v, L;
        cin >> v >> L;
        int ans = 0;
        vint Vc, Wc;
        while (v >= m) { Vc.push_back(V[v]), Wc.push_back(W[v]), v >>= 1; }
        rep(j, bit(Vc.size())) {
            int Vcc = 0, Wcc = 0;
            rep(k, Vc.size()) { if (j & bit(k)) { Vcc += Vc[k], Wcc += Wc[k]; }}
            if (Wcc > L) { continue; }
            chmax(ans, (lower_bound(all(WV[v]), pint(L - Wcc, LLONG_MAX)) - 1)->second + Vcc);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 182252
#include <iostream>

using namespace std;

int main(){
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int i=0; i<=K; i++){
    for (int j=0; j<=K; j++){
      if (S - i - j >= 0 && S - i - j <= K) ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n; double a, b = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a;
		b += 1 / a;
	}
	cout << 1 / b << endl;
	cin >> n;
}

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

const int mod=1e9+7;

int main(){
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>=2){cout<<0<<endl; return 0;}
    ll ans=1;
    for(int i=1; i<=n; ++i){
        ans*=i;
        ans%=mod;
    }
    for(int i=1; i<=m; ++i){
        ans*=i;
        ans%=mod;
    }
    if(n==m)ans*=2;
    ans%=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int n,m; //input intergers:n,m
vector<pair<int,int> > e[100010]; //the vector array of DFS
long long pos[100010]; //the positions of each person 
bool vis[100010]; //the bool array of DFS to know each person has visited or not
 
inline void dfs(int x) //DFS
{
	vis[x]=1; //visited this person(x)
	for(int i=0;i<e[x].size();i++) //visit the person who has relation of this person(x)
	{
		pair<int,int> cur=e[x][i];
		if(vis[cur.first]) //if(this person(e[x][i])'s position has known)
		{
			if(pos[cur.first]-pos[x]!=cur.second) {cout<<"No";exit(0);} //if this person(e[x][i]) is wrongful then exit
		}
		else //if this person(e[x][i])'s position hasn't known then take notes and DFS
		{
			pos[cur.first]=pos[x]+cur.second;
			dfs(cur.first);
		}
	}
}
 
int main()
{
	cin>>n>>m; //input
	for(int i=0;i<m;i++)
	{
		int l,r,d;
		cin>>l>>r>>d; //input
		e[l].push_back({r,d}); //take notes
		e[r].push_back({l,-d}); //take notes
	}
	
	for(int i=0;i<n;i++) if(!vis[i]) dfs(i); //DFS
	
	cout<<"Yes"; //if every one isn't wrongful then print 'Yes'
	
	return 0; //END
}

Measured memory_bytes: 11648
atcg = ['A','T','C','G']
s = gets
max_len = 0
cur_len = 0

s.chars.each do |c|
  if atcg.include?(c)
    cur_len+=1
  else
    if cur_len > max_len
      max_len = cur_len
    end
    cur_len = 0
  end
end
puts max_len

Measured memory_bytes: 1788
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	string s;
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7') Yes();
	else No();
}


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

public class Main {
	
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] r = new int[n];
		
		for(int i = 0; i < n; i++){
			r[i] = Integer.parseInt(br.readLine());
		}
		
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			max = Math.max(max, r[i] - min);
			min = Math.min(min, r[i]);
		}
		
		System.out.println(max);
	}
}

Measured memory_bytes: 43172