akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
long long fact(int x){//x! 階乗 O(n)
  long long ans=1;
  for (int i=1;i<=x;i++){
    ans *= i;}
  return ans;
}
long long combination(double n,int k){//nCk　組み合わせ　fact関数必須! O(1)
  long long ans=0;
  if(k==2){
    ans=n/2*(n-1);
  }
  if(k-2)ans=fact(n)/(fact(k)*fact(n-k));
  return ans;
}
  
int main() {
  ll ans=0;
  int n;
  cin>>n;
  vector<ld>v(n);
  vector<ld>cnt(n);
  rep(i,n){cin>>v[i];cnt[v[i]-1]++;}
  cerr<<"input end..."<<endl;
  rep(j,n){
    ans+=combination(cnt[j],2);
    cerr<<"LOOP "<<j+1<<" "<<ans<<endl;
  }
  cerr<<"ans end..."<<endl;
  cerr<<ans;
  rep(k,n){
    ll ansk=ans;
    ansk=ans+ ((cnt[v[k]-1]-1)/2*(cnt[v[k]-1]-2)-(cnt[v[k]-1]-1)/2*(cnt[v[k]-1]-0));
    cout<<ansk<<endl;
  }
}

Measured memory_bytes: 8832
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int N;
int H[100000];

int main(){
    cin>>N;
    rep(i,N) cin>>H[i];

    H[0]--;
    for(int i=0;i<N-1;i++){
        if(H[i]<H[i+1]){
            H[i+1]--;
        }else if(H[i]>H[i+1]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
from heapq import *
n,m=map(int,input().split())
l=list(map(int,input().split()))
arr=[list(map(int,input().split())) for i in range(m)]
arr.sort(key=lambda x:x[1],reverse=True)
l.sort()
i=0
j=0
while(i<n):
    if(l[i]>=arr[j][1]):
        break
    l[i]=arr[j][1]
    arr[j][0]-=1
    if(arr[j][0]==0):
        j+=1
    if(j>=m):
        break
    i+=1
    #print(j,l)
#print(l)
print(sum(l))

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<ll,ll> pll ;
typedef vector<pii> vpii ;
typedef vector<pll> vpll ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define NP next_permutation
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}
//-----------------------------------------




















//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  str s ;
  cin >> n >> s ;
  vector<int> cnt(26,0) ;
  REP(i,n){
    cnt[s[i]-'a']++ ;
  }
  ll ans = 1 ;
  REP(i,26){
    ans *= (cnt[i]+1) ;
    ans %= MOD ;
  }
  
  cout << ans -1 <<endl ;
  
  
  
  
  return 0 ;
}



Measured memory_bytes: 512
//ProblemC

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

//ProblemC

class Solve {
private:
	long long n, m;

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

		if (n < m) swap(n, m);

		long long rst = 0;
		if (m == 1) {
			if (n == 1) rst = 1;
			else if (n == 2) rst = 0;
			else rst = n - 2;
		}
		else if (m == 2) {
			rst = 0;
		}
		else {
			rst = (n - 2) * (m - 2);
		}
		cout << rst << endl;
	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

string s;
int n;

bool check(int u) {
    int g = n - u;
    if (g * 2 >= n) return true;
    FOR(i,g+1,n-g-1)
        if (s[i] != s[i+1]) return false;
    return true;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> s;
    n = SZ(s);
    s = " " + s;
    int dau = 1, cuoi = n;
    while (dau <= cuoi) {
        int mid = (dau + cuoi) >> 1;
        if (check(mid)) dau = mid+1;
        else cuoi = mid-1;
    }
    cout << cuoi;
    return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

ll dp[1000][1000];

int main() {
	speed;
	int n, m;
	cin >> n >> m;
	vector<string>v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (v[i][j] == '.') {
				if (i && j)
					dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
				else if (j)
					dp[i][j] = dp[i][j - 1];
				else if (i)
					dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[n - 1][m - 1];
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int a[100005],b[100005],c[100005];
ll ans=0;
int main(int argc,char const* argv[])
{
  cin >> N;
  for(int i=0;i<N;i++)
    {
      cin >> a[i];
    }
  for(int i=0;i<N;i++)
    {
      cin >> b[i];
    }
  for(int i=0;i<N;i++)
    {
      cin >> c[i];
    }
  sort(a,a+N);
  sort(b,b+N);
  sort(c,c+N);
  for(int i=0;i<N;i++)
    {
      auto low=lower_bound(a,a+N,b[i])-1;
      auto up=upper_bound(c,c+N,b[i]);
      //cout << distance(a,low) << ' ' << distance(c+N,up) << endl;
      ans+=(distance(a,low)+1)*abs(distance(c+N,up));
    }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
MAX = (10 ** 9) * (-1)
def solve(N, H, a, b):
    import heapq
    import math
    # Get the highest attack value for a 
    max_a = max(a)
    max_a_index =[]
    for i in range(N):
        if(a[i] == max_a):
            max_a_index.append(i)

    minimum_b_in_max_a_index = -1
    minimum_b_in_max_a = MAX
    for i in max_a_index:
        temp_b = b[i]
        if(temp_b >= minimum_b_in_max_a):
            minimum_b_in_max_a = temp_b
            minimum_b_in_max_a_index = i
    
    main_sword_index = minimum_b_in_max_a_index
    main_sword_a = a.pop(main_sword_index)
    main_sword_b = b.pop(main_sword_index) * (-1)

    heapq.heapify(b)
    answer = 0

    #Throwing swords other than main
    while len(b) > 0:
        new_sword = heapq.heappop(b) * (-1)
        if(new_sword < main_sword_a):
            break
        else:
            H -= new_sword
            answer += 1
            if(H <= 0):
                return answer

    # Slush with main sword

    if(H <= main_sword_b):
            # Throw main sword
            answer += 1
    else:
        H -= main_sword_b
        answer += 1
        answer += (math.ceil(H / main_sword_a))
    return answer


def main():
    N, H = map(int, input().split())
    swords = []
    a = [0] * N
    b = [0] * N
    for i in range(N):
        #swords.append(list(map(int, input().split[])))
        X, Y = map(int, input().split())
        a[i] = X
        b[i] = Y * (-1)
    
    print(solve(N, H, a, b)) 
    


main()

Measured memory_bytes: 63192
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <class T>
class cumulativeSum
{
private:
    int n;
    vector<T> sum;
public:
    cumulativeSum(const vector<T>& a)
    {
        n = a.size();
        sum.assign(n+1, 0);
        for(int i=0; i<n; ++i)
            sum[i+1] = a[i] + sum[i];
    }
    T getSum(int x1, int x2)
    {
        x1 = max(x1, 0);
        x2 = min(x2, n-1);
        if(x1 > x2)
            return 0;
        return sum[x2+1] - sum[x1];
    }
};

int main()
{
    vector<vector<int> > v(2);
    for(int i=0; i<2; ++i){
        string s;
        cin >> s;
        v[i].resize(s.size()+1);
        for(unsigned j=0; j<s.size(); ++j){
            if(s[j] == 'A')
                v[i][j+1] = 1;
            else
                v[i][j+1] = 2;
        }
    }
    vector<cumulativeSum<int> > cs = {v[0], v[1]};

    int q;
    cin >> q;
    while(--q >= 0){
        int a, b, c, d;
        cin >> a >> b >> c >> d;

        int x = cs[0].getSum(a, b);
        int y = cs[1].getSum(c, d);
        if(x % 3 == y % 3)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 2744
#include <iostream>
#include <set>

using namespace std;
typedef long long ll;

int main(int argc, const char *argv[])
{
    ll N, a;
    set<ll> s;
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        cin >> a;
        decltype(s)::iterator it = s.find(a);
        if (it == s.end()) {
            s.insert(a);
        } else {
            s.erase(it);
        }
    }

    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;
 
signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  
  lol n,k;
  cin >> n >> k;
  cout << min(n%k,abs(n % k, k)) << '\n';
  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use itertools::Itertools;

fn main() {
    input! {
        n: i32,
        l_vec: [i32; n]
    }

    let it = (0..n).combinations(3);
    let mut num_patterns = 0;
    for pattern in it {
        let mut l_pattern = vec![
            l_vec[pattern[0] as usize],
            l_vec[pattern[1] as usize],
            l_vec[pattern[2] as usize],
        ];
        l_pattern.sort();
        let first = l_pattern[0];
        let second = l_pattern[1];
        let third = l_pattern[2];
        let is_all_diff = first != second && first != third && second != third;
        let is_triangle = first + second > third;
        if is_all_diff && is_triangle {
            num_patterns += 1;
        }
    }
    println!("{}", num_patterns);
}


Measured memory_bytes: 2188
#include <iostream>
#include <cstring>

using namespace std;

#define M 1046527
#define L 14

char H[M][L];

int getChar(char c) {
	if (c == 'A') return 1;
	if (c == 'C') return 2;
	if (c == 'G') return 3;
	if (c == 'D') return 4;
	return 0;
}

long long getKey(char str[]) {
	long long sum = 0, p = 1;
	for (int i = 0; i < strlen(str); ++i) {
		sum += p * getChar(str[i]);
		p *= 5;
	}
	return sum;
}

int h1(int key) {
	return key % M;
}

int h2(int key) {
	return 1 + (key % (M - 1));
}

bool find(char str[]) {
	long long key, h;
	key = getKey(str);
	for (int i = 0;; ++i) {
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0) return true;
		if (strlen(H[h]) == 0) return false;
	}
	return false;
}

bool insert(char str[]) {
	long long key, h;
	key = getKey(str);
	for (int i = 0;; ++i) {
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0) return true;
		if (strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return false;
		}
	}
	return false;
}

int main() {
	int n;
	char str[L], com[9];
	for (int i = 0; i < M; ++i) H[i][0] = '\0';
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> com >> str;
		if (com[0] == 'i') insert(str);
		else {
			if (find(str)) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 17396
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

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

  if (K == 1)
    cout << 0 << "\n";
  else
    cout << (N - K) << "\n";
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
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; }
typedef unsigned long ul;
const ul INF = 1LL<<60;
ul N,M;
inline void solve(){
  IN2(N,M);
  if(N==1&&M==1)OUT(1);
  else if(N==1)OUT(M-2);
  else if(M==1)OUT(N-2);
  else OUT((M-2)*(N-2));
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
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;}



signed main(){
	int N;
	cin>>N;
	int t = 0;
	REP(i,N){
		int a;
		cin>>a;
		t ^= a;
	}
	if(t)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> pre(n+1);
    foi(0,n)
    {
        if(s[i]=='W')
            pre[i+1] = pre[i]+1;
        else
            pre[i+1] = pre[i];
    }
    ll ans = LLONG_MAX;
    for(ll i=n;i>=0;i--)
    {
        ll tmp1 = pre[i],tmp2 = (n-i)-(pre[n]-pre[i]);
        ll oper = min(tmp1,tmp2);
        oper = tmp1+tmp2-oper;
        ans = min(oper,ans);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
        // freopen("input1.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
        ll n;
    cin >> n;
    ve<ll> arr;
    rep(i, 0, 12)
    {
        arr.pb(pow(26, i));
    }
    ve<char> ans;
    rev(i, 12, 0)
    {
        if (arr[i] <= n)
        {
            ans.pb((n / arr[i]) + 'a'-1);
            n %= arr[i];
        }
        else
        {
            ans.pb('0');
        }
    }
    ll start=0;
    rep (i,0,12)
    {
        if (ans[i]!='0')
        {
            start=i;
            bb;
        }
    }
    rep (zz,0,15)
    rep (z,start,11)
    {
        if (ans[z+1]<'a')
        {
            ans[z]-=1;
            ans[z+1]='z';
        }
    }
    rep (i,0,12)
    {
        if (ans[i]=='0'||ans[i]<'a')
        {
            //fo
        }
        else
        {
            start=i;
            bb;
        }
    }
    rep (i,start,12)
    {
        cout<<ans[i];
    }
    cout<<"\n";
}


Measured memory_bytes: 4064
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}



fn main() {
    let n:i64 = read();
    let ax:Vec<i64> = (0..n).map(|_|read()).collect();
    let q:i64 = read();
    let bcs:Vec<(i64, i64)> = (0..q).map(|_|read_tuple2()).collect();
    let mut counter = HashMap::new();
    let mut sum:i64 = ax.iter().sum();
    for a in ax {
        let count = counter.entry(a).or_insert(0);
        *count += 1;
    }
    for (b, c) in bcs {
        let num = counter.get(&b);
        if let Some(n) = num {
            let n = *n;
            sum += (c - b) * n;
            println!("{}", sum);
            counter.insert(b, 0);
            let c = counter.entry(c).or_insert(0);
            *c += n;
        } else {
            println!("{}", sum);
        }
    }
}


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


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

	int a[3] = {};
	int m[3] = {};
	int p = 0;
	int b;
	for (int i = 0; i < n; i++) {
		cin >> b;
		int s;
		for (s = 0; s < p; s++) {
			if (a[s] == b) break;
		}
		if (s >= 3) {
			cout << "No" << endl; return 0; }
		if (s == p) { a[s] = b; p++; }
		m[s]++;
	}

	if (p == 1) {
		if (a[0] == 0) {
			cout << "Yes" << endl; return 0;
		}
	}
	else if (p == 2) {
		if (n % 3 != 0) {
			cout << "No" << endl; return 0;
		}
		if (a[0] == 0 && m[1] == m[0] * 2) {
			cout << "Yes" << endl; return 0;
		}
		if (a[1] == 0 && m[0] == m[1] * 2) {
			cout << "Yes" << endl; return 0;
		}
	}
	else {
		if (n % 3 != 0) {
			cout << "No" << endl; return 0;
		}
		if (m[0] == m[1] && m[1] && m[2])
			if (a[2] == (a[0] ^ a[1]))
			{
				cout << "Yes" << endl; return 0;
			}
	}


	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int x;
	cin >> x;
	if (x%7+1==2 || x==1){
		cout << "fri" << endl;
	}else if (x%7+1==3 || x==2){
		cout << "sat" << endl;
	}else if (x%7+1==4 || x==3){
		cout << "sun" << endl;
	}else if (x%7+1==5 || x==4){
		cout << "mon" << endl;
	}else if (x%7+1==6 || x==5){
		cout << "tue" << endl;
	}else if (x%7+1==7 || x==6){
		cout << "wed" << endl;
	}else if (x%7==0){
		cout << "thu" << endl;
	}
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll a,b,c; cin >> a >> b >> c;
    cout << a*b/2 << endl;
}

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

using namespace std;

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

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

int months[]={31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    REP(i,a-1){
        if(months[i]>=i)ans++;
    }
    if(b>=a)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W = IL()
grid = [list(S()) for i in range(H)]

ans = 0
for i in range(H):
  for j in range(W):
    if grid[i][j] == ".":
      ans += 1

data = [[MAX_INT]*W for i in range(H)]

d = deque()
d.append((1, 0, 0)) # (cnt, h, w)
while d:
  cnt, h, w = d.popleft()
  if data[h][w] > cnt:
    data[h][w] = cnt
    for i,j in ((-1,0), (0,-1),(1,0),(0,1)):
      if 0 <= h+i < H and 0 <= w+j < W:
        if grid[h+i][w+j] == ".":
          d.append((cnt+1, h+i, w+j))
if data[-1][-1] == MAX_INT:
  print(-1)
else:
  print(ans - data[-1][-1])

Measured memory_bytes: 40816
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int n, k;
    cin >> n >> k;
    auto p = vector<pair<int, int>>(n);
    for (auto i = 0; i < n; ++i) {
        p[i].second = i;
        cin >> p[i].first;
    }
    sort(p.begin(), p.end());
    p.resize(k);
    cout << accumulate(p.begin(), p.end(), 0LL, [](auto sum, auto item) {
        cerr << item.first << "\n";
        return sum + item.first;
    }) << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x;
  while(1){
    int ans=0;
    cin>>n>>x;
    if(n==0&&x==0){
      break;
    }
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        for(int k=j+1;k<=n;k++){
          if(i+j+k==x){
            ans++;
          }
        }
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3080
# Falling Asleep

# prepare input
N = int(input()) # データ数
playlist = [] # プレイリスト
for i in range(N):
    s, t = input().split()
    t = int(t)
    playlist.append([s,t])
X = input() # 寝落ちした時の曲

# Xのある要素を線形探索 O(N)
p = 0
for i in range(N):
    if playlist[i][0]==X:
        p = i
        break

# 時間の集計
playlist = playlist[p+1:] # プレイリストのカット
time = 0
for i in playlist:
    time = time + i[1]

# 結果の出力
print(time)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r; 
	if((x-r)>=0 && (x+r)<=W&&(y-r)>=0&&(y+r)<=H)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
 } 


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

using namespace std;

namespace mod {

template <class T, int M>
class MInt;

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp);

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n);

template <class T, int M>
class MInt {
  T n_;

 public:
  MInt() : n_(0) {}
  MInt(T n) : n_((n % M + M) % M) {}

  MInt &operator+=(const MInt &rhs) {
    n_ += rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator-=(const MInt &rhs) {
    n_ += M - rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator*=(const MInt &rhs) {
    n_ = n_ * rhs.n_ % M;
    return *this;
  }

  MInt &operator/=(const MInt &rhs) { return (*this) *= Inv(rhs); }

  T Get() { return n_; }
};

template <class T, int M>
MInt<T, M> operator-(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res -= rhs;
}

template <class T, int M>
MInt<T, M> operator+(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res += rhs;
}

template <class T, int M>
MInt<T, M> operator*(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res *= rhs;
}

template <class T, int M>
MInt<T, M> operator/(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res /= rhs;
}

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp) {
  if (exp == 0) {
    return 1;
  }

  auto a = Pow(base, exp / 2);
  a *= a;
  if (exp % 2 == 1) {
    a *= base;
  }

  return a;
}

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n) {
  return Pow(n, static_cast<T>(M - 2));
}
}  // namespace mod

const int md = 1e9 + 7;
using MInt = mod::MInt<long long, md>;

// |s| > |T|
MInt solve(string &s, string &t, int i, int j,
           vector<array<optional<MInt>, 4>> &memo) {
  if (i == s.size()) {
    return j == t.size();
  }

  if (!memo[i][j].has_value()) {
    MInt ans = solve(s, t, i + 1, j, memo);
    if (j < t.size() && s[i] == t[j]) {
      ans += solve(s, t, i + 1, j + 1, memo);
    }

    memo[i][j] = ans;
  }

  return memo[i][j]->Get();
}

int main(int argc, const char *argv[]) {
  string s, t;
  cin >> s;

  int s_qcnt = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '?') {
      s_qcnt++;
    }
  }

  vector<MInt> pow3(s_qcnt + 1);
  pow3[0] = 1;
  for (int i = 1; i < pow3.size(); ++i) {
    pow3[i] = pow3[i - 1] * MInt(3);
  }

  MInt ans = 0;
  for (int i = 0; i < (1 << 3); ++i) {
    string t = "ABC";
    int t_qcnt = 0;
    for (int j = 0; j < 3; ++j) {
      if (!(i & (1 << j))) {
        t[j] = '?';
        t_qcnt++;
      }
    }

    vector<array<optional<MInt>, 4>> memo(s.size() + 1);
    ans += solve(s, t, 0, 0, memo) * pow3[max(0, s_qcnt - t_qcnt)];
  }

  cout << ans.Get() << '\n';
  return 0;
}

Measured memory_bytes: 19796
#include<algorithm>
#include<cstring>
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef unsigned long long ull;
typedef set<int>::iterator sit;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void tempwj(){freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){a %= mod;ll ans = 1;while(b){if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}
struct cmp{bool operator()(const pii & a, const pii & b){return a.second < b.second;}};
int lb(int x){return  x & -x;}
//friend bool operator < (Node a,Node b)   重载
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 305+10;


int main()
{
	int n;
	scanf("%d",&n);
	if(n >= 30)
		printf("Yes\n");
	else
		printf("No\n");

}



Measured memory_bytes: 3164
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
const int MAXN = 1e5 + 10;
int nums[MAXN];

int solve(int n, int k, int p) {
    if (k == 0) return 0;
    if (p == -1) return -nums[n-k];
    int ret = INT_MAX;
    for (int i = 0; i < p; i++) {
        if (p-i > k) continue;
        if (p-i == k) {
            ret = min(ret, -nums[i]);
        } else {
            int tmp = k - (p-i);
            if (tmp+p-1 < n) {
                int tmp2 = 2*min(-nums[i], nums[tmp+p-1]) + max(-nums[i], nums[tmp+p-1]);
                ret = min(ret, tmp2);
            }
        }
    }
    if (p+k-1 < n) ret = min(ret, nums[p+k-1]);
    return ret;
}


int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL
    freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    int p = -1;
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
        if (nums[i] == 0) {
            i--;
            n--;
            k--;
        }
        if (p == -1 && nums[i] > 0) p = i;
    }
    cout << solve(n, k, p) << endl;





/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
    return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 640
strings = input().split(' ')
A = strings[0]
B = strings[1]

strings = input().split(' ')
S = int(strings[0])
T = int(strings[1])

U = input()
  
if A == U:
    print('{0} {1}'.format(S-1, T))
elif B == U:
    print('{0} {1}'.format(S, T-1))

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> s;
	int x = stoi(s.substr(5, 2));
	if (x <= 4)
		cout << "Heisei" << endl;
	else
		cout << "TBD" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		sc.close();
		System.out.println(s1.substring(0, 1).toUpperCase()
				+ s2.substring(0,1).toUpperCase()
				+s3.substring(0, 1).toUpperCase());
	}
}

Measured memory_bytes: 21844
program hrn;
 var
  a,b:array[1..100]of longint;
  i,n,j,m,x:longint;
 begin
  read(n);
  for i:=1 to n do read(a[i]);
  for i:=1 to n do read(b[i]);
  for i:=1 to n do begin
   for j:=1 to i do m:=m+a[j];
   for j:=n downto i do m:=m+b[j];
   if m>x then x:=m;m:=0;
  end;
  writeln(x);
 end.

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
    static Scanner sc;
    public static void main(String[] args) {
        
        sc = new Scanner(System.in);
        int N = parseInt();
        int R = parseInt();

        if (N> 10){
            System.out.println(R);
        }else{
            System.out.println((R + (100*(10-N))));
        }
    }

    public static int parseInt(){
        return Integer.parseInt(sc.next());
    }
}

