akhauriyash/Code-Regression huggingface dataset:
/*
 Shahadat Hossain
 I.C.T Department
 Comilla University
 Session: 2013-2014
 */

#include<bits/stdc++.h>
using namespace std;

//#define int long long
#define valid(x,y) x>=0 && y>=0 && x<n && y<n
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define ms(a,b) memset(a, b, sizeof(a))
#define eps 1e-5
#define input freopen("/Users/shahadat/Desktop/input.txt", "r", stdin)
#define output freopen("/Users/shahadat/Desktop/output.txt", "w", stdout)
#define d(x) cout << #x << " = " << x << endl
#define dd(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define ddd(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
//fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
//int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
#define bit(n,k) (((n)>>(k))&1)
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pr(x) {cout << (x) << '\n';  }
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define mask(i) ((1LL<<(i)))
#define endl '\n'
double const PI = acos(-1);
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}


int Check(int n, int pos){return n & (1 << pos);}
int Set(int n, int pos){return n |= (1 << pos);}


using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int const MOD = 1e9 + 7;

int const N = 1e5 + 5;

vector<int> edges[N];
int dp[N];

int dfs(int node){
    if(dp[node] != -1)
        return dp[node];
    int res = 0;
    for(auto c: edges[node]){
        res = max(res, 1 +  dfs(c));
    }
    return dp[node] =  res;
}


int32_t main(){
    ms(dp, -1);
    int n, m;
    cin >> n >> m;
    
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        edges[u].push_back(v);
    }
    for(int i = 1; i <= n; i++){
        if(edges[i].size() == 0)
            dp[i] = 0;
    }
    
    int res = 0;
    for(int i = 1; i <= n; i++){
        if(dp[i] == -1){
            dp[i] = dfs(i);
        }
        res = max(res, dp[i]);
    }
    
    cout << res << endl;
}


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

