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

public class Main implements Runnable {

    long[] dp = new long[100001];
    int N;
    long A;
    long B;
    long[] x;
    private void solve() throws IOException {

        N = nextInt();
        A = nextLong();
        B = nextLong();
        x = new long[N];
        for(int i = 0; i < N; ++i) {
            x[i] = nextLong();
        }
        Arrays.fill(dp, -1L);
        long best = go(0,x[0]);
        writer.println(best);

    }

    private long go(int id,long cur) {
        if(id == N - 1) return 0L;
        if(dp[id] != -1) return dp[id];

        long best = Long.MAX_VALUE;
        // walk by A
        best = Math.min(best,go(id + 1, x[id + 1]) + (A * Math.abs(x[id+1] - cur)));
        best = Math.min(best,go(id + 1,x[id + 1]) + B);
        return dp[id] =best;
    }

    public static void main(String[] args) {
        new Main().run();
    }

    BufferedReader reader;
    //    BufferedReader reader2;
    StringTokenizer tokenizer;
    PrintWriter writer;
    //    BufferedWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//            reader = new BufferedReader(new FileReader("highcard.in"));
            //            reader2 = new BufferedReader(new FileReader("1.in"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
//            writer = new     PrintWriter("highcard.out");
//                                                    writer = new BufferedWriter(System.out);
            //                        writer = new BufferedWriter(new OutputStreamWriter(System.out));
            solve();
            reader.close();
            //            reader2.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    short nextShort() throws IOException {
        return Short.parseShort(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }

}

Measured memory_bytes: 31420
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
 
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        //int c = stdIn.nextInt();
        //int x = stdIn.nextInt();
        //int num[] = new int[];
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        
        //c[0] += 1;
        //int sum = 0;
        //boolean flag = true;
        //for(int i = 0; i < s.length(); i++){
        //}
        String s = "";
        if(a > b){
            for(int i = 0; i < a; i++){
                s += b;
            }
            
        }else{
            for(int i = 0; i < b; i++){
                s += a;
            }
        }
        
        System.out.println(s);
        //System.out.println();
        //System.out.print();
 
        stdIn.close();
    }
}

Measured memory_bytes: 22352
(defun fun (n a)
  (let ((flg nil)
	(res 0))
    (loop
       (dotimes (i n)
	 (if (not (zerop (rem (aref a i) 2)))
	     (setf flg t)))
       (if (eq flg t) (return))
       (setf res (+ res 1))
       (dotimes (i n)
	 (setf (aref a i) (/ (aref a i) 2))))
    res))
	 
	   

(defun input ()
  (let* ((n (read))
	 (a (make-array n)))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (values n a)))

(multiple-value-bind (n a) (input)
  (format t "~A~%" (fun n a)))


Measured memory_bytes: 6504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    string s;
    cin >> s;
    if(s.size() != 26){
        char c = 'a';
        for (char x = 'a'; x <= 'z'; x++)
        {
            bool flag = true;
            rep(i, s.size())
            {
                if (s[i] == x) flag= false;
            }
            if(flag){
                c = x;
                break;
            }
        }
        cout << s + c << endl;
    }
    else if (s == "zyxwvutsrqponmlkjihgfedcba")
    {
        cout << -1 << endl;
    }else
    {
        int x;
        vector<string> v;
        string t = s;
        for (int i = 25; i > 0; i--)
        {
            if(s[i] > s[i-1]){
                string t = s.substr(i, 26 - i);
                sort(t.begin(), t.end());
                auto it = upper_bound(t.begin(), t.end(), s[i - 1]);
                s[i-1] = *it;
                s = s.substr(0, i);
                break;
            }
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int i,j,k;
int a[10];
for(i=0;i<10;i++){
scanf("%d",&a[i]);
}
for(i=0;i<10;i++){
    for(j=0;j<10;j++){
            if(a[i]>a[j]){k=a[i]; a[i]=a[j]; a[j]=k;}
    }
}
for(i=0;i<3;i++){
printf("%d\n",a[i]);
}
return 0;
}



Measured memory_bytes: 2048
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	ll A,B;
	cin>>A>>B;
	ll ans = 0;
	vint v(n);
	rep(i,n) cin>>v[i];
	rep(i,n-1){
		if((v[i+1]-v[i])*A<B){
			ans += (v[i+1]-v[i])*A;
		}
		else{
			ans += B;
		}
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toInt).toMutableList()
    aList.add(0, 0)
    aList.add(0)

    val betweenFlg = mutableListOf<Boolean>()
    for (i in 1 until n + 1) {
        betweenFlg.add(aList[i] in aList[i - 1]..aList[i + 1] || aList[i] in aList[i + 1]..aList[i - 1])
    }

    var totalCost = 0L
    for (i in 1 until n + 2) {
        totalCost += Math.abs(aList[i] - aList[i - 1])
    }

    for (i in 1 until n + 1) {
        if (betweenFlg[i - 1]) {
            println(totalCost)
        } else {
            val removalCost = Math.min(Math.abs(aList[i] - aList[i - 1]), Math.abs(aList[i + 1] - aList[i])) * 2
            println(totalCost - removalCost)
        }
    }

}



