akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    
    char[] src = new char[26];
    char[] dst = new char[26];
    
    for (int i = 0; i < S.length(); i++) {
      char s = S.charAt(i);
      char t = T.charAt(i);
      if (src[s-'a'] == 0 && dst[t-'a'] == 0) {
        src[s-'a'] = t;
        dst[t-'a'] = s;
      } else {
        if (src[s-'a'] != t || dst[t-'a'] != s) {
          System.out.println("No");
          return;
        }
      }
    }
    System.out.println("Yes");
  }
}

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

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

  string s;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    int digit = 0;
    s = to_string(i);
    for (int j = 0; j < s.size(); j++) {
      digit += s.at(j) - '0';
    }

    if (digit >= a) {
      if (b >= digit) {
        sum += i;
      }
    }
  }
  cout << sum;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int n;
  // int mt;
  // vector<int> m;
  string s;
  cin  >> n;
  cin>>s;
  // for (int i = 0; i < n; ++i) {
  //   cin >> mt;
  //   m.push_back(mt);
  // }
  // for (auto l : s) {
  //   cout << l << endl;
  // }

  vector<int> w(n);
  vector<int> e(n);
  if(s[0]=='W')
    w[0]=1;
  else
    w[0]=0;
  if(s[0]=='E')
    e[0]=1;
  else
    e[0]=0;
  for(int i=1;i<n;i++){
    if(s[i]=='W'){
      w[i]=w[i-1]+1;
      e[i]=e[i-1];
    }
    else{
      e[i]=e[i-1]+1;
      w[i]=w[i-1];
    }
  }

  int w_s=w[n-1];
  int e_s=e[n-1];
  vector<int> shikato;
  for (int i = 0; i < n; ++i) {
    int eshikato=e_s - e[i];
    int wshikato;
    if(s[i]=='W')
      wshikato=w[i]-1;
    else
      wshikato=w[i];

    shikato.push_back(wshikato+eshikato);
  }

    
  int minn = *min_element(shikato.begin(), shikato.end());
  cout << minn << endl;
}


