akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long int A,B,C,K,ans;
    cin>>A>>B>>C>>K;
    if (K<=A){
        ans=K;
    }
    else if (K>A&&K<=A+B){
        ans=A;
    }
    else{
        ans=2*A+B-K;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int answer;
		int[] table = new int[50001];
		table[0] = 0;
		table[1] = 0;
		for (int i = 2; i <= 50000; i++) {
			table[i] = 1;
		}
		for (int i = 2; i <= Math.sqrt(50000) + 1; i++)
			if (table[i] == 1)
				for (int j = i * 2; j <= 50000; j += i)
					table[j] = 0;
		while (true) {
			int n = sc.nextInt();
			answer = 0;
			if (n == 0)
				break;
			if (n >= 4) {
				for (int i = 2; i <= n / 2; i++)
					if (table[i] == 1 && table[n - i] == 1)
						answer++;
			}
			System.out.println(answer);
		}
		sc.close();
	}
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i) // ROF(i,n,0)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int l, r; cin >> l >> r;
  if(r - l + 1 >= 2019){
    cout << 0 << endl;
    return 0;
  }
  int ans = inf;
  FOR(i,l,r+1) FOR(j,i+1,r+1){
    int tmp = (i*j) % 2019;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $s = trim(fgets(STDIN));
  $eng = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  $english = [];
  for($i=0; $i<strlen($eng); $i++){
    $english[] = $eng[$i];
  }
  for($i=0; $i<strlen($s); $i++){
    $j = array_search($s[$i],$english)."\n";
    if($j+$n > count($english)-1){
      $step = ($j+$n)-count($english);
    }else{
      $step = $j+$n;
    }
    echo $english[$step];
  }
  echo "\n";

Measured memory_bytes: 4604
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())

def count(x, y):
    cnt = 0
    for dx in range(-1, 2):
        for dy in range(-1, 2):
            if not (0<=x+dx<w and 0<=y+dy<h):
                continue
            if s[y+dy][x+dx]=='#':
                cnt += 1
    return str(cnt)

for i, row in enumerate(s):
    new_str = ''
    for j, e in enumerate(row):
        new_str += count(j, i) if e=='.' else '#'
    print(new_str)

Measured memory_bytes: 3064
import sys

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    h, w = read_int_list()
    n = read_int()
    a = read_int_list()
    c = [[0] * w for i in range(h)]
    color = [0] * (w * h)
    t = 0
    for k in range(n):
        for l in range(a[k]):
            color[t] = k + 1
            t += 1
    t = 0
    for i in range(h):
        if i % 2 == 1:
            for j in range(w):
                c[i][j] = color[t]
                t += 1
        else:
            for j in range(w - 1, -1, -1):
                c[i][j] = color[t]
                t += 1
    for i in range(h):
        for j in range(w):
            print(c[i][j], end='')
            end = ' '
            if j == w - 1:
                end = '\n'
            print(end=end)
    return 0


def main():
    res = solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 4272
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 100010;

int p[MAXN];
int pos[MAXN];
int res[MAXN];

int cir[MAXN];
int len;

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri;
	for(int i = 1; i <= n; i++) p[i] = ri;
	for(int i = 1; i <= n; i++) pos[i] = i;
	for(int i = n; i >= 1; i--) p[i] -= p[i - 1];
	int m = ri, x; ll k = rl;
	for(int i = 1; i <= m; i++) x = ri, swap(pos[x], pos[x + 1]);
	for(int i = 1; i <= n; i++) {
		if(!pos[i]) continue;
		int p = i;
		len = 0;
		while(pos[p]) {
			cir[++len] = pos[p];
			int tp = pos[p];
			pos[p] = 0, p = tp;
		}
		for(int j = 1; j <= len; j++)
			res[cir[j]] = cir[(j + k - 1) % len + 1];
	} ll P = 0;
	for(int i = 1; i <= n; i++) P += p[res[i]], printf("%lld.0\n", P);
	return 0;
}

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

using namespace std;

int cnt;

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    int mx = max(max(a, b), c), mn = min(min(a, b), c);
    int av = a + b + c - mx - mn;
    cnt += mx - av;
    mn += cnt;
    if((mx - mn) % 2 != 0) {
        mx ++;
        cnt ++;
    }
    cout << cnt + (mx - mn) / 2;
    return 0;
}



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

#define rep(i, N) for(int i=0; i<N; i++)
#define ALL(v) v.begin(), v.end()

