akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
from itertools import product, groupby, permutations
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N, M, R = map(int, input().split())
    r_list = list(map(int, input().split()))
    dp = [[float("inf")] * (N + 1) for _ in range(N + 1)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        dp[A][B] = dp[B][A] = C

    for i in range(N):
        dp[i][i] = 0

    for m in range(N + 1):
        for s in range(N + 1):
            for e in range(N + 1):
                dist = dp[s][m] + dp[m][e]
                if dist < dp[s][e]:
                    dp[s][e] = dist

    ans = float("inf")
    for p in permutations(r_list, len(r_list)):
        total = 0
        for i in range(len(p) - 1):
            total += dp[p[i]][p[i + 1]]
            if total >= ans:
                break
        else:
            if total < ans:
                ans = total
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4976
#include <bits/stdc++.h>
using namespace std;
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; }

 
int main() {
  int N=0,Y=0;
  bool exitflg=false;
  cin >> N >> Y;
  for(int i=0;i<=N;i++){
    for(int j=0;j<=N;j++){
      int k=Y-10000*i-5000*j;
      if(k%1000==0 && k>=0 && k/1000+i+j==N){
        cout << i << " " << j << " " << k/1000 << endl;
        exitflg=true;
      }
      if(exitflg) break;
    }
    if(exitflg) break;
  }
  
  if(!exitflg)   cout << -1 << " " << -1 << " " << -1 << endl;
 
  

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        char[][] c = new char[h][w];
        for (int i = 0; i < h; i++) {
            String s = sc.next();
            for (int j = 0; j < w; j++) {
                c[i][j] = s.charAt(j);
            }
        }
        List<Integer> cuth = new ArrayList<>();
        List<List<Integer>> cutw = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            boolean hasS = false;
            List<Integer> tempList = new ArrayList<>();
            for (int j = 0; j < w; j++) {
                if (c[i][j] == '#') {
                    tempList.add(j);
                    hasS = true;
                }
                if (j == w - 1 && c[i][j] == '.' && hasS) {
                    tempList.remove(tempList.size() - 1);
                    tempList.add(j);
                }
            }
            if (tempList.size() != 0) {
                cutw.add(tempList);
            }
            if (hasS) {
                cuth.add(i);
            }
            if (i == h - 1 && !hasS) {
                cuth.remove(cuth.size() - 1);
                cuth.add(i);
            }
        }
        int[][] ans = new int[h][w];
        int starth = 0;
        int startw = 0;
        int ansNum = 1;
        for (int i = 0; i < cuth.size(); i++) {
            List<Integer> tempList = cutw.get(i);
            for (int a : tempList) {
                for (int j = starth; j <= cuth.get(i); j++) {
                    for (int l = startw; l <= a; l++) {
                        ans[j][l] = ansNum;
                    }
                }
                startw = a + 1;
                ansNum++;
            }
            starth = cuth.get(i) + 1;
            startw = 0;
        }
        StringBuilder sb = new StringBuilder();
        for (int[] list : ans) {
            for (int a : list) {
                sb.append(a + " ");
            }
            sb.setLength(sb.length() - 1);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 46376
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define dprint(v) cout << #v"=" << v << endl //;)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define INF (ll)1e16
#define endl '\n'
#define isin(x,y) ((y).find(x)!=(y).end())

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll c=1;
    ll x;
    cin>>x;
    set<ll> yes;
    while(c*100<100002){
        for(int i = 100*c; i <= 105*c; i++){
            yes.insert(i);
        }
        ++c;

    }
    cout<<(isin(x,yes)?1:0)<<endl;
	return 0;
}


