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

typedef priority_queue<int> maxHeap;
typedef priority_queue<int, vector<int>, greater<int>> minHeap;
#define endl "\n"
#define int long long
#define MOD 1000000007
#define ump unordered_map
#define pb push_back
#define mp make_pair
#define pie acos(-1)
#define max(x, y) ((x > y) ? x : y)
#define min(x, y) ((x < y) ? x : y)
#define mid(s, e) ((s + (e - s) / 2))

bool test_cases;

struct precompute {
    void compute() {
    }
};

void init(bool k) {
    test_cases = k;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

struct test_cases {
    void test_case(int test) {
        int n;
        cin >> n;
        int a[n];
        for (int i = 0; i < n; i++) cin >> a[i];

        int stools[n];
        stools[0] = 0;
        int maxidx = 0;
        int sum_stools = 0;
        for (int i = 1; i < n; i++) {
            if (a[maxidx] <= a[i]) {
                maxidx = i;
                stools[i] = 0;
            } else {
                int j = i - 1;
                while (j >= 0) {
                    if (a[j] >= a[i]) {
                        stools[i] = stools[j] + (a[j] - a[i]);
                        break;
                    }
                    j--;
                }
            }

            sum_stools += stools[i];
        }

        cout << sum_stools << endl;
    }
};

int32_t main() {
    init(false);
    int tc;
    if (test_cases) {
        cin >> tc;
    } else {
        tc = 1;
    }
    struct precompute l;
    l.compute();
    for (int i = 0; i < tc; i++) {
        struct test_cases o;
        o.test_case(i + 1);
    }
    return 0;
};

Measured memory_bytes: 6772
N = int(input())
A = list(map(int,input().split()))

count = 0
for i in range(N):
    if A[i] < 0:
        count += 1
        
Aabs = [abs(i) for i in A]

if count % 2 == 0:
    print(sum(Aabs))
else:
    mini = min(Aabs)
    print(sum(Aabs) - 2*mini)

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

typedef long long ll;
ll n, a, b, c, d;
int main()
{
	ll i;
	cin >> n >> a >> b >> c >> d;
	n--; b -= a;
	for (i = 0; i <= n; i++) {
		if (-(n - i) * d + i * c <= b && b <= -(n - i) * c + i * d) {cout << "YES"; return 0;}
	}
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
  char S[3];
  int i;
  for (i=0;i<3;i++) {
  if(scanf("%s", S)==1);
  }
  if ('B'==S[1]) {
    printf("ARC");
  }
  else {
    printf("ABC");
  }
  return 0;
}


Measured memory_bytes: 1728
# -*- coding: utf-8 -*-

import sys
from math import hypot

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
XY = []
for i in range(N):
    x, y = MAP()
    XY.append((x, y))

dist = 0
for i in range(N):
    x, y = XY[i]
    for j in range(i+1):
        x2, y2 = XY[j]
        dist += hypot(x-x2, y-y2)
print(dist * 2 / N)


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n;cin>>n;
	vi a(n),b(n);
	rep(i,n){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(all(b));
    if(b[n/2-1]==b[n/2]){
		rep(i,n)cout<<b[n/2]<<endl;
		return 0;
	}
	rep(i,n){
		if(a[i]<=b[n/2-1])cout<<b[n/2]<<endl;
		if(a[i]>=b[n/2])cout<<b[n/2-1]<<endl;
	}
}


Measured memory_bytes: 3712
import java.util.*;


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

        Queue<Long> queue = new LinkedList<>();
        for (long i = 1; i <= 9; i++) {
            queue.add(i);
        }
        int i = 0;
        long x = 0;
        long v = 0;
        while (i < K) {
            x = queue.poll();
            i++;
            if (x % 10 != 0)  {
                v = 10 * x + (x % 10) - 1;
                queue.add(v);
            }
            v = 10 * x + (x % 10);
            queue.add(v);
            if (x % 10 != 9) {
                v = 10 * x + (x % 10) + 1;
                queue.add(v);
            }
        }
        System.out.println(x);
    }
}


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

using namespace std;

#define ll long long

const ll mod  = 1e9 + 7;
const ll INF = 1e14;

void solve(){

    int n; cin >> n;
    int arr[n];
    for(int i = 0; i < n; ++i) cin >> arr[i];

    int setwise = arr[0];
    for(int i = 1; i < n; ++i) setwise = __gcd(setwise, arr[i]);
    if(setwise != 1){
        cout << "not coprime\n";
        return;
    }

    //unordered_set<int> set;
    int lim = *max_element(arr, arr+n);
    vector<bool> pres (lim+1, false);

    int flag = true;
    for(int i = n-1; i >= 0 && flag; --i){
        if(arr[i] == 1) continue;
        int num = arr[i];
        int sqr_i = sqrt(num);
        int fac = 2;
        if(pres[num] == true){
            flag = false;
            continue;
        }
        pres[num] = true;
        while(fac <= sqr_i){
            if(num % fac == 0){
                if(pres[fac] || pres[num / fac]){
                    flag = false;
                    break;
                }
                pres[fac] = true;
                pres[num / fac] = true;
            }
            ++fac;
        }
    }
    cout << (flag ? "pairwise coprime\n" : "setwise coprime\n");

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}



