akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>

#define INF 100
using namespace std;
struct data{
	int x,y,p,q,dir;
	data(){}
	data(int yy,int xx,int dd,int pp,int qq){
		x=xx;
		y=yy;
		p=pp;
		q=qq;
		dir=dd;
	}
	bool operator<(const data &d)const{
		return q>d.q;
	}
};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m,a;
int fie[101][101];
int dp[101][101][4][11];
int sx,sy,gx,gy;

int dijk(){
	int res=INF;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			for(int k=0;k<4;k++){
				for(int l=0;l<=a;l++){
					dp[i][j][k][l]=INF;
				}
			}
		}
	}
	priority_queue<data> que;
	que.push(data(sy,sx,1,0,0));
	dp[sy][sx][1][0]=0;
	while(que.size()){
		data q=que.top();
		que.pop();
		if(dp[q.y][q.x][q.dir][q.p]<q.q)continue;
		if(0<=q.x+dx[q.dir] && q.x+dx[q.dir]<m && 0<=q.y+dy[q.dir] && q.y+dy[q.dir]<n){
			if(fie[q.y+dy[q.dir]][q.x+dx[q.dir]]!=-1 && dp[q.y+dy[q.dir]][q.x+dx[q.dir]][q.dir][q.p]>q.q){
				if(fie[q.y+dy[q.dir]][q.x+dx[q.dir]]==1 && q.dir==3)continue;
				dp[q.y+dy[q.dir]][q.x+dx[q.dir]][q.dir][q.p]=q.q;
				que.push(data(q.y+dy[q.dir],q.x+dx[q.dir],q.dir,q.p,q.q));
			}
		}
		if(q.p<a){
			int ndir=-1;
			if(q.dir==0)ndir=3;
			if(q.dir==1)ndir=2;
			if(q.dir==2)ndir=1;
			if(q.dir==3)ndir=0;
			if(fie[q.y][q.x]==0 && dp[q.y][q.x][ndir][q.p+1]>q.q){
				dp[q.y][q.x][ndir][q.p+1]=q.q;
				que.push(data(q.y,q.x,ndir,q.p+1,q.q));
			}
		}
		if(q.q<a){
			int ndir=-1;
			if(q.dir==0)ndir=1;
			if(q.dir==1)ndir=0;
			if(q.dir==2)ndir=3;
			if(q.dir==3)ndir=2;
			if(fie[q.y][q.x]==0 && dp[q.y][q.x][ndir][q.p]>q.q+1){
				dp[q.y][q.x][ndir][q.p]=q.q+1;
				que.push(data(q.y,q.x,ndir,q.p,q.q+1));
			}
		}
	}
	for(int i=0;i<=a;i++){
		for(int j=0;j<4;j++){
			res=min(res,dp[gy][gx][j][i]+i);
		}
	}
	return res!=INF?res:-1;
}

int main(void){
	scanf("%d %d %d %d",&n,&m,&a);
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		for(int j=0;j<m;j++){
			if(str[j]=='S')sx=j,sy=i,fie[i][j]=1;
			if(str[j]=='G')gx=j,gy=i,fie[i][j]=2;
			if(str[j]=='#')fie[i][j]=-1;
		}
	}
	printf("%d\n",dijk());
	return 0;
}

Measured memory_bytes: 2968
N = int(input())