Measured memory_bytes: 6528
// ------------------------------------
// Date:2018/ 2/28
// Problem:ABC 052 IncrementDecrement b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int main()
{
  int N, ans = 0;
  string S;
  cin >> N;
  cin >> S;
  int x = 0;
  REP(i, S.size()) {
    if (S[i] == 'I') ++x;
    else             --x;
    ans = max(x, ans);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#define ll long long
#define il inline
#define rgi register int

using namespace std;

const int N = 100000 + 10;

int n, flag;
int h[N];

il int read()
{
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main()
{
	n = read();
	for(rgi i = 1; i <= n; ++i)
		h[i] = read();
	for(rgi i = n; i >= 2; --i)
	{
		if(h[i] < h[i - 1])
			h[i - 1]--;
	}
	for(rgi i = 1; i <= n - 1; ++i)
		if(h[i + 1] < h[i])
		{
			flag = 1;
			break;
		}
	if(flag)
		printf("No");
	else
		printf("Yes");
	return 0;
}


Measured memory_bytes: 512
import heapq


dp = {}
hq = []

N, M, S = map(int, input().split())

MAX_S = (N-1)*50
INF = 10**18
S = min(S, MAX_S)

for i in range(1,N+1):
    dp[i] = {}
    for j in range(MAX_S+1):
        dp[i][j] = INF

uv = {}
for i in range(N):
    uv[i+1] = []
for i in range(M):
    U, V, A, B = map(int, input().split())
    uv[U].append((V,A,B))
    uv[V].append((U,A,B))

c = {}
d = {}
for i in range(N):
    C, D = map(int, input().split())
    c[i+1] = C
    d[i+1] = D

def q_push(v, money, time):
    if money < 0:
        return 
    if dp[v][money] <= time:
        return
    dp[v][money] = time
    heapq.heappush(hq, (time, v, money))


q_push(1,S,0)
while hq:
    now_t, now_v, now_m = heapq.heappop(hq)

    if dp[now_v][now_m] != now_t:
        continue

    new_money = min(now_m+c[now_v],MAX_S)
    q_push(now_v,new_money,now_t+d[now_v])
    for next_v, next_a, next_b in uv[now_v]:
        q_push(next_v,now_m-next_a,now_t+next_b)

for i in range(2, N+1):
    ans = INF
    for j in range(0, MAX_S+1):
        ans = min(ans, dp[i][j])
    
    print(ans)

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    cout << s1.at(0) << s2.at(0) << s3.at(0) << endl; 
    return 0;
}


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

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  if(b-a <= 0){
    cout << "delicious" << endl;
  }
  else if(b-a > x){
    cout << "dangerous" << endl;
  } 
  else if(b-a <= x){
    cout << "safe" << endl;
  }
} 


Measured memory_bytes: 256
import java.util.Scanner;
 
 
public class Main{
     
    public static void main(String[] args){
    	
    	final Scanner sc = new Scanner(System.in);
    	
    	final int n = sc.nextInt();
    	
    	int num = (int) (Math.ceil(Math.log10(n) / Math.log10(3)));
    	
    	System.out.println(num);
    }
     
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

const ll INF = 1e16;
class SegmentTree{
public:
    ll n;
    vector<ll> node;

    SegmentTree(vector<ll> v){
        ll size = v.size();
        n = 1;
        while(n < size) n *= 2;
        node.resize(2*n-1, INF);

        for(ll i = 0; i < size; i++){
            node[n-1+i] = v[i];
        }
        for(ll i = n-2; i >= 0; i--){
            node[i] = min(node[2*i+1], node[2*i+2]);
        }
    }

    void update(ll idx, ll val){
        idx += n-1;
        //node[idx] = val;
        chmin(node[idx], val);
        while(idx > 0){
            idx = (idx-1)/2;
            //node[idx] = min(node[2*idx+1], node[2*idx+2]);
            ll tmp = min(node[2*idx+1], node[2*idx+2]);
            chmin(node[idx], tmp);
        }
    }

    //return min value within [a,b)
    //call get_min(a, b);
    ll get_min(ll a, ll b, ll k=0, ll l=0, ll r=-1){
        if(r < 0) r = n;

        if(b <= l || r <= a) return INF;

        if(a <= l && r <= b) return node[k];

        ll vl = get_min(a, b, 2*k+1, l, (l+r)/2);
        ll vr = get_min(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};


int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> X(N, INF);
    X[0] = 0;
    SegmentTree tree(X);

    vector<tuple<ll, ll, ll>> BAC;
    REP(i,M){
        ll a, b;
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        BAC.emplace_back(b, a, c);
    }

    sort(BAC.begin(), BAC.end());
    for(auto&& t : BAC){
        ll a, b;
        ll c;
        a = get<1>(t);
        b = get<0>(t);
        c = get<2>(t);
        ll m = tree.get_min(a,b+1);
        tree.update(b, m+c);
    }

    ll ans;
    ans = tree.get_min(N-1, N);
    //ans = tree.node[tree.n-1 + N-1];
    if(ans == INF)
        ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8208
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		
		Map<Integer,Integer> data=new HashMap<Integer,Integer>();
		
		for(int i=0;i<n;i++) {
			
			int buf=sc.nextInt();
			
			
			
			if(data.containsKey(buf)) {
				
				int nokori=(data.get(buf)+1)%2;
				
				data.put(buf,nokori);
			}else {
				data.put(buf,1);
			}
			
		}
		
		int counter=0;
		
		for(Integer key:data.keySet()) {
			
			if(data.get(key)==1) {
				counter++;
			}
			
		}
		
		System.out.println(counter);

		
		sc.close();


	}



}


Measured memory_bytes: 60900
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int S[1000] = { 0 };


int main() {
	ll N,Q;
	cin >>N>>Q;
	list<ll>Y[N];
	rep(i, Q) {
		int a;
		cin >> a;
		if (a == 0) {
			int b,c;
			cin >> b>>c;
			Y[b].push_back(c);
		}
		else if (a == 1) {
			int b;
			cin >> b;
			if (0<Y[b].size()) {
				list<ll>::iterator flg = Y[b].begin();
				int counter = Y[b].size()-1;
				for (; flg != Y[b].end(); ++flg) {
					if (0 < counter) {
						cout << *flg <<" ";
						counter--;
					}
					else {
						break;
					}
				}
				cout << *flg << endl;
			}
			else {
				cout << endl;
			}
		}
		else {
			int b,c;
			cin >> b>>c;
			Y[c].splice(Y[c].end(), Y[b]);
		}
	}
	return 0;
}





Measured memory_bytes: 18696
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = 0x3f3f3f3f;

void Bubble(int m[], char str[], int n)
{
	int flag = 1;
    while(flag)
    {
        flag = 0;
        for(int i = n-1; i > 0; i--)
        {
            if(m[i] < m[i-1])
            {
                int temp = m[i];
                m[i] = m[i-1];
                m[i-1] = temp;
                flag = 1;
                char temp1 = str[i];
                str[i] = str[i-1];
                str[i-1] = temp1;
            }
        }
    }
    cout << str[0] << m[0];
    for(int i = 1; i < n; i++)
        cout<<" "<<str[i]<<m[i];
    cout<<endl<<"Stable"<<endl;
}

void Selection(int m[], char str[], int n)
{
	for(int i = 0; i < n; i++)
	{
		int Min = INF, loc = i;
		for(int j = i; j < n; j++)
		{
			if(m[j]<Min)
			{
				Min = m[j];
				loc = j;
			}
		}
		int temp = m[i];
		m[i] = m[loc];
		m[loc] = temp;
        char temp1 = str[i];
        str[i] = str[loc];
        str[loc] = temp1;
	}

	cout << str[0] << m[0];
	for(int i = 1; i < n; i++)
		cout<< " " << str[i] << m[i];
	cout << endl;
}

int main()
{
	int n, m[105], m1[105];
	char str[105], str1[105];
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> str[i] >> m[i];
	for(int i = 0; i < n; i++)
	{
		m1[i] = m[i];
		str1[i] = str[i];
	}
	Bubble(m,str,n);
	Selection(m1, str1, n);
	int flag = 1;
	for(int i = 0; i < n; i ++)
		if(str[i] != str1[i])
			flag = 0;
	if(flag)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
	return 0;
}

Measured memory_bytes: 3104
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int a,b;
int main() {
	cin>>a>>b;


	int N=0;
	if(b/10==0){
		N=a*10+b;
	}
	if(b/10>0 && b/100==0){
		N=a*100+b;
	}
	if(b/10>0 && b/100>0){
		N=a*1000+b;
	}
	for(int i=1;i<N/2;i++){
		if((i*i)==N){
			cout<<"Yes"<<endl;
			return 0;
		}
	}

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


Measured memory_bytes: 256
import math
n = int(input())
lis = []
cou = 0
li = list(map(int,input().split()))
for i in range(n):
    if li[i] >= 3200:
        cou += 1
    else:
        if math.floor(li[i] // 400) not in lis:
            lis.append(li[i] // 400)
if len(lis) == 0:
    print(1,min(len(lis) + cou,8))
else:
    print(len(lis),min(n,len(lis) + cou))


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main() {
    long long n, k;
    cin >> n >> k;
    vector<int> v(n+1);
    for(int i=0; i<n; i++)
    {
        cin >> v[i];
        v[i]--;
    }
    vector<int> vis(n, -1);
    vector<int> path;
    int i = 0;
    while(vis[i] == -1)
    {
        path.push_back(i);
        vis[i] = path.size()-1;
        i = v[i];
    }
    long long l = vis[i];
    long long m = path.size();
    //cout << l << " " << m << "\n";
    if(k < l)
    {
        cout << path[k]+1 << "\n";
    }
    else
    {
        cout << path[l + (k - l) % (m - l)]+1 << "\n";
    }
}

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

const int MAXL = 3e3 + 5;
int dp[MAXL][MAXL];
pair<int, int> pre[MAXL][MAXL];

int main() {
    string s, t;
    cin >> s >> t;
    for(int i = 1; i <= s.length(); i++) {
        for(int j = 1; j <= t.length(); j++) {
            if(dp[i - 1][j] > dp[i][j]) {
                dp[i][j] = dp[i - 1][j];
                pre[i][j] = {i - 1, j};
            }
            if(dp[i][j - 1] > dp[i][j]) {
                dp[i][j] = dp[i][j - 1];
                pre[i][j] = {i, j - 1};
            }
            if(s[i - 1] == t[j - 1] && dp[i - 1][j - 1] + 1 > dp[i][j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                pre[i][j] = {i - 1, j - 1};
            }
        }
    }
    string ans = "";
    int i = s.length(), j = t.length();
    while(i > 0 && j > 0) {
        pair<int, int> p = pre[i][j];
        if(dp[i][j] > dp[p.first][p.second])
            ans += s[i - 1];
        i = p.first, j = p.second;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 105984
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int S[1000] = { 0 };


int main() {
	ll Q;
	cin >>Q;
	vector<ll>Y;
	rep(i,Q) {
		int a;
		cin >> a;
		if (a==0) {
			int b;
			cin >> b;
			Y.push_back(b);
		}
		else if(a==1){
			int b;
			cin >> b;
			cout << Y.at(b) << endl;
		}
		else {
			Y.pop_back();
		}
	}

	return 0;
}





Measured memory_bytes: 4984
#include <cstdio>
const int maxn = 1e9 + 7;
int main()
{
    long long a;
    scanf("%lld", &a);
    int sum = 0;
    long long n = a;
    while(a){
        sum += a % 10;
        a /= 10;
    }
    //printf("%d\n", sum);
    if(n % sum == 0)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace AOJ
{
    class Program
    {
        struct Vector
        {
            private double x;
            private double y;
            public double X { get { return x; } set { x = value; } }
            public double Y { get { return y; } set { y = value; } }

            public Vector(double x, double y)
                : this()
            {
                X = x;
                Y = y;
            }

            public static Vector operator -(Vector a, Vector b)
            {
                return new Vector(a.X - b.X, a.Y - b.Y);
            }

            public double Cross(Vector a)
            {
                return X * a.Y - Y * a.X;
            }
        }

        static bool IsConvex(Vector a, Vector b)
        {
            return a.Cross(b) > 0;
        }

        static void Main(string[] args)
        {
            string line;
            while((line = Console.ReadLine()) != null)
            {
                var a = line.Split(',').Select(double.Parse).ToArray();
                var vectors = Enumerable.Range(0, 6).Select(x => new Vector(a[(x % 4) * 2], a[(x % 4) * 2 + 1])).ToArray();
                bool all_t = true;
                bool all_f = true;
                for(int i = 0; i < 4; i++)
                {
                    if (IsConvex(vectors[i] - vectors[i + 1], vectors[i + 2] - vectors[i + 1]))
                    {
                        all_f = false;
                    }
                    else
                    {
                        all_t = false;
                    }
                }

                if (all_t || all_f)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    ll ans = 0, cur = 0;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        if(cur <= a) cur = a;
        else {
            ans += cur - a;
        }
    }
    cout << ans << endl;
}


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

int main(){
    int n;cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i] = a[i];
    }
    int ans=0;
    sort(b.begin(),b.end());

    for(int i=0;i<n;i++){
        if(a[i]==b[n-1]) cout<<b[n-2]<<endl;
        else cout<<b[n-1]<<endl;
    }
}

Measured memory_bytes: 3200
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        long dp[][][]=new long[2][n+1][n+1];
        for (int i = 0; i < n; i++) {
			dp[0][1][i+1] = sc.nextLong();
		}
        
        for (int i = 2; i <= n; i++) {
        	fill(dp[1][i],1L<<62);
        	for (int t = 1; t+i-1 <= n ; t++) {
				for (int v = 0,s = 1; v < i-1; v++,s++) {
					dp[0][i][t] = dp[0][s][t] + dp[0][i-s][t+s];
					dp[1][i][t] = min(dp[1][i][t], dp[1][s][t] + dp[1][i-s][t+s] + dp[0][i][t]);
				}
			}
		}
	     
        out.println(dp[1][n][1]);
        out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int ans=0;
    int cnt=0;
    for(int i=0;i<n-1;i++)
    {
        if(v[i]>=v[i+1])
        {
            cnt++;
            ans=max(ans,cnt);
        }
        else
            cnt=0;
    }
cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 10**9

int main() {
    ll n,prev=-1;
    cin >> n;
    rep(i,100000){
        if (pow(i,2)<=n){
            prev=pow(i,2);
        }
        else{
            cout << prev << endl;
            break;
        }
    }
}

Measured memory_bytes: 3588
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    char a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    if (a == f && b == e && c == d) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 384
/**
 *    author:  tourist
 *    created: 06.07.2020 09:41:01       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int L = 0, R = 0;
  while (L < n && k >= a[L]) {
    k -= a[L];
    ++L;
  }
  int ans = L;
  while (R < m) {
    k -= b[R];
    ++R;
    while (k < 0 && L > 0) {
      --L;
      k += a[L];
    }
    if (k < 0) {
      break;
    }
    ans = max(ans, L + R);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4708
k, n = map(int, input().split())
l = list(map(int, input().split()))
a=0

l.sort()
for i in range(n-1):
  if a > l[i+1]-l[i]:
    continue
  else:
    a = l[i+1]-l[i]
    
if l[0] + k - l[n-1] > a:
  a = l[0] + k - l[n-1]

print(k-a)

Measured memory_bytes: 26444
import sys
# import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
# from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
sys.setrecursionlimit(10 ** 7)
# inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
# dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, m, d = wi()

#nHr=n+r−1Cr#
if d == 0:
    print(((n - d) / n ** 2) * (m - 1))
else:
    print((2 * (n - d) / n ** 2) * (m - 1))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
    long long int A, B, K;
    cin >> A >> B >> K;
    for (int i = 1; i <= K; i++) if (A + i - 1 <= B) cout << A + i - 1 << endl;
    for (int i = 1; i <= K; i++) if (B - K + i > A + K - 1) cout << B - K + i << endl;
}

Measured memory_bytes: 256
import math
import fractions
a,b,c,d=map(int,input().split())
base=b-a+1
n_c=b//c-(a+c-1)//c+1
n_d=b//d-(a+d-1)//d+1
cd=c*d//fractions.gcd(c,d)
n_cd=b//cd-(a+cd-1)//cd+1
print(base-n_c-n_d+n_cd)

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

int main() {
	long long int N,ans;
	cin >> N;
	ans = 0;
	for (int i = 1; i < N + 1; i++) {
		if (i % 3 == 0) {

		}
		else if (i % 5 == 0);
		else  {
			ans += i;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 3608
L, R = map(int , input().split())
mod = 2019
ans = float('inf')
if R - L  >= 2019:
    print(0)
    exit()

for i in range(2020):
    for j in range(2020):
        if L + i > R or L + j > R or i == j:
            break
        tmp_mod = ((L + i) % mod * (L + j) % mod) % mod
        if ans > tmp_mod:
            ans = tmp_mod

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a; cin >> a;
		if (a%2==0) {
			if (a%3==0 || a%5==0) continue;
			else {
				cout << "DENIED";
				return 0;
			}
		}
	}
	cout << "APPROVED";			
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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


int main() {
    string s;
    cin>>s;
    int k;
    cin>>k;
    set<string> n;
    if(s.length()<=5){
        //set<string> n;
        for (int i = 0; i < s.length(); ++i) {
            for (int j = 1; j <= s.length()-i+1; ++j) {
                n.insert(s.substr(static_cast<unsigned long>(i), static_cast<unsigned long>(j)));
            }
        }
    }
    else {
        //set<string> n;
        for (int i = 1; i <= k; ++i) {
            for (int j = 0; j < s.length() - i + 1; ++j) {
                n.insert(s.substr(j,i));
            }
        }
    }
    auto itr = n.begin();
    for (int l = 1; l < k; ++l) {
        //cout<<*itr<<endl;
        itr++;
    }
    cout<<*itr<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;

    

    int N=S.size();
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            if(S[i]==S[j]){
                cout<<"no"<<endl;
            return 0;
            }

        }
    }
    cout<<"yes"<<endl;
}

Measured memory_bytes: 256
import numpy as np
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for _ in range(n)]
a=[np.array(i[1:]) for i in ca]
c=[i[0] for i in ca]
xx=np.array([x]*m)
ans=pow(10,9)

for i in range(2**n):
  count=0
  aa=np.array([0]*m)
  for j in range(n):
    if ((i >> j) & 1):
      aa+=a[j]
      count+=c[j]  
    if all(i>=x for i in aa):
      ans=min(ans,count)
print(ans if ans<pow(10,9) else -1)

Measured memory_bytes: 27104
N, K = map(int, input().split())
A = list(map(int, input().split()))
T0 = 0
T1 = 0
s = 0
for i in range(N):
  a = A[i]
  T0 = 0
  T1 = 0
  for j in range(i,N):
    if a > A[j]:
      T0 += 1
  for j in range(N):
    if a > A[j]:
      T1 += 1
  s += T1*K*(K-1)//2+T0*K
  s %= 1000000007
print(s)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int h, w;
char grid[25][25];
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

int main(){
	cin>>h>>w;
	for(int i = 0; i<h; i++){
		for(int j = 0; j<w; j++){
			cin>>grid[i][j];
		}
	}
	int ans = 0;
	auto is_good = [&](int row, int col){
		return row >= 0 && col >= 0 && row < h && col < w && grid[row][col] == '.';
	};
	for(int s_row = 0; s_row < h; s_row++){
		for(int s_col = 0; s_col < w; s_col++){
			if(is_good(s_row, s_col)){
				vector<vector<bool>> vis(h, vector<bool>(w));
				vector<vector<int>> dist(h, vector<int>(w));
				queue<pair<int, int>> q;
				q.push(make_pair(s_row, s_col));
				vis[s_row][s_col] = true;
				while(!q.empty()){
					pair<int, int> me = q.front();
					q.pop();
					for(int dir = 0; dir < 4; dir++){
						int row2 = me.first + dx[dir];
						int col2 = me.second + dy[dir];
						if(is_good(row2, col2) && !vis[row2][col2]){
							dist[row2][col2] = dist[me.first][me.second] + 1;
							vis[row2][col2] = true;
							ans = max(ans, dist[row2][col2]);
							q.push(make_pair(row2, col2));
						}
					}
				}
			}
		}
	}
	cout<<ans<<endl;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll inf = 1e18+5;
const ll mod = 1e9+7;
ll n, a[10005], ans, bigg[1000005];
map<ll, ll> m[10005]; //each index stores a map of the prime factors and their powers
ll add(ll x, ll y){
	return (x%mod + y%mod+mod)%mod;
}
ll mult(ll x,ll y){
	return (x%mod * y%mod+mod)%mod;
}
void sieve(ll x, ll ind){ 
	while (x % 2 == 0){
		x /= 2;
		(m[ind].find(2) == m[ind].end()? m[ind][2] = 1:m[ind][2]++);
		if (m[ind][2] > bigg[2])bigg[2] = m[ind][2];
	}
	for (ll i= 3; i <= sqrt(x); i+=2){
		while (x % i == 0){
			x /= i;
			(m[ind].find(i) == m[ind].end()? m[ind][i] = 1:m[ind][i]++);
			if (m[ind][i] > bigg[i])bigg[i] = m[ind][i];
		}
	}
	if (x > 2){
		(m[ind].find(x) == m[ind].end()? m[ind][x] = 1:m[ind][x]++);
		//~ bigg[x]++;
		if (m[ind][x] > bigg[x])bigg[x] = m[ind][x];
	}
}
ll quick_expo(ll x, ll exp){
	ll anss = 1, base = x;
	while (exp){
		if (exp & 1)anss *= base;
		base *= base;
		base %= mod;
		anss %= mod;
		exp >>= 1;
	}
	return anss;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 0; i< n;i++){
		cin >> a[i];
		sieve(a[i], i);
	}
	vector<ll> v;
	for (ll i = 0; i < 1000001; i++){
		if (bigg[i] != 0){
			v.pb(i);
		}
	}
	for (ll i = 0; i< n; i++){
		ll cur = 1;
		//~ auto it = m[i].begin();
		//~ while (it != m[i].end()){
			//~ ll k = it->F;
			//~ ll v = it->S;
			//~ cur = mult(cur, mult(bigg[k]-v, k));
			//~ it++;
		//~ }
		for (auto ii:v){ //each guy
			if (m[i].find(ii) != m[i].end()){//here have
				cur = mult(cur, quick_expo(ii, bigg[ii]-m[i][ii]));
			}else{ //mult full thing
				cur = mult(cur, quick_expo(ii, bigg[ii]));
			}//not mult but exponential oof 
		}
		ans = add(ans, cur);
	}
	cout << ans;
	//~ ll i = 0;
	//~ auto it = m[i].begin();
		//~ while (it != m[i].end()){
			//~ ll k = it->F;
			//~ ll v = it->S;
			//~ cout << k << ' ' << v << '\n';
			//~ it++;
		//~ }
	//~ for (ll i = 0; i <= 5; i++)cout << bigg[i] << ' ';
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	 int a,b,c;
	cin>>a;
	b=a*a;
	c=b*a;
	cout<<a+b+c;
}

Measured memory_bytes: 3648
package main

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

func main() {
	nextReader = newScanner()
	h := nextInt()
	// fmt.Println(int(math.Pow(2, 1+math.Floor(math.Log2(float64(h)))) - 1))
	fmt.Println(solve(h))
}

func solve(h int) int {
	if h == 1 {
		return 1
	}
	return 1 + solve(h/2)*2
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
    int N, W;
    cin >> N >> W;
    int item[101][2];
    item[0][0] = 0; item[0][1] = 0;
    for (int i = 1; i < N+1; ++i){
        int v, w;
        cin >> v >> w;
        item[i][0] = v; item[i][1] = w;
    }
    int c[101][10001];
    for(int i = 0; i < W+1; i++){
        c[0][i] = 0;
    }
    for(int j = 0; j < N+1; j++){
        c[j][0] = 0;
    }
    for(int i = 1; i < N+1; ++i){
        int v = item[i][0];
        int w = item[i][1];
        for(int j = 1; j < W+1; ++j){
            if(j < w){
                c[i][j] = c[i-1][j];
            }else{
                c[i][j] = max(c[i-1][j], c[i][j-w] + v);
            }
        }
    }
    cout << c[N][W] << endl; 
}

Measured memory_bytes: 7004
while True:
    list_a = []
    a, L = input().split(" ")
    if a=='0' and L=='0': break
    L = int(L)
    list_a.append(int(a))

    while True:
        if len(a) < L: a += '0'*(L-len(a))
        an = int(''.join(sorted(a, reverse=True))) - int(''.join(sorted(a)))
        if an in list_a:
            idx = list_a.index(an)
            print("{0} {1} {2}".format(idx, an, len(list_a)-idx))
            break

        list_a.append(an)
        a = str(an)

Measured memory_bytes: 7608
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    System.out.println(s.equals("Sunny") ? "Cloudy" : s.equals("Cloudy") ? "Rainy" : "Sunny");
  }
}

Measured memory_bytes: 23120
#include <stdio.h>

int main(int argc, const char * argv[]) {

    int a;
    int b;
    int c;
    int i;
    int count = 0;
    scanf("%d %d %d", &a,&b,&c);
    
    for (i=a; i<=b; i++) {
        
        if (c%i==0) {
            count++;
        }
        
    }
    printf("%d\n",count);
        
    
    
    return 0;
}

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

using namespace std;

typedef long long LL;

int n;

bool ok(int x){
    int m = n - x;
    LL sum = 1LL * x * (x - 1) / 2;
    if(sum < m)	return 0;
    return 1;
}

int main(){
	while(~scanf("%d", &n)){
		int low = 1, top = n, ans = n, mid;
		while(low <= top){
			mid = low + top >> 1;
			if(ok(mid)){
                ans = min(ans, mid);
                top = mid - 1;
			} else {
				low = mid + 1;
			}
		}
        for(int i=ans; i>=1; i--){
            if(n <= i){
                printf("%d\n", n);
                for(int j=i+1; j<=ans; j++){
					printf("%d\n", j);
                }
                break;
            } else {
				n -= i;
            }
        }
	}
	return 0;
}


Measured memory_bytes: 256
// Do you knOW what it feels like?

		// To be TorTured by your own MinD?
	
	// I don't wanna feel the PAIN.

// I BeG you to KILL me, pleASE...

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=4e2+10, lg=22, mod=1e9+7, inf=1e18;

ll n,m,x[100010],y[100010];
bool b[maxn];
bitset<maxn> nw[maxn];

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>x[i]>>y[i];
	for(int i=1;i<=n;i++){
		nw[i][i]=1;
		b[i]=1;
		for(int j=m;j>=1;j--){
			if(nw[i][x[j]] && nw[i][y[j]]){ b[i]=0; break; }
			if(nw[i][x[j]] || nw[i][y[j]]) nw[i][x[j]]=nw[i][y[j]]=1;
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(b[i] && b[j] && (nw[i]&nw[j])==0) ans++;
	cout<<ans<<endl;
	
	return 0;
}

















Measured memory_bytes: 1792
sx,sy,tx,ty=map(int,input().split())

countx=tx-sx
county=ty-sy

ans=[]
for i in range(county):
    ans.append("U")
for i in range(countx):
    ans.append("R")

for i in range(county):
    ans.append("D")
for i in range(countx):
    ans.append("L")

ans.append("L")

for i in range(county+1):
    ans.append("U")
for i in range(countx+1):
    ans.append("R")
ans.append("D")

ans.append("R")

for i in range(county+1):
    ans.append("D")
for i in range(countx+1):
    ans.append("L")

ans.append("U")

Z=[str(a) for a in ans]
Z="".join(Z)
print(Z)


Measured memory_bytes: 9192
function main(input) {
    input = input.trim().split("\n");
    n = parseInt(input[0]);
    x = input[1].split(" ").map(p => Number(p));

    var total = 0;
    for (var i = 0; i < x.length; i++) {
        total += x[i];
    }

    var c = Math.round(total/n);
    var ans = 0;
    for (var i = 0; i < x.length; i++) {
        ans += Math.pow(Math.abs(x[i]-c), 2);
    }

    console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
# blue card: N
N = int(input())
s = [''] * N
for i in range(N):
    s[i] = str(input())

# red card: M
M = int(input())
t = [''] * M
for i in range(M):
    t[i] = str(input())

# max(blueの要素xの重複数　- redの要素xの重複数), xがないときは0
scoreList1 = []
for i in range(N):
    win1 = 0
    lose1 = 0
    if s[i] in s:
        win1 += s.count(s[i])
    if s[i] in t:
        lose1 += t.count(s[i])
    if s.count(s[i]) < t.count(s[i]):
        win1 = 0
        lose1 = 0
    scoreList1.append(win1 - lose1)

scoreList2 = []
for j in range(M):
    win2 = 0
    lose2 = 0
    if t[j] in s:
        win2 += s.count(t[j])
    if t[j] in t:
        lose2 += t.count(t[j])
    if s.count(t[j]) < t.count(t[j]):
        win2 = 0
        lose2 = 0
    scoreList2.append(win2 - lose2)

scoreList = scoreList1 + scoreList2
print(max(scoreList))


Measured memory_bytes: 3064
n=input()
cnt=0
for i in range(len(n)):
    if n[0]=="0":
        if i%2==0 and n[i]=="1" :
            cnt+=1
        if i%2==1 and n[i]=="0" :
            cnt+=1
    else:
        if i%2==0 and n[i]=="0" :
            cnt+=1
        if i%2==1 and n[i]=="1" :
            cnt+=1
print(cnt)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#define INF 1000000
using namespace std;

main() {
  while(1) {
    int n, m;
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    int data[2][m][m];
    fill(&data[0][0][0], &data[1][m-1][m-1]+1, INF);
    for(int i = 0; i < n; i++) {
      int a, b, c, time;
      cin >> a >> b >> c >> time;
      a--;
      b--;
      data[0][a][b] = data[0][b][a] = c;
      data[1][a][b] = data[1][b][a] = time;
    }

    int k;
    cin >> k;
    for(int t = 0; t < k; t++) {
      int p, q, r;
      cin >> p >> q >> r;
      p--;
      q--;
      
      bool visited[m];
      fill(&visited[0], &visited[m], false);
      int cost[m];
      fill(cost, cost+m, INF);
      cost[p] = 0;
      while(1) {
	int min = INF;
	int index;
	for(int i = 0; i < m; i++) {
	  if(!visited[i] && cost[i] < min) {
	    min = cost[i];
	    index = i;
	  }
	}
	if(min == INF) break;
	visited[index] = true;
	
	for(int i = 0; i < m; i++) {
	  if(visited[i]) continue;
	  int newValue = cost[index] + data[r][index][i];
	  if(newValue < cost[i]) {
	    cost[i] = newValue;
	  }
	}
      }
      cout << cost[q] << endl;
    }
  }
}

Measured memory_bytes: 944
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	int h;
	cin>>h>>a;
	int b;
	int g;
	cin>>g>>b;
//	int jsq=h;
//	int cnt=g;
	while(1)
	{
		g-=a;
		if(g<=0)
		{
			cout<<"Yes\n";
			return 0;
		}
		h-=b;
		if(h<=0)
		{
			cout<<"No\n";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	vector<int>vec(3,0);
	cin >> vec[0] >> vec[1] >> vec[2];
	sort(vec.begin(),vec.end());
	cout << vec[0]+vec[1] << endl;
}

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

int main() {
    int n, buf;
    vector<int> v;
    cin >> n;
    v.reserve(n);
    for(int i=0; i<n; i++) {
        cin >> buf;
        v.push_back(buf);
    }

    int cnt;
    for (int& x: v) {
        cnt = 0;
        while (x%2 == 0) {
            x /= 2;
            cnt += 1;
        }
        x = cnt;
    }
    cout << *min_element(v.begin(), v.end()) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] ch = sc.next().toCharArray();
		sc.close();

		String ans = "Good";
		for(int i = 0;i < ch.length-1;i++) {
			if(ch[i] == ch[i+1]) {
				ans = "Bad";
				break;
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 23892
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
	mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
	mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
	mint operator+(const mint a) const {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
 		return a;
	}

	// For prime mod.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

int n;
vector<vi> a;
vector<mint> dp;
vector<bool> memo;

mint rec(int state, int cnt) {
    if(memo[state]) return dp[state];
    mint res = 0;
    for(int i = 0; i < n; i++) {
        if((state & (1 << i)) == 0) continue;
        if(a[cnt][i] == 0) continue;
        res += rec(state ^ (1 << i), cnt + 1);
    }
    memo[state] = true;
    return dp[state] = res;
}

int main() {
//	cout << fixed << setprecision(15);
    cin >> n;
    a = vector<vi>(n, vi(n));
    rep(i, n) rep(j, n) cin >> a[i][j];
    dp = vector<mint>(1 << n);
    memo = vector<bool>(1 << n, false);
    dp[0] = 1;
    memo[0] = true;
    cout << rec((1 << n) - 1, 0).x << endl;
}


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

int main() {
  int n,m; 
  cin >>n>>m;
  int A[n][m];
  int B[m];
  int C[n];
  for(int i=0;i<n;i++){
    C[i]=0;
    for(int j=0;j<m;j++){
      cin>>A[i][j];
    }
  }
  for(int j=0;j<m;j++){
    cin>>B[j];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      C[i]+=A[i][j]*B[j];
    }
  }
  for(int i=0;i<n;i++){
    cout<<C[i]<<endl;
  }
  return 0;
}
  


Measured memory_bytes: 3124