typedef long long ll;

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

    if(N >= 10){
        cout << R << endl;
    }

    else{
        cout << 100 * (10 - N) + R << endl;
    }
}

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

using namespace std;

int main()
{
    int x, y;

    cin >> x >> y;

    if(y > x * 4 || y % 2 != 0 || y < x * 2)
    {
        cout << "No\n";
    }
    else
    {
        cout << "Yes\n";
    }

    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin >> x;
    int r = x / 100;
    x %= 100;
    int count = 0;
    while(x >= 5){
        x -= 5;
        count ++;
    }
    while(x >= 4){
        x -= 4;
        count++;
    }
    while(x >= 3){
        x -= 3;
        count++;
    }
    while(x >= 2){
        x -= 2;
        count++;
    }
    while(x >= 1){
        x--;
        count++;
    }
    if(count <= r)
        cout << '1' << endl;
    else cout << '0' << endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		if (a >= b) {
			System.out.println(getGCD(a, b));
		} else {
			System.out.println(getGCD(b, a));
		}
	}

	public static int getGCD(int a, int b) {
		if (a % b == 0) return b;
		else if (a < b) {
			return getGCD(b % a, a);
		}
		else return getGCD(b, a % b);
	}
}

Measured memory_bytes: 24316
#include <cstdio>
#include <queue>

std::priority_queue<std::pair<int, int> > H;