Measured memory_bytes: 7644
from fractions import gcd


n, k = map(int, input().split())
a = list(map(int, input().split()))
g = a[0]
for a_ in a[1:]:
    g = gcd(a_, g)
if max(a) >= k and k % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 16280
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*3 for _ in range(n+1)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][j] = max(abc[i][j]+dp[i][k], dp[i+1][j])
            dp[i+1][k] = max(abc[i][k]+dp[i][j], dp[i+1][k])

print(max(dp[-1]))

Measured memory_bytes: 100476
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	int hap[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	int dp[n][3];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
	}
	int z;
	z=max(dp[n-1][0],dp[n-1][1]);
	z=max(z,dp[n-1][2]);
	cout<<z<<endl;
}

Measured memory_bytes: 2560
/*
ID: jerrywcy
TASK: AtCoder ABC 102 Problem A
LINK: https://abc102.contest.atcoder.jp/tasks/abc102_a
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n;

int main()
{
	cin>>n;
	if (n%2==0)cout<<n<<endl;
	else cout<<n*2<<endl;

	return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
S = input()[:-1]
acc = [0]

for Si in S:
    if Si=='#':
        acc.append(acc[-1]+1)
    else:
        acc.append(acc[-1])

ans = 10**18

for i in range(N+1):
    ans = min(ans, acc[i]+N-i-(acc[N]-acc[i]))

print(ans)

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  
  if (v <= w) {
    cout << "NO\n";
    return 0;
  }
  
  ll dis = abs(a - b), shr = (v - w);
  
  if (shr * t >= dis) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<map>
#include<tuple>
using namespace std;
#define INF 11000000000000000
#define MAX 110000
#define MOD 998244353
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,ll> p;
//typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

const int MAX_N=1<<17;

//セグメント木を持つグローバル配列
int n;
ll dat[2*MAX_N-1];

//初期化
void init(int n_){
    //簡単のために要素数を2のべき乗に
    n=1;
    while(n<n_) n*=2;

    //全ての値をINT_MAXに
    for(int i=0;i<2*n-1;i++) dat[i]=INF;
}

//k番目の値(0-indexed)をaに変更
void update(int k,ll a){
    //葉の節点
    k+=n-1;
    dat[k]=a;
    //登りながら更新
    while(k>0){
        k=(k-1)/2;
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
}

//[a,b)の最小値を求める
//後ろの方の引数は、計算の簡単のための引数
//ｋは接点の番号、l,rはその接点が[l,r)に対応づいていることを表す
//したがって、外からはquery(a,b,0,0,n)として呼ぶ
ll query(int a,int b,int k,int l,int r){
    //[a,b)と[l,r)が交差しなければ,INT_MAX
    if(r<=a || b<=l) return INF;

    //[a,b)が[l,r)を完全に含んでいれば、この節点の値
    if(a<=l && r<=b) return dat[k];
    else{
        //そうでなければ、２つの子の最小値
        ll vl=query(a,b,k*2+1,l,(l+r)/2);
        ll vr=query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}


int main(){
    int N,M;
    cin>>N>>M;
    vector<p> V;
    for(int i=0;i<M;i++){
        int l,r;
        ll c;
        cin>>l>>r>>c;
        l--; r--;
        V.push_back(p(P(l,r),c));
    }
    sort(V.begin(),V.end());
    init(N);
    update(0,0LL);
    for(int i=0;i<M;i++){
        int l,r;
        ll c;
        l=V[i].first.first;
        r=V[i].first.second;
        c=V[i].second;
        ll x=query(l,r,0,0,n);
        if(x==INF) continue;
        x+=c;
        if(x<=query(r,r+1,0,0,n)){
            update(r,x);
        }
    }
    if(query(N-1,N,0,0,n)>=INF) cout<<-1<<endl;
    else cout<<query(N-1,N,0,0,n)<<endl;
}



Measured memory_bytes: 3952
#include <bits/stdc++.h>
#define NMAX 300005

using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
ll cnt1[NMAX],cnt2[NMAX];
pll targets[NMAX];
int main()
{
    ll n,m,k,max1=0,max2=0;
    set<ll> s1,s2;
    cin>>n>>m>>k;
    for(ll i=0;i<k;i++){
        ll a,b;
        cin>>a>>b;
        cnt1[a]++;
        cnt2[b]++;
        targets[i]={a,b};
    }
    for(ll i=0;i<=n;i++){
        if(cnt1[i]>max1){
            s1.clear();
            max1=cnt1[i];
        }
        if(cnt1[i]==max1)
            s1.insert(i);
    }
    for(ll i=0;i<=m;i++){
        if(cnt2[i]>max2){
            s2.clear();
            max2=cnt2[i];
        }
        if(cnt2[i]==max2)
            s2.insert(i);
    }
    ll cnt=0;
    for(ll i=0;i<k;i++){
        if(s1.count(targets[i].first) && s2.count(targets[i].second))
            cnt++;
    }
    cout<<max1+max2-(cnt==s1.size()*s2.size());
    return 0;
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    string s;cin >> s;
    sort(ALL(s));
    if(s[0] != s[2]) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 764
fun main(args:Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    if(N >= a.sum()){
        println(N -a.sum())
    }else{
        println(-1)
    }
}


Measured memory_bytes: 39252
S = input()
f = True
for s, i in zip(S, range(1, len(S) + 1)):
    if i % 2 == 0:
        if s == "R":
            f = False
            break
    else:
        if s == "L":
            f = False
            break
if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
const int N = 2001;

int dp[N][N];
int n;
pi a[N];

int solve(int l,int r){
	if(l+r>=n)
		return 0;
	int &tmp = dp[l][r];
	if(tmp != -1)
		return tmp;
	tmp = solve(l+1,r)+abs(l+1-a[l+r+1].ss)*a[l+r+1].ff;
	tmp = max(tmp,solve(l,r+1)+abs(n-r-a[l+r+1].ss)*a[l+r+1].ff);
	return tmp;
}

int32_t main() { 
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].ff;
		a[i].ss=i;
	}

	sort(a+1,a+n+1,greater<pi>());
	memset(dp,-1,sizeof dp);
	int ans = solve(0,0);
	cout<<ans<<endl;
}


Measured memory_bytes: 35016
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}


Measured memory_bytes: 3192
loop do
    n,s = gets.split.map(&:to_i)
    if n==0 && s == 0
        break
    end
    r = Array.new(101,0)
    n.times do |i|
        r[gets.to_i] += 1
    end
    count = 0
    for i in 1..100
        if r[i] == 0
            next
        end
        if i*2 > s
            count += r[i]*(r[i]-1)/2
        end
        for j in i+1..100
            if i+j > s
                count += r[i]*r[j]
            end
        end
    end
    puts count
end

Measured memory_bytes: 6120
/*
 * atcoder/dp_3rd/b.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int MAX = 100200;
const ll INF = 100000000000000000;
ll N, K;
vector<ll> A;
ll dp[MAX];

void input() {
  cin >> N >> K;
  ll a;
  loop(n,0,N) {
    cin >> a;
    A.push_back(a);
  }
}

void solve() {
  loop(n,0,N) dp[n] = INF;
  dp[0] = 0;
  for (int n=0; n<N; n++) {
    for (int k=1; k<=K; k++) {
      if (n+k>=N) break;
      chmin(dp[n+k], dp[n] + abs(A[n+k] - A[n]));
    }
  }
  cout << dp[N-1] << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 1908
import java.util.Scanner


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val s = sc.nextLine()
    val ss = s.replaceAll("BC", "D")
    var countA = 0L
    var ans = 0L

    var flag = true

    for (i <- 0 until ss.length) {
      if (flag) {
        ss(i) match {
          case 'A' => countA += 1
          case 'D' => ans += countA
          case _ => countA = 0
        }
      }
    }

    println(ans)
  }
}

Measured memory_bytes: 38380
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

constexpr double EPS = 1e-7;

template <typename T>
constexpr T INF = numeric_limits<T>::max();

template <class T>
constexpr T PI = static_cast<T>(3.14159265358979323846);

constexpr int MOD = 1e9 + 7;

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

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

template <typename T>
std::vector<T> table(int n, T v) { return std::vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
	auto val = table(args...);
	return std::vector<decltype(val)>(n, std::move(val));
}

// 組み合わせを列挙
void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
	if (rest == 0) {
		f(indexes);
	} else {
		if (s < 0)
			return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}
// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
	int indexes[k];
	recursive_comb(indexes, n - 1, k, f);
}

long long comb(long long N, long long R) {
	if (R < 0 || R > N)
		return 0;
	if (R == 1)
		return N;
	else if (R == 2)
		return N * (N - 1) / 2;
	else
		return N * (N - 1) * (N - 2) / 6;
}

ll pow(ll x, ll n) {
	ll ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x;
		n = (n >> 1);
	}
	return ans;
}

/*
ll rec(string &N, int K, int indexes[], int i, bool b) {
	if (i >= K) {
		return 1;
	}

	int d = N[indexes[i]] - '0';
	ll ret = 0;
	if (b) {
		if (d != 0) {
			ret += (d - 1) * rec(N, K, indexes, i + 1, false);
			ret += rec(N, K, indexes, i + 1, true);
		} else {
			return 0;
		}
	} else {
		ret += 9 * rec(N, K, indexes, i + 1, false);
	}
	return ret;
}
*/

