akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <sstream>
#include <bitset>

using namespace std;

int main(){
    string s;
    while(getline(cin,s)){
        if(s=="0") break;
        stringstream ss;
        ss << s;
        vector<int> c;
        int temp;
        while(ss >> temp) c.push_back(temp);
        bitset<22> bits;
        bits.set(0);
        for(int i=0;i<c.size();i++){
            bitset<22> newbits;
            int x = c[i];
            for(int j=0;j<22;j++){
                if(!bits[j]) continue;
                if(x>=10) x = 10;
                if(x != 1 && j+x <= 21) newbits.set(j+x);
                if(x == 1){
                    if(j+11 <= 21) newbits.set(j+11);
                    if(j+1 <= 21) newbits.set(j+1);
                }
            }
            bits = newbits;
        }
        int mm=0;
        for(int i=0;i<22;i++){
            if(bits[i]) mm = i;
        }
        cout << mm << endl;
    }
}

Measured memory_bytes: 1244
n = int(input())
#a,b = map(int,input().split())
L = list(map(int,input().split()))
#print(L)
dp = [0]*(n+2)
dp[0] = 0
dp[1] =abs(L[1]-L[0])
#print(dp)
for i in range(1,n-1):
    dp[i+1] = min( (dp[i-1] +abs(L[i+1]-L[i-1])) , (dp[i] + abs(L[i+1]-L[i]))  )
#print(dp)
print(dp[n-1])

Measured memory_bytes: 13980
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
	using namespace std;

	int n;
	cin >> n;

	cout << n * n * n << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int numStones = scanner.nextInt();

    if (numStones < 2 || numStones > 100000) {
      System.out.println("0");
      return;
    }

    ArrayList<Integer> heights = new ArrayList<>();
    for (int i = 0; i < numStones; i++) {
      heights.add(i, scanner.nextInt());
    }
    int cost = calcCost(numStones, heights);
  
    System.out.println(cost);
  }

  public static int calcCost(int N, ArrayList<Integer> heights) {
    ArrayList<Integer> dp = new ArrayList<>();

    dp.add(0, 0);
    dp.add(1, Math.abs(heights.get(1)-heights.get(0)));
    
    if (N == 2) {
      return dp.get(1);
    }

    int cost;
    int firstJump;
    int secondJump;
    for (int i = 2; i < N; i++) {
      firstJump = Math.abs(heights.get(i)-heights.get(i-1));
      secondJump = Math.abs(heights.get(i)-heights.get(i-2));
      cost = Math.min(firstJump + dp.get(i-1), secondJump + dp.get(i-2));
      dp.add(i, cost);
    }
    return dp.get(N-1);
  }
}

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

using namespace std;

int i;

class string_S
{
public:
	string_S();
	void check();
private:
	char S[11];
	int countC = 0;
	int count = 0;
};

string_S::string_S()
{
	char temp[11];
	cin >> temp;
	strcpy(S,temp);
}

void string_S::check()
{
	for (i = 0; i < 11; i++) {
		if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') {
			countC++;
		}
		else
		{
			if (count < countC)count = countC;
			countC = 0;
		}
	}
	cout << count<<"\n";
}

int main() {

	string_S ob;
	ob.check();
	return 0;
}

Measured memory_bytes: 256
n = int(input())
b = 26
ans = []
for i in range(1,99):
    if n <= b**i:
        n -= 1
        for j in range(i):
            ans.append(chr(97 + n % b))
            n //= b
        break
    else:
        n -= b ** i
for k in range(1,len(ans)+1):
    print(ans[-k],end="")

Measured memory_bytes: 9140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int N, M;
	cin >> N >> M;

	int P[M];
	int Y[M];
	vector<vector<int>> PY_List(N+1, vector<int>(0, 0));
	
	for(int i=0; i<M; i++) {
		int p, y;
		cin >> p >> y;
		P[i] = p;
		Y[i] = y;
		PY_List[p].push_back(y);
	}
	
	for(int i=1; i<=N; i++) {
		sort(PY_List[i].begin(), PY_List[i].end());
	}

	for(int i=0; i<M; i++) {
		char pStr[7];
		sprintf(pStr, "%06d", P[i]);

		int size = PY_List[P[i]].size();
		int lb = -1;
		int tgt = size/2;
		int ub = size;
		while(PY_List[P[i]][tgt] != Y[i]) {
			if(PY_List[P[i]][tgt] < Y[i]) {
				lb = tgt;
			} else {
				ub = tgt;
			}
			tgt = (lb + ub)/2;
		}
		char tStr[7];
		sprintf(tStr, "%06d", tgt+1);
		
		for(int j=0; j<size; j++) {
			if(PY_List[P[i]][j] == Y[i]) {
				break;
			}
		}
		cout << pStr << tStr << endl;
	}
	return 0;
}