Measured memory_bytes: 5244
#include<bits/stdc++.h>
using namespace std;
signed main()
{ 
  int a[10];
  for(int i=0;i<4;i++){
    cin>>a[i];
  }
  sort(a,a+4);
  if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9){
      cout<<"YES\n";
    }
    else{
      cout<<"NO\n";
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

bool is_prime(const unsigned n){
  switch(n){
  case 0: // fall-through                                                                                       
  case 1: return false;
  case 2: // fall-through                                                                                       
  case 3: return true;
  } // n > 3 が保証された                                                                                       

  if(n%2 == 0) return false;
  if(n%3 == 0) return false;
  // 2と3の倍数でないので6の倍数ではないことが保証された                                                        

  if(n%6 != 1 && n%6 != 5) return false;
  // 6の倍数前後の数(素数かもしれない数)であることが保証された                                                  

  // 6の倍数前後の数を使って試し割りをする                                                                      
  for(unsigned i=5;i*i<=n;i+=6){
    if(n%i     == 0) return false; // 6n-1                                                                      
    if(n%(i+2) == 0) return false; // 6n+1                                                                      
  }

  return true;
}

int main(){
  int N;
  cin >> N;
  int tmp = 31;
  for(int i=0; i<N; i++){
    while(!is_prime(tmp))
      tmp += 30;
    cout << tmp << ' ';
    tmp += 30;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int pare[100001];
int rank[100001];
int kumi[100001];

void init(int n){
	int i;
	for(i=0;i<n;i++){
		pare[i]=i;
		rank[i]=0;
		kumi[i]=1;
	}
}

int find(int x){
	if(pare[x]==x){
		return x;
	}else return pare[x]=find(pare[x]);
}

int kn(int x){
	x=find(x);
	return kumi[x];
}


int unite(int x,int y){
	x=find(x);
	y=find(y);
	int kx=kumi[x];
	int ky=kumi[y];
	if(x==y)return 0;
	if(rank[x]<rank[y]){
		pare[x]=y;
		kumi[x]=kx+ky;
		kumi[y]=kx+ky;
	}else {
		pare[y]=x;
		kumi[y]=kx+ky;
		kumi[x]=kx+ky;
		if(rank[x]==rank[y])rank[x]++;
	}
}

int same(int x,int y){
	if(find(x)==find(y))return 1;
	else return 0;
}

int main(){
	long n,m,i;
	long long ans[100001];
	int ab[100000][2];
	scanf("%ld%ld",&n,&m);
	for(i=0;i<m;i++)scanf("%d%d",&ab[i][0],&ab[i][1]);
	ans[m]=(long long)n*(n-1)/2;
	init(n+1);
	for(i=m-1;i>=0;i--){
		if(same(ab[i][0],ab[i][1])==1)ans[i]=ans[i+1];
		else{
			ans[i]=ans[i+1]-(long long)kn(ab[i][0])*kn(ab[i][1]);
			unite(ab[i][0],ab[i][1]);
		}
	}
	for(i=1;i<=m;i++)printf("%lld\n",ans[i]);
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

struct UnionFind{
  vll par;
  vll rank;

  UnionFind(ll n){
    par = vll(n);
    rank = vll(n, 1);
    REP(i, n)
      par[i] = i;
  }

  ll find(ll x){
    if(par[x] == x)
      return x;
    else{
      par[x] = find(par[x]);
      return par[x];
    }
  }

  void unite(ll x, ll y){
    x = find(x);
    y = find(y);
    if(x == y)
      return;
    else{
      if(rank[x] < rank[y])
        par[x] = y;
      else{
        par[y] = x;
        if(rank[x] == rank[y])
          rank[y]++;
      }
    }
  }

  bool same(ll x, ll y){
    return find(x) == find(y);
  }

  ll size(ll x){
    return rank[x];
  }
};

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

  ll n, m;
  cin >> n >> m;

  vector<pll> xy(m);
  vll z(m);
  REP(i, m){
    cin >> xy[i].FI >> xy[i].SE >> z[i];
    xy[i].FI--;
    xy[i].SE--;
  }

  UnionFind uf(n);
  sort(xy.begin(), xy.end());
  REP(i, m){
    ll x = xy[i].FI;
    ll y = xy[i].SE;
    uf.unite(x, y);
  }

  vll a;
  REP(i, n){
    a.push_back(uf.find(i));
  }

  sort(a.begin(), a.end());
  auto it = unique(a.begin(), a.end());
  a.erase(it, a.end());

  cout << a.size() << endl;




}


Measured memory_bytes: 5752
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode('utf-8')

alphabet = set(chr(ord('a')+x) for x in range(26))

def F_short(S):
    se = alphabet - set(S)
    x = min(se)
    return S + x

def F_long(S):
    if S == ''.join(sorted(alphabet, reverse=True)):
        return '-1'
    # 1文字ずつpopして、増加チャンスを待つ
    cand = []
    S = list(S)
    while True:
        x = S[-1]
        if not cand or (x > max(cand)):
            cand.append(S.pop())
            continue
        y = min(ch for ch in cand if ch > x)
        return ''.join(S[:-1]) + y

L = len(S)
answer = F_short(S) if L < 26 else F_long(S)
print(answer)

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

int main(){
    int op_hole[70][70];//開く穴の数
    int n,m,t,p;
    int fold[2];
    while(1){
        cin>>n>>m>>t>>p;
        if(n==0&&m==0&&t==0&&p==0)break;
        int f_n=n,f_m=m;//おられた後の横の長さ及び縦の長さを記録
        for(int i=0;i<70;i++)
            for(int j=0;j<70;j++)
                op_hole[i][j]=0;
        for(int i=0;i<m;i++)//1で初期化
            for(int j=0;j<n;j++)
                op_hole[i][j]=1;
        for(int i=0;i<t;i++){
            cin>>fold[0]>>fold[1];
            int f=fold[1];
            if(fold[0]==1){//横におる場合の重なりを計算
                for(int j=0;j<f;j++)
                    for(int k=0;k<f_m;k++)
                        op_hole[k][2*f-1-j] += op_hole[k][j];
                if(f_n-f >= f){f_n = f_n-f;}
                else{f_n = f;} //f_n-f+f-(f_n-f)より
                for(int j=0;j<f_m;j++)//座標の移動
                    for(int k=0;k<f_n;k++)
                        op_hole[j][k] = op_hole[j][k+f];
                for(int j=0;j<f_m;j++)//座標移動による残骸を0にして処理
                    for(int k=f_n;k<70;k++)
                        op_hole[j][k]=0;
            }
            else if(fold[0]==2){//縦におる場合の重なりを計算
                for(int j=0;j<f;j++)
                    for(int k=0;k<f_n;k++)
                        op_hole[2*f-1-j][k] += op_hole[j][k];
                if(f_m-f >= f){f_m = f_m-f;}
                else{f_m = f;}
                for(int j=0;j<f_n;j++)
                    for(int k=0;k<f_m;k++)
                        op_hole[k][j] = op_hole[k+f][j];
                for(int j=0;j<f_n;j++)
                    for(int k=f_m;k<70;k++)
                        op_hole[k][j]=0;
            }
        }
        for(int i=0;i<p;i++){
            int a,b;
            cin>>a>>b;
            cout<<op_hole[b][a]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3108
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main()
{
    ll a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin>>k;
    cout<<a[k-1];
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> P;
int dp[3001][3001];
P prv[3001][3001];
int main() {
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < t.size(); j++) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
				prv[i + 1][j + 1] = P(i, j);
			}
			else {
				if (dp[i][j + 1] >= dp[i + 1][j]) {
					dp[i + 1][j + 1] = dp[i][j + 1];
					prv[i + 1][j + 1] = P(i, j + 1);
				}
				else {
					dp[i + 1][j + 1] = dp[i + 1][j];
					prv[i + 1][j + 1] = P(i + 1, j);
				}
			}
		}
	}
	string ans = "";
	P p = P(s.size(), t.size());
	while (p.first > 0 || p.second > 0) {
		P q = prv[p.first][p.second];
		if (dp[p.first][p.second] > dp[q.first][q.second]) {
			ans.push_back(s[p.first - 1]);
		}
		p = q;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}


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

int main(void) {
  int n, *C, *S, *F;
  scanf("%d", &n);
  C = (int*)calloc(n, sizeof(int));
  S = (int*)calloc(n, sizeof(int));
  F = (int*)calloc(n, sizeof(int));
  for (int i = 0; i < n-1; i++) {
    scanf("%d %d %d", &C[i], &S[i], &F[i]);
  }

  for (int i = 0; i < n; i++) {
    int time = 0;
    for (int j = i; j < n-1; j++) {
      if (time < S[j]) {
        time = S[j] + C[j];
      } else if (time % F[j] == 0) {
        time += C[j];
      } else {
        time += (F[j] - time % F[j]) + C[j];
      }
    }
    printf("%d\n", time);
  }

  return 0;
}


Measured memory_bytes: 128
line = input()
S = list(map(int, (i for i in line)))

a = S[0] * 10 + S[1]
b = S[2] * 10 + S[3]

if a == 0:
    if b == 0 or 12 < b:
        print("NA")
    else:
        print("YYMM")
elif 0 < a <= 12:
    if b == 0 or 12 < b:
        print("MMYY")
    else:
        print("AMBIGUOUS")
elif 12 < a:
    if b == 0 or 12 < b:
        print("NA")
    else:
        print("YYMM")


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	sort(a.begin(), a.end(), greater<int>());
	auto alice = 0;
	auto bob = 0;
	for (auto i = 0; i < N; ++i)
	{
		if ((i % 2) == 0)
		{
			alice += a[i];
		}
		else
		{
			bob += a[i];
		}
	}

	cout << alice - bob << endl;

	return 0;
}


Measured memory_bytes: 256
//59
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

int V;
vector<int> G[1000];
int match[1000];
bool used[1000];

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

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

int solve(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0;v<V;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v)){
	res++;
      }
    }
  }
  return res;
}