ll rec(string &N, int i, int k, bool smaller) {
	if (k == 0) {
		return 1;
	}
	if (i >= N.size()) {
		return 0;
	}

	if (smaller) {
		return comb(N.size() - i, k) * pow(9, k);
	}

	if (N[i] == '0') {
		return rec(N, i + 1, k, false);
	}

	ll a = rec(N, i + 1, k, true);
	ll b = (N[i] - '0' - 1) * rec(N, i + 1, k - 1, true);
	ll c = rec(N, i + 1, k - 1, false);
	return a + b + c;
}

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	string N;
	int K;
	cin >> N >> K;

	ll ans = 0;
	/*
	foreach_comb(N.size(), K, [&](int indexes[]) {
		if (indexes[0] == 0) {
			ans += rec(N, K, indexes, 0, true);
		} else {
			ans += rec(N, K, indexes, 0, false);
		}
	});
	*/

	cout << rec(N, 0, K, false) << endl;
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
int main(){
    int i,a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    for(i = 0 ; i < 32; i ++)
    {/*
        if((a & 1) || ( b & 1 ) || ( c & 1 )) break;
        int x,y,z;
        x = (b + c) / 2;
        y = (a + c) / 2;
        z = (a + b) / 2;
        a = x, b = y, c = z;*/
        /*
         
         */
        int x = a & (1 << i), y = b & (1 << i), z = c & (1 << i);
        if(i == 0 && x) break;
        if(x == y && y == z)
            continue;
        else break;
    }/*
    int ans[3][20],cnt = 0;
    for(int j = 10; j >= 0; j --){
        
        bool x = a & (1 << j), y = b & (1 << j), z = c & (1 << j);
        ans[0][cnt] = x, ans[1][cnt] = y, ans[2][cnt] = z;
        cnt ++;
    }
    for(int j = 0; j <= 10; j ++)
        printf("%d",ans[0][j]);
    putchar('\n');
    for(int j = 0; j <= 10; j ++)
        printf("%d",ans[1][j]);
    putchar('\n');
    for(int j = 0; j <= 10; j ++)
        printf("%d",ans[2][j]);
    putchar('\n');*/
    if(i == 32)
        printf("-1\n");
    else
        printf("%d\n",i);
    return 0;
}