Measured memory_bytes: 7808
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<string>
#include<vector>
#include<math.h>
#include<time.h>
#include<utility>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
//#include<conio.h>
//ios::sync_with_stdio(false);
using namespace std;
string str;
map<char,int> mp;
long long ans=1;
int main(){
	cin>>str;
	for(int i=0;i<str.size();i++) mp[str[i]]++;
	for(int i=0;i<str.size();i++) ans+=i; 
	for(int i='a';i<='z';i++){
        for(int j=0;j<mp[i];j++){
           ans-=j;
        } 
    }         
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
# s, t = input().split(" ")
n, k = map(int, input().split())

#A = []
A = list(map(int, input().split()))

tmp = sum(A[:k])
#print(tmp)
ans = tmp
for i in range(n - k):
    tmp += A[i + k] - A[i]
    ans = max(ans, tmp)
#    print(ans)
print((ans + k) / 2.0)


Measured memory_bytes: 25060
#include<stdio.h>

int main(void)
{
    int max=0;
    char s[3];
    scanf("%s", s);

    if(s[0] == 'R') {
        if(s[1] == 'R') {
            if(s[2] == 'R') {
                max = 3;
            } else {
                max = 2;
            }
        } else {
            if(s[2] == 'R') {
                max = 1;
            } else {
                max = 1;
            }
        }
    } else {
        if(s[1] == 'R') {
            if(s[2] == 'R') {
                max = 2;
            } else {
                max = 1;
            }
        } else {
            if(s[2] == 'R') {
                max = 1;
            } else {
                max = 0;
            }
        }
    }
    

    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    ll n,m;
    cin >> n >> m;
    vl a(n);
    ll sum = 0;
    rep(i,m){
        cin >> a[i];
        sum += a[i];
    }
    if(sum>n){dame}
    cout << n - sum  << endl;

    return 0;
}

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

int main() {
    int n,k,x,y; cin >> n >> k >> x >> y;
    int ans = 0;
    for(int i = 0; i < n; i ++) {
        if(i<k) ans += x;
        else ans += y;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long W = sc.nextLong();
    // パターン1
    long min1 = Long.MAX_VALUE;
    if (3 <= H) {
      if (H % 3 == 0) {
        min1 = 0;
      } else {
        min1 = W;
      }
    }
    // パターン2
    long min2 = Long.MAX_VALUE;
    if (3 <= W) {
      if (W % 3 == 0) {
        min2 = 0;
      } else {
        min2 = H;
      }
    }
    // パターン3
    long min3 = Long.MAX_VALUE;
    for (int i = 1; i < H; i++) {
      long s1 = i * W;
      long w1 = W / 2;
      long w2 = W - w1;
      long s2 = (H - i) * w1;
      long s3 = (H - i) * w2;
      long tmp = Math.max(Math.max(s1, s2), s3) - Math.min(Math.min(s1, s2), s3);
      if (tmp < min3) {
        min3 = tmp;
      }
    }
    // パターン4
    long min4 = Long.MAX_VALUE;
    for (int i = 1; i < W; i++) {
      long s1 = i * H;
      long h1 = H / 2;
      long h2 = H - h1;
      long s2 = (W - i) * h1;
      long s3 = (W - i) * h2;
      long tmp = Math.max(Math.max(s1, s2), s3) - Math.min(Math.min(s1, s2), s3);
      if (tmp < min4) {
        min4 = tmp;
      }
    }
    System.out.println(Math.min(Math.min(min1, min2), Math.min(min3, min4)));
  }
}

Measured memory_bytes: 23124
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int x = scan.nextInt();

        if(x == 0)
            os.println(1);
        else
            os.println(0);

    }
}

Measured memory_bytes: 27044
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int A,B,C;
	cin>>A>>B>>C;
	
	cout<<C - min(A-B,C)<<endl;
	return 0;
}

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

string S;
string K = "keyence";