bool cd(int a,int b){
  if(a<b){
    swap(a,b);
  }
  while(b){
    int r=a%b;
    a=b;
    b=r;
  }
  return a>1;
}

int main(){
  for(int m,n;cin>>m>>n,m|n;){
    vector<int> b,r;
    for(int i=0;i<m;i++){
      int j;
      cin>>j;
      b.push_back(j);
    }
    for(int i=0;i<n;i++){
      int j;
      cin>>j;
      r.push_back(j);
    }
    V=n+m;
    for(int i=0;i<m+n;i++){
      G[i].clear();
    }
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	if(cd(b[i],r[j])){
	  add_edge(i+n,j);
	}
      }
    }
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include <algorithm>
#include <cstring>
#include<queue>
#include <stack>
using namespace std;

long long zd(long long a,long long b){
    if(a < b){
        long long t = a;
        a = b;
        b = t;
    }
    long long x = a%b;
    while(x != 0){
        a = b;
        b = x;
        x = a%b;
    }
    return b;
}

int main(){
    long long a;
    long long b;
    cin >> a >> b;
    long long ans1 = zd(a,b);
    cout << (long long)a*b/ans1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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;
  cin >> n;

  vector<int> fib(n + 1, 1);
  for (int i = 2; i <= n; ++i) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }

  cout << fib[n] << endl;
  return 0;
}