int main (){
    int d;
    cin >> d;
    if (d == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    } else if (d == 23){
        cout << "Christmas Eve Eve" << endl;
    } else if (d == 24){
        cout << "Christmas Eve" << endl;
    } else {
        cout << "Christmas" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
Max = 10**18
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())

def wa(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

def on():
    N,M,L = m()

    e = [[Max for i in range(N)]for j in range(N)]

    for i in range(M):
        a,b,c = m()
        e[a-1][b-1] = c
        e[b-1][a-1] = c

    for i in range(N):
        e[i][i] = 0

    d = wa(e)


    E = [[Max for i in range(N)]for j in range(N)]

    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                E[i][j] = 1

    for i in range(N):
        E[i][i] = 0

    E = wa(E)
    q = onem()
    for i in range(q):
        s,t = m()
        if E[s-1][t-1] == Max:
            print(-1)
        else:
            print(E[s-1][t-1]-1)

if __name__ == "__main__":
    on()




Measured memory_bytes: 61400
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
const int MAXN = 2e5 + 10;
int N;
int A[MAXN], d[MAXN];
int stk[MAXN], top;
ll ans;

int main() {
	register int i;
	scanf("%d", &N);
	for(i = 1; i <= N; ++i) {
		scanf("%d", A + i);
		while(A[stk[top]] >= A[i]) --top;
		d[i] = stk[top]; stk[++top] = i;
	}
	top = 0, stk[0] = N + 1;
	for(i = N; i; --i) {
		while(A[stk[top]] >= A[i]) --top;
		ans += 1ll * A[i] * (i - d[i]) * (stk[top] - i); stk[++top] = i;
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

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

const int N = 100010;
const double eps = 1e-6;

int n;
int a[N], l[N], r[N];

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    for(int i = 1; i <= n; i++) l[i] = gcd(a[i], l[i - 1]);
    for(int i = n; i >= 1; i--) r[i] = gcd(a[i], r[i + 1]);

    int res = 0;
    for(int i = 1; i <= n; i++) res = max(res, gcd(l[i - 1], r[i + 1]));
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 1408
package main

import "fmt"

type chunk struct {
	l   int
	r   int
	len int
}

func (c chunk) String() string {
	return fmt.Sprintf("<%d,%d #%d>", c.l, c.r, c.len)
}

func main() {
	var S []byte
	fmt.Scan(&S)

	chunks := []*chunk{}

	var lastOp byte = '\000'
	var lastChunk *chunk = &chunk{}
	chunks = append(chunks, lastChunk)
	for _, op := range S {
		if op == '>' {
			if lastOp == '>' {
				lastChunk.l++
				lastChunk.len++
			} else {
				lastChunk = &chunk{l: 1, len: 1}
				chunks = append(chunks, lastChunk)
			}
		} else if op == '<' {
			lastChunk.r++
			lastChunk.len++
		}
		lastOp = op
	}
	sum := 0
	for _, c := range chunks {
		sum += (c.l*(c.l+1))/2 + (c.r*(c.r+1))/2
	}
	for i := 1; i < len(chunks); i++ {
		sum -= Min(chunks[i-1].r, chunks[i].l)
	}
	fmt.Println(sum)
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int main()
{
	ll n;cin>>n;
	ll a[5];ll minn=10000000000000000;int sum=0;
	for(int i=0;i<5;i++) 
	{
		cin>>a[i];//int tmp=a[i]%10;
		//if(tmp<(a[maxx]%10) && tmp!=0) maxx=i;
		minn=min(minn,a[i]);
	}
	ll t=((n-1ll)/minn+1ll);
	cout<<t+4ll<<endl;
 } 

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))

c = []
for _ in range(3):
    c.append(LI())
a1_range = min(c[0])
for a1 in range(a1_range+1):
    a = [0]*3
    b = [0]*3
    a[0] = a1
    b[0] = c[0][0] - a[0]
    b[1] = c[0][1] - a[0]
    b[2] = c[0][2] - a[0]
    a[1] = c[1][0] - b[0]
    a[2] = c[2][0] - b[0]
    flag = True
    for i in range(3):
        for j in range(3):
            if c[i][j] != a[i] + b[j]:
                flag = False
                break
        if not flag:
            break
    if flag:
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	int N,W;
	cin >> N >> W;
	vector<ll> dp(W+1,0);
	vector<ll> weight(N+1);
	vector<ll> value(N+1);
	//½T©w¨C­Ó­«¶q¥i¥H¦³ªº³Ì¤j»ù­È 
	for(int i = 0; i<N; ++i){
		cin >> weight[i] >> value[i];
	}
	for(int item = 0; item<N; ++item){ //item = 4
		for(int now_wei = W; now_wei>=weight[item]; --now_wei){ //now_wei = 3
			dp[now_wei] = max(dp[now_wei],dp[now_wei-weight[item]] + value[item]);
		}
	}
	cout << dp[W];
	
} 

Measured memory_bytes: 1024
import math
x = int(input())
if x==2:
    print(2)
else:
    for i in range(x, 100004):
        if i%2==0:
            continue
        for j in range(3, int(math.sqrt(i)+1)):
            if i%j==0:
                break
        else:
            print(i)
            break

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
	bool is_prime[65536];
	for(int i=0;i<65536;i++)
		is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<65536;i++)
		if(is_prime[i])
			for(int j=2*i;j<65536;j+=i)
				is_prime[j]=false;
	int n;
	while(cin >> n,n){
		int count=0;
		for(int i=2;i<=n/2;i++)
			if(is_prime[i]&&is_prime[n-i])
				count++;
		cout << count << endl;
	}
return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
using namespace std;

int t, n, sum;

int main(){
	int s, f;
	while (true) {
		sum = 0;
		scanf("%d", &t);
		if (t == 0) return 0;
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			scanf("%d %d", &s, &f);
			sum += f - s;
		}
		if (sum >= t) {
			printf("OK\n");
		}
		else {
			printf("%d\n", t - sum);
		}
	}

	return 0;
}

Measured memory_bytes: 2672
def main():
  t = input().split(" ")
  H, W = int(t[0]), int(t[1])
  
  s = ["."*(W+2)]
  for i in range(H):
    t = input().strip()
    s.append("".join(['.', t, '.']))
  s.append("."*(W+2))
  flag = True
  for i in range(H):
    for j in range(W):
      if s[i+1][j+1] == '#':
        if s[i][j+1]=='.' and s[i+2][j+1]=='.' and s[i+1][j]=='.' and s[i+1][j+2]=='.':
          flag = False
  if flag:
    print("Yes")
  else:
    print("No")
main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
using  ll = long long;
using ld = long double;
using Byte = unsigned char;
using namespace std;

//string ans = "Yes";

///summary : とりあえず貪欲法
int vmax(std::vector<int> v)
{
	int ans = 0;
	int maxVal = INT_MIN;       // 整数最小値
	for (int i = 0; i < (int)v.size(); i++) {
		if (v[i] > maxVal) {
			maxVal = v[i];
			ans = i;
		}
	}
	return ans;
}

vector<int> SetAns() {
	/// normal_input
	int D;
	cin >> D;

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	rep(i, 26) cin >> c[i];
	rep(i, D) rep(j, 26) cin >> s[i][j];;
	
	/// main_process
	vector<int> t(D);
	rep(i, D) t[i] = vmax(s[i]);

	return t;
}