Measured memory_bytes: 58288
N=int(input())
d={}
ans=0
a=list(map(int,input().split()))
for i in range(N):
    d[a[i]]=0
for i in range(N):
    d[a[i]]+=1
for k in d:
    val=d[k]
    if val>=k:
        ans+=d[k]-k
    else:
        ans+=d[k]
print(ans)


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

const int N_MAX = 100010;
vector<vector<int>> G(N_MAX, vector<int>(0));
vector<bool> gone(N_MAX);

void dfs(int x) {
  gone[x] = true;
  for (auto g : G[x]) {
    if (gone[g]) continue;
    dfs(g);
  }
  return;
}

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (!gone[i]) {
      dfs(i);
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8832
// AtCoder Beginner Contest 111

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>

using namespace std;

bool is_repdigit(int x) {
    int n_100 = x / 100;
    int n_10 = (x - 100 * n_100) / 10;
    int n_1 = (x - 100 * n_100 - 10 * n_10);

    if (n_100 == n_10 && n_10 == n_1) {
        return true;
    }
    return false;
}

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

    int x;
    for (x = n; x <= 999; x++) {
        if (is_repdigit(x)) {
            break;
        }
    }

    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
def f;gets.split.map &:to_i;end
while(n,m=f)[0]>0
l=(0..2).map{(i=f)[0]=0;i}
r=[0,1].map{|x|a,b,c=t=l.map(&:dup);(0..m).find{|d|!(b[1]||a[1]&&c[1])||!(t[z=x][-1]>t[y=x+1][-1]&&(x,y=y,x);t[x].push t[y].pop;x=1-z)}||1e8}.min
p r<1e8?r:-1
end

Measured memory_bytes: 6132
if __name__ == '__main__':
    b, c = map(int, input().split())
    num = b*3 -c

    count = 0
    for i in range (0,b+1):
        for j in range(0,b+1):
            if c-(i+j)<=b and c-(i+j) >=0:
                count+=1
    print(count)



Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    int Q;
    int N;
    int div;
    int count;
    int max;
    int i;
    
    scanf("%d", &Q);
    for (i = 0; i < Q; i++){
        scanf("%d", &N);
        count = 0;
        while (N > 9){
            div = 10;
            max = 0;
            while (N / div > 0){
                if (max < (N % div) * (N / div)){
                    max = (N % div) * (N / div);
                }
                div *= 10;
            }
            N = max;
            count++;
        }
        printf("%d\n", count);
    }
    return (0);

}
            

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int dp[105][100005];
int pre[105][100005];

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, k; cin>>n>>k;
    vector<int> vect(n);
    For(i, 0, n) cin>>vect[i];
    For(i, 0, n){
    	dp[i][0]=1LL;
    	pre[i][0]=1LL;
    }
    for(int i=1; i<=k; i++){
    	if(i <= vect[0]){
    		dp[0][i]=1LL;
    	}
    	else{
    		dp[0][i]=0LL;
    	}
    	pre[0][i]=pre[0][i-1]+dp[0][i];
    }
    for(int i=1; i<n; i++){
    	for(int j=1; j<=k; j++){
    		if(j<=vect[i]){
    			dp[i][j]=pre[i-1][j];
    		}
    		else{
    			dp[i][j]=(pre[i-1][j]-pre[i-1][j-vect[i]-1]+MOD)%MOD;
    		}
    		pre[i][j]=(pre[i][j-1]+dp[i][j])%MOD;
    	}
    }
    cout<<dp[n-1][k];
    return 0;
}




Measured memory_bytes: 160000
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const long long T = 5e15 - 1;

long long k;
long long t;
string s;

int main () {
    cin >> s >> k;
    int sz = s.size();
    for(int i = 0; i < sz && i < k; i++){
        if(s[i] == '1')
          continue;
        cout << s[i];
        return 0;
    }
    cout << s[0];
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int A[100][100],b[100],out[100],n,m,i,j,sum;

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

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

  for(i=0;i<m;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      sum+=A[i][j]*b[j];
    }
    out[i]=sum;
    sum=0;
  }
  for(i=0;i<n;i++){
    printf("%d\n",out[i]);
  }

  return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main()
{
    int n;cin >> n;
    vector<int> a(n);rep(i,n)cin >> a[i];
    map<int, ll> r;

    rep(i,n)
    {
        r[i-a[i]]++;
    }
    ll sum = 0;
    rep(i,n)
    {
        int ind = a[i]+i;
        if(r.count(ind))
        {
            sum += r[ind];
        }
    }
    cout << sum << endl;


}

Measured memory_bytes: 15520
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        d: usize,
        t: usize,
        s: usize,
    }

    if d as f64 / (s as f64) <= t as f64 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