Measured memory_bytes: 3112
s = input()
total = 0
i = 0
inRange = False
range_start = 0
range_minus = 0
range_cnt = 0

while i < len(s)-1:
    # BC=>0
    if s[i] == 'B' and s[i+1] == 'C':
        if inRange:
            total += (range_cnt - range_minus)
            range_cnt += 1
            range_minus += 1
        i += 1
    elif s[i] == 'A':
        inRange = True
        range_cnt += 1
    else:
        inRange = False
        range_start = 0
        range_minus = 0
        range_cnt = 0
    i+=1
    
print(total)

Measured memory_bytes: 3500
#include <stdio.h>

int main()
{ int A,P,m;
    scanf("%d %d",&A,&P);
    m=((A*3)+P)/2;
    if (m!=0)
    {printf("%d\n",m);
        
    }
    else
    { printf("0");
        
    }
    return 0;
    
    
    
    
    
    
}
 


Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int isprime(int);

int main(){
  int n,i,x,ip,count=0;

  scanf("%d",&n);
  if(n<1 || n>10000){
    exit(1);
  }

  for(i=0;i<n;i++){
    scanf("%d",&x);
    
    ip=isprime(x);

    if(ip==1){
      count++;
    }
  }

  printf("%d\n",count);

  return 0;
}

int isprime(int x){
  int i;

  if(x==2){
    return 1;
  }else if(x<2 || x%2==0){
    return 0;
  }

  i=3;

  while(i<=sqrt(x)){
    if(x%i==0){
      return 0;
    }

    i=i+2;
  }

  return 1;
}

Measured memory_bytes: 596
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = 0.until(n).map { readLine()?.toInt() ?: return }
    val m = Array(n) { false }
    var c = 0
    var p = a.first()
    while (true) {
        c++
        if (p == 2) {
            println(c.toString())
            return
        } else {
            if (m[p - 1]) {
                println("-1")
                return
            } else {
                m[p - 1] = true
                p = a[p - 1]
            }
        }
    }
}


Measured memory_bytes: 40792
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (100)
#define MOD (998244353)


int main(void)
{
    int n;
    scanf("%d",&n);
    printf("%d\n",n*n*n);
    return 0;
}