int main() {
	vector<int> ans = SetAns();
	for (const auto& i : ans) {
		cout << i + 1 << endl;
	}
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3216
#include <stdio.h>

#define M 10000

int main(void){
  int n,q,i,j,S[M],T,res = 0;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&T);
    for(j = 0 ; j < n ; j++){
      if(T == S[j]){
        res++;
        break;
      }
    }
  }
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int c,d,w,x;
	while(cin>>c>>d>>w>>x,c||d||w||x){
		int e[20][35],f[20][35];
		for(int i=0;i<c;i++)
		for(int j=0;j<d;j++)
			cin>>e[i][j];
		for(int i=0;i<c;i++)
		for(int j=0;j<d;j++)
			cin>>f[i][j];
		int dp[35][55][10];
		memset(dp,-1,sizeof(dp));
		dp[0][0][0]=0;
		for(int i=0;i<d;i++){
			for(int j=0;j<=w;j++)
			for(int k=0;k<=x;k++){
				if(dp[i][j][k]==-1)
					continue;
				for(int l=0;l<c;l++){
					int now=l,nx=k,nw=j,nowe=dp[i][j][k];
					while(now<c){
						nowe+=e[now][i],nw+=f[now][i];
						if(!e[now][i]||x<nx||w<nw)
							break;
						dp[i+1][nw][nx]=max(dp[i+1][nw][nx],nowe);
						
						now++;
						nx=k+1;
					}
					
				}
				dp[i+1][j][k]=max(dp[i][j][k],dp[i+1][j][k]);
			}
			
			
		}
		int ans=0;
		for(int i=0;i<=w;i++)
		for(int j=0;j<=x;j++)
			ans=max(ans,dp[d][i][j]);
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 948
#include<stdio.h>
#define Max 100

int main(void){
	int i, j, a, temp;
	int mo[Max];
	
	for(i=0;i<10;i++)
	{
		scanf("%d",&a);
		mo[i] = a;
	}
	for(i=0;i<10;i++)
	{
		for(j=i+1;j<10;j++)
		{
			if(mo[i]<=mo[j])
			{
				temp = mo[i];
				mo[i] = mo[j];
				mo[j] = temp;
			}
		}
	}
	for(i=0;i<3;i++)
	{
		printf("%d\n",mo[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
//-0.4620981203755741
int main(){
    int h,w;
    std::cin >> h>>w;
    vvector(v,int,h,w,0);
    int a,b;
    std::cin >> a>>b;
    //a--;b--;
    
    reprep(i,j,h,w){
        bool aa=0,bb=0;
        if(a>j)aa=1;
        if(b>i)bb=1;
        if(aa^bb)v[i][j]=0;
        else v[i][j]=1;
    }
    rep(i,h){
        rep(j,w)std::cout << v[i][j] ;
        std::cout  << std::endl;
    }
}

Measured memory_bytes: 5120
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void insertionSort(int A[], int N) {
	int i;
	int v;
	int j;

	for (i = 1; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (0 <= j && v < A[j]) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
	}
}

int check(int m, int A[], int l) {
	if (l == 0) {
		if (A[0] == m) {
			return 1;
		}
		else {
			return 0;
		}
	}

	if (A[l] == m) {
		return 1;
	}
	if (A[l] > m) {
		return check(m, A, l - 1);
	}

	if (check(m - A[l], A, l - 1)) {
		return 1;
	}
	else {
		return check(m, A, l - 1);
	}
}

int main() {
	int n;
	int A[20];
	int q;
	int m;
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", A + i);
	}
	insertionSort(A, n);

	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &m);
		if (check(m, A, n)) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}


	return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int a,b;
		Scanner input = new Scanner(System.in);
		a = input.nextInt();
		b = input.nextInt();
		int c = a*b;
		if(c%2 == 0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}
	}
}

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long int;
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main(){
	int n;
	int a,b,c,d;
	int p[100]={};
	vi pp;
	cin>>n;
	REP(i,(n*(n-1))/2){
		cin>>a>>b>>c>>d;
		if(c>d)p[a-1]+=3;
		else if(c<d)p[b-1]+=3;
		else {
			p[a-1]++;
			p[b-1]++;
		}
	}
	REP(i,n){
		pp.pb(p[i]);
	}
	sort(all(pp),greater<int>());
	/*
	REP(i,n)cout<<p[i]<<" ";cout<<"\n\n";
	REP(i,n)cout<<pp[i]<<" ";cout<<"\n";
	//*/
	REP(i,n){
		auto iter=find(all(pp),p[i]);
		cout<<distance(pp.begin(),iter)+1<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3140
#include<stdio.h>
int main(){
	int a, c=0, max=0;
	scanf("%d", &a);
	char b[a+1];
	scanf("%s", b);
	for(int i=0; b[i]!='\0'; i++){
		if(b[i]== 'D'){
			c--;
		}
		else if(b[i]=='I'){
			c++;
		}
		if(max<c){
			max=c;
		}
	}
	printf ("%d\n", max);
	return 0;
}

Measured memory_bytes: 1684
#include <iostream>
#include <string>

using namespace std;

int main() {
        string o, e;
        cin >> o >> e;
        int len = e.length();
        if (o.length() == e.length()) {
                for (int i = 0; i < len; i++) {
                        cout << o[i] << e[i];
                }
        } else {
                for (int i = 0; i < len; i++) {
                        cout << o[i] << e[i];
                }
                cout << o[len];
        }
        cout << endl;
        return 0;
}

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


using namespace std;


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

    vector<vector<int>> cs(10, vector<int>(10, 0));

    string si;
    int start_num, last_num;

    for (int i=1; i<n+1; i++) {
        si = to_string(i);
        cs[si[0]-'0'][si[si.size()-1]-'0']++;
    }

    int ans = 0;
    for (int i=1; i<10; i++) {
        for (int j=1; j<10; j++) {
            ans += cs[i][j] * cs[j][i];
        }
    }

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



Measured memory_bytes: 888
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::string x;
  int64_t result = 0;
  cin >> x;
  result    = x.size();
  int count = 0;
  for (auto c : x) {
    if (c == 'S') {
      count++;
    } else if (c == 'T') {
      if (count > 0) {
        count--;
        result -= 2;
      }
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1336
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int A[n-1];
	for(int i=0;i<n-1;i++)
	cin>>A[i];
	int sum=0;
	sum=A[0]+A[n-2];
	for(int i=n-2;i>=1;i--)
	sum+=min(A[i],A[i-1]);
/*	for(int i=0;i<n-1;i++)
	cout<<A[i]<<endl;*/
	cout<<sum;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = sorted(A)
l1 = [(A[i], A[j]) for i in range(N) for j in range(i,N) if A[i] > A[j]]
l2 = [(A[i], A[j]) for i in range(N) for j in range(N) if A[i] > A[j]]
print ((K * (K - 1) // 2 * len(l2) + len(l1) * K) % (10 ** 9 + 7))

Measured memory_bytes: 218220
import sys


def print_(ans):
    print(ans)
    sys.exit()


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split(' ')))
    if n == 0:
        if a[0] == 1:
            print_(1)
        else:
            print_(-1)
    if a[0] != 0:
        print_(-1)
    max_rest = [0 for _ in range(n + 1)]
    max_rest[0] = 1 - a[0]
    for i in range(1, n + 1):
        max_rest[i] = max_rest[i - 1] * 2 - a[i]
    for i in range(n + 1):
        if max_rest[i] < 0:
            print_(-1)
    rest = [0 for _ in range(n + 1)]
    for i in range(n - 1, -1, -1):
        req_rest = (a[i + 1] + rest[i + 1] + 1) // 2
        if max_rest[i] < req_rest:
            print_(-1)
        rest[i] = min(max_rest[i], a[i + 1] + rest[i + 1])
    ans = sum(a) + sum(rest)
    print_(ans)


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

int H, W;
char s[110][110];

int diff(int sx, int sy, int gx, int gy) {
  if (s[sy][sx] != '#' && s[gy][gx] =='#')
    return 1;
  else return 0;
}

int main()
{
  int d[110][110] = {INF};
  int res=0;
  cin >> H >> W;
  rep(i,H) cin >> s[i];

  d[0][0] = (s[0][0] == '#') ? 1 : 0;
  rep(i, W) {
    d[0][i+1] = d[0][i] + diff(i,0,i+1,0);
  }
  rep(j, H) {
    d[j+1][0] = d[j][0] + diff(0,j,0,j+1);
  }

  FOR(i, 0, H-2) {
    FOR(j, 0, W-2) {
      d[i+1][j+1] = min(d[i  ][j+1] + diff(j+1, i  , j+1, i+1),
                        d[i+1][j  ] + diff(j,   i+1, j+1, i+1));
    }
  }

#if 0
  rep(i, H) {
    rep(j, W) {
      printf("%3d ", d[i][j]);
    }
    printf("\n");
  }
#endif

  cout << d[H-1][W-1] << endl;
}

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

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline void pv(vector<T> v) { for(ll i=0, N=v.size()-1; i<=N; i++) if(i!=N) cout << v[i] << ' '; else cout << v[i] << endl; }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/
ll N;
vector<ll> a;

ll f(ll init){
	ll candidate=init;
	rep(i,N){
		ll j=N-i-1;
		candidate=((candidate+a[j]-1)/a[j])*a[j];
	}
    return candidate;
}

signed main() {
	cin>>N;
	a.assign(N,0);
	rep(i,N){
		cin>>a[i];
	}
	if(a[N-1]!=2){
		p(-1);
		return 0;
	}

	ll a2=f(2);
    ll a3=f(3);
    debug(a2);debug(a3);
	if(a2==a3){
		p(-1);
		return 0;
	}
	cout<< a2 <<' '<< a3-1 <<endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans, n, a, b;
int main()
{
	scanf("%lld%lld%lld", &n, &a, &b);
	if (b-a <= 2 || a >= n)
	{
		printf("%lld\n", n+1);
	}
	else
	{
		ll time = a-1;
		ll biscuits = a;
		while (time <= n-2)
		{
			ll cansell = biscuits/a;
			cansell = min(cansell, (n-time)/2);
			biscuits -= cansell*a;
			biscuits += cansell*b;
			time += cansell*2;
		}
		biscuits += n-time;
		printf("%lld\n", biscuits);
	}
}

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

#define DIV 1000000007

long long dp[10][200];
long long H, W, K;

bool has(long long pat, long long left){
	return ((pat>>left)&1);
}

bool check(long long pat){
	for(long long i = 0; i <= W; i++){
		if(has(pat,i) && has(pat, i + 1)){
			return false;
		}
	}
	return true;
}

long long draw(long long left){
	long long count = 0;
	for(long long pat = 0; pat < pow(2, W-1); pat++){
		if(check(pat) && has(pat, left)){
			count++;
		}
	}
	return count;
}

long long blank(long long left){
	long long count = 0;
	for(long long pat = 0; pat < pow(2, W-1); pat++){
		if(check(pat) && !has(pat, left)){
			count++;
		}
	}
	return count;
}


long long doubleblank(long long left1, long long left2){
	long long count = 0;
	for(long long pat = 0; pat < pow(2, W-1); pat++){
		if(check(pat) && !has(pat, left1) && !has(pat,left2)){
			count++;
		}
	}
	return count;
}

int main(){
	cin >> H >> W >> K;K--;
	dp[0][0] = 1;

	for(long long row = 1; row <= H; row++){
		for(long long col = 0; col < W; col++){
			if(col == 0){
				dp[col][row] = dp[col][row-1] * blank(0);
				dp[col][row] += dp[col+1][row-1] * draw(0);
				dp[col][row] %= DIV;
			}else if(col == W-1){
				dp[col][row] = dp[col][row-1] * blank(W-2);
				dp[col][row] += dp[col-1][row-1] * draw(W-2);
				dp[col][row] %= DIV;
			}else{
				dp[col][row] = dp[col][row-1] * doubleblank(col-1, col); //down
				dp[col][row] += dp[col-1][row-1] * draw(col-1); //from left
				dp[col][row] += dp[col+1][row-1] * draw(col); //from right
				dp[col][row] %= DIV;
			}
		}
	}

	cout << dp[K][H] << endl;

}


Measured memory_bytes: 256
n=int(input())
A=list(input())+["#"]
B=list(input())+["*"]
C=""
mod=10**9+7

i=0
while i<n:
    if A[i]==B[i]:
        C +="X";i +=1
    elif A[i]==A[i+1] and B[i]==B[i+1]:
        C +="Y";i +=2

cnt=3 if C[0]=="X" else 6
for i in range(1,len(C)):
    word=C[i-1]+C[i]
    if word=="XY":cnt *=2
    elif word=="XX":cnt *=2
    elif word=="YX":cnt *=1
    elif word=="YY":cnt *=3
    cnt %=mod
print(cnt)

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

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
};

mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    mint ans = f(n);
    ans -= 1;
    ans -= choose(n, a);
    ans -= choose(n, b);
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

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

  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int A = 0;
    cin >> A;
    if ((A % 2 == 0) && ( (A % 3 != 0) && (A % 5 != 0))) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


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

int main(){
    int n, m, k; cin >> n >> m >> k;
    for(int i=0; i<n+1; i++){
        for(int j=0; j<m+1; j++){
            // cout << i << " " << j << " " <<i * m + j * n - i * j << endl; 
            if(i * m + j * n - i * j * 2 == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

typedef pair <int, int> P;

int main() {
	int n;
	long long int m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		priority_queue<P> pq;
		for (int i = 0; i < n; i++) {
			P p;
			cin >> p.second >> p.first;
			pq.push(p);
		}
		while (!pq.empty()) {
			P pp = pq.top();
			pq.pop();
			if (m >= pp.second) {
				m -= pp.second;
			} else {
				pp.second -= m;
				pq.push(pp);
				break;
			}
		}
		long long int count = 0;
		while (!pq.empty()) {
			P pp = pq.top();
			pq.pop();
			count += pp.first*pp.second;
		}
		cout << count << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int nax = 1e5 + 2;
vector<int> edges[nax];

void dp(int a, int pa, vector<ll>& dpb, vector<ll>& dpw) {
  if((int)edges[a].size() == 1 && edges[a][0] == pa) {
    dpb[a] = dpw[a] = 1;
    return;
  }
  ll answ = 1, ansb = 1;
  for(int b : edges[a]) {
    if(b == pa) {
      
    } else {
      dp(b, a, dpb, dpw);      
      answ *= (dpw[b] + dpb[b]);
      answ %= mod;
      ansb *= dpw[b];
      ansb %= mod;
    }
  }
  dpw[a] = answ;
  dpb[a] = ansb;
  return;    
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for(int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }  
  vector<ll> dpb(n + 1), dpw(n + 1);  
  dp(1, -1, dpb, dpw);
  cout << (dpb[1] + dpw[1])%mod << '\n';
  return 0;
    
  
}
  


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

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ssize = S.size();
    int counter = 0;
    int xmax = 0;
    for (int i; i < N; i++)
    {
        if (S.at(i) == 'I')
        {
            counter++;
        }
        else
        {
            counter--;
        }
        xmax = max(xmax, counter);
    }
    cout << xmax << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length

    fun f(s: String): Boolean {
        return s == s.reversed()
    }

    println(if (f(s) && f(s.slice(0 until n / 2)) && f(s.slice(n / 2 + 1 until n))) "Yes" else "No")
}


Measured memory_bytes: 33748
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;



int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({b*d,b*c,a*c,a*d});


 
 
    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 3816
#include <iostream>

int main() {
	int N;
	std::cin >> N;

	int result = 0;

	// 奇数
	for(int n = 1; n <= N; n+=2) {
		int numDivisor = 0;
		for(int m = 1; m <= n; m++) {
			if(n % m == 0) {
				numDivisor++;
			}
		}
		if(numDivisor == 8) {
			result++;
		}
	}

	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
from numpy import*
n, m = map(int, input().split())
l = []
for i in range(m):
    *a,=map(int,input().split())
    l.append(a[1:])
*p,=map(int,input().split())
ans = 0
for t in range(2**n):
    tmp=array([t>>s&1 for s in range(n)])
    if p==[sum(tmp[array(i)-1])%2for i in l]:
        ans+=1
print(ans)

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

int main(){
  int n,m,b,c;
  cin>> n >> m;
  vector<int> a(n);
  vector<vector<int>> op(m);
  for (int i=0; i<n; i++) cin>> a.at(i);
  for (int i=0; i<m; i++){
    cin>> b >> c;
    op.at(i)={c,b};
  } 
  sort(a.begin(),a.end()); sort(op.begin(),op.end()); reverse(op.begin(),op.end());
  
  int p=0;
  for (int i=0; i<m; i++){
    b=op.at(i).at(1); c=op.at(i).at(0);
    while (b>0 && p<n && a.at(p)<c){ //判定の順序のせいでa[n]out_of_rangeになった
      a.at(p)=c;
      b--;
      p++;
    }
    if (b>0) break;
  }
  
  int64_t ans=0;
  for (int i=0; i<n; i++) ans+=a.at(i);
  
  cout<< ans <<endl;
}

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

using namespace std;

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

const int  N = 1111;

int main(){
	int n,k;
	cin>>n>>k;
	
	int masu[N]={0};
	
	rep(i,k){
		int a,b;
		cin>>a>>b;
		
		reps(j,a,b){
			masu[j]=1;
		}
	}
	
	int sum = 0;
	rep(i,N){
		sum += masu[i];
	}
	
	printf("%d\n",n+sum*2+1);
	
	
}

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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = a, i##end = b; i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = a, i##end = b; i < i##end; ++ i)
#define Rep(i, a, b) for (int i = a, i##end = b; i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = b; i >= i##end; -- i)

typedef long long LL;

template <class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template <class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template <class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template <class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template <class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/

const int MAXN = 100000 + 5;

int a[MAXN];

int main() {
  int n;
  scanf("%d", &n);
  For(i, 1, n) {
    scanf("%d", &a[i]);
  }
  std::sort(a + 1, a + n + 1, std::greater<int>());
  int x = 0, y = 0;
  for (; y + 1 < a[x + 2]; ++ x, ++ y);
  int p = x + 1;
  for (; y < a[p + 1]; ++ p);
  puts(((a[x + 1] - y) & 1) && ((p - x) & 1) ? "Second" : "First");
  return 0;
}

Measured memory_bytes: 640
N = int(input())
INF = 10 ** 9
dp =  [INF] * (N + 1)
dp[0] = 0
for i in range(N):
    dp_i = dp[i]
    x = 1
    while N >= i + x:
        if dp[i+x] > dp_i + 1:
            dp[i+x] = dp_i + 1
        x *= 6
    x = 1
    while N >= i + x:
        if dp[i+x] > dp_i + 1:
            dp[i+x] = dp_i + 1
        x *= 9
print(dp[N])


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string s;
    cin >> s;

    int ans = INF;
    for(int i = 0; i < (int)s.size()-2; i++){
        int x = stoi(s.substr(i, 3));
        ans = min(ans, abs(x - 753));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long A=Long.parseLong(sc.next());
		long B=Long.parseLong(sc.next());

		long C;
		if(A >= B) {
			C = getGcd(A,B);
		} else {
			C = getGcd(B, A);
		}
		long ans = (A*B)/C;
		System.out.println(ans);

	}

	public static long getGcd(long a , long b) {
		long c ;
		while(true) {
			c = b;
			if(a%b ==0) {
				return b;
			}
			b = a%b;
			a = c;
		}

	}
}


Measured memory_bytes: 23764
#include <stdio.h>

int main(void){
    int A,B,C;
    
    scanf("%d %d %d",&A,&B,&C);
    
    if(A>=B&&A>=C)
        printf("%d\n",10*A+B+C);
    else if(B>=A&&B>=C)
        printf("%d\n",10*B+A+C);
    else
        printf("%d\n",10*C+A+B);

}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll N, W;
    cin >> N >> W;
    vector<ll> weight(N), value(N);
    for (ll i = 0; (i < N); ++i) {
        cin >> weight[i] >> value[i];
    }
    vector<vector<ll>> dp(N, vector<ll>(W+1, 0));
    for (ll j = 0; (j < W+1); ++j) {
        if (j >= weight[0]) {
            dp[0][j] = value[0];
        }
    }
    for (ll i = 1; (i < N); ++i) {
        for (ll j = 0; (j < W+1); ++j) {
            dp[i][j] = dp[i-1][j];
            if (j - weight[i] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i-1][j-weight[i]] + value[i]);
            }
        }
    }
    cout << dp[N-1][W] << endl;
    return 0;
}


Measured memory_bytes: 79360
object Main extends App{
    val a = for(_ <- 1 to 3) yield scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val b = for(_ <- 1 to scala.io.StdIn.readInt) yield scala.io.StdIn.readInt
    val a_series = a.reduce(_ ++: _)
    val hit = for(count <- a_series) yield b.contains(count)
    val yoko = hit.grouped(3).map(e1 => e1.forall(e2 => e2 == true)).reduce(_ || _)
    val tate = (0 to 6 by 3).map(hit(_)).forall(_ == true) || (1 to 7 by 3).map(hit(_)).forall(_ == true) || (2 to 8 by 3).map(hit(_)).forall(_ == true)
    val name = (0 to 8 by 4).map(hit(_)).forall(_ == true) || (2 to 6 by 2).map(hit(_)).forall(_ == true)
    if(yoko || tate || name) println("Yes") else println("No")
}

Measured memory_bytes: 25520
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
#warning "// FOR has been inclusive now!!!!"
string S;
string store,prevv="*";
int main(){
	FAST
	cin>>S;
	ll co=0; ll ans=0;
	while(co^siz(S)){
		store+=S[co];
		if(store==prevv);
		else { ++ans, prevv=store, store=""; }
		++co;	
	}
	cout<<ans<<'\n';
}
/*
 * 
aaaccacabaababc
* 
*/


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

signed main(){
  string s;
  cin>>s;
  int sum=0,a=0,bc=0;
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='C'&&s[i-1]=='B'){
      i--;
      bc++;
    }
    else if(s[i]=='A'){
      a++;
      sum+=bc;
    }
    else bc=0;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 640
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
a, b, x = map(int, input().split())
if a <= x <= a + b:
    print("YES")
else:
    print("NO")

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

int main(){
	string s,t;
	cin>>s>>t;
	int i,ans = 0;
	for(i=0;i<s.size();i++)
		if(s[i]!=t[i])
			ans++;
	cout<<ans;
}

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

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <

// Output, Common Containers
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream& os, const set<T>& v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream& os, const map<T,S>& v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef SANYAM1101
	#define trace(args...) do{ cerr << "TRACE ON! (Line: " << __LINE__ << ")\n"; auto _stream = istringstream{string{#args}}; d_f(_stream, args); } while(0)
	void d_f(__attribute__((unused)) istringstream& _stream) {}
	template<typename Head, typename... Tails> void d_f(istringstream& _stream, Head H, Tails... T) { string _name; _stream >> _name; if(_name.back() == ',') _name.pop_back(); cerr << "\t" << _name << " <=> [" << H << "]\n"; d_f(_stream, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

void solve(){
	int n;
	cin >> n;

	map<int,int> m;
	ll su = 0;

	while(n--){
		int x; cin >> x;
		++m[x]; su += x;
	}

	int q;
	cin >> q;

	while(q--){
		int b, c;
		cin >> b >> c;

		su += (ll)(c - b) * m[b];
		m[c] += m[b];
		m.erase(b);

		cout << su << "\n";
	}
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


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

struct lan {
    int x;
    int y;
    int w;
    lan(){}
    ~lan(){}
};

bool cmp_x(const lan& a, const lan& b){
    return a.x < b.x;
}

bool cmp_y(const lan& a, const lan& b){
    return a.y < b.y;
}

int main() {
    int N, W, H;
    lan p[100000];
    scanf("%d%d%d", &N, &W, &H);
    for(int i = 0; i < N; ++i){
        scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].w); 
    }
    bool answer = false;
    int av[100005], ac = 0;
    bool flg;
    sort(p, p + N, cmp_x);
    fill(av, av + W + 1, 0);
    for(int i = 0; i < N; ++i){
        ++av[max(0, p[i].x - p[i].w)];
        --av[min(W, p[i].x + p[i].w)];
    }
    //for(int i = 0; i < W; ++i){ printf("%d ", av[i]); } printf("\n");
    ac = 0;
    flg = true;
    for(int i = 0; i < W; ++i){
        ac += av[i];
        flg = flg && !!ac;
        if(!flg) break;
    }
    answer = answer || flg;
    sort(p, p + N, cmp_y);
    fill(av, av + H + 1, 0);
    flg = true;
    for(int i = 0; i < N; ++i){
        ++av[max(0, p[i].y - p[i].w)];
        --av[min(H, p[i].y + p[i].w)];
    }
    //for(int i = 0; i < H; ++i){ printf("%d ", av[i]); } printf("\n");
    ac = 0;
    flg = true;
    for(int i = 0; i < H; ++i){
        ac += av[i];
        flg = flg && !!ac;
        if(!flg) break;
    }
    answer = answer || flg;
    printf("%s\n", answer ? "Yes" : "No");
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> c;
    s += c;
  }
  set<int> se;
  for (int i = 0; i < n; ++i) {
    for (int m = 1; m <= 3; ++m) {
      se.insert(stoi(s.substr(i, m)));
    }
  }
  for (int x = 0; ; ++x) {
    if (not se.count(x)) {
      cout << x << '\n';
      return 0;
    }
  }
}



Measured memory_bytes: 3272
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int N;
int A[100005];
int ans;

signed main(){
    cin>>N;
    for(int i=0;i<N;++i)cin>>A[i];
    sort(A,A+N);
    int cnt=1;
    if(N==1){
        cout<<1<<endl;
        return 0;
    }
    for(int i=1;i<N;++i){
        if(A[i]==A[i-1])cnt++;
        else {
            if(cnt&1)ans++;
            cnt = 1;
        }
    }
    if(cnt&1)ans++;
    cout<<ans<<endl;
}


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

int main(){
    int N;
    std::cin >> N;
    std::vector< std::string > s(N);
    for(int i=0; i<N; i++){
        std::cin >> s[i];
    }
    
    int AB_cnt = 0, lastA_cnt = 0, firstB_cnt = 0, lAfB_cnt = 0;
    for(int i=0; i<N; i++){
        if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A'){
            lAfB_cnt++;
        }else if(s[i][0] == 'B'){
            firstB_cnt++;
        }else if(s[i][s[i].size()-1] == 'A'){
            lastA_cnt++;
        }
        bool A_flag = false;
        for(int j=0; j<s[i].size(); j++){
            if(s[i][j] == 'A'){
                A_flag = true;
            }else if(A_flag && s[i][j] == 'B'){
                AB_cnt++;
                A_flag = false;
            }else{
                A_flag = false;
            }
        }
    }
    
    int ans = AB_cnt;
    if(lAfB_cnt > 0){
        ans += lAfB_cnt - 1;
        if(lastA_cnt > 0){
            ans++;
            lastA_cnt--;
        }
        if(firstB_cnt > 0){
            ans++;
            firstB_cnt--;
        }
    }
    ans += std::min(lastA_cnt, firstB_cnt);
    
    std::cout << ans << std::endl;
    
    
    return 0;
}



Measured memory_bytes: 768