Measured memory_bytes: 35744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[15],num[5];
int main() {
	ll n,p[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=0;j<15;j++){
			if(i%p[j]==0){
				ll x=i;
				while(x%p[j]==0){
					cnt[j]++;
					x/=p[j];
				}
			}
		}
	}
	for(int i=0;i<15;i++){
		if(cnt[i]>=2)num[0]++;
		if(cnt[i]>=4)num[1]++;
		if(cnt[i]>=14)num[2]++;
		if(cnt[i]>=24)num[3]++;
		if(cnt[i]>=74)num[4]++;
	}
	ll ans=max(0ll,(num[0]-2)*num[1]*(num[1]-1)/2)+max(0ll,(num[1]-1)*num[2])+max(0ll,(num[0]-1)*num[3])+num[4];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import queue
inf = float('inf')
N,M = map(int,input().split())
edge = {}
for i in range(N):
    edge[i] = {}
for i in range(M):
    L,R,D = map(int,input().split())
    L -= 1
    R -= 1
    edge[L][R] = D
    edge[R][L] = -D

x = [inf for i in range(N)]

def bfs(n):
    que = queue.Queue()
    que.put(n)
    x[n] = 0
    ans = True
    while que.qsize():
        L = que.get()
        for R in edge[L]:
            if x[R] != inf:
                if x[R] != x[L]+edge[L][R]:
                    ans = False
            else:
                x[R] = x[L]+edge[L][R]
                que.put(R)
    return ans
