akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()

	nf := float64(n)
	ans := math.Floor(nf / 1.08)
	var k float64
	for k = -2; k < 2; k++ {
		if math.Floor((ans+k)*1.08) == float64(n) {
			ans += k
			break
		}
	}

	if k < 2 {
		fmt.Fprintln(stdout, ans)
	} else {
		fmt.Fprintln(stdout, ":(")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  long long n, p;
  cin >> n >> p;
  vector <pair <long long, long long> > prime;
  for (int i = 2; i <= sqrt(p); i++) {
	  if (p % i == 0) {
		  int c = 0;
		  while (p % i == 0) {
			  p /= i;
			  c++;
			}
		  prime.push_back(make_pair(c, i));
		}
	}
  prime.push_back(make_pair(1, p));
  long long ans = 1;
  for (auto itr = prime.begin(); itr != prime.end(); itr++) {
	  for (long long i = 0; i < (*itr).first / n; i++) {
		  ans *= (*itr).second;
		}
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N , A , B;
  cin >> N >> A >> B;
  
  if (A * N > B) {
    cout << B << endl;
  }
  
  else if(A * N == B) {
    cout << B << endl;
  }
  
  else if (A * N < B) {
    cout << A * N << endl;
  }
  
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>

using namespace std;

long n, x;
long ans = 0;
long countP[51];

void rec(int nn, long from, long to)
{
    if(from < 0 || to < 0 || ans<0) return;

    if(nn == 0)
    {
        ans++;
        return;
    }

    long midP = from + (to - from)/2;

    if(x == from) return;
    else if(x < midP)
    {
        rec(nn-1, from + 1, midP-1);
    }
    else if(x == midP)
    {
        ans += countP[nn-1] + 1;
    }
    else if(x == to || x == to - 1)
    {
        ans += countP[nn];
    }
    else
    {
        ans += countP[nn-1] + 1;
        rec(nn-1, midP+1, to-1);
    }

}

int main() {

    countP[0] = 1;
    for(int i=1; i<=50; i++)
    {
        countP[i] = countP[i-1] * 2 + 1;
    }

    cin >> n;
    cin >> x;

    long len = 1;
    for(int i=1; i<=n; i++) len = len * 2 + 3;

    rec(n, 1, len);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   string arr[9];
   arr[0]="',.!?";
   arr[1]="abcABC";
   arr[2]="defDEF";
   arr[3]="ghiGHI";
   arr[4]="jklJKL";
   arr[5]="mnoMNO";
   arr[6]="pqrsPQRS";
   arr[7]="tuvTUV";
   arr[8]="wxyzWXYZ";
   string ss;
   string result;
   while(getline(cin,ss))
   {
     result="";
     for(int i=0;i<ss.length();i++)
     {
       int count=1;
       int count0=1;
       while(i<ss.length()&&ss[i]==ss[i+1])
       {
         i++;
         count++;
       }       
       if((ss[i]-'0')==0)
       {
         int m=count-1;
         while(m--) result+=" ";                  
       }
       else
       {
         int kk=(count-1)%(arr[(ss[i]-'1')].length());
         result+=(arr[(ss[i]-'1')].at(kk));
       }
     }                      
     cout<<result<<endl;
   }
   //while(1);
   return 0;
 }

 
 

 

Measured memory_bytes: 3148
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int count=0;
        int maxHigh =0;
        int tmp;
        for(int i=0;i<number;i++){
            tmp = sc.nextInt();
            if(tmp >= maxHigh){
                maxHigh=tmp;
                count++;
            }
        }
        System.out.print(count);
    }
    
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
   int n,i;
   cin>>n;
   int a[n];
   long long dp[n];
   for(i=0;i<n;i++)
   {
     cin>>a[i];
   }
   dp[0]=0;
   dp[1]=abs(a[1]-a[0]);
   for(i=2;i<n;i++)
   {
     dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
   }
   cout<<dp[n-1];
   return 0;
 }

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	vector<int> l(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}

	int d = 0;
	int ans = 1;
	for (auto y: l) {
		d += y;
		if (d <= x) {
			ans++;
		}
	}

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


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