long long n,sumA,sumB,mn;
int main(){
	cin>>n;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
		sumA += arr[i];	
	}
	mn = 1e15;
	for(int i=n-1; i>0; i--){
		sumA -= arr[i];
		sumB += arr[i];
		mn = min(mn, abs(sumA - sumB));
	}
	cout<<mn<<endl;
}

Measured memory_bytes: 1024
n,k=map(int,input().split())
h=list(map(int,input().split()))
ans=[float("inf")]*n
ans[0]=0
for i in range(1,n):
    if i-k<=0:
        tmp=float("inf")
        for j in range(i):
            tmp=min(tmp,ans[j]+abs(h[j]-h[i]))
        ans[i]=tmp
    else:
        tmp=float("inf")
        for j in range(i-k,i):
            tmp=min(tmp,ans[j]+abs(h[j]-h[i]))
        ans[i]=tmp
print(ans[n-1])

Measured memory_bytes: 55520
#include<cstdio>
using namespace std;
int k,s,c=0,z;
int main(){
	scanf("%d %d",&k,&s);
	if (s==k*3){
		c=1;
	}else{
		for (int x=0;x<k+1;x++){
			for (int y=0;y<k+1;y++){
				if ((s-x-y>=0)&&(s-x-y<k+1)){
					c+=1;
				}
			}
		}
	}
	printf("%d",c);
return 0;}

