akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LEN 100005

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

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

int isEmpty(){
	if(head==tail){
		return 1;
	}
	else{
		return 0;
	}
}

int isFull(){
	if(head==(tail+1)%LEN){
		return 1;
	}
	else{
		return 0;
	}
	
}

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

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

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

	for ( 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();
		if(q<u.t){
			u.t=u.t-q;
			elaps=elaps+q;
			enqueue(u);
		}
		else{
			elaps=elaps+u.t;
			printf("%s %d\n",u.name,elaps);
		}
	}
  return 0;
}


Measured memory_bytes: 11852
#include <stdio.h>
#include <stdlib.h>
int main (){
	int N,D;
	scanf("%d",&N);
	int A[100002];
	A[0] = 0;
	A[N+1]=0;
	for(int i=1;i<=N;i++){
		scanf("%d",&A[i]);
	}
	//まずはすべての経路を通ったときの距離Dを求める。
	D=0;
	for(int i=0;i<N+1;i++){
		D = D + abs( A[i] -A[i+1]);
	}
	//次にi番目を抜かした場合のことを考える
	int X =0;
	for(int i=1;i<N+1;i++){
	//i は抜かす番号
		X = 0;
		X = X + abs(A[i-1] - A[i]);
		X = X + abs(A[i] - A[i+1]);
		X = X - abs(A[i-1] -A[i+1]);
		printf("%d\n",D-X);
	}
	return 0;
}

Measured memory_bytes: 1536
import java.math.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.*;
public class Main {
    public static long num[] = new long[1023];
    public static int k=0;
    public static void main(String args[])throws IOException
    {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        int a = (int)in.nval;
        in.nextToken();
        int b = (int)in.nval;
        out.println(a*b);
        out.flush();
    }
                  }

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

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(void){
    int N,A[10],ans;
    int cnt1 = 0;
    int cnt2 = 0;
    cin >> N;
    for (int i=0;i<N;i++){
        cin >> A[i];
        if (A[i] % 2 == 1) cnt1++;
        else cnt2++;
    }
    //cout << cnt1 << endl;
    cout << pow(3,N) - pow(2,cnt2) << endl;

}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp.to!long;
    auto AS = readln.split.to!(long[]);
    auto BS = readln.split.to!(long[]);

    long solve(long N, long[] XS, long[] YS) {
        int[] ps;
        foreach (i; 0..3) if (XS[i] < YS[i]) ps ~= i;

        if (ps.length == 1) {
            auto i = ps[0];
            N = N/XS[i]*YS[i] + N%XS[i];
        } else if (ps.length == 2) {
            auto i = ps[0];
            auto j = ps[1];

            auto n = N;
            foreach (x; 0..N/XS[i]+1) {
                auto nn = N - x*XS[i];
                n = max(n, x*YS[i] + nn/XS[j]*YS[j] + nn%XS[j]);
            }
            N = n;
        } else if (ps.length == 3) {
            auto n = N;
            foreach (x; 0..N/XS[0]+1) {
                auto nn = N - x*XS[0];
                foreach (y; 0..nn/XS[1]+1) {
                    auto nnn = nn - y*XS[1];
                    auto z = nnn/XS[2];
                    n = max(n, x*YS[0] + y*YS[1] + z*YS[2] + nnn%XS[2]);
                }
            }
            N = n;
        }
        return N;
    }
    writeln(solve(solve(N, AS, BS), BS, AS));
}

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

int main() {
    string sa,sb,sc;
    int A,B,C;

    cin >> sa >> sb >> sc;
    A=sa.size();
    B=sb.size();
    C=sc.size();
    char ch;
    for(int i=0;;i++){
        if(i==0){
            ch=sa[0];
            A--;
            sa.erase(sa.begin(),sa.begin()+1);
        }
        if(ch=='a'){
            
            if(A==0){
                cout << "A" << endl;
                return 0;
            }else {
                A--;
                ch=sa[0];
                sa.erase(sa.begin(),sa.begin()+1);
                
            }
            
        }
        else if(ch=='b'){
            if(B==0){
                cout << "B" << endl;
                return 0;
            }
            B--;
            ch=sb[0];
            sb.erase(sb.begin(),sb.begin()+1);
            
        }
        else if(ch=='c'){
            if(C==0){
                cout << "C" << endl;
                return 0;
            }else {
                C--;
                ch=sc[0];
                sc.erase(sc.begin(),sc.begin()+1);
            }
        }
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
	long long x;
	cin>>x;
	vector<long long> hoge;
	for(long long i=-4000;i<=4000;i++){
		hoge.push_back(i*i*i*i*i);
	}
	for(int i=0;i<hoge.size();i++){
		int id=lower_bound(hoge.begin(),hoge.end(),hoge[i]+x)-hoge.begin();
		if(hoge[id]==hoge[i]+x){
			cout<<-4000+id<<" "<<-4000+i<<endl;
			break;
		}
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int b=0,a=0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == '1') a++;
    else b++;
  }
  cout << min(a,b) * 2 << endl;
}

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