#define pb push_back
#define pp pop_back
#define mp make_pair
typedef long long Long;

const int N = 1e5;

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int tc, ca = 0;
  Long a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << Long(max(a*c, max(a*d, max(b*c, b*d)))) << '\n';
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int,int> P;
//スター
int main(){
  int n, k;
  cin >> n >> k;
  int mx = (n-1)*(n-2)/2;
  if (mx < k) {
    puts("-1");
    return 0;
  }
  vector<P> res;

  //スターを作る(nが真ん中)
  for (int i = 1; i <= n-1; i++) {
    res.push_back({i,n});
  }
  
  //最短距離が2になる頂点対がｋ個になるように辺を追加
  int add = mx - k;
  vector<P> edge;//追加する辺の候補
  rep(i,n-1)rep(j,i) edge.push_back({i+1,j+1});
  rep(i,add) res.push_back(edge[i]);
  cout << res.size() << endl;
  for (auto e : res) {
    cout << e.first << " " << e.second << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
    int x1,x2,y1,y2,a,b;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    a = y2 - y1;
    b = x2 - x1;
    printf("%d %d %d %d\n",(x1 + b - a),(y1 + a + b),(x1 - a),(y1 + b));
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		StringBuilder[] sbarr = new StringBuilder[w];
		int count = 0;
		for (int i = 0; i < h; i++) {
			String x = sc.next();
			if (x.contains("#")) {
				count++;
				for (int j = 0; j < w; j++) {
					if (sbarr[j] == null) {
						sbarr[j] = new StringBuilder();
					}
					sbarr[j].append(x.charAt(j));
				}
			}
		}
		StringBuilder[] outputs = new StringBuilder[count];
		for (int i = 0; i < w; i++) {
			if (sbarr[i].toString().contains("#")) {
				for ( int j = 0; j < count; j++) {
					if (outputs[j] == null) {
						outputs[j] = new StringBuilder();
					}
					outputs[j].append(sbarr[i].charAt(j));
				}
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for (StringBuilder output : outputs) {
			sb.append(output).append("\n");
		}
			
		System.out.print(sb);
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).rbegin(), (v).rend())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define DESC(v) sort((v).rbegin(), (v).rend())
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    ll N;
    cin >> N;
    vll A(N);
    for(auto &a:A) cin >> a;
    vpll vp;
    for(int i = 0; i < N; i++) {
        vp.push_back(make_pair(A[i], i));
    }
    ASC(vp);
    vll ans(N);
    for(int i = 0; i < N; i++) {
        ll idx = vp[i].second;
        ans[idx] = vp[N/2 - (i >= (N / 2) ? 1 : 0)].first;
    }
    for(auto &a:ans) {
        cout << a << endl;
    }
}

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


Measured memory_bytes: 9196
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author koneko096
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    BHomework solver = new BHomework();
    solver.solve(1, in, out);
    out.close();
  }

  static class BHomework {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt(), m = in.nextInt(), sum = 0;
      for (int i = 0; i < m; i++) {
        sum += in.nextInt();
      }
      out.println(Math.max(-1, n - sum));
    }

  }


  static class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

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

  }
}



Measured memory_bytes: 27392
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
int n,m;
vector<int>p[100010];
int pref[100010];
int vis[100010];
int sum;
void bfs(int i){
	queue<int>q;
	q.push(i);
	vis[i]=1;
	while(!q.empty()){
		int id=q.front();
		q.pop();
		for(int j=0;j<p[id].size();j++){
			//cout<<id<<" "<<p[id][j]<<endl;
			if(!vis[p[id][j]]){
				pref[p[id][j]]=id;
				vis[p[id][j]]=1;
				q.push(p[id][j]);
				sum++;
			}
		}
	}
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>m;
    rep(i,1,m+1){
    	int u,v;
    	cin>>u>>v;
    	p[u].pb(v);
    	p[v].pb(u);
	}
	bfs(1);
	/*rep(i,2,n+1){
			cout<<pref[i]<<endl;
	}*/
	if(sum==n-1){
		cout<<"Yes"<<endl;
		rep(i,2,n+1){
			cout<<pref[i]<<endl;
		}
	}
	else
	cout<<"No";
    return 0;
}