Measured memory_bytes: 128
#方針: 753数を全列挙

def is_753?(s)
  f7=f5=f3 = false
  s.chars do |c|
    case c
    when "7"
      f7=true
    when "5"
      f5=true
    when "3"
      f3=true
    end
  end
  return f7&&f5&&f3
end

list = ["7","5","3"]
ary = []
(3..9).each do |digit|
  (0..3**digit-1).each do |bit|
    tmp = ""
    (0..bit.to_s(3).rjust(digit,"0").length-1).each do |i|
      tmp += list[bit.to_s(3).rjust(digit,"0")[i].to_i]
    end
    ary << tmp if is_753?(tmp)
  end
end

n = gets.to_i

ans = 0
ary.each_with_index do |a, i|
  if a.to_i <= n
    ans+=1
  end
end

p ans

Measured memory_bytes: 3964
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n;
  cin >> n;
  cout << n * n * n << endl;
  return 0;
}


Measured memory_bytes: 888
#[allow(unused_imports)]
use std::cmp::Ordering::{Equal, Greater, Less};
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;

// c.rs ---
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize,
        abs: [(i64, i64); n],
    };

    let mut dishes = abs;
    dishes.sort_by_key(|&(a, b)| a + b);
    dishes.reverse();

    let ans = dishes
        .iter()
        .enumerate()
        .map(|(i, &(a, b))| if i % 2 == 0 { a } else { -b })
        .sum::<i64>();

    // let mut dish_map = BTreeMap::<i64, Vec<(i64, i64)>>::new();

    // for (a, b) in dishes.into_iter() {
    //     let key = a + b;

    //     if !dish_map.contains_key(&key) {
    //         dish_map.insert(a + b, vec![]);
    //     }

    //     dish_map.get_mut(&key).unwrap().push((a, b));
    // }

    // let mut ans = 0;
    // let mut i = 0;
    // for key in dish_map.keys().rev() {
    //     let mut vec = dish_map.get(&key).unwrap();
    //     let mut cnt = vec.len();
    //     // TODO simplify
    //     ans += if i % 2 == 0 {
    //         vec[0..(cnt + 1 / 2)].iter().map(|&(a, _)| a).sum::<i64>()
    //             - vec[(cnt + 1 / 2)..].iter().map(|&(_, b)| b).sum::<i64>()
    //     } else {
    //         vec[0..(cnt / 2)].iter().map(|&(a, _)| a).sum::<i64>()
    //             - vec[(cnt / 2)..].iter().map(|&(_, b)| b).sum::<i64>()
    //     };
    //     i += cnt;
    // }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    cin >> A >> B >> C;
        if(A>B){
        swap(A,B);
    }
    if(B>C){
        swap(B,C);
    }
    if(A>B){
        swap(A,B);
    }
    if(A==B&&B==C){
        cout << "No" << endl;
    }else if(A!=B&&B!=C){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


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 c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println((Math.abs(a - b) <= d && Math.abs(c - b) <= d)
			|| Math.abs(c - a) <= d ? "Yes" : "No");
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N,0);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	sort(A.begin(),A.end());
	
	int ans = 0;
	
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			for(int k=j+1;k<N;k++){
				if(A[i]+A[j]>A[k])ans++;
			}
		}
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main () {
  string S, T;
  cin >> S >> T;
  bool ok = true;
  for (int i = 0; i < S.size(); i ++) {
    if (S[i] != T[i]) ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n,m;
  cin>>n>>m;
  auto f = [](int a){
    return a*(a-1)/2;
  };

  cout<<f(n)+f(m)<<endl;

}

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

using namespace std;

typedef long long ll;


ll power(ll base, ll exp){
    ll ret = 1;
    while(exp > 0){
        if(exp % 2 == 0){
            base *= base;
            exp /= 2;
        }
        else{
            ret *= base;
            exp -= 1;
        }
    }
    return ret;
}

ll getDigit(ll K, vector<vector<ll>>& dp, ll i, ll j){
    ll ret = power(10, i) * j;
    if(i == 0){
        return ret;
    }
    ll tmp = 0;
    if(j > 0){
        tmp = dp[i-1][j-1];
    }
    if(tmp >= K){
        ret += getDigit(K, dp, i-1, j-1);
        return ret;
    }
    K -= tmp;
    tmp = dp[i-1][j];
    if(tmp >= K){
        ret += getDigit(K, dp, i-1, j);
        return ret;
    }
    K -= tmp;
    ret += getDigit(K, dp, i-1, j+1);
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll K;
    cin >> K;
    vector<vector<ll>> dp(10, vector<ll>(10));
    for(int i = 0 ; i < 10; ++i){
        dp[0][i] = 1;
    }
    for(int i = 1 ; i < 10; ++i){
        for(int j = 0; j < 10; ++j){
            dp[i][j] += dp[i-1][j];
            if(j > 0){
                dp[i][j] += dp[i-1][j-1];
            }
            if(j < 9){
                dp[i][j] += dp[i-1][j+1];
            }
        }
    }

    ll ret = 0;
    for(int i = 0; i < 10; ++i){
        for(int j = 1; j < 10; ++j){
            if(K <= dp[i][j]){
                ret = getDigit(K, dp, i, j);
                break;
            }
            K -= dp[i][j];
        }
        if(ret > 0){
            break;
        }
    }

    cout << ret << endl;
    
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> A(N);
  rep(i, N) cin >> A.at(i);
  
  int ans = 0;
  rep(i, N) {
    if (A.at(i) >= K) {
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

int main(){
    using namespace std;
    unsigned long L;
    cin >> L;
    L *= L * L;
    L = min(L * 1000000 - 27, L * 999999);
    auto r{L % 27}, k{L / 27};
    r *= 37;
    printf("%lu.%06lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu%03lu\n", k / 1000000, k % 1000000, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int N, i, num;
    char A[100], B[100], C[100], tmp_var[100][100], tmp_num[100][100];

    scanf("%d", &N);
    scanf("%s%s%s", A, B, C);

    num = 0;
    for (i = 0; i < N; i++) {
        if (A[i] == B[i] && B[i] == C[i])
            continue;
        else if (A[i] != B[i] && B[i] != C[i] && C[i] != A[i])
            num += 2;
        else
            num++;
    }
    printf("%d\n", num);

    return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
	"strings"
)

type card struct {
	mark string
	num  int
}

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

	cards1 := make([]card, n)
	cards2 := make([]card, n)

	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		sp := strings.Split(s, "")
		x, _ := strconv.Atoi(sp[1])
		cards1[i] = card{mark: sp[0], num: x}
		cards2[i] = card{mark: sp[0], num: x}
	}

	stable := bubbleSort(cards1)
	selection := selectionSort(cards2)

	printCards(stable)
	fmt.Println("Stable")
	
	printCards(selection)
	if isStable(selection, stable) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}

func bubbleSort(n []card) []card {
	for i := 0; i < len(n); i++ {
		for j := len(n) - 1; j > i; j-- {
			if n[j].num < n[j-1].num {
				n[j], n[j-1] = n[j-1], n[j]
			}
		}
	}
	return n
}

func selectionSort(n []card) []card {
	for i := 0; i < len(n); i++ {
		minIndex := i
		for j := i; j < len(n); j++ {
			if n[j].num < n[minIndex].num {
				minIndex = j
			}
		}
		n[i], n[minIndex] = n[minIndex], n[i]
	}
	return n
}

func isStable(n, stable []card) bool {
	for i := 0; i < len(n); i++ {
		for j := i + 1; j < len(n); j++ {
			for a := 0; a < len(n); a++ {
				for b := a + 1; b < len(n); b++ {
					if n[i].num == n[j].num && n[i] == stable[b] && n[j] == stable[a] {
						return false
					}
				}
			}
		}
	}
	return true
}

func printCards(n []card) {
	for _, c := range n[:len(n)-1] {
		fmt.Print(c.mark, c.num, " ")
	}
	fmt.Printf("%v%v\n", n[len(n)-1].mark, n[len(n)-1].num)
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if (A == 1) {
		if (B == 1) cout << "Draw" << endl;
		else cout << "Alice" << endl;
	}
	else if (B == 1) {
		if (A == 1) cout << "Draw" << endl;
		else cout << "Bob" << endl;
	}
	else if (A == B) cout << "Draw" << endl;
	else if (A < B) cout << "Bob" << endl;
	else if (A > B) cout << "Alice" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int main(void){
    string S;
    string T;
    int N;

    cin >> S >> T;
    
    cin >> N;

    int s_s, s_e, t_s, t_e;

    int S_asum[100005];
    S_asum[0] = 0;
    for(int j=1;j<=S.length();j++){
        S_asum[j] = (S_asum[j-1] + S[j -1] - 'A' + 1) % 3;
    }
    int T_asum[100005];
    T_asum[0] = 0;
    for(int j=1;j<=T.length();j++){
        T_asum[j] = (T_asum[j-1] + T[j -1] - 'A' + 1) % 3;
    }

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

        cin >> s_s >> s_e >> t_s >> t_e;
        /*scanf("%d%d%d%d", &s_s, &s_e, &t_s, &t_e);*/

        int s_tmp = 0;
        int t_tmp = 0;

        s_tmp = S_asum[s_e] - S_asum[s_s-1] + 3;
        t_tmp = T_asum[t_e] - T_asum[t_s-1] + 3;

        /*string ans = "NO";*/
        if((s_tmp - t_tmp) % 3 == 0){
            /*ans = "YES";*/
            printf("YES\n");
        }
        else{printf("NO\n");}
        /*cout << ans << endl;*/
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
    int t,a,b,x,y,z,mx,mn,tmp;
    scanf("%d",&t);
    vector<string>vc;
    vector<int>vc2;
    map<string,int>mp;
    unordered_map<int,int>mp2;
    for(int i=0;i<t;i++){
        string s="";
        cin>>s;
        sort(s.begin(),s.end());
        vc.push_back(s);
        mp[s]++;
    }
    int cnt=0;
    for(int j=0;j<vc.size();j++){
        ///cout<<vc[j]<<" ";
        ///printf("%d\n",mp[vc[j]]);
        if(mp[vc[j]]>1){
            vc2.push_back(mp[vc[j]]);
            mp[vc[j]]=0;
        }
    }
    if(vc.size()==0){
        puts("0");
        return 0;
    }
    llu tt=0,n;
    for(int j=0;j<vc2.size();j++){
        n=vc2[j];
        n--;
        tt=tt+((n*(n+1))/2);
    }
    cout<<tt<<"\n";



    return 0;
}






Measured memory_bytes: 16628
def main():
    n = int(input())

    N = n % 10
    if N == 2 or N == 4 or N == 5 or N == 7 or N == 9:
        print('hon')
    elif N == 0 or N == 1 or N == 6 or N == 8:
        print('pon')
    else:
        print('bon')


main()


Measured memory_bytes: 9164
import java.util.*;

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

        for (int a = 0; a <= Math.min(N, Y/10000); a++) {
            for (int b = 0; b <= Math.min(N-a, (Y - 10000*a)/5000); b++) {
                int c = N - a - b;
                if (10000 * a + 5000 * b + 1000 * c == Y) {
                    System.out.println(a + " " + b + " " + c);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
// 20min
int main(void){
  int a, b;
  int keta = 10;
  int tmp;
  int total;

  scanf("%d%d", &a, &b);

  tmp = b;
  while(tmp / 10 > 0){
    tmp = tmp / 10;
    keta *= 10;
  }

  total = a * keta + b;

  for(int i = 1; i < total; i++){
    if(i * i == total){
      printf("Yes\n");
      return 0;
    }
  }
  
  printf("No\n");

  return 0;
}


Measured memory_bytes: 128
while True:
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        break
    else:
        for i in range(x):
            for j in range(y):
                if i == 0 or i == x - 1:
                    print("#", end="")
                else:
                    if j == 0 or j == y - 1:
                        print("#", end="")
                    else:
                        print(".", end="")
            print()
        print()  


Measured memory_bytes: 7004
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int grid[14][14];

void solve(){
    int ans = 0;
    array<int, 4> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};
    queue<pair<int, int>> Q;
    for (int i = 1; i <= 12; ++i) {
        for (int j = 1; j <= 12; ++j) {
            if(grid[i][j]){
                grid[i][j] = 0;
                ans++;
                Q.emplace(i, j);
                while(!Q.empty()){
                    int y, x; tie(y, x) = Q.front(); Q.pop();
                    for (int k = 0; k < 4; ++k) {
                        if(grid[y+dy[k]][x+dx[k]]){
                            grid[y+dy[k]][x+dx[k]] = 0;
                            Q.emplace(y+dy[k], x+dx[k]);
                        }
                    }
                }
            }
        }
    }
    cout << ans << "\n";
}
int main() {
    fill_n((int*)grid, 196, 0);
    int cur = 0;
    string s;
    while(cin >> s){
        for (int i = 0; i < 12; ++i) {
            grid[cur+1][i+1] = s[i]-'0';
        }
        cur++;
        if(cur == 12) solve(), cur = 0;
    }
    return 0;
}


Measured memory_bytes: 3148
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cctype>
using namespace std;
typedef long long ll;

int main() {
	int n;
	scanf("%d", &n); int nx = 0, ny = 0, lst = 0;
	for(int i = 1; i <= n; i ++) {
		int x, y, t;
		scanf("%d%d%d", &t, &x, &y);
		int dis = abs(x-nx)+abs(y-ny);
		if(dis > t-lst) { puts("No"); return 0; }
		if((t-lst-dis)&1) { puts("No"); return 0; }
		nx = x; ny = y; lst = t;
	} puts("Yes");
	return 0;
}

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

int main()
{
    int s, w;
    std::cin >> s >> w;
    if (s > w)
    {
        std::cout << "safe" << std::endl;
    }
    else
    {
        std::cout << "unsafe" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3636
io = STDIN
h,w=io.gets.chomp.split.map(&:to_i)

def solve(a,b)
  return 0 if a%3 == 0 || b%3 ==0
  ans=Float::INFINITY
  (1..(a-1)).each do |i|
    s1=i*b
    s2=(a-i)*(b/2)
    s3=(a-i)*(b-b/2)
    s22=b*((a-i)/2)
    s33=b*((a-i)-(a-i)/2)
    sorted1=[s1,s2,s3].sort
    sorted2=[s1,s22,s33].sort
    ans=[sorted1[2]-sorted1[0],sorted2[2]-sorted2[0],ans].min
  end
  ans
end
puts [solve(h,w),solve(w,h)].min


Measured memory_bytes: 1788
N=int(input())
A=list(map(int,(input().split())))
B=list(map(int,((input()+" 0").split())))

ans=0
stockpre=0
for i in range(N+1):
    stocki=min(max(B[i]+stockpre-A[i],0),B[i])
    if stocki>0:
        ans+=A[i]
    else:
        ans+=min(B[i]+stockpre,A[i])
    
    stockpre=stocki

print(str(ans))

Measured memory_bytes: 18624
#include<stdio.h>
int main(void){
  int a,b,x,y;
  scanf("%d",&a);
  scanf("%d",&b);
  x=b%a;
  if(x==0){
    y=a+b;
  }
  else{
    y=b-a;
  }
  printf("%d",y);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int N;
    cin >> N;
    int* A = new int[N + 1];
    rep (i, N + 1)
    {
        cin >> A[i];
    }

    int Bprev = 0;
    int B;
    int temp;
    u64 ret = 0;

    rep (i, N)
    {
        cin >> B;
        ret += MIN(Bprev, A[i]);
        temp = MAX(MIN(B, A[i] - Bprev), 0);
        ret += temp;
        Bprev = B - temp;
    }

    B = B - temp;
    ret += MIN(B, A[N]);

    cout << ret << "\n";

    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>
#include <cmath>
#include <sstream>
#include <numeric>
#include <set>

using namespace std;
long long distance(long long x1, long long y1, long long x2, long long y2);

long long distance(long long x1, long long y1, long long x2, long long y2)
{
    return std::abs(x1 - x2) + std::abs(y1 - y2);
}

int main()
{
    long long n, m;
    std::cin >> n >> m;

    std::vector<std::pair<long long, long long>> students;
    for(long long i = 0; i < n; i++)
    {
        long long x, y;
        std::cin >> x >> y;
        students.push_back(std::pair<long long, long long>(x, y));
    }

    std::vector<std::pair<long long, long long>> point;
    for(long long i = 0; i < m; i++)
    {
        long long x, y;
        std::cin >> x >> y;
        point.push_back(std::pair<long long, long long>(x, y));
    }

    for(long long i = 0; i < students.size(); i++)
    {
        long long idx = 0;
        long long max = 10000000000000;
        for(long long j = 0; j < point.size(); j++)
        {
            long long dist = distance(students[i].first, students[i].second, point[j].first, point[j].second);
            if(dist < max)
            {
                max = dist;
                idx = j;
            }
        }
        std::cout << idx +1  << std::endl;
    }
    return EXIT_SUCCESS;
}


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

int main() {
    int X, Y; cin >> X >> Y;
    int res = 0;
    if(X <= 3) res += 100000 * (4 - X);
    if(Y <= 3) res += 100000 * (4 - Y);
    if(X == 1 && Y == 1) res += 400000;
    cout << res << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);
  int a;
  cin >> a;

  cout << a + pow(a,2) + pow(a,3) << endl;
  return 0;
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    vii p(m), y(m);
    vv<vii> py(n);
    rep(i, 0, m) {
      cin >> p[i] >> y[i];
      py[p[i]-1].pb(y[i]);
    }
    rep(i, 0, n) {
      sort(ALL(py[i]));
    }
    rep(i, 0, m) {
      int pos = lower_bound(ALL(py[p[i]-1]), y[i]) - py[p[i]-1].begin() + 1;
      printf("%06d%06d\n", p[i], pos);
    }
    return 0;
}



Measured memory_bytes: 7808
n,m = map(int,input().split())
l = []
for i in range(m):
    p,y = map(int,input().split())
    l.append([i,p,y])
count = [1 for i in range(n)]
l.sort(key=lambda x: x[2])
for i in l:
    pp = i[1]
    i.append(count[pp - 1])
    count[pp - 1] += 1
l.sort()
for i in l:
    x = i[1]
    x_zero = str(x).zfill(6)
    y = i[3]
    y_zero = str(y).zfill(6)
    print(x_zero+y_zero)


Measured memory_bytes: 31856
import math
N,D = map(int,input().split())
ans = 0
X_list = []
for a in range(N):
    X_list.append(list(map(int,input().split())))
for i in range(N):
    for j in range(i+1,N):
        rutononaka = 0
        for d in range(D):
            rutononaka += (X_list[i][d]-X_list[j][d])**2
        distance = math.sqrt(rutononaka)
        if distance == (distance//1):
            ans += 1
print(ans)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] NMXY = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long[] x = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long[] y = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            String result = "War";
            //X < Z <= Y
            if(NMXY[2] < y.Min() && y.Min() <= NMXY[3])
            {
                //x < z <= y
                if (x.Max() < y.Min())
                {
                    result = "No War";
                }
            }
            Console.WriteLine(result);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


Measured memory_bytes: 28228
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()


def inv_mod(a, N):
    """
    Fermatの小定理より(Nが素数のときしか使えない)
    aの逆元 ax = 1 (mod N)を満たすx = a^(N-2) mod Nを返す。
    O(log N)
    """

    def bpm(x, y, N):
        """
         Bisection power method : 二分累乗法
         O(log y)でx^(y) mod N を求める。
        """
        ans = 1
        x %= MOD
        digit = int((math.log(y, 2) // 1 + 1))  # yの２進数表示の桁数
        for i in range(digit):
            if (y >> i) & 1 == 1:
                ans *= x
                ans %= MOD
            x **= 2
            x %= MOD
        return ans

    return bpm(a, N - 2, N)


def bpm(x, y, N):
    """
     Bisection power method : 二分累乗法
     O(log y)でx^(y) mod N を求める。
    """
    ans = 1
    x %= MOD
    digit = int((math.log(y, 2) // 1 + 1))  # yの２進数表示の桁数
    for i in range(digit):
        if (y >> i) & 1 == 1:
            ans *= x
            ans %= MOD
        x **= 2
        x %= MOD
    return ans


n, a, b = map(int, input().split())

nCa = 1
nCb = 1

inv_list = []

for i in range(max(a, b)):
    inv_list.append(inv_mod(i + 1, MOD))

for i in range(a):
    nCa *= inv_list[i]
    nCa %= MOD
    nCa *= n - i
    nCa %= MOD

for i in range(b):
    nCb *= inv_list[i]
    nCb %= MOD
    nCb *= n - i
    nCb %= MOD

print((bpm(2, n, MOD) - 1 - nCa - nCb) % MOD)


Measured memory_bytes: 77656