int main() {
  int a[3][3];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  vector<int> b(n);
  for(int k = 0; k < n; k++){
    cin >> b[k];
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        if(b[k]== a[i][j]) a[i][j] = 0;
      }
    }
  }
  
  bool h = false;
  bool w = false;
  bool c = false;
  
  for(int i = 0; i < 3; i++){
    bool hx = true;
    bool wx = true;
    for(int j = 0; j < 3; j++){
      if(a[i][j] != 0) hx = false;
      if(a[j][i] != 0) wx = false;
    }
    if(hx) h = true;
    if(wx) w = true;
  }
  if(a[1][1] == 0){
    if(a[0][0] == 0 && a[2][2] == 0) c = true;
    if(a[2][0] == 0 && a[0][2] == 0) c = true;
  }
  
  if(h || w || c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
from string import ascii_lowercase
import sys
input=sys.stdin.readline
s=input().rstrip()
t=input().rstrip()
for alp in ascii_lowercase:
    switch=0
    for i in range(len(s)):
        if switch==0:
            if s[i]==alp:
                rem=t[i]
                switch=1
        else:
            if s[i]==alp:
                if t[i]!=rem:
                    print("No")
                    exit()
for alp in ascii_lowercase:
    switch=0
    for i in range(len(s)):
        if switch==0:
            if t[i]==alp:
                rem=s[i]
                switch=1
        else:
            if t[i]==alp:
                if s[i]!=rem:
                    print("No")
                    exit()
print("Yes")

Measured memory_bytes: 69996
#include <iostream>
#include <iomanip>

using namespace std;

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

    long long int d = a / b;
    long long int r = a % b;
    long double f = static_cast<long double>(a) / static_cast<long double>(b);

    cout << setprecision(100) << fixed << d << " " << r << " " << f << "\n";
    return 0;
}



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

int H, W, D, Q;
int A[310][310];
pii pos[90010];
int cost[90010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W >> D;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
      pos[A[i][j]] = pii(i, j);
    }
  }
  for (int i = D + 1; i <= H * W; i++) {
    cost[i] = cost[i - D] + abs(pos[i].first - pos[i - D].first) + abs(pos[i].second - pos[i - D].second);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int L, R;
    cin >> L >> R;
    cout << cost[R] - cost[L] << endl;
  }

  return 0;
}

Measured memory_bytes: 2688
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
const int INF = (1<<30);

int N, M;
vector<vector<pair<int, int>>> g;
priority_queue<pair<int, int>> heap;
vector<int> dist;

bool dfs(int el, int delta) {
    //debug() << el << " -> " << delta;
    if (dist[el] != -INF) {
        //debug() << dist[el] << " " << delta;
        return dist[el] == delta;
    }

    dist[el] = delta;

    for (auto entry : g[el]) {
        if (!dfs(entry.first, delta + entry.second)) {
            return false;
        }
    }

    return true;
}

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

    cin >> N >> M;
    g.resize(N);

    for (int i = 0; i < M; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        g[l].emplace_back(r, d);
        g[r].emplace_back(l, -d);
    }

    dist.assign(N, -INF);

    for (int i = 0; i < N; i++) {
        if (dist[i] == -INF) {
            if (!dfs(i, 0)) {
                cout << "No\n";
                return 0;
            }
        }
    }
    
    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