int main(){
  int n, i;
  long long k;
  scanf("%d%lld", &n, &k);
  for(i=0;i<n;i++){
    int x, y;
    scanf("%d%d",&x,&y);
    H.emplace(std::pair<int, int>(1000000-x, y));
  }
  long long a = 0;
  while(1){
    std::pair<int, int> x = H.top();
    H.pop();
    a += x.second;
    if(a >= k){
      printf("%d\n", 1000000-x.first);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int m = sc.nextInt();
		
		int ans = 0;
		
		for(int i =0; true ;i++) {
			n-=m;
			ans++;
			if(n<= 0) {
				break;
			}
		}
		
		System.out.println(ans);

	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    FOR(i,0,s.size()){
        s.at(i) = (s.at(i) - 'A' + n)%26 + 'A';

    }
    cout << s << endl;
    return 0;
}



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

struct Node{
	int key;
	Node *right,*left,*parent;
};

Node *root,*NIL;

void insert(int k){
	Node *y=NIL;
	Node *x=root;
	Node *z;
	
	z=(Node *)malloc(sizeof(Node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	
	while(x!=NIL){
		y=x;
		if(z->key<x->key){
			x=x->left;
		}else{
			x=x->right;
		}
	}
	
	z->parent=y;
	if(y==NIL){
		root=z;
	}else{
		if(z->key<y->key){
			y->left=z;
		}else{
		y->right=z;
		}
	}
}

void inorder(Node *u){
	if(u==NIL)return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u){
	if(u==NIL)return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		cin>>com;
		if(com=="insert"){
			scanf("%d",&x);
			insert(x);
		}else if(com=="print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 26752
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

string s,h;

int main(){
	int pos;
	cin >> s;
	for(int i = 0;i < s.size() - 8;i++){
		cout << s[i];
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> p;
typedef long long ll;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<p> cb;
  rep(i, m) {
    int b, c;
    cin >> b >> c;
    cb.emplace_back(c, b);
  }
  sort(a.begin(), a.end());
  sort(cb.begin(), cb.end());
  int min = a[0];
  int id = 0;
  rep(i, m) {
    if (min >= cb[m - 1 - i].first) break;
    // cout << min << endl;
    // cout << cb[m - 1 - i].first << endl;
    rep(j, cb[m - 1 - i].second) {
      if (a[id] >= cb[m - 1 - i].first) break;
      a[id] = cb[m - 1 - i].first;
      id++;
    }
    // rep(i, n) cout << a[i] << ' ';
    // cout << endl;
    min = a[id];
  }
  ll ans = 0;
  rep(i, n) ans += a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4720
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    int n,k;cin>>n>>k;

    vector<LL> minus;
    vector<LL> plus;
    minus.PB(0);
    plus.PB(0);

    REP(i,n){
        LL a;cin>>a;
        if(a<0){
            minus.PB(-a);
        }
        else{
            plus.PB(a);
        }
    }
    SORT_ASC(plus);
    SORT_ASC(minus);
    int sizeP = SIZE(plus);
    int sizeM = SIZE(minus);

    LL result = INF_LL;

    REP(i,k){
        //+からi個、-からk-i個
        if(sizeP > i && sizeM > k-i){
            LL tmp = plus[i]+minus[k-i]+min(plus[i],minus[k-i]);
            result = min(result,tmp);
        }

        //+からk-i個、-からi個
        if(sizeP > k-i && sizeM > i){
            LL tmp = plus[k-i]+minus[i]+min(plus[k-i],minus[i]);
            result = min(result,tmp);
        }
    }
    cout<<result<<endl;


	return;
}

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

Measured memory_bytes: 1656
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<iostream>

using namespace std;

string S,T;

map <char,char> mu;
map <char,char> pu;

int main()
{
	cin >> S;
	cin >> T;
	for(int i = 0; i < S.size(); i++){
		if(mu.count(S[i])){
			if(mu[S[i]] != T[i]) {
				printf("No\n");
				return 0;
			}
		}
		if(pu.count(T[i])) {
			if(pu[T[i]] != S[i]) {
				printf("No\n");
				return 0;
			}
		}
		mu[S[i]] = T[i];
		pu[T[i]] = S[i];
	}
	printf("Yes\n");
}

Measured memory_bytes: 900
n = int(input())
ts = []
for i in range(n):
    x, l = map(int, input().split())
    t = x + l
    s = x - l
    ts.append([t, s])

ts.sort()
ans = 0
T = float("inf") * - 1
for i in range(n):
    if T <= ts[i][1]:
        ans += 1
        T = ts[i][0]

print(ans)

Measured memory_bytes: 20104
#![allow(non_snake_case)]
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n:usize, k:i64,
        a: [i64; n]
    }
    let mut cnt = vec![0usize; 60];
    for &x in &a {
        for i in 0..60 {
            if (x >> i) & 1 > 0 {
                cnt[i] += 1;
            }
        }
    }
    let mut ans = 0;
    let mut v = 0;
    for i in (0..60).rev() {
        if cnt[i] < n - cnt[i] && v | (1 << i) <= k {
            v |= 1 << i;
            ans += (n - cnt[i]) << i;
        } else {
            ans += cnt[i] << i
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4048
/*
	0136:Frequency Distribution of Height
*/
#include	<iostream>

using namespace std;

int main(void) {
	int n, v[6] = { 0 };
	
	cin >> n;
	
	for(int i = 0; i < n; i++) {
		int rank;
		double num;
		
		cin >> num;
		
		if(num < 165.0) {
			v[0]++;
		}
		else if(num < 170.0) {
			v[1]++;
		}
		else if(num < 175.0) {
			v[2]++;
		}
		else if(num < 180.0) {
			v[3]++;
		}
		else if(num < 185.0) {
			v[4]++;
		}
		else {
			v[5]++;
		}
	}
	
	for(int i = 0; i < 6; i++) {
		cout << i+1 << ':';
		for(int j = 0; j < v[i]; j++) {
			cout << '*';
		}
		cout << endl;
	}
	
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    stable_sort(s.begin(),s.end());
    if(s.at(0)==s.at(1)&&s.at(2)==s.at(3)&&s.at(1)!=s.at(2)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
    string s; cin >> s;
    int q; cin >> q;
    bool rev = false;
    deque<char> sd;
    for (auto& c : s) sd.push_back(c);
    for (int i = 0; i < q; i++) {
        int t; cin >> t;
        if (t == 1) rev = !rev;
        else {
            int f; cin >> f;
            char c; cin >> c;
            if (!rev) {
                if (f == 1) sd.push_front(c);
                else sd.push_back(c);
            } else {
                if (f == 1) sd.push_back(c);
                else sd.push_front(c);
            }
        }
    }
    if (rev) reverse(sd.begin(), sd.end());
    for (auto& c : sd) cout << c;
    cout << "\n";
}

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

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

vector<ll> pw2(51,1);
vector<ll> pw10(19,1);

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

//a,b x
int main(){
	vector<ll> A(4);
	rep(i,4) cin>>A[i];
	sort(A.bg,A.ed);
	if(A[0]==1 && A[1]==4 && A[2]==7 && A[3]==9) cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n+1),b(m+1);
    for(int i=1;i<=n;i++){
        int s;
        cin>>s;
        a[i]=a[i-1]+s;
    }
    for(int i=1;i<=m;i++){
        int s;
        cin>>s;
        b[i]=b[i-1]+s;
    }

    ll ans=0,j=m;
    for(int i=0;i<=n;i++){
        if(a[i]>k) break;
        while(b[j]>k-a[i]) j--;
        ans=max(ans,i+j);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6380
#１４３．2つの数字を選んで掛けてから足し合わせる
N=int(input())
d= list(map(int, input().split()))
ans=0
for i in range (N-1):
    for j in range(i+1,N):
        ans=ans+d[i]*d[j]
print(ans)

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

int n, a[1010];

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

  int mini = 1e9 + 9;
  for (int i = -100; i <= 100; i++){
    int sum = 0;
    for (int j = 0; j < n; j++){
      sum += (i - a[j]) * (i - a[j]);
    }

    mini = min(mini, sum);
  }

  cout << mini << endl;
}


Measured memory_bytes: 256
s = input().rstrip()
A,Z = -1, -1
length = len(s) - 1

for i in range(length):
    if A == -1:
        if s[i] == "A":
            if A == -1:
                A = i
                A_flag = True
    if Z == -1:
        if s[length-i] == "Z":
            if Z == -1:
                Z = length-i
                Z_flag = True
    if A != -1 and Z != -1:
        break

print(Z-A+1)


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

int main(){
    int N;
    int a[100];
    cin >> N;
    for(int i = 0;i < N;i++) cin >> a[i];
    sort(a,a + N,greater<int>());
    int Alice =0;
    int Bob = 0;
    for(int i = 0;i < N;i++){
        if(i % 2 == 0)
            Alice += a[i];
        else 
            Bob += a[i];
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)


int main() {
	int n; cin >> n;
  cout << n *n*n << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String right = "CODEFESTIVAL2016";
		String input = in.next();
		int count = 0;
		for(int i=0;i<right.length();i++){
			char chtemp = input.charAt(i);
			char chright = right.charAt(i);
			if(chtemp != chright)
				count++;
		}
		System.out.println(count);

	}

}

Measured memory_bytes: 10064
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a < b) {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
		cout << endl;
	}
	else {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
		cout << endl;
	}
}


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

int main() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k) {
        cout << "Yay!" << endl;
    }
    else if (e - a > k ) {
        cout << ":(" << endl;
        }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n, a[100], count;

  // 1行目（数列の長さ）の読み込み
  scanf("%d", &n);
  // 2行目（数列の値）の読み込み
  for(count=0; count<n; count++) {
    scanf("%d", &a[count]);
  }

  // 値の出力
  for(count=n; count>0; count--) {
    printf("%d", a[count-1]);
    // 最後でなければ空白を表示
    if(count!=1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }
    static long GCD(long x,long y)
    {
        if (y == 0) return x;
        return GCD(y, x % y);
    }

    static long LCM(long x,long y)
    {
        return x * y / GCD(x, y);
    }
    

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var R = sc.intarr[0];
        if (R < 1200) wr.wri("ABC");
        else if (R < 2800) wr.wri("ARC");
        else wr.wri("AGC");
    }
}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13268
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 10000
	maxBufSize     = 10000000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

func main() {
	N := scanIntNum()
	A := scanIntNums()

	m := make(map[int]int, N)

	for _, num := range A {
		m[num] = m[num] + 1
	}

	for i := 1; i <= N; i++ {
		fmt.Println(m[i])
	}
}

func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

func scanIntNums() (nums []int) {
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums = make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}
	return nums
}


Measured memory_bytes: 16876
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	string a,b;
	cin>>a;
	cin>>b;
	vector<vi> dp;
	for(int i=0;i<=a.length();i++){
		vi x;
		for(int j=0;j<=b.length();j++){
			if(i==0||j==0){
				x.pb(0);
			}else if(a[i-1]!=b[j-1]){
				x.pb(max(dp[i-1][j], x[j-1]));
			}else{
				x.pb(1+dp[i-1][j-1]);
			}
		}
		dp.pb(x);
	}
	int index=dp.back().back();
	char ans[index+1];
	ans[index]='\0';
	int i=a.length(), j=b.length();
	while(i>0&&j>0&&index>=0){
		if(a[i-1]==b[j-1]){
			ans[--index]=a[i-1];
			i--;
			j--;
		}
		else if(dp[i][j-1]<dp[i-1][j]){
			i--;
		}else{
			j--;
		}
	}
	for(int i=0;i<sizeof(ans)-1;i++){
		cout<<ans[i];
	}
}

Measured memory_bytes: 35584
import java.util.*

object MainKt {
	@JvmStatic
	fun main(args: Array<String>) {
		val scanner = Scanner(System.`in`)
		val b: String = scanner.next()

		when(b){
			"A" -> println("T")
			"T" -> println("A")
			"C" -> println("G")
			"G" -> println("C")
		}
	}

}

Measured memory_bytes: 29728
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
#define fi first
#define se second
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    Int n;
    cin >> n;
    vector<Int> h(n);
    for (Int i = 0; i < n; i++) cin >> h[i];
    Int ma = 0;
    Int cur = 0;
    for (Int i = 0; i < n - 1; i++) {
        if (h[i] >= h[i + 1]) {
            cur++;
            ma = max(cur, ma);
        }
        else {
            cur = 0;
        }
    }
    dump(ma);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
//#define ln cout<<'\n'
#define ln cout<<endl
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  string s[2]={"",""};
  char b[2]={'.','#'};
  bool f=0;
  while(1) {
    rep(i,4) {
      if(!f) pr(s[0]+b[i&1]);
      else pr(b[i&1]+s[0]);
      if(!f) pr(s[1]+b[!!(i&2)]);
      else pr(b[!!(i&2)]+s[1]);
      char c;
      R c;
      if(c=='T') {
        if(!f) s[0]=s[0]+b[i&1];
        else s[0]=b[i&1]+s[0];
        if(!f) s[1]=s[1]+b[!!(i&2)];
        else s[1]=b[!!(i&2)]+s[1];
        goto next;
      } else if(c=='F') continue;
      else return;
    }
    f=1;
  next:;
  } 
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


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

#define ll long long
#define mod 1000000007
#define pii pair<ll,ll>

#define debug(a) { cout << #a << " = " << a << endl;}

const int maxn = 1e5+1;
ll arr[maxn], n, m, t, k;
unordered_map<ll,ll> u;

ll __min(ll a, ll b) {
    return a < b ? a : b;
}

ll __max(ll a, ll b) {
    return a > b ? a : b;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
	string s;
	cin>>s;
	ll su=0;
	for (char c:s) {
		su = (su + (ll)(c-'0'))%9;
	}
	if (su%9 == 0) cout << "Yes\n";
	else cout << "No\n";
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  string s;
  cin >> s;

  string dream = "dream";
  string dreamer = "dreamer";
  string erase = "erase";
  string eraser = "eraser";

  reverse(s.begin(), s.end());
  reverse(dream.begin(), dream.end());
  reverse(dreamer.begin(), dreamer.end());
  reverse(erase.begin(), erase.end());
  reverse(eraser.begin(), eraser.end());

  string t = "";
  int next = 0;

  while (1) {
    if (next == s.size()) {
      cout << "YES" << endl;
      return 0;
    }
    int i = s.find(dream, next);
    if (i == next) {
      next += dream.size();
      continue;
    }
    i = s.find(dreamer, next);
    if (i == next) {
      next += dreamer.size();
      continue;
    }
    i = s.find(erase, next);
    if (i == next) {
      next += erase.size();
      continue;
    }
    i = s.find(eraser, next);
    if (i == next) {
      next += eraser.size();
      continue;
    }
    cout << "NO" << endl;
    return 0;
  }
}


Measured memory_bytes: 512
#include<stdio.h>
#define N 1000
int main(void){
  int i,num;
  double h[N];
  double high,low;

  for(i=0;scanf("%lf",&h[i])==1;i++){}
  num=i;
  high=h[0];
  for(i=1;i<num;i++)
    if(h[i]>high)
      high=h[i];
  low=h[0];
  for(i=0;i<num;i++)
    if(h[i]<low)
      low=h[i];
  printf("%0.1f\n",high-low);
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int N = 200;
int D[N][N], V[N][N];

double max_r[N];

const int P = 1010;
double dp[N][P][2];

int main(){
    memset(D,-1,sizeof(D));
    memset(V,-1,sizeof(V));

    int n,m,p;
    scanf(" %d %d %d", &n, &m, &p);

    rep(i,m){
        int s,t,d,v;
        scanf(" %d %d %d %d", &s, &t, &d, &v);
        --s;
        --t;

        D[s][t] = D[t][s] = d;
        V[s][t] = V[t][s] = v;
    }

    rep(i,n){
        rep(j,n)if(D[i][j]!=-1){
            max_r[i] = max(max_r[i], (double)V[i][j]/D[i][j]);
        }
    }

    rep(i,N)rep(j,P)rep(k,2) dp[i][j][k] = -123456789;
    dp[0][0][0] = 0;
    rep(t,p+1){
        rep(v,n){
            rep(f,2){
                // 移動
                rep(nx,n)if(D[v][nx]!=-1){
                    int nt = t+D[v][nx];
                    if(nt<=p) dp[nx][nt][f] = max(dp[nx][nt][f], dp[v][t][f]+V[v][nx]);
                }
            }

            // うろうろ
            rep(a,p+1){
                int nt = t+a;
                if(nt>p) break;
                dp[v][nt][1] = max(dp[v][nt][1], dp[v][t][0]+max_r[v]*a);
            }
        }
    }

    printf("%.10f\n", dp[0][p][1]);
    return 0;
}



Measured memory_bytes: 6696
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using ll = long long;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main() {
  int n;cin>>n;
  for (Bint a=-150;a<150;a++){
    for (Bint b=-150;b<150;b++){
      if (a*a*a*a*a-b*b*b*b*b==n) {
        cout<<a<<' '<<b<<endl;
        return 0;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

set<int> primes;

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}

	return gcd(b, a % b);
}

int prime_factors(int n) {
	if (n % 2 == 0) {
		if(primes.find(2) != primes.end()) {
			return 0;
		}

		primes.insert(2);
		while(n % 2 == 0) {
			n = n/ 2;
		}
	}
	
	for (int i = 3; i <= sqrt(n); i+= 2) { 
		if (n % i == 0) {
			if (primes.find(i) != primes.end()) {
				return 0;
			}

			primes.insert(i);
			while(n % i == 0) {
				n = n/i;
			}
		}
	}

	if (n > 2) {
		if (primes.find(n) != primes.end()) {
			return 0;
		}
		primes.insert(n);
	}

	return 1;
} 
 
void c_p_c()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
   #ifndef ONLINE_JUDGE
	freopen("/home/abhinav/c++ codes/input output c++/input.txt", "r", stdin);
	freopen("/home/abhinav/c++ codes/input output c++/output.txt", "w", stdout);
   #endif
   
   int n;
   cin >> n;
   vector<int> v(n + 1);
   int gc;

   for (int i = 0; i < n; i++) {
   		cin >> v[i];
   		if (i == 0) {
   			gc = v[i];
   		}
   		else
   			gc = gcd(v[i], gc);
   }
   if (gc == 1) {
   		int flag = 1;
   		for (int i = 0; i < n; i++) {
   			flag = prime_factors(v[i]);
   			//cout << flag << endl;
   			if (flag == 0) {
   				break;
   			} 
   		}

   		if (flag == 0) {
   			cout << "setwise coprime";
   		}
   		else {
   			cout << "pairwise coprime";
   		}
    }
    else {
    	cout << "not coprime";
    }
   //cout << gcd(v[0], v[1]);
}
 
int32_t main()
{
    c_p_c();
    return 0;
}

Measured memory_bytes: 11180
S = str(input())
N = len(S)

left_b = 0
if N%2 == 0:
    for i in range(N//2):
        if S[2*i] == str(1): #もし奇数番目が白だったらひっくり返す
            left_b = left_b + 1
        if S[2*i+1] == str(0):
            left_b = left_b + 1
    mini = min(left_b,N - left_b)
        
else:
    for i in range(N//2):
        if S[2*i] == str(1): #もし奇数番目が白だったらひっくり返す
            left_b = left_b + 1
        if S[2*i+1] == str(0):
            left_b = left_b + 1
    if S[N-1] == str(1):
            left_b = left_b + 1
    mini = min(left_b,N - left_b)

print(mini)


        

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define inf (int)(1e9)
using namespace std;

int n;
string s;
vector<int> dp;
map<int, int> mp;

int solve();

int main() {
  cin >> s;
  n = s.size();
  cout << solve() << endl;
  return 0;
}

int solve() {
  int sum = 0;
  dp.assign(n + 1, inf);
  dp[0] = 0;
  mp[0] = 0;
  for (int i = 0; i < n; ++i) {
    sum ^= 1 << (s[i] - 'a');
    for (int j = 0; j < 26; ++j) {
      int bit = sum ^ (1 << j);
      if (mp.find(bit) != mp.end()) dp[i + 1] = min(dp[i + 1], mp[bit] + 1);
    }
    if (mp.find(sum) != mp.end()) dp[i + 1] = min(dp[i + 1], mp[sum] + 1);
    if (mp.find(sum) == mp.end() || mp[sum] > dp[i + 1]) mp[sum] = dp[i + 1];
  }
  return dp[n];
}

Measured memory_bytes: 13464
#include <iostream>
#define MAX 1000
#define MODULO 1000000007

using namespace std;

char mat[MAX + 5][MAX + 5];
int dp[MAX + 5][MAX + 5];

int main()
{
    int h, w;

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

    cin >> h >> w;
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            cin >> mat[i][j];

    dp[1][0] = 1;

    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            if(mat[i][j] == '.')
            {
                if(mat[i - 1][j] == '.' && mat[i][j - 1] == '.')
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

                dp[i][j] %= MODULO;
            }

    cout << dp[h][w];

    return 0;
}


Measured memory_bytes: 5248
<?php
// Your code here!
$input = explode(" ",trim(fgets(STDIN)));

if($input[0] != $input[1]){
    if($input[0] < $input[1]){
        for($i = 0; $i < $input[1]; $i++){
            echo $input[0]; 
        }
    }else{
        for($i = 0; $i < $input[0]; $i++){
            echo $input[1];
        }
    }
}else{
    for($i = 0; $i < $input[0]; $i++){
        echo $input[1]; 
    }
}
echo PHP_EOL;


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

int main()
{
    int n, k;
    cin >> n >> k;
    int x[100007], y[100007];
    char c[100007];
    int b[2007][2007], w[2007][2007];
    int s[2007][2007];
    for(int i = 0; i < k * 2; i++){
        fill(b[i], b[i] + k * 2, 0);
        fill(w[i], w[i] + k * 2, 0);
    }
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> c[i];
        if(c[i] == 'B') b[x[i] % (k * 2)][y[i] % (k * 2)]++;
        else w[x[i] % (k * 2)][y[i] % (k * 2)]++;
    }
    for(int j = 0; j < k * 2; j++){
        int sum = 0;
        for(int i = 0; i < k; i++){
            sum += w[i % (k * 2)][j % (k * 2)];
            sum += b[i % (k * 2)][(j + k) % (k * 2)];
        }
        for(int i = k; i < k * 2; i++){
            sum += b[i % (k * 2)][j % (k * 2)];
            sum += w[i % (k * 2)][(j + k) % (k * 2)];
        }
        s[0][j] = sum;
        for(int i = 0; i < k * 2 - 1; i++){
            sum = sum + w[(k + i) % (k * 2)][j % (k * 2)] + b[i % (k * 2)][j % (k * 2)]
                + b[(k + i) % (k * 2)][(j + k) % (k * 2)] + w[i % (k * 2)][(j + k) % (k * 2)]
                - (b[(k + i) % (k * 2)][j % (k * 2)] + w[i % (k * 2)][j % (k * 2)]
                + w[(k + i) % (k * 2)][(j + k) % (k * 2)] + b[i % (k * 2)][(j + k) % (k * 2)]);
            s[i + 1][j] = sum;
        }
    }
    int ans = 0;
    for(int i = 0; i < k * 2; i++){
        int sum = 0;
        for(int j = 0; j < k; j++){
            sum += s[i][j];
        }
        ans = max(ans, sum);
        for(int j = 0; j < k * 2 - 1; j++){
            sum = sum + s[i][(k + j) % (k * 2)] - s[i][j % (k * 2)];
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 48256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i, n + 1) cin >> a[i];
    ll ans = 0;
    rep(i, n) {
        ll b;
        cin >> b;
        if (a[i] < b) {
            b -= a[i];
            ans += a[i];
            ll v = min(a[i + 1], b);
            ans += v;
            a[i + 1] -= v;
        }
        else {
            ans += b;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
N = list(map(int, input().split()))
N = sorted(N, reverse=True)

one = N[0] - N[1]
two = N[0] - N[2]

ans = 0

if one % 2 == 0 and two % 2 == 0:
    ans += one /2 + two /2
elif one % 2 == 1 and two % 2 == 1:
    ans += one //2 + two //2 + 1
else:
    ans += one //2 + two //2 + 2

print(int(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define LL(x) ll x; scanf("%lld",&x)
#define INPUT(x) cin >> x
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF_INT 2147483647
#define INF_LL 9223372036854775807

typedef long long ll;

int main(){
    string s;
    cin >> s;
    
    int mini = 1000000;
    
    REP1(i, s.size()-1){
        if (s[i] != s[i+1]) {
            mini = min(mini, max(i+1, int(s.size()-1-i)));
        }
    }
    if (mini == 1000000) mini = s.size();
    
    cout << mini << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{

    int n;
    scanf("%d", &n);

    long a[200000];
    long y[200000];
    long o[200000];


    for (int i = 0; i < n; i++)
    {
        scanf("%ld", &a[i]);
        y[i]=a[i]+i+1;
        o[i] = i + 1 - a[i];
    }

    long pare[200001];
    for (int i = 0; i < 200001; i++)
    {
        pare[i] = 0;
    }

    long count = 0;
    for (int i = 0; i < n; i++)
    {
        if(o[i]>0){
        count = pare[o[i]] + count;
        //printf("%ld %d-\n", o[i],count);
        }
        if(y[i]<200001){
        pare[y[i]]++;
        }
//printf("%ld  %d----\n", y[i], pare[y[i]]);
        }

        printf("%ld",count);
   

    printf("\n");
}

Measured memory_bytes: 8404
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

w=gets.chomp
s=[]
while true
  s_input=get
  break if s_input[0]=="END_OF_TEXT"
  s.push(s_input)
end
s.flatten!
ans=0
s.each do|str|
  ans+=1 if str.downcase==w.downcase
end
puts ans


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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,X;
    cin >> N >> X;

    vector<int> m(N);
    int ans = 0;

    rep(i,N)
    {
        cin >> m[i];
        X -= m[i];
        ans++;
    }

    std::vector<int>::iterator iter = std::min_element(all(m));
    size_t index = std::distance(m.begin(), iter);

    while( X >= m[index] )
    {
        X -= m[index];
        ans++;
    }
    cout << ans << endl;





}


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

int main(){

	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(m);
	vector<int> d(m);
	for(int i=0; i<n; i++) cin >> a[i] >> b[i];
	for(int i=0; i<m; i++) cin >> c[i] >> d[i];
	for(int i=0; i<n; i++){
		int mn = 1000000000;
		int tmp = -1;
		for(int j=0; j<m; j++){
			if( mn > abs(a[i]-c[j])+abs(b[i]-d[j]) ){
				mn = abs(a[i]-c[j])+abs(b[i]-d[j]);
				tmp = j;
			}
		}
		cout << tmp + 1 << endl;
	}

	return 0;
}


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

int main(){
  int N;
  cin >> N;
  
  vector<ull> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (i) {
      if (a.at(i - 1) > 1) a.at(i - 1)--;
      if (a.at(i - 1) == a.at(i)) a.at(i)++;
    }
  }
  
  for (int i = 0; i < N; i++) {
    if (i) {
      if (a.at(i - 1) > a.at(i)) {
        cout << "No";
        return 0;
      }
    }
  }
  
  cout << "Yes";
  return 0;
}



Measured memory_bytes: 1024
N, M = map(int, input().split())
ac_counter = [0 for _ in range(N)]
wa_counter = [0 for _ in range(N)]
wa_sum = 0
for _ in range(M):
    line = input().split()
    problem = int(line[0])
    result = line[1]
    if not ac_counter[problem-1] == 1:
        if result == 'AC':
            ac_counter[problem-1] = 1
            wa_sum += wa_counter[problem-1]
        else:
            wa_counter[problem-1] += 1

answer = []
answer.append(str(sum(ac_counter)))
answer.append(str(wa_sum))
print(" ".join(answer))


Measured memory_bytes: 4760
N, M = list(map(int, input().split()))
sh_li = []
for i in range(N):
    a, b = list(map(int, input().split()))
    sh_li.append([a, b])
sh_li.sort(key=lambda x:x[0],reverse=False)

def calc(li, m):
    total = 0
    for sh in li:
        if sh[1] < m:
            total += sh[0] * sh[1]
            m -= sh[1]
        else:
            total += sh[0] * m
            return total

print(calc(sh_li, M))

Measured memory_bytes: 21600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>

#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))

using namespace std;

int A,B,C,D;

int main() {

	cin >> A >> B >> C >> D;

	if (A+B > C+D) cout << "Left" << endl;
	else if (A+B < C+D) cout << "Right" << endl;
	else cout << "Balanced" << 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 a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    int line = a + b;
    int area = line*h/2;
    System.out.println(area);
  }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n;
char s[N];
signed main()
{
	int cnt=0;ll ans=0;
	scanf("%s",s+1);n=strlen(s+1);
	for (int i=1;i<=n;i++)
	if (s[i]=='A') cnt++;
	else if (s[i]=='B')
	{
		if (s[i+1]=='C') i++,ans+=cnt;
		else cnt=0;
	}
	else cnt=0;
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}

Measured memory_bytes: 3904