Measured memory_bytes: 10960
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	char s[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> s[i][j];
		}
	}
	cout << s[0][0] << s[1][1] << s[2][2] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rrep(i,a,b) for(int i = a; i >=b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) (x).begin(),(x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using ii = pair<int, int>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pil = pair<int,ll>;
using vvi = vector<vi>;
using vpi = vector<ii>;

const int N = 100100;
ll mod=1000000007;
vector<bool> isprime(N,true);
void seive(){
    isprime[0] = false;
    isprime[1] = false;
    for(int i = 2; i < N; i++){
        if(isprime[i]){
            for(int j = i + i; j < N; j+=i){
                isprime[j] = false;
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    seive();
    int q;
    cin>>q;
    seive();
    vector<bool> isvalid(N,false);
    for(int i = 1; i < N; i+=2){
        if(isprime[i] and isprime[(i+1)/2]){
           isvalid[i]=true; 
        }
    }
    vector<ll> aiyasudhi(N,0);
    rep(i,1,N-1){
        aiyasudhi[i] = aiyasudhi[i-1] + isvalid[i]; 
    }
    while(q--){
        int l, r;
        cin>>l>>r;
        ll ans = aiyasudhi[r] - aiyasudhi[l-1]; 
        cout<<ans<<nl;
    }

    return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans = 1;
    if (b - a <= 2) {
        ans += k;
    } else {
        ans = a;
        ll remain = k - (a - 1);
        if (remain >= 2) {
            if (remain % 2 == 0) {
                ans += (b - a) * (remain / 2);
            } else {
                ans += (b - a) * (remain / 2) + 1;
            }
        } else {
            ans += remain;
        }
    }

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


Measured memory_bytes: 256
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include<string.h>
#include<math.h>

using namespace std;

const int kMax = 1600;
const int kInf = 1e9;

int a[30], ax = 0;
int b[30], bx = 0;
char cs[105];
int  main()
{
	int n;
	//while (cin >> n)
	while(~scanf("%d",&n))
	{
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		ax = 0;
		bx = 0;

		char c;
		for (int i = 0; i < n; i++)
		{
			cin >> c;
			cs[i] = c;
			if (b[c - 'a'] == 0)
			{
				bx++;
			}
			b[c - 'a']++;
		}
		int maxx = -1;
		for (int i = 0; i < n - 1; i++)
		{
			b[cs[i] - 'a']--;
			if (a[cs[i] - 'a'] == 0)ax++;
			if (b[cs[i] - 'a'] == 0)
			{
				ax--;
				if (ax < 0)ax = 0;
			}
			a[cs[i] - 'a']++;

			maxx = max(maxx, ax);
		}
		//cout << maxx << endl;
		printf("%d", maxx);
	}
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    if(s[2]==t[0]&&s[1]==t[1]&&s[0]==t[2])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


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

  VVll t(3, Vll(n+1));
  VV pos(3, V());
  string dmc = "DMC";

  rep(i, n) rep(j, 3) {
    t[j][i+1] = t[j][i];
    if (s[i] == dmc[j]) {
      ++t[j][i+1];
      pos[j].push_back(i);
    }
  }

  ll q; cin >> q;
  rep(_, q) {
    ll k; cin >> k;
    ll ans = 0;
    for (auto c : pos[2]) ans += t[1][c] * (t[0][c] - t[0][max(c-k+1, 0ll)]);
    for (auto a : pos[0]) ans -= t[1][a+1] * (t[2][min(a+k, n)] - t[2][a+1]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 32916
/*** keep hungry and calm CoolGuang!***/
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pp;
const ll INF=1e17;
const int Maxn=2e7+10;
const int maxn =3e5+10;
const int mod=1e9+9;
const int Mod = 1e9+7;
///const double eps=1e-10;
inline bool read(ll &num)
{char in;bool IsN=false;
    in=getchar();if(in==EOF) return false;while(in!='-'&&(in<'0'||in>'9')) in=getchar();if(in=='-'){ IsN=true;num=0;}else num=in-'0';while(in=getchar(),in>='0'&&in<='9'){num*=10,num+=in-'0';}if(IsN) num=-num;return true;}
ll n,m,p;
ll a[maxn],st[maxn];
int judge_min(int pos){
    if(pos>1&&st[pos]>st[pos-1]) return 0;
    if(pos<n&&st[pos]>st[pos+1]) return 0;
    return 1;
}
int judge_max(int pos){
    if(pos>1&&st[pos]<st[pos-1]) return 0;
    if(pos<n&&st[pos]<st[pos+1]) return 0;
    return 1;
}
int main()
{
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    int s = 0;
    for(int i=1;i<=n;i++)
        if(!s||a[i] != st[s]) st[++s] = a[i];
    ll pre= 1000,ans = 1000,f = 0,cot = 0;///0 - > 买点
    for(int i=1;i<=s;i++){
        int maxf = 0,minf = 0;
        maxf = judge_max(i);
        minf = judge_min(i);
        if(!f){
            if(minf){
                pre = ans;
                cot = (ans/st[i]);
                ans-= cot*st[i];
                f^=1;
            }
        }
        else{
            if(maxf){
                pre = ans;
                ans += cot*st[i];
                f^=1;
            }
        }
    }
    printf("%lld\n",max(pre,ans));
    return 0;
}
/**
a b c d
a*b*c > b*c*d
bc(a-d)>0
**/


Measured memory_bytes: 3772
from itertools import combinations, permutations
import math
N = int(input())
cor = []
for n in range(N):
    X, Y = map(int, input().split())
    cor.append((X, Y))

dist = [[0] * N for n in range(N)]
for i in range(N):
    for j in range(N):
        dist[i][j] = math.sqrt((cor[i][0] - cor[j][0]) ** 2 + (cor[i][1] - cor[j][1]) ** 2)

ans = 0
for item in list(permutations([i for i in range(N)], N)):
    for j in range(len(item) - 1):
        ans += dist[item[j]][item[j + 1]]
print(ans / math.factorial(N))

Measured memory_bytes: 7972
package main

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

var dummy = &Node{}

type Node struct {
	key        int
	next, prev *Node
}

func init() {
	// key = 0
	dummy.next = dummy
	dummy.prev = dummy
}

func main() {
	n := nextInt()

	for i := 0; i < n; i++ {
		v := strings.Split(nextLine(), " ")
		cmd := v[0]

		switch cmd {
		case "insert":
			num, err := strconv.Atoi(v[1])
			if err != nil {
				panic("error")
			}
			insert(num)
		case "delete":
			num, err := strconv.Atoi(v[1])
			if err != nil {
				panic("error")
			}
			deleteKey(num)
		case "deleteFirst":
			deleteFirst()
		case "deleteLast":
			deleteLast()
		default:
			panic("error")
		}
	}

	printLine()
}

func printLine() {
	cur := dummy.next
	r := make([]string, 0, 1000000)
	for cur != dummy {
		r = append(r, strconv.Itoa(cur.key))
		cur = cur.next
	}
	fmt.Println(strings.Join(r, " "))
}

func insert(key int) {
	node := &Node{key: key}
	node.next = dummy.next
	dummy.next.prev = node
	dummy.next = node
	node.prev = dummy
}

func deleteNode(node *Node) {
	node.prev.next = node.next
	node.next.prev = node.prev
}

func deleteKey(key int) {
	node := search(key)
	if node == dummy {
		return
	}
	deleteNode(node)
}

func deleteFirst() {
	deleteNode(dummy.next)
}

func deleteLast() {
	deleteNode(dummy.prev)
}

func search(key int) *Node {
	cur := dummy.next
	for cur != dummy {
		if cur.key == key {
			return cur
		}
		cur = cur.next
	}
	return cur
}

// =================================
// I/O util
// =================================

var sc = bufio.NewScanner(os.Stdin)

// Scan required
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

// =================================


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

int main()
{
   int K,s;
   cin>>K>>s;
   int ans = 0;
   for(int i=0;i<=K;i++)
   {
      for(int j=0;j<=K;j++)
      {
         int k = s - i - j;
         if(k>=0 && k<=K)
            ans++;
      }
   }
   cout<<ans;
   return 0;
   
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef long long ll;

using namespace std;

int main() {
    
    string s;
    cin >> s;
    
    int k;
    cin >> k;
    
    int n = s.size();
    
    vector<string> vec;
    FOR(j, 1, min(n,5)+1){
        FOR(i, 0, n-j+1){
            vec.push_back(s.substr(i,j));
        }
    }
    
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    
    cout << vec[k-1] << endl;
    
    return 0;
}


Measured memory_bytes: 1660
#include<stdio.h>
int main(void){
  unsigned int submit=0,i,input;
  for(i=0;i<28;i++){
    scanf("%d",&input);
    submit+=(1<<(input-1));
  }
  for(i=0;i<30;i++){
    if((submit&1)==0) printf("%u\n",i+1);
    submit>>=1;
  }
  return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def insertionSort(A, N):
    """N個の要素を含む0-オリジンの配列A"""
    print(' '.join(map(str, A)))
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(' '.join(map(str, A)))

N = int(input())
A = [int(w) for w in input().split()]

insertionSort(A, N)



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

struct edge {
    int to, cost;
};
vector<edge> G[100050];
int ans[100050];

void dfs(int v, int p, int color){
    ans[v] = color;
    for(auto e : G[v]) {
        if(e.to == p) continue;
        if(e.cost % 2) dfs(e.to, v, 1-color);
        else dfs(e.to, v, color);
    }
}

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

int N;
cin >> N;

rep(i,N-1) {
    int u,v,w;
    cin >> u >> v >> w;
    u--;v--;
    G[u].pb({v, w});
    G[v].pb({u, w});
}
dfs(0,-1,0);
rep(i,N) cout << ans[i] << endl;

return 0;
}

Measured memory_bytes: 9216
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int n, k;
signed main() {
	cin >> n >> k;
	for (int i = 1; i <= k; i++) {
		if (i == 1) {
			printf("%lld\n", n - k + 1);
		}
		else {
			int cnt = 0;
			rep(j, n - k) {
				int r = n - k - j;
				if (r < i - 1) break;
				cnt += (j + 1) * comb(r - 1, i - 2);
				if (mod <= cnt) cnt %= mod;
			}
			cnt *= comb(k - 1, i - 1);
			if (mod <= cnt) cnt %= mod;
			printf("%lld\n", cnt);
		}
	}
}

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

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, m, now, ans;
  cin >> n >> m;
  ans = now = m;
  for(int i = 0; i < n; i++){
    int in, out;
    cin >> in >> out;
    now += in - out;
    if(now < 0){
      ans = 0;
      break;
    }
    ans = max(ans, now);
  }

  cout << ans << "\n";
}

Measured memory_bytes: 3220
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CStep solver = new CStep();
        solver.solve(1, in, out);
        out.close();
    }

    static class CStep {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.readIntArray(n);

            long answer = 0;
            int max = 0;
            for (int x : a) {
                answer += Math.max(0, max - x);
                max = Math.max(max, x);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public final BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }
}



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

int main(){
  int N;
  cin >>N;
  int a[N];
  for (int i=0;i<N;i++){
    cin >> a[i];
  }
  
  int temp=0;
  
  for (int i=0;i<N;i++){
    temp=a[temp]-1;
    if (temp==1){
      cout<<i+1<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 640
import scipy.sparse.csgraph;L=lambda:list(map(int,input().split()));n,m=L();s=[n*[float("inf")]for _ in range(n)];d=[L()for _ in range(m)]
for a,b,c in d:s[a-1][b-1]=s[b-1][a-1]=c
x=scipy.sparse.csgraph.floyd_warshall(s);print(sum(c!=x[a-1][b-1]for a,b,c in d))

Measured memory_bytes: 18656
#include <stdio.h>
int sum,x,y;
void Euclidean(void){
    int temp;
    x%=y;
    temp=x;
    x=y;
    y=temp;
    sum++;
}
int main(void){
    int n1,n2;
    for(;sum=0,scanf("%d %d",&n1,&n2),n2;){
        n1>=n2?(x=n1,y=n2):(x=n2,y=n1);
        while(y)  Euclidean();
        printf("%d %d\n",x,sum);
    }
    return 0;
}

Measured memory_bytes: 600
use std::cmp::min;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let s = sc.chars();
    let t = sc.chars();
    assert_eq!(s.len() + 1, t.len());
    for i in 0..s.len() {
        if s[i] != t[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2148
import math
a, b, h, m = map(int, input().split())
bk = 6 * m
ak = 30 * h + 0.5 * m
if ak >= bk + 180:
	k = 360 - ak + bk
elif bk >= ak + 180:
	k = 360 - bk + ak
elif bk > ak:
	k = bk - ak
else:
	k = ak - bk
ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(k)))
print(ans)

Measured memory_bytes: 9516
import sys
input = sys.stdin.readline
n=int(input())
AB=[]
append=AB.append
for i in range(n):
  a,b=map(int,input().split())
  append((a+b,a,b))
AB.sort(key=lambda x:x[0],reverse=True)
ans=0
sign=0
for i in range(n):
  ab,a,b=AB[i]
  if sign==0:
    ans+=a
    sign=1
  else:
    ans-=b
    sign=0
print(ans)


Measured memory_bytes: 22120
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> 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; }

ll n, c;

ll solve(vector<ll> &x, vector<ll> &v){
	vector<ll> rmax(n);
	rmax[0] = max(v[0] - x[0] * 2, 0LL);
	ll sum = v[0];
	for(ll i = 1; i < n; ++i){
		sum += v[i];
		rmax[i] = max(sum - 2 * x[i], rmax[i-1]);
	}
	ll res = 0, lsum = 0;
	for(ll i = n-1; i > 0; --i){
		lsum += v[i];
		chmax(res, lsum - (c - x[i]) + rmax[i-1]);
	}
	lsum += v[0];
	chmax(res, sum - x[n-1]);
	chmax(res, sum - c + x[0]);
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> c;
	vector<ll> x(n), v(n);
	rep(i,n) cin >> x[i] >> v[i];
	ll ans = solve(x, v);
	reverse(x.begin(), x.end());
	rep(i,n) x[i] = c - x[i];
	reverse(v.begin(), v.end());
	chmax(ans, solve(x, v));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2672
// @date 2020-02-07 19:19 

#include <bits/stdc++.h>
using namespace std;

#define ll long long

ll A[200001];

int main(void) {
    int N, K;
    scanf("%d%d", &N, &K);
    for(int i=0; i<N; i++)
        scanf("%d", &A[i]);
    sort(A, A+N);

    ll ans=0;
    for(int i=0; i<N-K; i++)
        ans+=A[i];

    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 1792
# abc103_c.py
# https://atcoder.jp/contests/abc103/tasks/abc103_c

# C - Modulo Summation /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# N個の正整数 a1,a2,...,aNが与えられます。
# 非負整数 mに対して、f(m)=(m mod a1)+(m mod a2)+...+(m mod aN)とします。
# ここで、X mod Yは X を Yで割った余りを表します。
# fの最大値を求めてください。

# 制約
#     入力は全て整数である
#     2≤N≤3000
#     2≤ai≤10^5

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# a1 a2 ... aN


# 出力
# fの最大値を出力せよ。

# 入力例 1
# 3
# 3 4 6

# 出力例 1
# 10

# f(11)=(11 mod 3)+(11 mod 4)+(11 mod 6)=10が fの最大値です。

# 入力例 2
# 5
# 7 46 11 20 11

# 出力例 2
# 90

# 入力例 3
# 7
# 994 518 941 851 647 2 581

# 出力例 3
# 4527


def calculation(lines):
    N = int(lines[0])
    values = list(map(int, lines[1].split()))
    # ☆3000近くの大きな素数をいっぱい並べた時に、これじゃだめだと思う。
    return [sum(values) - N]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '3 4 6']
        lines_export = [10]
    if pattern == 2:
        lines_input = ['5', '7 46 11 20 11']
        lines_export = [90]
    if pattern == 3:
        lines_input = ['7', '994 518 941 851 647 2 581']
        lines_export = [4527]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9380
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll>h(n);
	ll minv = INF;
	repp(i, 0, n)cin >> h[i];
	sort(h.begin(), h.end());
	reverse(h.begin(), h.end());
	repp(i, 0, n+1-k) {
		minv = min(minv, h[i] - h[i + k - 1]);
	}
	cout << minv << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll dp[200010][10];

int main()
{
  ll l;
  cin >> l;
  vector<ll> a(l);
  for (auto &e : a)
    cin >> e;
  for (int i = 0; i <= l; ++i)
  {
    for (int j = 0; j < 5; ++j)
      dp[i][j] = 1LL << 60;
  }
  dp[0][0] = 0;

  for (int i = 0; i < l; ++i)
  {
    ll nmin = dp[i][0];
    dp[i + 1][0] = min(dp[i + 1][0], nmin + a[i]);
    nmin = min(dp[i][1], nmin);
    dp[i + 1][1] = min(dp[i + 1][1], nmin + a[i] % 2 + 2 * (a[i] == 0));
    nmin = min(dp[i][2], nmin);
    dp[i + 1][2] = min(dp[i + 1][2], nmin + (a[i] + 1) % 2);
    nmin = min(dp[i][3], nmin);
    dp[i + 1][3] = min(dp[i + 1][3], nmin + a[i] % 2 + 2 * (a[i] == 0));
    nmin = min(dp[i][4], nmin);
    dp[i + 1][4] = min(dp[i + 1][4], nmin + a[i]);
  }
  cout << min({dp[l][0], dp[l][1], dp[l][2], dp[l][3], dp[l][4]}) << endl;

  return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr ll INF=1e18;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(ll h,w;cin>>h>>w&&h|w;){
		ll res=INF;
		if(h>=3){
			ll x=h/3,y=(h+2)/3;
			res=min(res,(y-x)*w);
		}
		if(w>=3){
			ll x=w/3,y=(w+2)/3;
			res=min(res,(y-x)*h);
		}
		rep(_,2){
			repi(i,1,h){
				ll x=i*w,y=(h-i)*(w/2),z=(h-i)*((w+1)/2);
				res=min(res,max({abs(x-y),abs(y-z),abs(z-x)}));
			}
			swap(h,w);
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <string>
#include <ios>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int N, K;
	string S;
	cin >> S;

	string result = "NA";
	int str_first = atoi(S.substr(0, 2).c_str());
	int str_second = atoi(S.substr(2, 2).c_str());
	
	if (str_first >= 1 && str_first <= 12 && 
		 str_second >= 1 && str_second <= 12) {
		result = "AMBIGUOUS";
	}
	else if (str_second >= 1 && str_second <= 12) {
		result = "YYMM";
	}
	else if (str_first >= 1 && str_first <= 12) {
		result = "MMYY";
	}
	cout << result;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    string s, t;
    cin >> s >> t;
    
    //cout << s + t[t.size()-1] << endl;
    
    if(s + t[t.size()-1] == t) {
        cout << "Yes" << endl;
    } else { 
        cout << "No" << endl;
}
    return 0;
}

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

int main(){
    int N,L;
    cin >> N >> L;
    vector<int> apple(N);
    int sum = 0;
    for(int i=0;i<N;i++) {
        apple[i] = L+i+1-1;
        sum += apple[i];
    }
    int diff = abs(sum - (sum - apple[0]));
    int anssum = sum - apple[0];
    for(int i=1;i<N;i++){
        int tmpdiff = abs(sum - (sum - apple[i]));
        if(diff > tmpdiff) {
            diff = tmpdiff;
            anssum = sum - apple[i];
        }
    }
    cout << anssum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for (int i = 0; i < r; i++)
#define repeq(i,r) for (int i = 0; i <= r; i++)
#define isc(n) scanf("%d", &n)

int main() {
  int H, A;
  isc(H);
  isc(A);
  printf("%d", H / A + (H % A > 0 ? 1 : 0));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;


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

	i64 n, a, b; cin >> n >> a >> b;
	i64* h = new i64[n];
	rep(i, 0, n) cin >> h[i];

	auto f = [&](i64 x) {
		i64 res = 0;
		rep(i, 0, n) res += max((i64)0, ((h[i] - b * x) + a - b - 1) / (a - b));
		return x >= res;
	};

	i64 ng = 0, ok = 1 << 30;
	while (ok - ng > 1) {
		i64 mid = (ok + ng) >> 1;
		if (f(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok;
	delete[] h;
	return 0;
}

Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ll N, K, S;
  cin >> N >> K >> S;
  /*if(N==K){
    REP(i, N-1) { cout << S<<" ";}
      cout << S;
  }else{
    REP(i, K-1) cout << S<<" ";
    cout << S ;
    for (int i = K ; i < N; i++) cout << " " << S+1;
  }*/
  if (K == 0) {
    if (S == 1e+9) {
      REP(i, N) cout << 1 << " ";
    } else {
      REP(i, N) cout << S + 1 << " ";
    }
    cout << endl;
    return 0;
  }
  REP(i, K - 1) cout << S << " ";
  cout << S;
  if (S == 1e+9) {
    for (int i = K; i < N; i++) cout << " " << 1;
  } else {
    for (int i = K; i < N; i++) cout << " " << S + 1;
  }

  cout << endl;
}

Measured memory_bytes: 1280
n,l = list(map(int,input().split()))

ringo = []
for i in range(1,n+1):
  ringo += [l + i - 1]
ans_list = []

sr = sum(ringo)
dic = {}
for x in ringo:
  tmp = sum(ringo) - x
  ans = abs(sum(ringo) - tmp)
  dic[ans] = tmp
x = min(dic)
print(dic[x])
    



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

const long mod = 998244353;

int main(){
  int n;
  cin >> n;
  vector<int>d(n);
  for(int i=0; i<n; i++){
    cin >> d[i];
  }
  if(d[0]!=0){
    cout << 0;
    return 0;
  }
  vector<long>cnt(n);
  for(int i=0; i<n; i++){
    cnt[d[i]]++;
  }
  if(cnt[0]>1){
    cout << 0;
    return 0;
  }
  int max;
  for(int i=n-1; i>=0; i--){
    if(cnt[i]>0){
      max=i;
      break;
    }
  }
  long ret=1;
  for(int i=1; i<=max; i++){
    for(int j=0; j<cnt[i]; j++){
      ret *= cnt[i-1];
      ret %= mod;
    }
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{
    int n, c = 0;
    cin >> n;
    string s;
    cin >> s;
    for  (int i = 0; i < n-2; i++)
    {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
            c++;
        }
    }
    cout << c;
    return 0;
}


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


int main () {
    string s;
    cin >> s;
    if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) {
        cout << "Bad";
    } else {
        cout << "Good";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

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

    int ans = INT_MAX;
    for (int i=1; i<=100; i++) {
        int cnt = 0;
        for (int j=0; j<n; j++) {
            cnt += (i - x[j]) * (i - x[j]);
        }
        ans = min(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 888