int main(){
  cin >> S;
  int answer = 0;
  for(int i = 0; i < S.length(); ++i){
    for(int j = i; j < S.length(); ++j){
      for(int k = 0; k < 7; ++k){
        //cout << S.substr(i - k, i) << endl;
        if(i - k >= 0 && j + (7 - k)){
          if(S.substr(i - k, i) + S.substr(j, j + (7 - k)) == K){
          answer = 1;
          }
        }
        
      }
    }
  }
  if(answer == 1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

alias AB = Tuple!(int, bool);

int N, H;
AB[(10^^5)*2] ABS;

void main()
{
    readf("%d %d", &N, &H);
    int a, b;
    foreach (i; 0..N) {
        readf(" %d %d", &a, &b);
        ABS[i] = AB(a, true);
        ABS[N+i] = AB(b, false);
    }

    ABS[].sort!"a[0] > b[0]";

    int cnt;
    foreach (ab; ABS) {
        if (ab[1]) {
            cnt += (H+ab[0]-1)/ab[0];
            break;
        } else {
            cnt++;
            H -= ab[0];
            if (H <= 0) break;
        }
    }
    writeln(cnt);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define v vector
#define vi vector< int >
#define vpi vector< pair< int,int > >
#define forl(a) for(int i = 0;i < a;i ++)
using namespace std;
ll modF=1e7;

void solve(){
	int n;
	cin >> n;
	int h[n+1];
	int dp[n+1];

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

	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	for(int i = 3;i <= n;i ++){
		dp[i] = min(dp[i-1] + abs(h[i] - h[i - 1]),dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[n] << "\n";
}

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

Measured memory_bytes: 4384
import java.util.*;
import java.io.UnsupportedEncodingException;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        String S = sc.next();
        String[] splitS = S.split("", 0);
        ArrayList<byte[]> list = new ArrayList<byte[]>();
        byte[] bytes = new byte[4];
        
        try{
            for(int i = 0; i < splitS.length; i++){
                bytes = splitS[i].getBytes("UTF-16");
                bytes[3] += N;
                if(bytes[3] > 90){
                    bytes[3] -= 26;
                }
                 String newStr = new String(bytes, "UTF-16");
                 System.out.print(newStr);
            }
        
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 27012
K,N = input().split()
A = input().split()
 
a_list = list(A)

dist = 0
dist_list = []
max = 0
sum = 0
 
for i in range(len(a_list)):
  if i == len(a_list) - 1:
    dist = int(K) - abs(int(a_list[i]) - int(a_list[0]))
  else:
    dist = abs(int(a_list[i]) - int(a_list[i + 1]))
  if i != 0: 
    if max < dist:
        sum += max
        max = dist
    else:
        sum += dist
  else:
      max = dist
  
    
print(sum)

Measured memory_bytes: 20044
A = input()
B = input()

if len(A) != len(B):
    if len(A) > len(B):
        print('GREATER')
    else:
        print('LESS')
else:
    for a, b in zip(A, B):
        if int(a) > int(b):
            print('GREATER')
            exit()
        elif int(a) < int(b):
            print('LESS')
            exit()
    print('EQUAL')

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            //組み合わせを自らの手によって全列挙してしまえば難しいアルゴリズムなどは必要なくなる
            int[] P = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 };
            int[] Q = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 };
            int[] R = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 };

            int n = int.Parse(ReadLine());
            int[] s = Enumerable.Repeat(0, 5).ToArray();
            for (int i = 0; i < n; i++)
            {
                var tmp = ReadLine()[0];
                if (tmp == 'M') s[0]++;
                if (tmp == 'A') s[1]++;
                if (tmp == 'R') s[2]++;
                if (tmp == 'C') s[3]++;
                if (tmp == 'H') s[4]++;
            }
            long ans = 0;
            for (int i = 0; i < 10; i++)
            {
                ans += (long)(s[P[i]]) * (long)(s[Q[i]]) * (long)(s[R[i]]);
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	bool isOK = true;
	rep(i, N) {
		int A;
		cin >> A;
		if (A % 2 == 0) {
			if (!(A % 3 == 0 || A % 5 == 0))isOK = false;
		}
	}
	if (isOK)cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
const ll maxn=1e6+1;
void solve()
{
	ll n;
	cin>>n;
	vector<ll> p(maxn,0);
	for(ll i=1;i<=100;i++)
	{
		for(ll j=1;j<=100;j++)
		{
			for(ll k=1;k<=100;k++)
			{
				ll val=(i+j)*(i+j)+(j+k)*(j+k)+(k+i)*(k+i);
				if(val%2==0) p[val/2]++;
			}
		}
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<p[i]<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1;
	//cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 11096
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    bool inversion = false;
    for (int i = 0; i < H; i++) {
        if (i == B) inversion = true;
        for (int j = 0; j < W; j++) {
            if (j < A) cout << (inversion ? '1' : '0');
            else cout << (inversion ? '0' : '1');
        }
        cout << endl;
    }
}


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

#define endl '\n'

int n;
int A[12];
int inc[12];

inline bool add() {
    inc[0]++;
    for(int i = 0; i < n; i++) {
        if(inc[i] == 3) {
            inc[i] = 0;
            inc[i + 1]++;
        }
        else
            break;
    }
    if(inc[n] == 1) return false;
    return true;
}

int main() {
    ios::sync_with_stdio(0);

    memset(inc, 0, sizeof inc);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> A[i];
        A[i]--;
    }
    int res = 0;
    do {
        bool even = false;
        for(int i = 0; i < n; i++) {
            int v = A[i] + inc[i];
            if(v % 2 == 0) {
                even = true;
                break;
            }
        }
        if(even) res++;
    } while(add());
    cout << res;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
typedef long long ll;

int main(){
  int n; cin>>n;
  vector<ll>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int q; cin>>q;
  vector<int>k(q);
  for(int i=0;i<q;i++){
    cin>>k[i];
  }
  for(int i=0;i<q;i++){
    cout<<lower_bound(a.begin(),a.end(),k[i])-a.begin()<<" "<<upper_bound(a.begin(),a.end(),k[i])-a.begin()<<endl;

  }
  return 0;
}


Measured memory_bytes: 4392
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    int n, k; scanf("%d%d", &n, &k);
    vector<char> d(k); repeat (i,k) scanf(" %c", &d[i]);
    int i = n;
    for (; ; ++ i) {
        string s = to_string(i);
        bool invalid = false;
        for (char c : s) {
            if (whole(count, d, c)) {
                invalid = true;
                break;
            }
        }
        if (not invalid) {
            break;
        }
    }
    printf("%d\n", i);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int N = 0;
    int M = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &N, &M);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/

    
    if(N == M){
      /* 真の場合の処理 */
      printf("Yes");
    }else{
      /* 偽の場合の処理 */
      printf("No");
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
 // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>

#include<cstring>
#include<algorithm>
#define ll long long
#define MAXN 100000005

using namespace std;



struct TH{
	ll w,v;
}th[105];

ll v1[105],v2[105],v3[105],v4[105];

int cnt1=0,cnt2=0,cnt3=0,cnt4=0; 

bool cmp(ll a,ll b){
	return a>b;
}

int main(){
	ll n,w;
	scanf("%lld %lld",&n,&w);
	for(int i=1;i<=n;i++){
		scanf("%lld %lld",&th[i].w,&th[i].v);
		if(i==1){
			v1[++cnt1]=th[i].v;
			continue;
		}
		//以w[1]为基准， 把所有价值分为4类 
		int con=th[i].w-th[1].w;
		switch(con){//从1开始存放 
			case 0:v1[++cnt1]=th[i].v;break;
			case 1:v2[++cnt2]=th[i].v;break;
			case 2:v3[++cnt3]=th[i].v;break;
			case 3:v4[++cnt4]=th[i].v;break;
		}
	}
	//所有价值从大到小排序 
	sort(v1+1,v1+cnt1+1,cmp);
	sort(v2+1,v2+cnt2+1,cmp);
	sort(v3+1,v3+cnt3+1,cmp);
	sort(v4+1,v4+cnt4+1,cmp);
	//每种类型的物品价值叠加 
	for(int i=2;i<=cnt1;i++){
		v1[i]+=v1[i-1];
	} 
	for(int i=2;i<=cnt2;i++){
		v2[i]+=v2[i-1];
	} 
	for(int i=2;i<=cnt3;i++){
		v3[i]+=v3[i-1];
	} 
	for(int i=2;i<=cnt4;i++){
		v4[i]+=v4[i-1];
	} 
	ll ans=0;
	for(int i=0;i<=cnt1;i++){
		for(int j=0;j<=cnt2;j++){
			for(int k=0;k<=cnt3;k++){
				for(int h=0;h<=cnt4;h++){
					if(th[1].w*(i)+(th[1].w+1)*(j)+(th[1].w+2)*(k)+(th[1].w+3)*(h)<=w){
						ans=max(ans,v1[i]+v2[j]+v3[k]+v4[h]);
					}
				}
			}
		}
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		//String []s=br.readLine().split(" ");
		int digc[][]=new int[10][10];//to count the frequency of digits
		
		
		
		for(int i=1;i<=n;i++)
		{
			String s=String.valueOf(i);
			int len=s.length();
			char []d=s.toCharArray();
			
			digc[d[0]-'0'][d[len-1]-'0']++;//there is a number having first digit as d[0] adn last dgit as d[len-1]
		}
		
		long ans=0;
		
		for(int i=1;i<=9;i++)
			for(int j=1;j<=9;j++)
				ans+=(digc[i][j]*digc[j][i]);	//counts number of pairs which have first digit 'i' and last digit 'j' and vice-versa
			
		
		out.println(ans);
	}
}




Measured memory_bytes: 37972
/*
    When you are not practicing someone else is,
    and the day u meet them u will Lose.

    So, all you need is Practice, Practice and Practice.
*/
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,a,b)       for(i=a;i<=b;i++)
#define FOR(i,a,b)      for(i=a;i>=b;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define sz(v)           (int)v.size()
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p) {int ans=1;x%=mod;while(p>0){if(p&1)ans=(ans*x)%mod;p=p>>1;x=(x*x)%mod;}return ans;}
int inv(int x){return po(x,mod-2)%mod;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
/**********************************************************************************/



const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f,q;








void sol()
{   
    cin>>n;
    in(a,n);
    in(b,n);
    x=0;
    while (next_permutation(all(a)))
    {
        x++;
    }
    
    while (next_permutation(all(b)))
    {
        x--;
    }
    
    
    cout<<abs(x)  <<endl;
}





int32_t main()
{   
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //pre();
    //sp(10);
    // w(t)
    sol();
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int shrinking_count(char c, string S)
{
  int rst = 0;
  while (S != string(S.size(), c))
  {
    rst++;
    string temp;
    rep(i, S.size() - 1)
    {
      if (S[i] == c || S[i + 1] == c)
        temp += c;
      else
        temp += S[i];
    }
    S = temp;
  }

  return rst;
}

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

  int ans = INT32_MAX;
  rep(i, 26)
  {
    char c = 'a' + i;
    ans = min(ans, shrinking_count(c, s));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void)
{
	int i,j;
	int y,z;
	int e,m,tmp;
	double es;
	
	while(1)
	{
		scanf("%d ",&e);
		if(e==0)break;
		
		m=e;
		es = sqrt(e);
		
		for(y=0;y<=es;y++){
			i = y*y;
			for(z=0;z<e;z++){
				if(z*z*z > e-i){
					z--;
					tmp = e -i -z*z*z +y +z;
					if(m>tmp)m=tmp;
					break;
				}
			}
		}	
		
		printf("%d\n",m);
	}
	return 0;
}
	

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  int ans = 1000000000;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= 100; i++) {
    int a = 0;
    for (int j : x) {
      a += (i - j) * (i - j);
    }
    ans = min(ans, a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll gcd(ll a, ll b) {
	return (b == 0 ? a : gcd(b, a % b));
}

int main() {
	ll n, m;
	cin >> n >> m;
	n %= m;
	cout << min(n, m - n) << endl;
}

Measured memory_bytes: 256
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    a, b, c, k = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    if k <= a:
        print(k)
    elif k <= a + b:
        print(a)
    else:
        print(a - (k-b-a))

    #print("n")


resolve()

Measured memory_bytes: 61748
# E - Crested Ibis vs Monster
def main():
    INF = 1 << 30

    H, N, *AB = map(int, open(0).read().split())
    dp = [INF] * (H + 10001)  # dp[i] := min magic points to decrease monster's health by i
    dp[0] = 0
    for i in range(H):
        if dp[i] == INF:
            continue
        for a, b in zip(*[iter(AB)] * 2):
            dp[i + a] = min(dp[i + a], dp[i] + b)
    print(min(dp[H:]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 40048
#include <stdio.h>
 
#define N 100
#define NIL -1
 
int Pre(int t);
int In(int t);
int Post(int t);
 
struct Node{
  int p, left, right;
};
struct Node A[N];
 
int main(){
  
  int i, j;
  int n, id, h, d;
  
  scanf("%d", &n);
    
  for(i = 0; i < n; i++){
   A[i].p = NIL;
   A[i].left = NIL;
   A[i].right = NIL;
  }
  for(i = 0; i < n; i++){
    scanf("%d %d %d", &id, &h, &d);
    A[h].p = id;
    A[d].p = id;
    A[id].left = h;
    A[id].right = d;
  }
  for(i = 0; i < n; i++){
    if(A[i].p == NIL){
      break;
    }
  }
 
  printf("Preorder\n");
  Pre(i);
  printf("\n");
     
  printf("Inorder\n");
  In(i);
  printf("\n");
     
  printf("Postorder\n");
  Post(i);
  printf("\n");
  
  return 0;
}
  
int Pre(int t){
 
  printf(" %d",t);
 
  if(t != NIL){
    if(A[t].left != NIL)Pre(A[t].left);
 
    if(A[t].right != NIL)Pre(A[t].right);
  }
 return 0;
}
  
int In(int t){
 
  if(t != NIL){
    if(A[t].left != NIL){
      In(A[t].left);
    }
    printf(" %d",t);
       
    if(A[t].right != NIL){
      In(A[t].right);
    }
  }
  return 0;
}
   
int Post(int t){
 
  if(t != NIL){
    if(A[t].left != NIL)Post(A[t].left);
 
    if(A[t].right != NIL)Post(A[t].right);
  }
  printf(" %d",t);
  return 0;
}

Measured memory_bytes: 616
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by zzt on 17-1-17.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String N = scanner.next();
        int K = scanner.nextInt();
        ArrayList<Character> L = new ArrayList<>();

        char D = scanner.next().charAt(0);
        for (char i = '0'; i <= '9'; i++) {
            if (i == D) {
                K--;
                if (K == 0)
                    continue;
                D = scanner.next().charAt(0);
            } else {
                L.add(i);
            }
        }

        char[] NC = N.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (char aNC : NC) {
            for (Character aL : L) {
                if (aL == aNC) {
                    sb.append(aL);
                    break;
                }
            }
        }
        if (sb.length() < NC.length) {
            sb = new StringBuilder();
            for (int i = 0; i < NC.length; i++) {
                if (i == 0) {
                    for (Character aL : L) {
                        if (aL > NC[i]) {
                            sb.append(aL);
                            break;
                        }
                    }
                } else {
                    sb.append(L.get(0));
                }

            }
        }
        if (sb.length() < NC.length) {
            sb = new StringBuilder();
            for (int i = 0; i < NC.length + 1; i++) {
                if (i == 0)
                    if (L.get(0) == '0') sb.append(L.get(1));
                    else sb.append(L.get(0));
                else sb.append(L.get(0));
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 9680
#include<iostream>

using namespace std;

int main(void){
    int s,s1,s2;
    bool yymm=1,mmyy=1;
    cin>>s;
    s1=s/100;
    s2=s%100;
    if(s2>=13||s2==0){
        yymm=0;
    }
    if(s1>=13||s1==0){
        mmyy=0;
    }
    if(yymm&mmyy){
        cout<<"AMBIGUOUS"<<endl;
    }else if(yymm){
        cout<<"YYMM"<<endl;
    }else if(mmyy){
        cout<<"MMYY"<<endl;
    }else cout<<"NA"<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[3100][3100] = {};

int main(){
	
	int N;
	cin >> N;
	
	int a[3100];
	for(int i = 1; i <= N; i++){
		cin >> a[i];
	}
	
	for(int i = 2; i <= N + 1; i++){
		for(int j = 0; i + j <= N + 1; j++){
			if((N - i) % 2){
				DP[j][i] = max(DP[j][i - 1] + a[j + i - 1], DP[j + 1][i - 1] + a[j + 1]);
			}else{
				DP[j][i] = min(DP[j][i - 1] - a[j + i - 1], DP[j + 1][i - 1] - a[j + 1]);
			}
			//cout << j << " " << i + j << " " << DP[j][i] << endl;
		}
	}
	
	cout << DP[0][N + 1] << endl;
	
	return 0;
}


Measured memory_bytes: 73984
N,M = map(int,input().split())

x = list(map(int,input().split()))

dist = []
x.sort()
if M < N:
    print(0)
    exit()
for i in range(M-1):
    dist.append(abs(x[i+1]-x[i]))

dist.sort()

for i in range(N-1):
    dist.pop()
 
print(sum(dist))

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;


int main(){
        int n,m;
        cin >> n >> m;
        vector<int> c(m);
        rep(i,m)  cin >> c[i]; 
        vector<vector<int>> dp(m+1,vector<int>(n+1,INF));
        dp.at(0).at(0) = 0;
        
        for(int i=1;i<=m;i++){
                rep(j,n+1){
                           if(j < c.at(i-1)) dp.at(i).at(j) = dp.at(i-1).at(j);
                        else dp.at(i).at(j) = min(dp.at(i-1).at(j) , dp.at(i).at(j-c.at(i-1)) + 1);
                }
        }
        
        cout << dp.at(m).at(n) << endl;
        
           

        return 0;
}



Measured memory_bytes: 7124
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x){
   S[++top] = x;
}

int pop(){
   top--;
   return S[top+1];
}

int main(){
   int a, b;
   top = 0;
   char s[100];
   while(scanf("%s", s) != EOF){
      if(s[0] == '+'){
         a = pop();
         b = pop();
         push(a+b);
      }
      else if(s[0] == '-'){
         b = pop();
         a = pop();
         push(a-b);
      }
      else if(s[0] == '*'){
         a = pop();
         b = pop();
         push(a*b);
      }
      else push(atoi(s));
   }
   printf("%d\n", pop());
   
   return 0;
}


Measured memory_bytes: 2756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
// const int INFTY = (1 << 21); // 2097152
const ll INFTY = (1LL << 60);

class Edge{
public:
	int from, to; ll cost;
	Edge(int from = 0, int to = 0, ll cost = 0) :
			from(from), to(to), cost(cost){}

	bool operator < (const Edge &e) const{
		return cost < e.cost;
	}
	bool operator >(const Edge &e) const{
		return cost > e.cost;
	}

};

class Node{
public:
	vector<Edge> edges;
    ll dist;

	Node(){
		dist = INFTY;
	}
};

class Graph{
public:
	vector<Node> nodes;
	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
	}
	Node& operator[](int i){
		return nodes[i];
	}
};

class Data{

public:
    ll dist;
	Edge *edge;
	Data(ll dist, Edge *edge) {
		this->dist = dist;
		this->edge = edge;
	}

	bool operator < (const Data &d) const{
		return dist < d.dist;
	}
	bool operator >(const Data &d) const{
		return dist > d.dist;
	}
};

Graph G(0);
int N, E;

struct UnionFind
{
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n) : par(n), sizes(n, 1) {
        rep(i, n) par[i] = i;
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);

        if (x == y) return;

        if (sizes[x] < sizes[y]) swap(x, y);

        par[y] = x;
        sizes[x] += sizes[y];
        sizes[y] = 0;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sizes[find(x)];
    }
};

ll kruskal(){

    UnionFind U = UnionFind(N);

    vector<Data> v;
    rep(i, N){
        for(auto &ee: G[i].edges){
            v.push_back(Data(ee.cost, &ee));
        }
    }
    sort(v.begin(), v.end());

    ll ret = 0;

    for(auto &d: v){
        Edge &e = *d.edge;
        if(!U.same(e.from, e.to)){
            U.unite(e.from, e.to);
            // fprintf(stderr, "%d %d %lld\n", e.from, e.to, e.cost);
            ret += e.cost;
        }
    }

    return ret;
}

int main() {
	cin >> N >> E;
	G = Graph(N);

    rep(i, E){
        int from, to;
        ll dist;
        cin >> from >> to >> dist;
        G[from].edges.push_back(Edge(from, to, dist));
        G[to].edges.push_back(Edge(to, from, dist));
    }

	cout << kruskal() << endl;
}

Measured memory_bytes: 12584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 4e5 + 8;

ll n,a[MAXN],dp[MAXN][7];
inline ll poe(ll val) {
    if (val == 0) {
        return 2;
    } else {
        return val & 1;
    }
}

ll mn (vector<ll> idx,ll i) {
    ll ret = INF;
    for (auto x : idx) {
        ret = min(ret,dp[i][x]);
    }
    return ret;
}
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n;
    REP (i,n) {
        cin >> a[i];
    }

    dp[0][0] = 1 - (a[0] & 1);
    dp[0][1] = poe(a[0]);
    dp[0][2] = poe(a[0]);
    dp[0][3] = a[0];
    dp[0][4] = a[0];


    REP1 (i,n-1) {
        dp[i][0] = mn({0,1,3},i-1) + 1 - (a[i] & 1);
        dp[i][1] = mn({1,3},i-1) + poe(a[i]);
        dp[i][2] = mn({0,1,2,3},i-1) + poe(a[i]);
        dp[i][3] = dp[i-1][3] + a[i];
        dp[i][4] = mn({0,1,2,3,4},i-1) + a[i];
    }

    ll ans = INF;
    REP (i,5) {
        ans = min(ans,dp[n-1][i]);
    }

    REP (i,n) {
        pary(dp[i],dp[i]+5);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16640
/* "It's okay if you hate me. I hate me too." */

#include <bits/stdc++.h>

using namespace std;

int main() {
	int a[3];
	for (int i = 0; i < 3; ++i)
		scanf("%d", &a[i]);
	sort(a, a+3);
	printf("%d\n", a[0]+a[1]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,z,x,h;
pair <pair <long long, long long>, long long> p[109];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(b=1; b<=a; b++){
		cin>>p[b].first.first>>p[b].first.second>>p[b].second;
		if(p[b].second!=0){
			z=b;
		}
	}
	for(b=0; b<=100; b++){
		for(c=0; c<=100; c++){
			h=p[z].second+abs(p[z].first.first-b)+abs(p[z].first.second-c);
			for(d=1; d<=a; d++){
				if(max(h-abs(p[d].first.first-b)-abs(p[d].first.second-c),0LL)!=p[d].second) break;
			}
			if(d==a+1){
				cout<<b<<" "<<c<<" "<<h;
				return 0;
			}
		}
	}
	return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  vector<vector<char>> c(3, vector<char>(3));
  rep(i, 3) rep(j, 3) cin >> c[i][j];

  rep(i, 3) {
    rep(j, 3) {
      if (i == j) {
        cout << c[i][j];
      }
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	ll n,k;
	cin>>n>>k;
	if(k>((n-2)*(n-1))/2)
	{
		cout<<"-1";	
		return 0;
	}
    vector<pair<int,int>> v;
	v.pb(make_pair(1,2));
	for(int i=3;i<=n;i++)
	{
        v.pb(make_pair(2,i));
	}
	int cnt=((n-2)*(n-1))/2;
	for(int i=1;i<=n-1;i++)
	{
        int j;
		if(i==1)
			j=3;
		else if(i==2)
			continue;
		else
			j=i+1;
		for(;j<=n;j++)
		{
			if(cnt==k)
				break;
            v.pb(make_pair(i,j));
			cnt--;
		}
	}
    cout<<v.size()<<"\n";
    for(auto it: v)
        cout<<it.fi<<" "<<it.se<<"\n";
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<map>
#define Z int
#define V void
#define L long long
#define USE using namespace std
#define S(n) scanf("%lld",&n)
#define P(n) printf("%lld\n",n)
#define W while
#define sm(a,b) ((a)<(b)?(a):(b))
#define I if
#define R return
USE;
map<L,L>rem;
L t,n,a,b,c,d,lim=(L)(1e18),ans;
L dfs(L x){
	I(rem[x]||!x)R rem[x];
	rem[x]=lim;
	L y;
	y=x/2*2,rem[x]=sm(rem[x],dfs(y/2)+(x-y)*d+a);
	y=(x/2+1)*2,rem[x]=sm(rem[x],dfs(y/2)+(y-x)*d+a);
	y=x/3*3,rem[x]=sm(rem[x],dfs(y/3)+(x-y)*d+b);
	y=(x/3+1)*3,rem[x]=sm(rem[x],dfs(y/3)+(y-x)*d+b);
	y=x/5*5,rem[x]=sm(rem[x],dfs(y/5)+(x-y)*d+c);
	y=(x/5+1)*5,rem[x]=sm(rem[x],dfs(y/5)+(y-x)*d+c);
	I(x<=lim/d)rem[x]=sm(rem[x],x*d);
	R rem[x];
}
V doit(){S(n),S(a),S(b),S(c),S(d),rem.clear(),P(dfs(n));}
Z main(){
	S(t);
	W(t--)doit();
}

Measured memory_bytes: 4320
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int count=0;
		for(int i = 0; i <s.length();i++) if(s.charAt(i) == '1')count++;
		System.out.println(count);
	}
}


Measured memory_bytes: 21076
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(size_t i = static_cast<size_t>(a); i < static_cast<size_t>(b); i++)
#define FORR(i, a, b) for(size_t i = static_cast<size_t>(a); i >= static_cast<size_t>(b); i--)
#define REP(i, n) for(size_t i = 0; i < static_cast<size_t>(n); i++)
#define REPR(i, n) for(size_t i = static_cast<size_t>(n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

struct edge {
    int from, to;
    ll cost;
    edge(): from(0), to(0), cost(0) {};
    edge(int f, int t, ll c): from(f), to(t), cost(c) {};
};
int V, E;
ll d[1000];
bool neg[1000];
edge es[2000];

bool bellman_ford(int s)
{
    bool ret = true; // doesn't there exist negative loop?
    REP(i, V) d[i] = LINF;
    d[s] = 0;
    int loop = 0;
    REP(l, 2*V){
        bool update = false;
        REP(i, E){
            edge e = es[i];
            if(d[e.from] != LINF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
                if(l >= V) neg[e.to] = true;
            }
        }
        if(!update) break;
        if(update && l == V-1) ret = false;
    }
    return ret;
}

void init()
{
}

void solve()
{
    bellman_ford(0);
    if(!neg[V-1]) cout << -d[V-1] << endl;
    else cout << "inf" << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> V >> E;
    REP(i, E){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        es[i] = edge(a, b, -c);
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define INF 1e9 + 7
#define nd second
using namespace std;
typedef long long int lo;

int main(){
    //freopen("kenar.gir","r",stdin);
    //freopen("kenar.cik","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

    lo h,a;
    cin >> h >> a;
    cout << ((h % a == 0)?h / a:h / a + 1);
}



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

const int N = 1e5;

bool b[N];
int n, m, len[N];
vector<int> adj[N];

int DFS(int i) {
  if(b[i])
    return len[i];
  b[i] = true;
  for(int j : adj[i])
    len[i] = max(len[i], DFS(j));
  return ++len[i];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a-1].push_back(b-1);
  }
  
  for(int i = 0; i < n; i++)
    DFS(i);
  for(int i = 1; i < n; i++)
    len[0] = max(len[0], len[i]);
  cout << len[0]-1;
}

Measured memory_bytes: 7552