def num2alpha(N):
    if N<=26:
        return chr(64+N)
    elif N%26==0:
        return num2alpha(N//26-1)+chr(90)
    else:
        return num2alpha(N//26)+chr(64+N%26)

print(str.lower(num2alpha(N)))

Measured memory_bytes: 9152
def main():
    n = int(input())
    A,B = [],[]
    for i in range(n):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    if n%2==1:
        a_ = sorted(A)[(n-1)//2]
        b_ = sorted(B)[(n-1)//2]
        print(b_-a_+1)
    else:
        A,B = sorted(A),sorted(B)
        a_ = (A[n//2]+A[n//2-1])/2
        b_ = (B[n//2]+B[n//2-1])/2
        print(int(2*(b_-a_))+1)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 28620
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
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; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

bool isPrime(ll n) {
    if(n < 2) return false;
    else {
        for (ll i = 2; i * i <= n; i++) {
            if (n%i == 0) return false;
        }
        return true;
    }
}

int main(){
	ll a,b,ta,tb;
	cin >> a >> b;
	ta = a,tb = b;
	vector<ll> aa,bb;
	aa.push_back(1);
	for(ll i = 2; i*i <= ta; i++){
		if(a%i == 0){
			aa.push_back(i);
			while(a%i == 0) a /= i;
		}
	}
	if(a != 1) aa.push_back(a);
	bb.push_back(1);
	for(ll i = 2; i*i <= tb; i++){
		if(b%i == 0){
			bb.push_back(i);
			while(b%i == 0) b /= i;
		}
	}
	if(b != 1) bb.push_back(b);

	/*if(a < b) swap(a,b);
	if(a%b == 0 && isPrime(a) && isPrime(b)){
		c.push_back(a);
	}*/
	//for(auto cc : c) cout << cc << endl;
	//cout << c.size() << endl;
	
	int sum = 0;
	for(int i = 0; i < aa.size(); i++){
		for(int j = 0; j < bb.size(); j++){
			if(aa[i] == bb[j]) sum++;
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int ans=0;
  int n,d;
  cin >> n;
  int i,j,k;
  for(i=0;i<n;i++){
    cin >> d;
    k=1;
    for(j=2;j*j<=d;j++){
      if(d%j==0){
	k=0;
	break;
      }
    }
    ans+=k;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> d(n);
    for (int i = 0; i < n; ++i)
        std::cin >> d.at(i);
    
    std::sort(d.begin(), d.end());
    
    int m = n / 2;

    std::cout << d.at(m) - d.at(m-1) << std::endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;


namespace io{
    const int L = (1 << 20) + 1;
    
    char buf[L], *S , *T, c;
     
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
    
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
    
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
    
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
        
        if(!a)*--outs = '0';
        else 
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
        
        if(x)
            *--outs = x;
        
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};

using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 200010;
int n,k;
int a[maxN];
int c[maxN];
int f[maxN];

int main()
{
	n = inp();
	k = inp();
	for(int i=1;i<=n;i++)
	{
		int x = i%k;
		c[x]++;
	}
	ll ans = 0;
	for(int i=0;i<k;i++)
	{
		int p = (2*(i%k))%k;
		if(p == 0)
			ans += pow(c[i],3);
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 640
import numpy as np
def main():
    h,w = map(int, input().split())
    mat = []
    for i in range(h):
        b = input()
        mat.append([0 if j=="#" else h+w for j in b])
    arr = np.array(mat)

    for i in range(w-1):
        arr[:,i+1] = np.minimum(arr[:,i]+1,arr[:,i+1])
        #print(arr)

    for i in range(w-1,0,-1):
        arr[:,i-1] = np.minimum(arr[:,i]+1,arr[:,i-1])
        #print(arr)

    for i in range(h-1):
        arr[i+1,:] = np.minimum(arr[i,:]+1,arr[i+1,:])
        #print(arr)

    for i in range(h-1,0,-1):
        arr[i-1,:] = np.minimum(arr[i,:]+1, arr[i-1,:])
        #print(arr)
    print(np.max(arr))


if __name__ == '__main__' :
    main()

Measured memory_bytes: 60436
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
    name = input()
    if name[0] == 'M':
        m += 1
    elif name[0] == 'A':
        a += 1
    elif name[0] == 'R':
        r += 1
    elif name[0] == 'C':
        c += 1
    elif name[0] == 'H':
        h += 1
sum_ = 0
sum_ += m*a*r
sum_ += m*a*c
sum_ += m*a*h
sum_ += m*r*c
sum_ += m*r*h
sum_ += m*c*h
sum_ += a*r*c
sum_ += a*r*h
sum_ += a*c*h
sum_ += r*c*h
print(sum_)

Measured memory_bytes: 3064
N = int(input())
S = input()

def f(s):
    b = 0
    for i in s:
        if i == "#":
            b += 1
        yield b

def g(cb, n):
    bl = 0 if n == 0 else cb[n-1]
    wr = (len(cb) - n) - (cb[-1] - bl)

    return bl + wr

cb = list(f(S))
print(min([g(cb, i)for i in range(len(cb) + 1)]))


Measured memory_bytes: 19340
N = int(input())
A = list(map(int, input().split()))
ans = 0
t = 0
u = 0
m = max(A)
for i in range(60):
    if m >= 2**i:
        u += 1
    else: break
for i in range(u):
    for j in range(N):
        t += (A[j] >> i) & 1
    ans += (t * (N-t)) * 2**i
    t = 0
print(ans%1000000007) 

Measured memory_bytes: 122808
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <tuple>
#include <utility>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

int main()
{

    int a, b;
    cin >> a >> b;

    cout << max({a + b, a - b, a * b}) << endl;

    return 0;
}


Measured memory_bytes: 256
sx,sy,tx,ty = [int(i) for i in input().split()]
ans = []
dx = tx - sx
dy = ty - sy
for i in range(dy):
    ans.append('U')
for i in range(dx):
    ans.append('R')
for i in range(dy):
    ans.append('D')
for i in range(dx):
    ans.append('L')
ans.append('L')
for i in range(dy+1):
    ans.append('U')
for i in range(dx+1):
    ans.append('R')
ans.append('D')
ans.append('R')
for i in range(dy+1):
    ans.append('D')
for i in range(dx+1):
    ans.append('L')
ans.append('U')
print(''.join(ans))


Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;

int n;
bool a;
vector<int> ms;
vector<int> ms2;
vector<int> msp;

void msk()
{
    for (int i = 2; i < 300000; i++)
    {
        if (i % 7 == 1 || i % 7 == 6)
        {
            ms.push_back(i);
        }
    }

    for (int i = 0; i < ms.size(); i++)
    {
        a = true;
        for (int j = 0; ms.at(j) <= sqrt(ms.at(i)); j++)
        {
            if (ms.at(i) % ms.at(j) == 0)
            {
                a = false;
                break;
            }
        }
        if (a)
            ms2.push_back(ms.at(i));
    }

    for (int i = 0; i < ms2.size(); i++)
    {
        msp.push_back(ms2.at(i));
    }
}

int main()
{
    msk();
    while (1)
    {
        scanf("%d", &n);
        if (n == 1)
            return 0;

        printf("%d:", n);
        for (int i = 0; i < ms2.size(); i++)
        {
            if (n % ms2.at(i) == 0)
            {
                printf(" %d", ms2.at(i));
            }
        }
        printf("\n");
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int r; cin >> r; cout << (3 * r * r) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int A,int B){
  if(B==0){
    return A;
  }
  return gcd(B,A%B);
}
int main(){
  int K;
  cin >> K;
  long long sum=0;
  for(int a=1;a<K+1;a++){
    for(int b=1;b<K+1;b++){
      for(int c=1;c<K+1;c++){
        sum+=gcd(a,gcd(b,c));
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){

	int w, a, b;
	cin >> w >> a >> b;
	if( a > b ) swap(a, b);
	cout << max(0, b-(a+w)) << endl;

	return 0;
}


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

using namespace std;

/* Typedefs */
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;

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

    string a, b;
    cin >> a >> b;

    string concat = a.append(b);
    double num = 0;
    int place = 1;
    for(int i = concat.length() - 1; i >= 0; i--){
        num += place * (double)(concat[i] - '0');
        place *= 10;
    }

    if(abs(sqrt(num) - (int)(sqrt(num))) < 1e-4){
        cout << "Yes" << endl;
    } else 
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int h, w, n, a;
    vector<vector<int>> grid;
    queue<pair<int, int>> q;
    cin>>h>>w>>n;
    rep(i, 1, n + 1) {
        cin>>a;
        q.push({i, a});
    }
    rep(i, h) {
        vector<int> row;
        rep(j, w) {
            row.push_back(q.front().first);
            q.front().second--;
            if(q.front().second == 0) q.pop();
        }
        grid.push_back(row);
    }
    rep(i, h) {
        if(i % 2) reverse(all(grid[i]));
        each(j, grid[i]) cout<<j<<' ';
        cout<<endl;
    }
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)
#define ll long long

//セグ木ここから
//*
//↓ここを変える
typedef struct atai{ll a;}atai;
atai xx(atai x,atai y){
	atai r;
	r.a=x.a+y.a;//sum
	return r;
}
atai aid={0};
//↑ここを変える

int segNUM;
atai *segN,*seg;
void seguse(int n){
	segN=(atai*)calloc(2*n,sizeof(atai));
	segNUM=n;
	seg=segN+segNUM;
	rep(i,1,2*segNUM)segN[i]=aid;
}
//seg[]に値を与えてから初期化
void seginit(){for(int node=segNUM-1;node;node--)segN[node]=xx(segN[node*2],segN[node*2+1]);}
void segupdate(int node,atai x){
	//seg[node]をxに更新
	node+=segNUM;
	segN[node]=x;
	while(node/=2)segN[node]=xx(segN[node*2],segN[node*2+1]);
}

atai segcalcsub(int l,int r,int k,int cl,int cr){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return segN[k];

	int cm=(cl+cr)/2;
	//左側だけ
	if(r<=cm)return segcalcsub(l,r,2*k  ,cl,cm);
	//右側だけ
	if(cm<=l)return segcalcsub(l,r,2*k+1,cm,cr);
	//両方
	return xx(segcalcsub(l,r,2*k,cl,cm),segcalcsub(l,r,2*k+1,cm,cr));
}
atai segcalc(int l,int r){return segcalcsub(l,r,1,0,segNUM);}
//セグ木ここまで
//*/


int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	seguse(1<<19);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		seg[i].a=t;
	}
	seginit();
	
	while(q--){
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(t==0){
			atai aaa={seg[x].a+y};
			segupdate(x,aaa);
		}else{
			printf("%lld\n",segcalc(x,y).a);
		}
	}
}

Measured memory_bytes: 12384
//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
#pragma endregion
#pragma endregion


int main() {
	lint n; cin >> n;
	map<lint, lint> d;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		if (s[0] == 'M')
			d[0]++;
		if (s[0] == 'A')
			d[1]++;
		if (s[0] == 'R')
			d[2]++;
		if (s[0] == 'C')
			d[3]++;
		if (s[0] == 'H')
			d[4]++;
	}
	lint ans = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += d[i] * d[j] * d[k];
			}
		}
	}
	printf("%lld\n", ans);

	return 0;
}

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

using namespace std;

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

#define pb push_back
#define mp make_pair

int n, m;
vector<int> g[100000];
vector<int> g2[100000];
vector<char> used(100000, false);

void dfs(int v){
        used[v] = true;
        for(auto to: g[v])
                if(!used[to]) dfs(to);
}


int main()
{
        std::cin.sync_with_stdio(0);
        cin >> n >> m;
        for(int i = 0; i < n; i++){
                int k;
                cin >> k;
                for(int j = 0; j < k; j++){
                        int t;
                        cin >> t;
                        t--;
                        g2[t].pb(i);
                }
        }


        for(int i = 0; i < m; i++){
                if(g2[i].size() == 0) continue;
                for(int j = 0; j < g2[i].size() - 1; j++){
                        int from = g2[i][j];
                        int to = g2[i][j + 1];
                        g[from].pb(to);
                        g[to].pb(from);
                }
        }

        dfs(0);

        for(int i = 0; i < n; i++){
                if(!used[i]){
                        cout << "NO";
                        return 0;
                }
        }
        cout << "YES";
        return 0;
}


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

using namespace std;

int N, A[3][3], B[10];
bool appear[3][3];

int main()
{
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> A[i][j];
        }
    }
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> B[i];
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            appear[i][j] = false;
            for (int k = 0; k < N; k++)
            {
                if (A[i][j] == B[k])
                    appear[i][j] = true;
            }
        }
    }
    bool result = false;
    int count = 0;
    for (int i = 0; i < 3; i++)
    {
        count = 0;
        for (int j = 0; j < 3; j++)
        {
            if (appear[i][j] == true)
                count++;
        }
        if (count == 3)
        {
            result = true;
        }
    }
    for (int j = 0; j < 3; j++)
    {
        count = 0;
        for (int i = 0; i < 3; i++)
        {
            if (appear[i][j] == true)
                count++;
        }
        if (count == 3)
        {
            result = true;
        }
    }
    if (appear[0][0] && appear[1][1] && appear[2][2])
        result = true;
    if (appear[0][2] && appear[1][1] && appear[2][0])
        result = true;
    if(result){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
	std::cin >> N;
	std::map<std::string, int64_t> votes;

	std::string name;
	int64_t max_num = -1;
	for (int64_t i = 0; i < N; i++)
	{
		std::cin >> name;
		if (!votes[name])
		{
			votes[name] = 1;
		}
		else
		{
			votes[name] += 1;
		}

		if (votes[name] > max_num) max_num = votes[name];
	}

	for (auto vote:votes)
	{
		if (vote.second == max_num)
		{
			std::cout << vote.first << std::endl;
		}
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 19216
n,m,y=map(int,input().split())
List=[list(map(int,input().split())) for i in range(n)]
ans=10000000000
for i in range(2**n):
  money=0
  l=[0]*m
  for j in range(n):
    if (i>>j) & 1:
      money+=List[j][0]
      for x in range(m):
        l[x]+=List[j][x+1]
  if all(c>=y for c in l):
    if ans>money:
      ans=money
if ans==10000000000:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9212
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
#define eps 1.0e-14;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int M = max(max (A , B), C);
    int ans;
    if((A + B + C) % 2 == (3 * M) % 2){
        ans = ((3 * M) - (A + B + C)) / 2;
    }else{
        ans = ((3 * (M + 1)) - (A + B + C)) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll n;
    cin >> n;
    string ans;
    while (n > 0) {
      n--;
      ans += 'a' + n%26;
      n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

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

using namespace std;

const int MX = 100 * 1000 + 7;
const int INF = 1000 * 1000 * 1000 + 7;

ll dp[MX];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    for (int i = 1; i < MX; i++) {
        dp[i] = INF;
    }
    int n, w;
    cin >> n >> w;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = MX - 1; j >= b; j--) {
            dp[j] = min(dp[j], dp[j - b] + a);
        }
    }

    int ans = 0;
    for (int i = 0; i < MX; i++) {
        if (dp[i] <= w) {
            ans = max(ans, i);
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1024
a,b=map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            arr.append(i)
    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr
aa=factorization(a)
bb=factorization(b)
n=len(aa)
ans=[]
if n>len(bb):
    n=len(bb)
    for i in range(n):
        if bb[i] in aa:
            ans.append(bb[i])
else:
    for i in range(n):
        if aa[i] in bb:
            ans.append(aa[i])
ans.append(1)
ans=set(ans)
print(len(ans))

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

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

const ld PI = acos(-1.0);

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ld a, b, h, m;
	cin>>a>>b>>h>>m;
	ld angh = PI*(h + m*1.0/60)/6;
	ld angm = PI*m/30;
	ld xh = a*sin(angh);
	ld xm = b*sin(angm);
	ld yh = a*cos(angh);
	ld ym = b*cos(angm);
	ld dx = xh - xm;
	ld dy = yh - ym;
	cout<<sqrt(dx*dx + dy*dy)<<endl;;

	return 0;
}

Measured memory_bytes: 4184
n = gets.to_i

num_ary = []

n.times do
  num_ary << gets.to_i
end

min, max_diff = nil, nil

num_ary.each_with_index do |num, index|
  if index.zero?
    min = num
    next
  end

  if index == 1
    max_diff = num - num_ary[0]
    min = num if num < min
  end

  if index > 1
    diff = num - min
    max_diff = diff if max_diff < diff
    min = num if num < min
  end
end

puts max_diff

Measured memory_bytes: 10524
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
/*切り上げの計算！*/
int maxtime(int x) {
	return(x + 9) / 10 * 10;

}
int main() {
	int N = 100000;
	vector<int> s(100020,1);
	vector<int> k(100020, 0);
	s[0] = 0;
	s[1] = 0;
	for (int i = 2; i <= N; i++) {
		if (s[i] == 1) {
			for (int j = i * 2; j <= N; j = j + i) {
				s[j] = 0;
			}
		}
	}
	for (int i = 1; i <= N; i = i + 2) {
		if (s[i] == 1) {
			if (s[(i + 1) / 2] == 1) {
				k[i] = 1;
			}
		}
	}
	vector<int> ruiseki(100020, 0);
	ruiseki[0] = 0;
	for (int i = 0; i <= 100000; i++) {
		ruiseki[i + 1] = ruiseki[i] + k[i];
	}
	int Q;
	cin >> Q;
	vector<pair<int, int>>g;
	for (int i = 0; i < Q; i++) {
		int a, b;
		cin >> a >> b;
		pair<int, int>key;
		key.first = a;
		key.second = b;
		g.push_back(key);
	}
	for (int i = 0; i < Q; i++) {
		pair<int,int> key = g[i];
		cout << ruiseki[key.second + 1] - ruiseki[key.first] << endl;
	}
}

Measured memory_bytes: 2676
#include <algorithm>
#include <stdio.h>
#include <vector>

#define REP(i,s,n) for(int i=(s);i<(n);++i)
typedef long long ll;
using namespace std;
const int N=1010;

int x,y,z,k;
ll a[N],b[N],c[N];

vector<ll> ab;
vector<ll> abc;

int main(){
  scanf("%d%d%d%d",&x,&y,&z,&k);
  REP(i,0,x)scanf("%lld",a+i);
  REP(i,0,y)scanf("%lld",b+i);
  REP(i,0,z)scanf("%lld",c+i);
  REP(i,0,x)REP(j,0,y)ab.push_back(a[i]+b[j]);
  sort(ab.rbegin(),ab.rend());
  REP(i,0,z){
    REP(j,0,min(k,int(ab.size()))){
      abc.push_back(c[i]+ab[j]);
    }
  }
  sort(abc.rbegin(),abc.rend());
  REP(r,0,k){
    printf("%lld\n",abc[r]);
  }
}


Measured memory_bytes: 43364
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))

res = 0
for i, b in enumerate(B):
    a = A[i]
    a1 = A[i + 1]
    if a >= b:
        res += b
    else:
        res += a
        if a1 >= b - a:
            A[i + 1] = a1 - (b - a)
            res += b - a
        else:
            A[i + 1] = 0
            res += a1

print(res)

Measured memory_bytes: 20680
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	string s; cin >> s;
	int k; cin >> k;
	int i = 0;
	while (k > 0)
	{
		
		if ((int)('z' - s[i]) + 1 <= k && s[i]!='a')
		{
			k -= ('z' - s[i]) + 1;
			s[i] = 'a';
		}
		i++;
		if (i == sz(s))
		{
			k %= 26;
			s[i - 1] += k;
			if (s[i - 1] > 'z')s[i - 1] -= 'z' + 1;
			k = 0;
		}
	}
	co(s);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <unordered_map>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve(){
    int a, b;
    string s;
    cin >> a >> b;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(i == a && s[i] == '-'){

        }else if(i != a && (s[i] <= '9' && s[i] >= '0')){

        }else{
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main(){
    solve();
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int d[10];
int k=0;
int x,y;
int a[10][10];
int b[10];  //存每个数字的个数 
int c[10];	//每个数字到1 最少的步数； 
void bfs(int q,int sum)
{
	if(q==1&&c[k]>sum)
		c[k]=sum;
	
	for(int j=0;j<=9;j++)
		if(d[j]==0)
		{
			d[j]=1;
			bfs(j,sum+a[q][j]);
			d[j]=0;		
		}
}


int main()
{

	for(int i=0;i<=9;i++)
		c[i]=0x3f3f3f3f;
	memset(b,0,sizeof(b));
	memset(d,0,sizeof(d));
	scanf("%d%d",&x,&y);
	for(int i=0;i<=9;i++)
		for(int j=0;j<=9;j++)
			scanf("%d",&a[i][j]); 
	for(int i=1;i<=x;i++)
		for(int j=1;j<=y;j++)
		{
			int w;
			scanf("%d",&w);
			if(w!=-1&&w!=1)
				b[w]++;				
		}
		for(k=0;k<=9;k++)
			if(b[k]>=1&&k!=1)
			{
				memset(d,0,sizeof(d));
				d[k]=1;
				bfs(k,0);
			}
			long long anc=0;
		for(int i=0;i<=9;i++)
			if(i!=1)
				anc=anc+c[i]*b[i];
		printf("%lld\n",anc);
		return 0;
				
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> cells(h);
	vvi able(h, vi(w, 9999));
	REP(i, h)
		cin >> cells[i];
	int sx, sy, gx, gy;
	queue<pair<pii, int>> Qs;

	REP(i, h) {
		REP(j, w) {
			if (cells[i][j] == '@') {
				sx = j;
				sy = i;
			}
			if (cells[i][j] == '%') {
				gx = j;
				gy = i;
			}
			if (cells[i][j] == '$') {
				Qs.push({ {i,j},0 });
				able[i][j] = 0;
			}
			if (cells[i][j] == '#')
				continue;
		}
	}
	while (!Qs.empty())
	{
		pair<pii, int> q = Qs.front();
		Qs.pop();
		REP(k, 4) {
			int nx = q.first.second + dx[k];
			int ny = q.first.first + dy[k];
			if (0 <= ny&& ny < h && 0 <= nx && nx < w)
				if (cells[ny][nx] != '#')
					if (able[ny][nx] > q.second + 1) {
						able[ny][nx] = q.second + 1;
						Qs.push({ { ny,nx },q.second + 1 });
					}
		}
	}
	vvb visited(h, vb(w, false));
	visited[sy][sx] = true;
	queue<pair<pii, int>> Q;
	Q.push({{ sy,sx },0});
	bool ans = false;
	while (!Q.empty())
	{
		pair<pii, int> q = Q.front();
		Q.pop();
		if (q.first.first == gy&&q.first.second == gx) {
			ans = true;
			break;
		}
		REP(k, 4) {
			int nx = q.first.second + dx[k];
			int ny = q.first.first + dy[k];
			if (0 <= ny&& ny < h && 0 <= nx && nx < w)
				if (cells[ny][nx] != '#'&&able[ny][nx]>q.second+1)
					if (visited[ny][nx] == false) {
						visited[ny][nx] = true;
						Q.push({ { ny,nx },q.second+1 });
					}
		}
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3644
A = [1000000000,1000000000]
Q = []

def a(x,y,z)
 Q << [?+,x,y,z]*" "
 A[z] = (A[x]||=0) + (A[y]||=0)
end

def c(x,y,z)
 Q << [?<,x,y,z]*" "
 A[z] = (A[x]||=0) < (A[y]||=0) ? 1 : 0
end

c(3,0,3)
0.upto(62){|i|
 a(3+i,3+i,4+i)
}

def to_b(x,s)
 a(x,3,x)
 63.downto(0){|i|
  a(3+i,s+64+i+1,s+64+i)
  c(s+64+i,x,s+i)
  a(s+i,2,s+64+i)
  i.times{a(s+64+i,s+64+i,s+64+i)}
  a(s+64+i,s+64+i+1,s+64+i)
 }
end

to_b(0,67)
to_b(1,195)

30.times{|i|
 30.times{|j|
  a(67+i,195+j,324)
  c(3,324,325)
  a(326+i+j,325,326+i+j)
 }
}

60.times{|i|
 i.times{a(326+i,326+i,326+i)}
 a(2,326+i,2)
}

# STDERR.puts "Q = #{Q.size}"
# STDERR.puts A.map.with_index{|x,i|x||=0;"#{i}:#{x}"}*" "

puts Q.size
puts Q


Measured memory_bytes: 15460
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long x,y,z,k;
  cin >> x >> y >> z >> k;
  long long a[x],b[y],c[z];
  priority_queue<long long> que,ans;
  for(int i=0;i<x;i++){
    cin >> a[i];
  }
  for(int i=0;i<y;i++){
    cin >> b[i];
  }
  for(int i=0;i<z;i++){
    cin >> c[i];
  }
  for(int i=0;i<x;i++){
    for(int j=0;j<y;j++){
      que.push(a[i]+b[j]);
    }
  }
  for(int i=0;i<k and !que.empty();i++){
    for(int j=0;j<z;j++){
      ans.push(que.top()+c[j]);
    }
    que.pop();
  }
  for(int i=0;i<k;i++){
    cout << ans.top() << endl;
    ans.pop();
  }
  return 0;
}


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


int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int cnt = 0;
    int ans = 0;
    rep(i,N){
        if(S[i]=='A'){
            cnt = 1;
        }else{
            if(cnt==1&&S[i]=='B'){
                cnt = 2;
            }else{
                if(cnt==2&&S[i]=='C'){
                    ans++;
                    cnt = 0;
                }else{
                    cnt = 0;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n = Integer.parseInt(sc.next());
    int number_k = Integer.parseInt(sc.next());
    String str = sc.next();
    if(number_k == 1) str = str.substring(0, 1).toLowerCase() + str.substring(1);
    else str = str.substring(0, number_k - 1) + str.substring(number_k - 1, number_k).toLowerCase() + str.substring(number_k);
    System.out.println(str);
  }
}


Measured memory_bytes: 21332
obs, roads = [int(x) for x in input().split()]
heights = [int(x) for x in input().split()]
goodone = [1] * obs
for _ in range(roads):
    a, b = [int(x) for x in input().split()]
    if heights[a - 1] <= heights[b - 1]:
        goodone[a - 1] -= goodone[a - 1]
    if heights[a - 1]  >=  heights[b - 1]:
        goodone[b - 1] -= goodone[b - 1]
print(sum(goodone))



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

//nツづ債甘慊づ慊づ按つ「ツづヲツ！
vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main()
{
	int n;
	vector<int> V=sieve_of_eratosthenes(123457*2);
	while(cin>>n,n){
		int count=0;
		for(int i=n+1;i<=n*2;i++)
			if(V[i]!=0) count++;
		cout<<count<<endl;
	}
	return 0;
}

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

// #LIB#

using namespace std;
using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  vector<vector<ll>> maxl(100, vector<ll>(100, LLONG_MIN / 4)), maxr(100, vector<ll>(100, LLONG_MIN / 4));
  maxl[0][0] = maxr[0][0] = 0;
  repr(i, 1, n + 1) {
    set<ll> vs;
    ll sum = 0;
    rep(j, i) {
      sum += v[j];
      vs.insert(v[j]);
    }
    maxl[i][0] = sum;
    ll trash = 0;
    while (!vs.empty()) {
      auto p = vs.begin();
      sum -= *p;
      ++trash;
      vs.erase(p);
      maxl[i][trash] = sum;
    }
  }
  repr(i, 1, n + 1) {
    set<ll> vs;
    ll sum = 0;
    rep(j, i) {
      sum += v[n - 1 - j];
      vs.insert(v[n - 1 - j]);
    }
    maxr[i][0] = sum;
    ll trash = 0;
    while (!vs.empty()) {
      auto p = vs.begin();
      sum -= *p;
      ++trash;
      vs.erase(p);
      maxr[i][trash] = sum;
    }
  }
  ll ans = LLONG_MIN / 4;
  rep(ln, n + 1) rep(rn, n - ln + 1) {
    rep(lt, ln + 1) rep(rt, rn + 1) {
      if (ln + rn + lt + rt > k) continue;
      updatemax(ans, maxl[ln][lt] + maxr[rn][rt]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3748
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int , n+1)
	for i := 0 ; i < n +1; i++ {
		fmt.Scan(&a[i])

	}
	b := make([]int , n)
	for i := 0 ; i < n; i++ {
		fmt.Scan(&b[i])
	}
	cnt := 0
	for i := 0; i < n; i++ {
		if a[i] >= b[i] {
			cnt += b[i]
		} else {
			sub := b[i] - a[i]
			cnt += a[i]
			if a[i+1] > sub {
				cnt += sub
				a[i+1] -= sub
			} else {
				cnt += a[i+1]
				a[i+1] = 0
			}
		}
	}
	fmt.Println(cnt)
}



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

int main() {

  string S;
  cin >> S;
  
  int n = S.size();
  
  for (int i=0; i<n; i++) {
	S.at(i) = 'x';
  }
  
  cout << S << endl;
  
  return 0;
}

Measured memory_bytes: 256
class Card():
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value

    def __str__(self):
        return self.suit + str(self.value)

def ChkIfStable(c1, c2):
    for v in range(1,10):
        a1=[]
        for k1 in c1:
            if k1.value == v: a1.append(k1.suit)
        a2=[]
        for k2 in c2:
            if k2.value == v: a2.append(k2.suit)
        if a1!=a2:
            print('Not stable')
            return
    print('Stable')

def BubbleSort(C):
    for i in range(0, len(C)):
        for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                 C[j], C[j-1] = C[j-1], C[j]
    return C

def SelectionSort(C):
    for i in range(len(C)):
        mini = i
        for j in range(i, len(C)):
            if C[j].value < C[mini].value:
                mini = j
        C[i], C[mini] = C[mini], C[i]
    return C

cc = []
input()
for c in input().split():
    cc.append(Card(c[0], int(c[1])))

bs=BubbleSort(cc[:])
print(' '.join(map(str,bs)))
ChkIfStable(cc, bs)
ss=SelectionSort(cc[:])
print(' '.join(map(str,ss)))
ChkIfStable(cc, ss)


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

typedef long long ll;

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

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> t(n), x(n), y(n);
    F0R(i, n) cin >> t[i] >> x[i] >> y[i];
    bool works = true;
    int cx{}, cy{}, ct{};
    F0R(i, n) {
        int distreq = abs(x[i] - cx) + abs(y[i] - cy);
        int timedelta = t[i] - ct;
        if (distreq > timedelta || (((distreq ^ timedelta) & 1) != 0)) {
            works = false;
            break;
        }
        ct = t[i];
        cx = x[i];
        cy = y[i];
    }
    cout << (works ? "Yes" : "No") << nl;
}

Measured memory_bytes: 4428
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define endl '\n'
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
long long int gcd(long long int x,long long int  y){
   if(y==0)return x;
   return gcd(y,x%y);
}
long long exp(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = exp(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int prime(long long x){
if(x==2)return 1;
else{
    for(int i=3;i*i<=x;i+=2){
        if(x%i==0)
            return 0;
    }
}
return 1;
}
//main
int main() {
IOS;
int n,a,b,k=0;
cin>>n;
bool ok=false;
while(n--){
    cin>>a>>b;
    if(a==b)k++;
    else k=0;
    if(k==3)ok=true;
}
if(ok)cout<<"Yes";
else cout<<"No";
return 0;
}
//jaeger

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  string N;
  cin >> N;
  string ans;
  if (N[N.length() - 1] == '2' || N[N.length() - 1] == '4' ||
      N[N.length() - 1] == '5' || N[N.length() - 1] == '7' ||
      N[N.length() - 1] == '9') {
    ans = "hon";
  } else if (N[N.length() - 1] == '0' || N[N.length() - 1] == '1' ||
             N[N.length() - 1] == '6' || N[N.length() - 1] == '8') {
    ans = "pon";
  } else {
    ans = "bon";
  }

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

Measured memory_bytes: 3600
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll t[1000000];
string s[10000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
int main() {
	cin>>N;
	rep(i,0,N){
		cin>>a[i];
	}
	sort(a,a+N);
	double ans=0;
	rep(i,1,N-2){
		ans = max(ans,((double)(a[N-1]+a[N-2]))/((double)(a[i]-a[i-1])));
	}
	ans = max(ans,double(a[N-3]+a[N-4])/(double)(a[N-1]-a[N-2]));
	ans = max(ans,double(a[N-1]+a[N-4])/(double)(a[N-2]-a[N-3]));
	cout<<fixed<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

ll sum(string s) {
    ll ans=0;
    for (char c:s) ans+=c-'0';
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s=to_string(n);
    ll ans=sum(s);
    s[0]--;
    for(int i=1; i<(int)s.size(); i++) s[i]='9';
    cout << max(ans, sum(s)) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min({a+b, b+c, c+a}) << endl;
    return 0;
}


Measured memory_bytes: 3624
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N = getN()
S = input()

ans = 1
# 各i[1]について掛ける/掛けないがあるため
# (1 + i1[1]) * (1 + i2[1])...
# 約数の個数の求め方と同じ
for i in Counter(S).items():
    ans *= (i[1] + 1) % mod
print((ans - 1) % mod)

Measured memory_bytes: 10964