for n in range(N):
    if x[n] == inf:
        ans = bfs(n)
        if not ans:
            break

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 76080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const ll oo=1e18+5;
const int N=2e5+5;
const int mod=1e9+7;


ll dp[55][35][2];
string s[55][2];
ll cost[55];
int n;

bool isGud(const string& s,int l,int r){
	for(int i=l,j=r-1;i<j;++i,--j){
		if(s[i]!=s[j]) return 0;
	}
	return 1;
}

ll solve(int id,int suff,int dir){
	int len=(int)s[id][dir].size();
	if(isGud(s[id][dir],len-suff,len)) return 0;
	ll& res=dp[id][suff][dir];
	if(res>=0) return res;
	res=oo;
	int rev=dir^1;
	for(int i=0;i<n;++i){
		int sizee=(int)s[i][rev].size();
		if(sizee<=suff){
			if(s[i][rev]==s[id][dir].substr(len-suff,sizee)){
				res=min(res,cost[i]+solve(id,suff-sizee,dir));
			}
		}
		else{
			if(s[id][dir].substr(len-suff)==s[i][rev].substr(0,suff)){
				res=min(res,cost[i]+solve(i,sizee-suff,rev));
			}
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>s[i][0]>>cost[i];
		s[i][1]=s[i][0];
		reverse(all(s[i][1]));
	}
	ll ans=oo;	
	memset(dp,255,sizeof(dp));
	for(int i=0;i<n;++i){
		ll cur=cost[i]+solve(i,(int)s[i][0].size(),0);
		ans=min(ans,cur);
	}
	if(ans>=oo) ans=-1;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3664
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll ans = 0;

    rep(i, n) {
        int dmg = min(a[i], b[i]);
        b[i] = max(0, b[i] -a[i]);
        int dmg2 = min(a[i+1], b[i]);
        a[i+1] = max(0, a[i+1] -dmg2);
        ans += dmg + dmg2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {

    char a, b;
    cin >> a >> b;
    int ai = a - '0';
    int bi = b - '0';
    if (ai > bi) cout << ">" << endl;
    else if (ai < bi) cout << "<" << endl;
    else cout << "=" << endl;

    return 0;
}

Measured memory_bytes: 256
def ai():return input()#s
def a():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")

a = int(input())
c=set()
for i in range(a):
    t = int(input())
    if t in c:
        c.remove(t)
    else:
        c.add(t)
print(len(c))

Measured memory_bytes: 11884
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))



function main()
  N = readint()[1]
  A = readint()
  A = sort!(A)

  if N==1
    println(1)
    return
  end

  Nmax = 10^6
  kusi = Vector{Bool}(undef,Nmax)
  kusi .= false

  tot = 0
  if A[1] < A[2] 
    tot +=1
  end
  for i in A[1]:A[1]:Nmax
    kusi[i]=true
  end

  for i in 2:N-1
    kusi[A[i]] == true  && continue
    A[i] < A[i+1] && (tot += 1)

    for j in A[i]:A[i]:10^6
      kusi[j] = true
    end
  end

  kusi[A[N]] == false && (tot+=1)
  println(tot)

end

main()

Measured memory_bytes: 197492
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {
	
	int h, w, k, sy, sx, gy, gx;
	cin >> h >> w >> k >> sy >> sx >> gy >> gx;
	sy--, sx--, gy--, gx--;
	V<string> s(h);
	rep(i, h)cin >> s[i];

	vvi dist(h, vi(w, INF));
	dist[sy][sx] = 0;
	queue<P> q;
	q.push(P(sy, sx));

	while (!q.empty()) {
		P p = q.front();q.pop();
		int y = p.first, x = p.second;
		vi dy = { 0,0,1,-1 };
		vi dx = { 1,-1,0,0 };
		rep(i, 4)rep1(j, k) {
			int ey, ex;
			ey = y + dy[i] * j;
			ex = x + dx[i] * j;
			if (ey < 0 || h <= ey)break;
			if (ex < 0 || w <= ex)break;
			if (s[ey][ex] == '@')break;
			if (dist[ey][ex] != INF && dist[ey][ex] < dist[y][x] + 1)break;
			if (dist[ey][ex] != INF && dist[ey][ex] <= dist[y][x] + 1)continue;
			dist[ey][ex] = dist[y][x] + 1;
			q.push(P(ey, ex));
		}
	}

	if (dist[gy][gx] == INF)dist[gy][gx] = -1;
	cout << dist[gy][gx] << endl;

}

Measured memory_bytes: 12100
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    int N, K, Q, A[100009], val;
    cin >> N >> K >> Q;
    int origin = K-Q;
    MEMSET(A, 0);
    rep(i, Q){
        cin >> val;
        A[val-1]++;
        /*rep(i, N){
            cout << A[i] << " ";
        }
        cout << endl;*/
    }
    rep(i, N){
        cout << ((A[i]+origin > 0) ? "Yes" : "No") << endl;
    }
    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

template <typename Tp, size_t Nb>
auto make_vector(std::vector<size_t> &sizes, Tp const &x) {
    if constexpr (Nb == 1) {
        return std::vector<Tp>(sizes[0], x);
    } else {
        size_t size = sizes[Nb - 1];
        sizes.pop_back();
        return std::vector(size, make_vector<Tp, Nb - 1>(sizes, x));
    }
}

template <typename Tp, size_t Nb>
auto make_vector(size_t const (&sizes)[Nb], Tp const &x = Tp()) {
    std::vector<size_t> s(Nb);
    for (size_t i = 0; i < Nb; ++i)
        s[i] = sizes[Nb - i - 1];
    return make_vector<Tp, Nb>(s, x);
}

using p = pair<ll, ll>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, t;
    cin >> n >> t;
    vector<p> v(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        v[i] = p(a, b);
    }
    sort(v.begin(), v.end(), [&](const p &a, const p &b) {
        if (a.first == b.first) {
            return a.second < b.second;
        }
        return a.first < b.first;
    });

    auto dp = make_vector({(size_t)n - 1, (size_t)t}, 0LL);
    ll ans = v[0].second;

    rep(j, t) {
        ll time = v[0].first, value = v[0].second;
        if (j >= time) {
            dp[0][j] = value;
        }
        ans = max(ans, dp[0][t - 1] + v[0 + 1].second);
    }

    repd(i, 1, n - 1) {
        ll time = v[i].first, value = v[i].second;
        rep(j, t) {
            if (j - time < 0) {
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - time] + value);
            }
        }
        ans = max(ans, dp[i][t - 1] + v[i + 1].second);
    }

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