ll k;
ll sum;
const int Maxn=5005;
ll a[Maxn];
bool dp[Maxn];
int main(){
	scanf("%d%lld",&n,&k);
	rep(i,n){
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	sort(a,a+n);
	dp[0]=true;
	int res=0;
	for(int i=n-1;i>=0;i--){
		bool up=false;
		rep(j,k){
			if(dp[j]&&j+sum>=k){
				up=true;
				break;
			}
		}
		if(!up)res++;
		sum-=a[i];
		for(int j=k-1;j>=a[i];j--){
			dp[j]|=dp[j-a[i]];
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1);
    for(int i=0;i<=n;i++) cin>>a[i];
    vector<int> b(n);
    for(int i=0;i<n;i++) cin>>b[i];

    ll res=0;
    for(int i=0;i<n;i++){
        int tmp=min(a[i],b[i]);
        res+=tmp;
        b[i]-=tmp;
        a[i]-=tmp;
        tmp=min(a[i+1],b[i]);
        res+=tmp;
        b[i]-=tmp;
        a[i+1]-=tmp;
    }
    cout<<res<<endl;
    
    return 0;
}


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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(STL) STL.begin(), STL.end()
#define stl_rep(itr, STL) for (auto itr = STL.begin(); itr != STL.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int n = s.size();
    int accum_g = 0, accum_p = 0, win = 0, lose = 0;
    rep(i, n) {
        if (s[i] == 'g') {
            if (accum_g - accum_p > 0) {
                ++accum_p;
                ++win;
            } else {
                ++accum_g;
            }
        } else {
            if (accum_g - accum_p > 0) {
                ++accum_p;
            } else {
                ++accum_g;
                ++lose;
            }
        }
    }

    cout << win - lose << endl;

    return 0;
}

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

using namespace std;


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

    int k;
    cin >> k;
    long long sum =0;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= k; ++j) {
            for (int l = 1; l <= k; ++l) {
                sum += __gcd(__gcd(i, j),l);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3648
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  combination c(n+k);
  mint ans = 0;
  for (int i = 0; i <= k; ++i) {
    mint now = mint(26).pow(k-i);
    now *= mint(25).pow(i);
    now *= c(i+n-1,n-1);
    ans += now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35576
<?php

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d", $N);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));

$maxArr = [$A[0]];
for ($i = 1; $i < $N; $i++) {
    if ($maxArr[$i - 1] < $A[$i]) {
        $maxArr[$i] = $A[$i];
    } else {
        $maxArr[$i] = $maxArr[$i - 1];
    }
}

$total = 0;
for ($i = 1; $i < $N; $i++) {
    if ($maxArr[$i - 1] > $A[$i]) {
        $total += $maxArr[$i - 1] - $A[$i];
    }
}

echo $total, PHP_EOL;

Measured memory_bytes: 39184
n,q = map(int,input().split())
s = input()
cnt = [0] * (n+1)
for i in range(n):
    if s[i:i+2] == "AC":
        cnt[i+1] = cnt[i] + 1
    else:
        cnt[i+1] = cnt[i]
for i in range(q):
    l,r = map(int,input().split())
    print(cnt[r-1]-cnt[l-1])

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

int main() {
    int n;
    cin >> n;
    int64_t ans = n;
    vector<pair<int64_t, int64_t>> x(n);
    for (auto i = 0; i < n; i++) cin >> x[i].first >> x[i].second;
    for (auto i = 0; i < n; i++) {
        for (auto j = 0; j < n; j++) {
            if (j == i) continue;
            auto p = x[i].first - x[j].first, q = x[i].second - x[j].second;
            int64_t t = 0;
            for (auto k = 0; k < n; k++) {
                for (auto l = 0; l < n; l++) {
                    if(x[k].first - p == x[l].first and
                       x[k].second - q == x[l].second) {
                       t++;
                       break;
                    }
                }
            }
            ans = min(ans, n - t);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>a>>b;
    cnt=1;
    while(1){
        if(cnt>=b)break;
        cnt--;
        cnt+=a;
        ans++;
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>


int main()
{
	int i;
	char s;
	int sum[26];
    for(i=0;i<26;i++)
		sum[i] = 0;
    while(scanf("%c",&s)!=EOF){

		if( s>='a' && s<='z')
			sum[ s%'a' ]++;

		else if(s>='A' && s<='Z')
			sum[ s%'A' ]++;

	}
        for(i=0;i<26;i++)
            printf("%c : %d\n",'a'+i , sum[i]);
return 0;
}




Measured memory_bytes: 2048
//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_c"
package main

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

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *scanner) IntSlice2(l, n int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := 0; i < n; i++ {
		sl[i] = s.Int()
	}
	return sl
}

func solve(n int, u [][]int) int {
	t := make([][]int, n+1, n+1)
	for i := range t {
		t[i] = make([]int, 3, 3)
	}
	t[0] = u[0]
	for d := 0; d < n; d++ {
		for sel := 0; sel <= 2; sel++ {
			for k := range u[d] {
				if k == sel {
					continue
				}
				if v := t[d][sel] + u[d+1][k]; t[d+1][k] < v {
					t[d+1][k] = v
				}
			}
		}
	}
	max := math.MinInt64
	for _, v := range t[n-1] {
		if max < v {
			max = v
		}
	}
	return max
}

func main() {
	scan := newScanner(os.Stdin)
	n := scan.Int()
	u := make([][]int, n+1, n+1)
	for i := 0; i <= n; i++ {
		u[i] = []int{scan.Int(), scan.Int(), scan.Int()}
	}
	fmt.Println(solve(n, u))
}


Measured memory_bytes: 13320
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        long current = 100000;

        int weekCount = int.Parse(Reader.ReadLine());

        for (int i = 0; i < weekCount; i++) {
            current = (long)(current * 1.05);
            if(current%1000>0) {
                current = (current / 1000 + 1) * 1000;
            }
        }
        Console.WriteLine(current);
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



5


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 8952
// Tenshi ni Fureta yo!

#include <bits/stdc++.h>

using namespace std;

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

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

namespace fastIO
{
	const UI BUFFER_SIZE = (UI) 1 << 15;
	char buffer[BUFFER_SIZE], *cur, *ed;

	inline char getc() { return *(cur == ed ? ed = buffer + fread(buffer, 1, BUFFER_SIZE, stdin), cur = buffer : cur)++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

template<typename T> inline T sqr(const T &val) { return val * val; }
template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }

// END tpl.

const int MAXN = 300;

int MOD;

namespace MATH
{
	const int n = MAXN * 2;

	int C[n + 5][n + 5];

	inline void init()
	{
		C[0][0] = 1;
		for(int i = 1; i <= n; ++i)
		{
			C[i][0] = 1;
			for(int j = 1; j <= i; ++j) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
		}
	}
}
using MATH::C;

int n, K;

inline void input()
{
	n = read<int>(), K = read<int>(), MOD = read<int>();
}

inline void solve()
{
	static int f[MAXN + 5][MAXN + 5], suf[MAXN + 5][MAXN + 5];

	for(int i = 0; i <= K; ++i) f[1][i] = 1;
	for(int i = K; i >= 0; --i) suf[1][i] = (f[1][i] + suf[1][i + 1]) % MOD;

	for(int i = 2; i <= n + 1; ++i) for(int j = K; j >= 0; --j)
	{
		f[i][j] = 0;
		for(int k = 1; k < i; ++k) (f[i][j] += (LL) f[i - k][j] * suf[k][j + 1] % MOD * C[i - 2][k - 1] % MOD) %= MOD;
		suf[i][j] = (suf[i][j + 1] + f[i][j]) % MOD;
	}

	printf("%d\n", (f[n + 1][0] + MOD) % MOD);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	input();
	MATH::init();
	solve();

	return 0;
}




Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
#define lc (root<<1)
#define rc (root<<1|1)
#define lowbit(x) (x&-x)
using namespace std;
const int N = 2e5+7;
const ll inf = 1e18;
int n, m;
ll tre[N<<2], tag[N<<2];
vector<pair<int, int> > vec[N];
void push_down(int root)
{
	if(tag[root])
	{
		ll c = tag[root];
		tag[lc] += c;
		tag[rc] += c;
		tre[lc] += c;
		tre[rc] += c;
		tag[root] = 0;
	}
	return;
}
ll query(int root, int l, int r, int fl, int fr)
{
	if(l>fr||r<fl)
	{
		return 0;
	}
	if(l>=fl&&r<=fr)
	{
		return tre[root];
	}
	push_down(root);
	return max(query(lc, l, mid, fl, fr), query(rc, mid+1, r, fl, fr));
}
void modify(int root, int l, int r, int fl, int fr, ll v)
{
	if(l>fr||r<fl)
	{
		return;
	}
	if(l>=fl&&r<=fr)
	{
		tre[root] += v;
		tag[root] += v;
		return;
	}
	push_down(root);
	modify(lc, l, mid, fl, fr, v);
	modify(rc, mid+1, r, fl, fr, v);
	tre[root] = max(tre[lc], tre[rc]);
	return;
}
int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; i++)
    {
    	int l, r, v;
    	scanf("%d%d%d", &l, &r, &v);
    	vec[r].push_back(make_pair(l, v));
    }
    for(int i = 1; i <= n; i++)
    {
    	sort(vec[i].begin(), vec[i].end(), greater<pair<int, int> >());
    }
    for(int i = 1; i <= n; i++)
    {
		ll res;
		res = query(1, 1, n, 1, i);
    	for(int j = 0; j < vec[i].size(); j++)
    	{
			modify(1, 1, n, vec[i][j].first, i, vec[i][j].second);
    	}
    	modify(1, 1, n, i, i, res);
    }
    printf("%lld\n", max(0ll, query(1, 1, n, 1, n)));
    return 0;
}

Measured memory_bytes: 22912
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	while(1){
		int n, k;
		scanf("%d %d", &n, &k);
		if(n == 0 && k == 0) break;
		vector<int> v;
		for(int i=0; i<k; i++){
			int t;
			scanf("%d", &t);
			v.push_back(t);
		}
		sort(v.begin(), v.end());
		int ans = 1;

		if(v[0] != 0){
			int dp[k];
			dp[0] = 1;
			for(int i=1; i<k; i++){
				if(v[i] - v[i-1] == 1) dp[i] = dp[i-1] + 1;
				else dp[i] = 1;
				ans = max(ans, dp[i]);
			}
		}else{
			vector<int> w;
			int dp[k];
			dp[1] = 1;
			for(int i=2; i<k; i++){
				if(v[i] - v[i-1] == 1) dp[i] = dp[i-1] + 1;
				else{
					w.push_back(dp[i-1]);
					dp[i] = 1;
				}
			}
			w.push_back(dp[k-1]);
			for(int i=0; i<w.size()-1; i++){
				ans = max(ans, w[i] + 1 + w[i+1]);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3228
#include <stdio.h>
int main()
{
    int a, b, i, j, k;
    for(i=0; ; i++){
        scanf("%d %d", &a, &b);
        if(a==0 && b==0)
            return 0;
        for(j=0; j<a; j++){
            for(k=0; k<b; k++){
                if(j==0 || k==0 || k==b-1 || j==a-1)
                    printf("#");
                else
                    printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2548
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
T = []
L = [-1 for j in range(26)]
for i in range(d):
    max_diff = -10**7
    arg_max = 0
    for j in range(26):
        memo = L[j]
        L[j] = i
        diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)])
        if diff > max_diff:
            max_diff = diff
            arg_max = j
        L[j] = memo
    T.append(arg_max)
    L[arg_max] = i
for t in T:
    print(t + 1)


Measured memory_bytes: 74436
import sys
sys.setrecursionlimit(pow(10, 6))
N = 12
rs = []
def f(s, bb):
    if len(s) == N:
        rs.append(int(s))
        return
    b = int(s[-1])
    r = []
    if bb == 0:
        for i in range(10):
            if i == 0:
                f(s+str(i), bb)
            else:
                f(s+str(i), 1)
        return
    if b > 0:
        f(s+str(b-1), 1)
    f(s+str(b), 1)
    if b < 9:
        f(s+str(b+1), 1)

f(str(0), 0)
print(rs[int(input())])


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

int main()
{
  int n;  
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >>a.at(i);
  }
  
  sort(a.begin(), a.end(), greater<int>() );
  
  int ans = 0;
  for(int i = 0; i < n - 1; i += 2){
    ans += a.at(i) - a.at(i + 1);
  }
  
  if(n % 2){
    ans += a.at(n - 1);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

int main(){
    int A,B; cin>> A >> B;
    if(A<=B){
        if((A+B)%2==0){
            cout << (A+B)/2 << endl;
        }
        else{
            cout << "IMPOSSIBLE" << endl;
        }
    }
    else{
        if((A+B)%2==0){
            cout << (A+B)/2 << endl;
        }
        else{
            cout << "IMPOSSIBLE" << endl;
        }
    }
}

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

using namespace std;

#define MMAX 100
#define INF 10000000

typedef pair<int,int> PII;

struct side{
	int dir,wei[2];
};

int main(void){

	int n,m;
	int a,b,cost,time;
	int k;
	int p,q,r;
	int nod[MMAX+1];
	vector<side> ed[MMAX+1];
	priority_queue<PII,vector<PII>,greater<PII> > pq;
	side tmp;
	PII pii;
	int nm;

	while(1){

		for(int i=0;i<=MMAX;i++) nod[i]=0;
		for(int i=0;i<=MMAX;i++){
			if(!ed[i].empty()) ed[i].clear();
		}
		while(!pq.empty()) pq.pop();

		cin>>n>>m;
		if(n==0&&m==0) break;

		for(int i=0;i<n;i++){
			cin>>a>>b>>cost>>time;
			tmp.dir=b,tmp.wei[0]=cost,tmp.wei[1]=time;
			ed[a].push_back(tmp);
			tmp.dir=a;
			ed[b].push_back(tmp);
		}

		cin>>k;

		for(int i=0;i<k;i++){

			cin>>p>>q>>r;
			for(int j=0;j<=m;j++) nod[j]=INF;
			nod[p]=0;
			pq.push(PII(0,p));

			while(!pq.empty()){
				pii=pq.top();
				pq.pop();
				nm=pii.second;
				if(nod[nm]<pii.first) continue;
				for(int j=0;j<ed[nm].size();j++){
					tmp=ed[nm][j];
					if(nod[tmp.dir]>nod[nm]+tmp.wei[r]){
						nod[tmp.dir]=nod[nm]+tmp.wei[r];
						pq.push(PII(nod[tmp.dir],tmp.dir));
					}
				}
			}
			cout<<nod[q]<<endl;

		}

	}

}

Measured memory_bytes: 1308
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int dm = 1 << 17;
char *dn = cn, * di = dn, * owad = dn + dm - 20;
inline void putint(int X) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int keta = 0;
	char C[6];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}
const int bm = 500001;
int BIT[bm];
void add(int A) {
	while (A > 0) {
		BIT[A]++;
		A -= A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A < bm) {
		ret += BIT[A];
		A += A & -A;
	}
	return ret;
}
int L[500001], R[500001], C[500001], ne[500001];
int are[500001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), Q = getint();
	rep1(i, N) C[i] = getint();
	rep1(i, Q) {
		L[i] = getint();
		int r = getint();
		ne[i] = R[r];
		R[r] = i;
	}
	rep1(i, N) {
		if (are[C[i]]) add(are[C[i]]);
		are[C[i]] = i;
		
		for (int r = R[i]; r; r = ne[r]) {
			L[r] = i - L[r] - query(L[r]) + 1;
		}
	}

	rep1(i, Q) putint(L[i]);
	fwrite(dn, 1, di - dn, stdout);


	Would you please return 0;
}

Measured memory_bytes: 14888
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int n,s,a;
	while(~scanf("%d",&n)){
		s = 0;
		for(int i=0;i<n;i++){
		scanf("%d",&a);
		if(a%2 == 0)
			s++;
		}
		int ans;
		ans = pow(3,n)-pow(2,s);
		printf("%d\n",ans);
	}
	
} 

Measured memory_bytes: 512
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
if not n % 2:
    print(n * (n-1) // 2 - n // 2)
    for i in range(1, n+1):
        for j in range(1, n+1):
            if i + j != n + 1 and i < j:
                print(i, j)
else:
    print(n * (n - 1) // 2 - (n - 1) // 2)
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if i + j != n and i < j:
                print(i, j)

Measured memory_bytes: 44144
N = int(input())
A = list(map(int, input().split()))
rain_sum = sum(A) // 2
rain_other = 0
for i in range((N - 1) // 2):
    rain_other += A[(2 * i + 1) % N]
rain_before = (rain_sum - rain_other) * 2
print(rain_before, end = ' ')
for i in range(N - 1):
    rain_before = 2 * A[i] - rain_before
    print(rain_before, end = ' ')


Measured memory_bytes: 14092
#include<stdio.h>
#include<string.h>
int main(void)
{
    int a,b,i,c=0;
    char s[11];
    scanf("%d%d%s",&a,&b,s);
    for(i=0;i<a;i++){
        if((s[i]>='0')&&(s[i]<='9'))
            c++;
    }
    if(s[i]=='-')
        c++;
    i++;
    while(i<=a+b){
        if((s[i]>='0')&&(s[i]<='9'))
            c++;
        i++;
    }
    if(c==strlen(s))
        printf("Yes\n");
    else 
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b, ans int
	var s string
	fmt.Scan(&a, &b)
	for i := a; i <= b; i++ {
		s = strconv.Itoa(i)
		palindrome := true
		for j := 0; j < len(s)/2; j++ {
			if s[j] != s[len(s)-j-1] {
				palindrome = false
				break
			}
		}
		if palindrome {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;
const double PI=3.14159265358979323846;

int main (){
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    rep(i,0,N) {
        cin >> A[i];
    }

    ll tmp = 1;
    ll cnt = 1;
    while(tmp<K) {
        tmp*=2;
        cnt++;

    }
    //cout << cnt << endl;

    ll B[cnt][N];

    rep(i,0,N) {
        B[0][i] = A[i];
    }

    rep(i,1,cnt) {
        rep(j,0,N) {
            B[i][j] = B[i-1][B[i-1][j]-1];
        }
    }

    ll ans = 1;
    rep(i,0,cnt) {
        if (K>>i & 1) {
            ans = B[i][ans-1];
        }
    }

    cout << ans << endl;


}





Measured memory_bytes: 100104
//c.c C-*3 or /2
#include<stdio.h>

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

    for(int i=0;i<n;++i){
        while(a[i]%2==0){
            eve++;
            a[i] /= 2;
        }
    }

    printf("%d\n",eve);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sum(a)
for i in range(n):
  a[i], b[i] = max(a[i]-b[i], 0), max(b[i]-a[i], 0)
  a[i+1] = max(a[i+1]-b[i], 0)
  
s2 = sum(a)
print(s-s2)

Measured memory_bytes: 24240
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int, int> P;
Int m, n, i, j, k, a, b, c, d;
main()
{
    string s;
    cin >> s;
    for( int i = 0; i < s.size()-1; i++ )
    {
        if( s[i] == s[i + 1] ) {
            puts( "Bad");
            return 0;
        }
    }
    puts("Good");
    return 0;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    set<int> b;
    map<int, int> cnv;
    rep(i, N) cin >> a[i];
    rep(i, N) cnv[a[i]] = i;
    rep(i, N) {
        int t;
        cin >> t;
        b.insert(t);
    }
    if (a.size() == b.size()) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
        vector<int> c(N), d(N);
        rep(i, N) {
            if (b.count(a[i])) {
                d[cnv[a[i]]] = c[cnv[a[i]]] = 1;
            } else {
                d[cnv[a[i]]] = 1;
                c[cnv[a[i]]] = 2;
            }
        }
        rep(i, N) cout << c[i] << (i + 1 == N ? "" : " ");
        cout << endl;
        rep(i, N) cout << d[i] << (i + 1 == N ? "" : " ");
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 12600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int m=1000000000;
  int c=0;
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    m=min(m,abs(a.at(i)));
    c+=(a.at(i)<=0?1:0);
  }
  int64_t s=0;
  for(int i=0;i<n;i++)
    s+=abs(a.at(i));
  cout<<s-(c%2==1?m*2:0)<<endl;
}

Measured memory_bytes: 640
from collections import Counter

input()
V = [int(v) for v in input().split()]
count1 = 0
count2 = 0
c11 = Counter(V[::2]).most_common()[0][0]
c12 = Counter(V[1::2]).most_common()[0][0]
for v1, v2 in zip(V[::2], V[1::2]):
    if v1 != c11:
        count1 += 1
    if v2 != c12:
        count2 += 1
c21 = Counter(V[1::2]).most_common()
c22 = Counter(V[::2]).most_common()
c21.append((0, 1))
c22.append((0, 1))
c21 = c21[0][0] if c21[0][0] != c11 else c21[1][0]
c22 = c22[0][0] if c22[0][0] != c12 else c22[1][0]
for v1, v2 in zip(V[1::2], V[::2]):
    if v1 != c21:
        count1 += 1
    if v2 != c22:
        count2 += 1
print(min(count1, count2))

Measured memory_bytes: 20636
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4 4");
            WillReturn.Add("1 2");
            WillReturn.Add("2 3");
            WillReturn.Add("3 4");
            WillReturn.Add("4 2");
            //Yes
            //1
            //2
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("6 9");
            WillReturn.Add("3 4");
            WillReturn.Add("6 1");
            WillReturn.Add("2 4");
            WillReturn.Add("5 3");
            WillReturn.Add("4 6");
            WillReturn.Add("1 5");
            WillReturn.Add("6 2");
            WillReturn.Add("4 5");
            WillReturn.Add("5 6");
            //Yes
            //6
            //5
            //5
            //1
            //1
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int N = wkArr[0];

        // 移動可能な座標のSetのDict
        var LinkListDict = new Dictionary<int, HashSet<int>>();

        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();
        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            int A = wkArr[0];
            int B = wkArr[1];

            Action<int, int> AddAct = (pFrom, pTo) =>
            {
                if (LinkListDict.ContainsKey(pFrom) == false) {
                    LinkListDict[pFrom] = new HashSet<int>();
                }
                LinkListDict[pFrom].Add(pTo);
            };
            AddAct(A, B);
            AddAct(B, A);
        }

        var Que = new Queue<int>();
        Que.Enqueue(1);

        var AnswerDict = new Dictionary<int, int>();
        var Visited = new HashSet<int>();
        Visited.Add(1);

        while (Que.Count > 0) {
            int Dequeued = Que.Dequeue();

            foreach(int EachInt in LinkListDict[Dequeued]){
                //再訪禁止
                if (Visited.Add(EachInt) == false) {
                    continue;
                }
                Que.Enqueue(EachInt);
                AnswerDict[EachInt] = Dequeued;
            }
        }
        Console.WriteLine("Yes");
        for (int I = 2; I <= N; I++) {
            Console.WriteLine(AnswerDict[I]);
        }
    }
}


Measured memory_bytes: 94312
#include <bits/stdc++.h>
using namespace std;
#define N 100005

template <class T>
void scan(T &number)
{
    bool negative = false;
    register T c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}

int n,A,B;
int h[N],Max;

bool  check(int x)
{
	int least = x;
	for(int i = 1; i <= n && least >= 0; i++)
		least-=(max(h[i] - x * B, 0) + A - 1) / A;
	return (least>=0);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	scan(n); scan(A); scan(B);
	A-=B;
	for(int i = 1; i <= n; i++)
	{
		scan(h[i]);
		Max=max(Max, h[i]);
	}

	int l = 0, r = Max / B + 1;

	while(l < r)
	{
		int mid = l + r >> 1;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%d\n", l);
    return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll x;cin >> x;
    vi div;
    for(int i=1;i*i<=x;i++){
        if(x%i==0){
            div.push_back(i);
            if(i*i!=x)div.push_back(x/i);
        }
    }
    
    for(int a=0;a<=x;a++){
        for(int i=0;i<div.size();i++){
            int b = a - div[i];
            if((ll)pow(a,5) - (ll)pow(b,5) == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4272
// g++ -std=c++14 -O2 -Wall qa.cpp
#include <bits/stdc++.h>
using namespace std;

typedef long long 		ll;
typedef vector<int>		VI;
typedef vector<bool>  	VB;
typedef vector<ll>  	VLL;
typedef pair<int, int>  PII;
typedef pair <ll, ll>  	PLL;
typedef vector<PII>  	VPII;
typedef tuple<int,int,int>  TI;

typedef unordered_set<int> USI;
typedef set<int> SI;

typedef unordered_map<int, int> UMP;
typedef map<int, int> MP;

typedef queue<int> QI;
typedef queue<PII> QP;

typedef priority_queue<int> PQI;
typedef priority_queue<PII> PQP;

#define sc(n)		scanf("%d",&n)
#define sc2(i,j)	scanf("%d%d",&i,&j)
#define sc3(i,j,k)	scanf("%d%d%d",&i,&j,&k)
#define scl(n) 		scanf("%lld",&n)
#define scf(n) 		scanf("%lf",&n)
#define scs(n)  	scanf("%s",n)

#define FOR(i,x,y) 	for(int i=(x); i<=(y); i++)
#define REV(i,x,y) 	for(int i=(x); i>=(y); i--)
#define ALL(v) 		(v).begin(),(v).end()
#define SZ(v) 		(int)v.size()

#define PR(i)		printf("%d\n", (i))
#define PRL(i)		printf("%lld\n", (i))
#define PRA(arr)	FOR(i,0,(arr.size()-1)){ cout << arr[i] << " ";} cout << "\n"
#define PRV(v)		for(auto i : v) { cout << i << " ";} cout << "\n"

#define DBG2(i,j)	cout <<"DBG: "<< i << " " << j << endl
#define DBG3(i,j,k)	cout <<"DBG: "<< i << " " << j << " " << k << endl

#define bit(x,i) (x&(1<<i)) //ith bit of x;
#define ceilint(a,k) ((a-1)/k + 1) // round up a/k
#define min3(x,y,z) min(x,min(y,z))
#define max3(x,y,z) max(x,max(y,z))

#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define mod 1000000007

char a[6][6];
int h,w,k;
ll ans;
int ph, pw;
struct pair_hash {
    inline std::size_t operator()(const std::pair<int,int> & v) const {
        return v.first*31+v.second;
    }
};

unordered_set<PII, pair_hash> st;

void solve(int r, int c){
    if(r == ph || c == pw) return;
    if(st.count({r,c})) return;
    st.insert({r,c});
    bitset<7> br(r);
    bitset<7> bc(c);
    int bl = 0;

    FOR(i, 0 , h-1) {
        if(br[i]) continue;
        FOR (j, 0 , w -1){
            if(bc[j]) continue;
            if(a[i][j] == '#') bl++;
        }
    }
    if(bl == k) {
        ans++;
        //DBG3(br,bc,bl);
    }
    solve(r+1, c);
    solve(r, c+1);
}

int main() {
	ios::sync_with_stdio(false);
    cin >> h >> w >> k;
    ph = pow(2,h);
    pw = pow(2,w);
    string s;
    getline(cin, s);

    FOR(i, 0 , h-1) {
        getline(cin, s);
        FOR (j, 0 , w -1){
            a[i][j] = s[j];
        }
    }
    solve(0,0);
    PRL(ans);

	return 0;
}


Measured memory_bytes: 4404
A,B = map(int,input().split())
grid_b = [["#"]*100 for i in range(50)]
grid_w = [["."]*100 for i in range(50)]
for i in range(A-1):
    grid_b[(i//50)*2][(i%50)*2] = "."
for i in range(B-1):
    grid_w[49-(i//50)*2][(i%50)*2] = "#"
grid = grid_b+grid_w
print(100,100)
for y in grid:
    for x in y:
        print(x,end="")
    print()

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

int main () {
  int N,X;
  cin >> N >> X;
  
  vector<int> vec(N);
  for (int i=0;i<N;i++) {
    cin >> vec.at(i);
    X-=vec.at(i);
  }
  
  int a=1000;
  for (int i=0;i<N;i++) {
    if (a>vec.at(i)) {
      a=vec.at(i);
    }
  }
  
  cout << N + (X / a) << endl;
  
  
  
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long r = 0;
        for (int i = 1; i <= a; i++) {
            if (i % 3 != 0 && i % 5 != 0) {
                r += i;
            }
        }
        System.out.println(r);
    }

}

Measured memory_bytes: 27200
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

const int MAX_SIZE = 10;

int calc(char s[]) {
  int c = 0, l = strlen(s);
  if (l % 2) {
    if (s[l / 2] <= ')') c++;
  }
  for (int i = 0; i < l / 2; ++i) {
    if (s[i] <= ')') {
      if (abs(s[i] - s[l - i - 1]) != 1) c++;
    } else {
      if (s[i] != s[l - i - 1]) c++;
    }
  }
  return c;
}

int main() {
  char s[MAX_SIZE + 1];
  cin >> s;
  cout << calc(s) << endl;
}

Measured memory_bytes: 1148