Measured memory_bytes: 1708
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  int a,b,res;
  cin >> a >> b;
  if(a <= 5){
    res = 0;
  }
  else if(a>=6 && a<= 12){
    res = b/2;
  }
  else{
    res = b;
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long long k,max=2,min=2;
    scanf("%lld",&k);
    long long a[k];
    for (int i=0; i<k; i++){
        scanf("%lld",&a[i]);
    }
    for (int i=k-1; i>=0; i--){
        min=((min+a[i]-1)/a[i])*a[i];
        if (min>(max/a[i])*a[i]){
            printf("-1\n");
            return 0;
        }
        max=((max/a[i])*a[i])+a[i]-1;
    }
    printf("%lld %lld\n",min,max);
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>

int main() {
	std::string s, t;
	std::cin >> s >> t;
	if (s.size() > t.size()) {
		std::cout << "GREATER" << std::endl;
	}
	else if (s.size() < t.size()) {
		std::cout << "LESS" << std::endl;
	}
	else {
		if (s > t) {
			std::cout << "GREATER" << std::endl;
		}
		else if (s < t) {
			std::cout << "LESS" << std::endl;
		}
		else {
			std::cout << "EQUAL" << std::endl;
		}
	}
	return 0;
}
	


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <bitset>
using namespace std;


inline bool in(int a, int b, int c){
	return a <= b && b < c;
}


int main(){
	int m, n, d, s;
	while( scanf("%d%d%d", &m, &n, &d), m != 0 ){
		int sz = m * n;
		vector<bitset<626> > v(sz);
		bitset<625> used;

		int p = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < m; ++j, ++p){
				v[p][p] = true;
				
				for(int k = 0; k < d; ++k){
					if( in(0, i - d + k, n) && in(0, j + k, m) ){
						v[p][(i - d + k) * m + (j + k)] = true;
					}
					if( in(0, i + k, n) && in(0, j + d - k, m) ){
						v[p][(i + k) * m + (j + d - k)] = true;
					}
					if( in(0, i + d - k, n) && in(0, j - k, m) ){
						v[p][(i + d - k) * m + (j - k)] = true;
					}
					if( in(0, i - k, n) && in(0, j - d + k, m) ){
						v[p][(i - k) * m + (j - d + k)] = true;
					}
				}

				scanf("%d", &s);
				if( s != 0 ){
					v[p][sz] = true;
				}
			}
		}

		for(int i = 0; i < sz; ++i){
			int index = -1;

			for(int j = 0; j < sz; ++j){
				if( !used[j] && v[j][i] ){
					index = j;
					used[j] = true;
					break;
				}
			}

			if( index >= 0 ){
				for(int j = 0; j < sz; ++j){
					if( j != index && v[j][i] ){
						v[j] ^= v[index];
					}
				}
			}
		}


		int ans = 1;
		for(int i = 0; i < sz; ++i){
			if( v[i][sz] && v[i].count() == 1 ){
				ans = 0;
				break;
			}
		}
		
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1084
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int min(int a,int b){
	if(a<b)return a;
	else return b;
}
int main(){
	int n,x,y;
	cin>>n>>x>>y;
	vector<int>map(n*n);
	rep(i,n){
		for(int j=i;j<n;j++){
			map[i*n+j]=j-i;
			map[j*n+i]=j-i;
		}
	}
	map[(x-1)*n+y-1] = 1;
	map[(y-1)*n+x-1] = 1;
	rep(i,n){
		rep(j,n){
			map[i*n+j] = min(map[i*n+j],map[i*n+x-1]+map[(x-1)*n+j]);
		}
	}
	rep(i,n){
		rep(j,n){
			map[i*n+j] = min(map[i*n+j],map[i*n+(y-1)]+map[(y-1)*n+j]);
		}
	}
	/*
	rep(i,n){
		rep(j,n){
			cout<<map[i*n+j]<<" ";
		}
		cout<<endl;
	}
	*/

	vector<int> a(n,0);
	rep(i,n){
		for(int j=i+1;j<n;j++){
			a[map[i*n+j]-1]+=1;
		}
	}
	rep(i,n-1){
		cout<<a[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 18820
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,j;
	int a[100005]={0};
	scanf("%d",&n);
	int MAX,MAX1;
	for(i=0;i<n;i++)
	{
		scanf("%d",&j);
		if(j==0)
		{
			a[j]++;
			a[j+1]++;
		}
		if(j!=0)
		{
			a[j-1]++;
			a[j]++;
			a[j+1]++;
		}
		MAX1=max(a[j-1],a[j]);
		MAX1=max(MAX1,a[j+1]);
		MAX=max(MAX,MAX1);
	}
	printf("%d\n",MAX);
	return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
namespace SOLVE {
    vector<vector<int>> memo;
    string a, b;
    
    int lcs(int alength, int blength) {
        if (alength == 0 || blength == 0) {
            return memo[alength][blength] = 0;
        }
        
        if (memo[alength][blength] != -1) {
            return memo[alength][blength];
        }
        
        int ans;
        if (a[alength - 1] == b[blength - 1]) {
            ans = lcs(alength - 1, blength - 1) + 1;
        }
        else {
            int ans1 = lcs(alength - 1, blength);
            int ans2 = lcs(alength, blength - 1);
            ans = max(ans1, ans2);
        }
        memo[alength][blength] = ans;
        // cout << a << ' ' << b << ' ' << ans << endl;
        return ans;
    }
    void main() {
        cin >> a >> b;
        int na = a.length(), nb = b.length();
        memo.resize(na + 5, vector<int>(nb + 5,-1));
        int iptr = na, jptr = nb, current, top, left;
        stack<char> ans;
        
        lcs(na, nb);
        while (iptr != 0 && jptr != 0) {
            // cout << iptr << ' ' << jptr << endl;
            current = memo[iptr][jptr];
            top = memo[iptr - 1][jptr];
            left = memo[iptr][jptr - 1];
            
            if (current == left) {
                jptr--;
            }
            else if (current == top) {
                iptr--;
            }
            else {
                ans.push(a[iptr - 1]);
                iptr--;
                jptr--;
            }
        }
        
        while (sz(ans)) {
            cout << ans.top();
            ans.pop();
        }
    }
}

signed main() {
    
    int t;
    //    in(t);
    t = 1;
    while (t--) {
        SOLVE::main();
        
    }
    
    return 0;
}


Measured memory_bytes: 36096
#include <stdio.h>

int isIncludedInS(int x);

int S[10000],T[500];
int n,q;
int count = 0;

main(){

  int i;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
    count += isIncludedInS(T[i]);
  }

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

return 0;

}

int isIncludedInS(int x){

  int i;
  for(i=0; i<n; i++){
    if(x == S[i]){
      return 1;
    }
  }
  return 0;

}

Measured memory_bytes: 0
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func main() {
	sc.Split(bufio.ScanWords)

	r := nextInt()
	ans := float64(r) * math.Pi * 2.0000

	fmt.Println(ans)
}


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

int main()
{
	int n, i, j;
	int cards[4][13]={0};
	char suit; //?????????
	int num;
	
	cin >> n;
	
	for(i = 0; i < n; i++){
		cin >> suit >> num;
		
		if(suit == 'S'){
			cards[0][num - 1]++;
		}else if(suit == 'H'){
			cards[1][num - 1]++;
		}else if(suit == 'C'){
			cards[2][num - 1]++;
		}else{
			cards[3][num - 1]++;
			
		}
	}
	for(i = 0; i < 4; i++){
		for(j = 0; j < 13; j++){
			if(cards[i][j] == 0){
				if(i == 0){
					cout << 'S'<< " " << j + 1 << endl;
				}else if(i == 1){
					cout << 'H'<< " " << j + 1 << endl;
				}else if(i == 2){
					cout << 'C'<< " " << j + 1 << endl;
				}else{
					cout << 'D'<< " " << j + 1 << endl;
				}
			}
		}
	}

	
	return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>
int main(void) {
	int i, j, n, v, a[100];
	scanf("%d", &n); /*1 <= n <= 100*/
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (j = 0; j < n - 1; j++)
		printf("%d ", a[j]);
	printf("%d\n", a[n - 1]);
	for (i = 1; i < n; i++) {
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;
		}
		for (j = 0; j < n - 1; j++)
			printf("%d ", a[j]);
		printf("%d\n", a[n - 1]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  string S;
  cin >> N >> S;
  int ans = -1;
  REPS(i, N - 1) {
    int curAns = 0;
    map< char, int > mp;
    REP(j, i) {
      if (mp[S[j]] == 0)
        mp[S[j]]++;
    }
    FOR(j, i, N) {
      if (mp[S[j]] == 1)
        mp[S[j]]++;
    }
    // PRINTALL(mp);
    FORA(e, mp) {
      // print(e.first);
      // print(e.second);
      if (e.second == 2)
        curAns++;
    }
    chmax(ans, curAns);
  }
  print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <time.h>
#define int long long int
#define pb push_back
#define all(a) a.begin(), a.end()
#define scnarr(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace chrono;
/*
	Things to remember : check for coners n = 1, pass references instead
*/
/* -------------------------------Solution Sarted--------------------------------------*/

//Constants
const int MOD = 1000000007; // 1e9 + 7
const int MAXN = 1000005; // 1e6 +5
const int INF = 100000000000005; // 1e15 +5

int dp[3005][3005][4];

int rec(vector<vi> &mat, int i, int j, int cnt, int r, int c){
	if(i == r and j == c){
		if(cnt > 0)
			return dp[i][j][cnt] = mat[i][j];
		return dp[i][j][cnt] = 0;
	}

	if(dp[i][j][cnt] != -1)
		return dp[i][j][cnt];

	int one = 0, two = 0;

	if(j < c){
		if(cnt > 0 and mat[i][j] > 0){
			two = max(rec(mat, i, j +1, cnt -1, r, c) + mat[i][j], rec(mat, i, j +1, cnt, r, c));
		}else{
			two = rec(mat, i, j +1, cnt, r, c);
		}
	}
	if(i < r){
		if(cnt > 0){
			one = rec(mat, i +1, j, 3, r, c) + mat[i][j];
		}else{
			one = rec(mat, i +1, j, 3, r, c);
		}
	}

	return dp[i][j][cnt] = max(one, two);

}

void solve(){
	int r, c, k, x, y, v;
	cin >> r >> c >> k;
	vector<vi> mat(r +1, vi(c +1, 0));
	for(int i = 0; i < k; ++i){
		cin >> x >> y >> v;
		mat[x][y] = v;
	}

	for(int i = 0; i <= r +1; ++i){
		for(int j = 0; j <= c +1; ++j){
			for(int l = 0; l < 4; ++l){
				dp[i][j][l] = -1;
			}
		}
	}

	cout << rec(mat, 1, 1, 3, r, c) << endl;
}

signed main()
{
	faster;
#ifndef ONLINE_JUDGE
	freopen("ip.txt", "r", stdin);
	freopen("op.txt", "w", stdout);
#endif
	// int t; cin >> t; while(t--)
		solve();
	return 0;
}


//Author : Ankit Raj
//Problem Link :

/*Snippets*/
/*
sieve - prime factorization using sieve and primes in range
zpower - pow with mod
plate - Initial template
bfs 
dfs
fenwik - BIT
binary_search
segment_tree
*/
	

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

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//------------------------

int32_t main()
{ 
  io;
 
  int a,b,c;
  cin>>a>>b>>c;

  cout<<(a==b&&b==c?"Yes":"No");
  
 return 0;
}

Measured memory_bytes: 256
package main


import (
    "fmt"
)

func main() {
  var N,A,B int
  var count int
  var res int = 500000000

  fmt.Scan(&N)

  for i := 0; i < N; i++ {
    fmt.Scan( &A )
    B = A
    count = 0

    for j := 1; j < 500000000; j++ {
      if B % 2 == 0 {
        B /= 2
        count ++
      } else {
        break
      }
    }

    if count < res {
      res = count
    }

  }

    fmt.Println(res)

}


Measured memory_bytes: 512
import java.util.*

fun main(args: Array<String>) {
    abc153f()
}

fun abc153f() {
    val (n, length, damage) = readLine()!!.split(' ').map { it.toLong() }
    val xhList = (1..n).map {
        readLine()!!.split(' ').map { it.toLong() }.let { Enemy(it[0], it[1]) }
    }.sortedBy { it.pos }

    var answer = 0L
    var currDamage = 0L
    val blasts = ArrayDeque<Blast>()

    for (i in 0 until n) {
        var (pos, hp) = xhList[i.toInt()]

        while (blasts.isNotEmpty() && blasts.peekFirst().endPos < pos) {
            currDamage -= blasts.poll().totalDamage
        }

        hp -= currDamage

        if (hp > 0) {
            val needBomb = (hp + damage - 1) / damage
            answer += needBomb
            currDamage += damage * needBomb
            blasts.add(Blast(pos + length * 2, damage * needBomb))
        }
    }

    println(answer)
}

private data class Enemy(val pos: Long, val hp: Long)
private data class Blast(val endPos: Long, val totalDamage: Long)


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

using namespace std;

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

    if(n == 0){
      break;
    }

    vector<pair<int,int>> wg;
    vector<pair<int,int>> ob;
    for(int i = 0;i < n;++i){
      int w,o;
      cin>>w;
      cin>>o;

      wg.push_back(make_pair(w,o));
      ob.push_back(make_pair(o,w));
    }

    sort(wg.begin(),wg.end());
    sort(ob.begin(),ob.end());    

    int fir = 0;
    int sec = 0;
    bool wg_check = true;
    bool ob_check = true;

    for(pair<int,int> e : wg){
      fir += e.first;
      sec = e.second;

      if(sec < fir){
        wg_check = false;
      }
    }

    fir = 0;
    sec = 0;
    
    if(wg_check != true){
      for(pair<int,int> e : ob){
        fir = e.first;
        sec += e.second;

        if(sec > fir){
          ob_check = false;
        }
      }
    }

    if(wg_check == false && ob_check == false){
      cout<<"No"<<endl;
    }
    else{
      cout<<"Yes"<<endl;
    }
  }
  return 0;
}


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

int main()
{
  int h, w;
  cin >> h >> w;

  vector<string> a(h);

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

  for(int j = 0; j < w+2; j++){
    cout << '#';
  }

  cout << endl;

  for(int i = 0; i < h; i++){
    cout << '#' << a[i] << '#' << endl;
  }

  for(int j = 0; j < w+2; j++){
    cout << '#';
  }

  cout << endl;

  return 0;

}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scanner = new Scanner(System.in);
		String[] str = scanner.nextLine().split(" ");

		double length01 = Double.parseDouble(str[0]);
		double length02 = Double.parseDouble(str[1]);
		double angle = Math.toRadians(Double.parseDouble(str[2]));

		double area = (length01 * length02 * Math.sin(angle)) / 2;
		double sumLength = (length01 + length02) + Math.sqrt((length01 * length01) + (length02 * length02) - (2 * length01 * length02 * Math.cos(angle)));
		double high = length02 * Math.sin(angle);

		System.out.println(area + "\n" + sumLength + "\n" + high);
	}

}

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

int main() {
	long long a, b, x; cin >> a >> b >> x;
	
	long long ans = 0;
	if (a == 0); else ans -= (a-1) / x + 1;
	ans += b / x + 1;
	cout << ans << endl;

	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const int mod = 1e9+7;
int N;
string S, T;

int mult(int a, int b) {
   return ((a%mod) * (b%mod))%mod;
}

signed main() {
   cin >> N;
   cin >> S >> T;

   // 最初
   int ans = 3;
   int init = 1;
   char sBef = S[0], tBef = T[0];
   if (S[0] != T[0]) {
      ans = 6;
      init = 2;
   }

   // 2本目から
   for (int i = init; i < N; ) {
      int add = 1;
      if (sBef == tBef) { // 縦長
         if (S[i] != T[i]) {
            add = 2;
         }
         ans = mult(ans, 2);
      } else { // 横長
         if (S[i] != T[i]) {
            add = 2;
            ans = mult(ans, 3);
         }
      }

      sBef = S[i], tBef = T[i];
      i += add;
   }

   cout << ans << endl;


   return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]

count = 0

for i in range(n):
    for j in range(len(s[i])-1):
        if s[i][j] == 'A' and s[i][j+1] == 'B':
            count += 1


a = 0
b = 0
ba = 0

for i in range(n):
    if s[i][0] == 'B' and s[i][-1] == 'A':
        ba += 1
    elif s[i][0] == 'B':
        b += 1
    elif s[i][-1] == 'A':
        a += 1

if ba == 0:
    count += min(a, b)
else:
    if ba > 1:
        count += ba - 1
    if a > 0:
        a -= 1
        count += 1
    if b > 0:
        b -= 1
        count += 1
    count += min(a, b)

print(count)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define maxn 1000

using namespace std;

int cap[maxn][maxn],N;

bool dfs(vector<int> &vis,int i,int t){
  if(i==t)return true;
  vis[i]=1;
  for(int j=0;j<N;j++)
    if(!vis[j] && cap[i][j]>0 && dfs(vis,j,t)){
      cap[i][j]--,cap[j][i]++;
      return true;
    }
  return false;
}

int max_flow(int s, int t){
  vector<int>vis(N);
  for(int flow=0;;flow++,fill(ALL(vis),0))
    if(!dfs(vis,s,t))return flow;
}

int main(void){ 
  int e,a,b,c;
  cin >> N >> e;
  for(int i=0;i<e;i++){
    cin >> a >> b >> c;
    cap[a][b]=c;
  }
  cout << max_flow(0,N-1) << endl;;
}

Measured memory_bytes: 1588
#include <iostream>

using namespace std;

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

    for(int i=1;i<10;i++){
        if(N%i==0){
            int tmp=N/i;
            if(0<tmp&&tmp<10){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
K = int(input())-1
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][K])

Measured memory_bytes: 3060
H, W = gets.to_s.split.map{|t|t.to_i}

# p '.'.ord #=> 46
# p '#'.ord #=> 35
S = Array.new(H){ gets.to_s.chomp.bytes } 

def bfs(sx, sy)
  
  dx = [1, 0, -1, 0]
  dy = [0, 1, 0, -1]
  
  q = [[sx,sy,1]]
  
  used = Array.new(H){ Array.new(W+1){ false } }
  while q.any?
    x, y, d = q.shift
    used[x][y] = true
    d += 1
    4.times do |i|
      nx = x + dx[i]
      ny = y + dy[i]
      return d if nx == H - 1 && ny == W - 1
      if 0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] == 46 && !used[nx][ny]
        used[nx][ny] = true
        q.push( [nx, ny, d] )
      end
    end
  end
  
  puts(-1)
  exit
end

p S.flatten.count(46) - bfs(0,0)

Measured memory_bytes: 3836
function main(input) {
  let n,k = 0;
  [n, k] = input[0].trim().split(" ").map(i => parseInt(i));

  let sum = 0;

  function　sum1toN(n) {
    return n*(n+1)/2;
  }

  for(let i=k;i<=n+1;i++){
    const min = sum1toN(i-1);
    const max = sum1toN(n) - sum1toN(n-i);
    sum = (sum+(max-min+1))%(10**9+7);
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 33192
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n,k; cin >>n >>k;
  int h[n],ans=MOD;
  for(auto &i:h) cin >>i;
  sort(h,h+n);
  for(int i=0; i<n-k+1; i++) ans=min(ans,h[i+k-1]-h[i]);
  cout <<ans;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long, long long> ii; 
typedef vector<ii> vii;  
typedef vector<ll> vi;
#define PI acos(-1)
#define endl "\n"
#define f first 
#define s second
#define pb push_back
#define mp make_pair
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

void arrayIn(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
void arrayOut(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cout << A[K]<<' '; } }
vector<int> Graph[100001];	
vector<bool> visited(100001);
//DFS
void DFS(int root) {
	visited[root] = 1;
	cout << root << endl;
	for (int j = 0; j < Graph[root].size(); j++)	{
		if (!visited[Graph[root][j]]) {
			DFS(Graph[root][j]);
		}
	}
}
//BFS
void BFS() {
	queue<int> stored;
	stored.push(1);
	while (!stored.empty())
	{
		int t = stored.front();
		stored.pop();
		cout << t << " ";
		for (int i = 0; i < Graph[t].size(); i++){
			stored.push(Graph[t][i]);
			cout << Graph[t][i] << " ";
		}
		cout << endl;
	}
}

//declare variable-------------------------------------------------------------
ll n;
ll a[200000];
ll b[200000];


//--------------------------------------------------------------------------
int main(){
	FASTIO;
  /*
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    */
	// CODE--------------------------------------------------------------
	cin>>n;
	arrayIn(a,n+1);
	arrayIn(b,n);
	ll r=0;
	for(ll i=0;i<n;i++){
		r+=min(a[i]+a[i+1],b[i]);
		//cout<<a[i]+a[i+1]<<' '<<b[i]<<endl;
		if(b[i]<a[i]+a[i+1]){
			b[i]-=a[i];
			if(b[i]>0){
				a[i+1]-=b[i];
			}
		}
		else{
			a[i+1]=0;
		}
	}
	cout<<r;
//---------------------------------------------------------------------
	return 0;
}

Measured memory_bytes: 4992
program main;
var 
    x, y, i, count : integer;
    vote : real;
    A : array[1..1000] of integer;
begin
    readln(x, y);
    vote := 0;
    count := 0;
    for i := 1 to x do begin
        read(A[i]);
        vote := vote + A[i];
    end;
    vote := vote/(4*y);
    for i := 1 to x do 
        if A[i] >= vote
            then count := count + 1;
    if count >= y
        then writeln('Yes')
        else writeln('No');
end.


Measured memory_bytes: 1364
N, P = input().split()
p_len = len(P)
N = int(N)
P = int(P)

S = input()


cnt = 0
if P in [2,5]:
    for i in range(N):
        cnt += i+1 if int(S[i]) % P == 0 else 0
else:
    table = [0] * P # ?1
    Ui = 0
    ten = 1
    
    S = S[::-1]
    table[0] = 1 # ?2
    
    for i in range(N):
        Ui = (Ui + int(S[i]) * ten) % P # ?3
        
        cnt += table[Ui] # ?4
        
        table[Ui] += 1 # ?5
        ten = (ten * 10) % P # ?6
print(cnt)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

ll dp[3005][3005];

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) dp[i][i] = a[i];
    for (int len = 1; len < n; len++) {
        for (int l = 0; l < n-len; l++) {
            int r = l + len;
            dp[l][r] = max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
        }
    }
    cout << dp[0][n-1] << endl;
}

Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ll n;
	cin >> n;
	vector<ll> d(n + 1, 0);
	for (ll i = 1; i <= n; ++i)cin >> d[i];
	sort(d.begin(), d.end());
	vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
	dp[0][0] = 100;
	for (ll i = 0; i < n; ++i) {
		for (ll j = 0; j <= i; ++j) {
			dp[i + 1][i] = max(dp[i + 1][i], min(dp[i][j], d[i + 1] - d[j]));
			dp[i + 1][j] = max(dp[i + 1][j], min(dp[i][j], d[i + 1] - d[i]));
		}
	}
	ll ans = 0;
	for (ll i = 0; i < n; ++i) {
		ans = max(ans, min(dp[n][i], 24 - d[i] - d[n]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 3624
from fractions import gcd
def lcm(a,b):
    return a*b/gcd(a,b)
def ge(a,m):
        i, b = 1, a%m
        while b!=1:
            b = (a*b)%m
            i += 1
        return i
while True:
    tmp = map(int, raw_input().split(" "))
    if not tmp[1]:
        break
    print reduce(lcm,(ge(a,m) for a,m in zip(tmp[::2],tmp[1::2])))

Measured memory_bytes: 5900
#include<iostream>
#include<cstdio>
using namespace std;
long long a[222222],sum,n,cur,mn;
long long Abs(long long x)
{
	return max(-x,x);
}
int main()
{
	mn=1e18;
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	for (int i=1;i<n;i++)
	{
		cur+=a[i];
		mn=min(mn,Abs(cur-sum+cur));
	}
	printf("%lld\n",mn);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const int maxn=4*2000+10, oo= 1<<29;

bool A[maxn], B[maxn], mrk[maxn];

int N, M, ld[maxn], rd[maxn], bt[maxn], ans;
char s[maxn];
bool cmp(int a, int b){
	return rd[a] > rd[b] || (rd[a]==rd[b] && ld[a] < ld[b]);
}

void Solve();

int main(){
	scanf("%s", s);
	N = strlen(s);
	bool empyB= true,empyA=true;
	for (int i=0; i<N; i++) A[i] = s[i]-'0';
	scanf("%s",s);
	
	for (int i=0; i<N; i++)B[i] = s[i]-'0';
	for (int i=0; i<N; i++) empyA&=A[i]^1 , empyB &= B[i]^1;
	if ( empyB && !empyA) { printf("-1\n"); return 0;}
	ans= oo;
	Solve();
	for (int i=0,j=N-1; i<j; i++,j--) swap(A[i], A[j]), swap(B[i], B[j]);
	Solve();
	printf("%d\n", ans);
	return 0;
}

void Solve(){
	for (int i=N; i<(N<<1); i++) A[i] = A[i-N], B[i] = B[i-N];
	int las= 0;
	for (int i=0; i<N; i++)	if ( B[i]) las= i;
	for (int i=N; i<(N<<1); i++){
		if (B[i]) las= i;
		ld[i] =ld[i-N]= i-las;
	}
	for (int i=2*N-1; i>=N; i--) if ( B[i]) las = i;
	for (int i=N-1; i>=0; i--){
		if ( B[i] ) las= i;
		rd[i] =rd[i+N]= las-i;
	}
	for (int i=0; i<N; i++) bt[i] = i;
	sort(bt, bt+N, cmp);
	#ifdef che
	debug("A=");for (int i=0;i<N; i++) debug("%d",A[i]);
	debug("\nB=");for (int i=0;i<N; i++) debug("%d",B[i]);
	for (int i=0; i<N; i++) debug("\nld[%d] = %d\trd[%d] = %d", i, ld[i], i, rd[i]);
	debug("\nbt:\n");
	for (int i=0; i<N; i++) debug("\t[%d] = %d\n", i, bt[i]);
	#endif 
	for (int d=0; d<N; d++){
		for (int i=0;i<N; i++) mrk[i] = false;
		int revs= 0;
		for (int i=0;i<N; i++)
			if ( B[i]^A[i+d]) mrk[(i+d)%N] = true, revs++;
		
		int maxld = 0, movs=oo;
		for (int i=0;i<N; i++)
			if ( mrk[bt[i]]){
				int ii= bt[i], _r = rd[ii],_l = maxld;
				if ( _l >d ) movs = min(movs, 2*_r+2*_l-d);
					else movs= min( movs, 2*_r+d);
				maxld = max( maxld , ld[ii]);
			}
		if ( maxld > d) movs= min(movs, 2*maxld-d);
			else movs= min(movs, d);
		ans = min(ans , movs+revs);
	}
}



Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
    int n,k;
    cin>>n>>k;
    ll h[n],ans=10000000001,tmp;
    for(int i=0;i<n;i++) cin>>h[i];
    sort(h,h+n);
    for(int i=0;i<n-k+1;i++){
        tmp=h[i+k-1]-h[i];
        if(ans>tmp) ans=tmp;
    }
    cout <<ans<< endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>

#define MOD 1000000007

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(int argc, char const *argv[]){
    long a, b, x, ans=0;
    scanf("%ld %ld %ld",&a, &b, &x);

    long b_ans = b/x + 1;
    long a_ans = 0;
    if(a != 0){
        a_ans = (a-1)/x + 1;
    }

    printf("%ld\n", b_ans - a_ans);

    return 0;
}

Measured memory_bytes: 256