Measured memory_bytes: 128
# １０部屋、３階建ての公舎４棟
# n件の情報が与えられます。各情報では、４つの整数b, f, r, vが与えられます。これは、
# b棟f階のr番目の部屋にv人が追加で入居したことを示します。vが負の値の場合、-v人退去したことを示します。
num = gets.to_i

a = {}
(1..4).each do |i|
    (1..3).each do |j|
        (1..10).each do |k|
            a[i.to_s + " " + j.to_s + " " + k.to_s] = 0
        end
    end
end

num.times do |i|
    pos = gets.split(" ")
    n = pos.pop
    a[pos.join(" ")] += n.to_i
end

(1..4).each do |i|
    (1..3).each do |j|
        (1..10).each do |k|
            print " ", a[i.to_s + " " + j.to_s + " " + k.to_s]
        end
        print "\n"
    end
    print "####################\n" if i != 4
end



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

int main() {
    int H, W;
    cin >> H >> W;

    int N;
    cin >> N;

    const int MAX_N = 20000;
    int a[MAX_N];

    vector<int> colors;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        for (int j = 0; j < a[i]; j++) colors.push_back(i + 1);
    }

    const int MAX_H = 200;
    const int MAX_W = 200;

    int r = 0, c = 0, dc = 1,
        painting[MAX_H][MAX_W];
    for (int col : colors) {
        painting[r][c] = col;
        if (c + dc < 0 || c + dc >= W) {
            r = r + 1;
            dc = -dc;
        } else c += dc;
    }

    for (int r = 0; r < H; r++) {
        for (int c = 0; c < W; c++) {
            cout << painting[r][c] << " ";
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;


int main()
{
    int n;
    long long a[100005];
    long long b[100005];
    
    cin >> n;
    for (int i = 0;i <= n;i++){
        cin >> a[i];
    }
    for (int i = 0;i < n;i++){
        cin >> b[i];
    }
    
    long long ans = 0;
    for (int i = 0;i < n;i++){
        if (i == 0){
            if (a[i] <= b[i]){
                ans += a[i];
                b[i] = b[i]-a[i];
                a[i] = 0;
            }
            else {
                ans += b[i];
                b[i] = 0;
                a[i] = a[i]-b[i];
            }
        }
        else {
            if (b[i-1] >= a[i]){
                ans += a[i];
                a[i] = 0;
                b[i-1] -= a[i];
            }
            else if (b[i-1]+b[i] >= a[i]){
                ans += a[i];
                b[i] = b[i]-a[i]+b[i-1];
                b[i-1] = 0;
                a[i] = 0;
            }
            else {
                ans += b[i-1]+b[i];
                b[i] = 0;
                b[i-1] = 0;
                a[i] = a[i] - b[i-1] - b[i];
            }
        }
        
        if (i == n-1){
            if (b[i] >= a[i+1]){
                b[i] = b[i] - a[i+1];
                ans += a[i+1];
                a[i+1] = 0;
            }
            else {
                ans += b[i];
                a[i+1] -= b[i];
                b[i] = 0;
            }
        }
    }
    
    cout << ans << endl;
}


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

using namespace std;

#define ll long long
#define N 100010

int main() {
  int x, y;
  cin >> x >> y;
  int a, b, c;
  cin >> a >> b >> c;
  ll sum = 0;
  vector<ll> p, q, r;
  ll z;
  for (int i = 0; i < a; i++) {
    cin >> z;
    p.push_back(z);
  }
  for (int i = 0; i < b; i++) {
    cin >> z;
    q.push_back(z);
  }
  for (int i = 0; i < c; i++) {
    cin >> z;
    r.push_back(z);
  }
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  vector<ll> ms;
  for (int i = 0; i < x; i++) {
    ms.push_back(p[a - x + i]);
  }
  for (int i = 0; i < y; i++) {
    ms.push_back(q[b - y + i]);
  }
  sort(ms.begin(), ms.end());
  int k = 0;
  for (int i = 0; i < ms.size(); i++) {
    if (k < c && r[k] > ms[i]) {
      sum += r[k++];
    } else {
      sum += ms[i];
    }
  }
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 4724
#include <stdio.h>
#include <math.h>
int main(void){


  int n,j,i,i2,j2,q,a,b,max=0;
  int score[101]={};
  int data[51][101]={}; 
  int m[51]={};

  for(;;){
    scanf("%d %d",&n,&q);
    if(n==0&&q==0){
      break;
    }

    for(i=1;i<=n;i++){
      scanf("%d",&m[i]);
      for(j=1;j<=m[i];j++){
	scanf("%d",&data[i][j]);
      }
    }

    for(i=1;i<=n;i++){
      for(j=1;j<=m[i];j++){   
	for(i2=1;i2<=n;i2++){  
	  for(j2=1;j2<=m[i2];j2++){

	    if(data[i][j]==data[i2][j2]){
	      a=data[i][j];
	      score[a]++;	 
	    }
	  }
	}
      }
    }
    // printf("%d %d\n",score[2],score[4]);
    for(i=1;i<=100;i++){
      if(max<score[i]){
	max=score[i];
	b=i;
      }
      if(max==score[i]){
	if(i<b){
	  b=i;
	}
      }
    }
    // printf("%d\n",score[b]);

    score[b]=sqrt(score[b]);
    // printf("%d\n",score[b]);

    if(score[b]<q){
      printf("0\n");
    }
    else if(score[b]==1){
       printf("%d\n",b);
    }
    else{
      if(score[b]>=q){
		printf("%d\n",b);
      }
      if(score[b]<q){
		printf("0\n");
      }
    }

  for(i=0;i<=101;i++){
    score[i]=0;
  }
  max=0;
  for(i=0;i<=51;i++){
    m[i]=0;
    for(j=0;j<=101;j++){
      data[i][j]=0;
    }
  }

  }
  return 0;
}

Measured memory_bytes: 644
a = [False for i in range(30)]#30行まで値を全部Falseとする
for i in range (28) :
    a[int(input()) -1]=True#aというリストの中で、読み込んだ値を降順に並べてTrueとする
for i in range (30) :
    if a[i] is False :#30までの値の中で(まだ)Falseのもの
        print(i +1)#を昇順に並べる



Measured memory_bytes: 5600
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int t[2000000],n=1;

void maxheapify(int i){
  int l=2*i,r=2*i+1,large,v;
  if(l<=n&&t[l]>t[i])large=l;
  else large=i;
  if(r<=n&&t[r]>t[large])large=r;
  if(large!=i){
    v=t[i];
    t[i]=t[large];
    t[large]=v;
    maxheapify(large);
  }
}

int main(){
  int i,j,v;
  char s[8];
while(1){
  scanf("%s",s);
  if(strcmp(s,"insert")==0){
    scanf("%d",&t[n]);
    j=n;
    for(i=n/2;i>=1;i=i/2){
        if(t[i]<t[j]){
          v=t[i];
          t[i]=t[j];
          t[j]=v;
          j=i;
        }
    }
    n++;
  }
  else if (strcmp(s,"extract")==0){
    printf("%d\n",t[1]);
    t[1]=t[n-1];
    n--;
    maxheapify(1);
  }
  else if(strcmp(s,"end")==0)break;
}
  return 0;
}
    




Measured memory_bytes: 5672
#include <iostream>
#include <cstdio>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

typedef long long ll;

int H, W;
int w[105], h[105];
char a[105][105];

int main(void) {
    scanf("%d %d", &H, &W);


    REP(i, 0, H) {
    	scanf("%s", &a[i]);
    }
    
    REP(i, 0, H) {
      REP(j, 0, W) {
        if (a[i][j] == '#') {
          h[i] = 1;
          w[j] = 1;
        }
      
      }
    
    }

    

    REP(i, 0, H) {
    	if (!h[i]) continue;
    	REP(j, 0, W) {
    	  if (!w[j]) continue;
    		printf("%c", a[i][j]);
    	}
    	printf("\n");
    }

	return 0;
}


Measured memory_bytes: 256