Measured memory_bytes: 73660
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		double max = -1;
		max = Math.Max(max, calc(X[0], Y[0], X[1], Y[1], X[2], Y[2]));
		max = Math.Max(max, calc(X[1], Y[1], X[2], Y[2], X[0], Y[0]));
		max = Math.Max(max, calc(X[2], Y[2], X[0], Y[0], X[1], Y[1]));
		
		Console.WriteLine(max);
		
	}
	
	double calc(double x0, double y0, double x1, double y1, double x2, double y2){
		
		double vx0 = x1 - x0;
		double vy0 = y1 - y0;
		double vx1 = x2 - x0;
		double vy1 = y2 - y0;
		double cos0 = vx0 * vx1 + vy0 * vy1;
		cos0 /= Math.Sqrt(vx0 * vx0 + vy0 * vy0) * Math.Sqrt(vx1 * vx1 + vy1 * vy1); 
		double theta0 = Math.Acos(cos0);
		
		vx0 = x0 - x1;
		vy0 = y0 - y1;
		vx1 = x2 - x1;
		vy1 = y2 - y1;
		double cos1 = vx0 * vx1 + vy0 * vy1;
		cos1 /= Math.Sqrt(vx0 * vx0 + vy0 * vy0) * Math.Sqrt(vx1 * vx1 + vy1 * vy1); 
		double theta1 = Math.Acos(cos1);
		
		double l = 1e-9, r = 1e9;
		double dist = Math.Sqrt(vx0 * vx0 + vy0 * vy0);
		for(int t=0;t<200;t++){
			double c = (l + r) / 2.0;
			double len = 2 * c + c * 1.0 / Math.Tan(theta0 / 2.0) + c * 1.0 / Math.Tan(theta1 / 2.0);
			if(len < dist){
				l = c;
			} else {
				r = c;
			}
		}
		
		return l;
	}
	
	
	int[] X,Y;
	public Sol(){
		X = new int[3];
		Y = new int[3];
		for(int i=0;i<3;i++){
			var d = ria();
			X[i] = d[0]; Y[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268