akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll n, m, q;
vl a, b, c, d;
vl v;
ll ans = 0;

void check(vl &v) {
    ll now = 0;
    rep(i, q) {
        if(v[b[i]] - v[a[i]] == c[i]) {
            now += d[i];
        }
    }
    chmax(ans, now);
}

void dfs(ll depth) {
    if(depth == n) {
        check(v);
        return;
    }
    exrep(i, v[depth-1], m) {
        v[depth] = i;
        dfs(depth+1);
    }
}

int main() {

    cin >> n >> m >> q;

    a.resize(q);  b.resize(q);
    c.resize(q);  d.resize(q);
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;  b[i]--;
    }

    v.resize(n);
    exrep(i, 1, m) {
        v[0] = i;
        dfs(1);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 3552
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int n, m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    cin >> a >> b;

    vector<ll> sum_a(n + 1), sum_b(m + 1);
    rep(i, n) sum_a[i + 1] = sum_a[i] + a[i];
    rep(i, m) sum_b[i + 1] = sum_b[i] + b[i];

    int maxi = 0;
    rep(cnt_a, n + 1) {
        if (k < sum_a[cnt_a]) break;

        ll rem = k - sum_a[cnt_a];
        int cnt_b = upper_bound(sum_b.begin(), sum_b.end(), rem) - sum_b.begin();
        cnt_b = max(0, cnt_b - 1);

        chmax(maxi, cnt_a + cnt_b);
    }

    cout << maxi << endl;
}

Measured memory_bytes: 9592
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
AA = inpl()
b = 0
s = 1
X = 1
for a in AA:
    X *= a

for a in AA:
    tmp = X//a
    b += tmp

print(X/b)


Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;

    ll n = 100;
    ll ct = 0;
    while (n < X) {
        n = ll(n * 1.01);
        ct++;
    }

    cout << ct << endl;
}


Measured memory_bytes: 3640
import sys
I = list(map(int, input().split()))
a = I[0]
b = I[1]
if not 1 <= a or not a <= 9:
    print("error")
    sys.exit()
if not 1 <= b or not b <= 9:
    print("error")
    sys.exit()

a_str = str(a)
b_str = str(b)
A_str = a_str * b
B_str = b_str * a
if A_str < B_str:
    print(A_str)
else:
    print(B_str)

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll N,A,B;
ll Fa[5454], iFa[5454];
ll mk[5050],dpa[5050],dpb[5050];
ll i, j, k;

void init(){
    ll i;
    Fa[0] = 1;
    fornum(i,0,5050){
        Fa[i + 1] = Fa[i] * (i + 1) % MOD;
    }
    iFa[5050] = moddiv(1, Fa[5050]);
    for (i = 5050; i > 0;--i){
        iFa[i - 1] = iFa[i] * i % MOD;
    }
}
ll C(ll a,ll b){
    if(a<b)
        return 0;
    return Fa[a] * iFa[a - b] % MOD * iFa[b] % MOD;
}
ll inv(ll a){
    return iFa[a - 1] * Fa[a] % MOD;
}

int main(){
    scanf("%lld%lld%lld", &N,&A,&B);
    if(A<B)
        swap(A, B);
    mk[0] = 1;
    fornum(i,1,A+1){
        mk[i] = mk[i-1];
        fornum(j,1,i){
            if(B+1<=i-j){
            //printf("%lld ", j);
                (mk[i] += mk[j]) %= MOD;
            }
        }
        //printf("%lld,%lld\n",i, mk[i]);
    }

    ll ans = 1;
    dpa[0] = 1;
    dpb[0] = 1;
    fornum(i,0,N){
        ans = ans * 2 % MOD;
        fornum(j,i+1,N+1){
            if (j - i < A){
                if(i==0||j==N)
                    (dpa[j] += dpb[i] * mk[j - i + 1]) %= MOD;
                else
                    (dpa[j] += dpb[i] * mk[j - i]) %= MOD;
            }
            if (j - i < B)
                (dpb[j] += dpa[i]) %= MOD;
        }
        //printf("%lld:%lld,%lld\n", i, dpa[i], dpb[i]);
    }
    //printf("%lld,%lld\n", dpa[N], dpb[N]);
    (ans += -dpa[N] - dpb[N] + MOD * 2) %= MOD;
    printf("%lld\n", ans);


    return 0;
}

Measured memory_bytes: 3844
N, M = map(int, input().split())
my_list =[]

for i in range(M):
    array = list(map(int, input().strip().split()))
    my_list.append(array)

my_list = list(map(list, set(map(tuple, my_list))))


def main(n, m, input_list):
    num = [0] * n
    done =[0] * n
    ans = ""

    for l in input_list:
        if done[l[0]-1] == 1:
            return -1
        num[l[0]-1] = l[1]
        done[l[0]-1] = 1

    if num[0] == 0 and len(num) != 1:
        if done[0] == 1:
            return -1
        else:
            num[0] = 1

    for i in range(len(num)):
        ans = ans + str(num[i])

    return int(ans)

print(main(N, M, my_list))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;



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

  int cnt = 0;
  while(h > 0){
    cnt++;
    h -= a;
  }

  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

 
public class Main {
	static final long MOD1=1000000007;
	static final long MOD2=998244353;
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		char[] cs=sc.next().toCharArray();
		long ans=((long)cs.length-1)*(long)cs.length/2+1;
		long[] a=new long[26];
		for (int i = 0; i < cs.length; i++) {
			a[cs[i]-'a']++;
		}
		for (int i = 0; i < a.length; i++) {
			ans-=(a[i]-1)*(a[i])/2;
		}
		System.out.println(ans);
	}
		static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 34344
#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

const double EPS = 1e-6;

int main(){
	while(true){
		int N[2], V, V_;
		double S[2] = {};
		for(int i = 0; i < 2; i++){
			cin >> N[i];
			if(N[i] == 0) return 0;
			V_ = 360;
			for(int j = 0; j < N[i]-1; j++){
				cin >> V;
				V_ -= V;
				S[i] += sin(M_PI*V/180);
			}
			S[i] += sin(M_PI*V_/180);
		}
		if(S[0] - S[1] > EPS) puts("1");
		else if(S[1] - S[0] > EPS) puts("2");
		else puts("0");
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cmath>
#include<map>
using namespace std;
#define lli long long int
int main(){
lli inf=1e9+7;
lli n;
scanf("%lld",&n);
map<lli,int>a;
map<lli,int>::iterator x = a.begin();
for(int i=0;i<n;i++){
	lli s;
	scanf("%lld",&s);
	pair<map<lli,int>::iterator,bool> ret;
	ret=a.insert(make_pair(s,1));
	if(ret.second==false){
			((ret.first)->second)+=1;
			//cout<<(ret.first)->second<<" "<<(ret.first)->second<<endl;

		}
}
//for(auto x:a){
	//cout<<x.first<<x.second<<endl;}
//cout<<"------"<<endl;
lli ans=1;bool f=false;
if(n%2==0){
	map<lli,int>::iterator x=a.begin();
	lli check=1;
	while(check<n){
		if(x->first==1&&x->second!=2){f=true;
			printf("0\n");return 0;}
		 else{
			 if(x->first==check&&x->second==2){
				 check+=2;
				 ans=(ans*2)%inf;
				 }
				 else{f=true;printf("0\n");return 0;}
			 }
			 ++x;
	}
	//ans=check;
}
else{
	map<lli,int>::iterator x=a.begin();
	lli check=0;
	while(check<n){
		if(x->first==0&&x->second!=1){f=true;
			printf("0\n");return 0;}
		else{
				if(x->first==0&&x->second==1){
					check+=2;
					}
				else{
					if(x->first==check&&x->second==2){check+=2;ans=(ans*2)%inf;}
					else{f=true;printf("0\n");return 0;}
					}
			}
			x++;
		}
		//ans=check;
	}
	//cout<<ans<<"---"<<n<<endl;
if(f==false){
	printf("%lld\n",(ans%inf));
	}
/*int sum=1;
cout<<"0"<<a[0]<<endl;
cout<<"0"<<a[1]<<endl;
if(a[1]>2){printf("0--\n");return 0;}
if(a[0]>2){printf("0---\n");return 0;}
for(auto x:a){
	if(n%2==0){
		if(x.second!=2&&x.first>0){printf("this");printf("0\n");return 0;}
		}
	}
for(auto x:a){
	cout<<"ENTERED"<<x.first<<x.second<<endl;
	if(x.second==0){continue;}
	sum=(sum%inf*x.second%inf)%inf;}
printf("%d\n",sum);
//cout<<inf<<endl;
*/
	return 0;}


Measured memory_bytes: 4224
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <list>
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
 
// #define int ll
 
using namespace std;
 
bool test = 0;
 
/* ?????????????????¬??¨ */
 
int main(){
  int i,j,k,l;
  int n;
  while(cin >> n) {
    if(n == 0) return 0;
    map<int,int> m;
    rep(i,n) {
      int a; cin >> a;
      if( m.count(a) == 0 ) m[a] = 1;
      else m[a]++;
    }
    auto itr = m.begin();
    for(; itr != m.end(); itr++) {
      // cout << itr->first;
      // cout << ":" << itr->second << endl;
      if(itr->second > n/2) break;
    }
    if(itr == m.end() ) puts("NO COLOR");
    else printf("%d\n",itr->first);
  }
  return 0;
}

Measured memory_bytes: 4672
#include <iostream>
using namespace std;
int odd(int n,int a[])
{
    int ans=0;
    for (int i = 1; i <=n ; ++i) {
        if((i%2!=0)&&(a[i-1]%2!=0))ans++;
    }
    return ans;
}
int main() {
    int n;
    cin>>n;
    int a[n];
    for (int i = 0; i <n ; ++i) {
        cin>>a[i];
    }
    cout<<odd(n,a)<<endl;
}


Measured memory_bytes: 3564
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        //int[] NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
        string w = Console.ReadLine();
        string res = "";
        foreach (var c in w)
        {
            if (c == 'B')
            {
                if (res.Length != 0) res = res.Substring(0, res.Length - 1);
            }
            else
            {
                res += c;
            }   
        }
        Console.WriteLine(res);
    }
}

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

int main(){
  vector<vector<int>>a(3,vector<int>(3));
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cin >> a.at(i).at(j);
  bool ans=true;
  int r1=a.at(0).at(0)-a.at(0).at(1),
  r2=a.at(0).at(1)-a.at(0).at(2);
  for(int i=0;i<3;i++)
    if(a.at(i).at(0)-a.at(i).at(1)!=r1)
      ans=false;
  for(int i=0;i<3;i++)
    if(a.at(i).at(1)-a.at(i).at(2)!=r2)
      ans=false;
  int g1=a.at(0).at(0)-a.at(1).at(0),
  g2=a.at(1).at(0)-a.at(2).at(0);
  for(int i=0;i<3;i++)
    if(a.at(0).at(i)-a.at(1).at(i)!=g1)
      ans=false;
  for(int i=0;i<3;i++)
    if(a.at(1).at(i)-a.at(2).at(i)!=g2)
      ans=false;
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 3632
n = int(input())
a = str(input())
b = str(input())
c = str(input())

ans = 0
for i in range(n):
    l = [a[i], b[i], c[i]]
    s = set(l)
    if len(s) == 3:
        ans += 2
    elif len(s) == 2:
        ans += 1
    else:
        pass
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
main(){
  int i,j,a[100],s,mini,p,count=0;
  scanf("%d",&s);
  for(i=0;i<s;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<s;i++){
      mini = i;
      for(j=i;j<s;j++){
	if(a[j]<a[mini])
	 mini = j;
       }
       p = a[i];
       a[i] = a[mini];
       a[mini] = p;
       if(i != mini)
       count++;
      
  }
      for(i=0;i<s;i++){
      printf("%d",a[i]);
      if(i != s-1)
	printf(" ");
    }
    printf("\n%d\n",count);
    return 0;
}
 

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll cnt[30];
int main(){
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++){
		cnt[s[i]-'a']++;
	}
	ll N = (ll)s.size();
	ll ans = N*(N-1)/2;
	for(int i=0;i<26;i++)ans -= cnt[i]*(cnt[i]-1)/2;
	cout << ++ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
using namespace std;
const long long INF=1e16;
long long Abs(long long x){
	return x<0?-x:x;
}
long long a[200100];
long long sum[200100];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	long long ans=INF;
	for(int i=1;i<n;i++)
	{
		if(Abs(sum[n]-sum[i]-sum[i])<ans)
			ans=Abs(sum[n]-sum[i]-sum[i]);
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;
typedef long long ll;

const int N = 10;

int n, l[N], dp[3][(1<<10)];
int a[3];

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin >> n >> a[0] >> a[1] >> a[2];
   for(int i=0; i<n; ++i)
       cin >> l[i];

   for(int i=1; i<(1 << n); ++i) {
       int cnt = 0;
       int tot = 0;
       for(int j=0; j<n; ++j) {
           if(i&(1<<j)) {
              tot += l[j];
              ++cnt;
           }
       }
       for(int j=0; j<3; ++j) {
          dp[j][i] = (cnt - 1)*10 + abs(a[j] - tot);
       }
   }
   int res = 1e9;
   for(int i=1; i<(1<<n); ++i) {
       for(int j=1; j<(1<<n); ++j) {
           for(int k=1; k<(1<<n); ++k) {
               if((i&j) == 0 && (i&k) == 0 && (j&k) == 0) {
                   res = min(res, dp[0][i] + dp[1][j] + dp[2][k]);
               }
           }
       }
   }
   cout << res << "\n";
   return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    ll sum = 0;
    rep(i, 1, N + 1) rep(j, 1, N + 1) rep(k, 1, N + 1) sum +=
        __gcd(__gcd(i, j), k);
    cout << sum << endl;
}


Measured memory_bytes: 3544
n = int(input())
h = [int(i) for i in input().split()]

c = [0] * n
c[0] = 0
c[1] = abs(h[0] - h[1])

for i in range(2, n):
    c[i] = min(c[i - 1] + abs(h[i - 1] - h[i]), c[i - 2] + abs(h[i - 2] - h[i]))

print(c[-1])


Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N;
	cin >> N;
	vector<int> x(N), y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}
	map<pair<int, int>,int> m;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i != j) {
				m[make_pair(x[i] - x[j], y[i] - y[j])]++;

			}
		}
	}
	int max_num = 0;
	int ax, ay;
	for (auto i : m) {
		if (i.second > max_num) {
			ax = i.first.first;
			ay = i.first.second;
			max_num = i.second;
		}
	}
	debug(ax);
	debug(ay);

	debug(max_num);
	cout << N - max_num << endl;
	return 0;
}

Measured memory_bytes: 384
using System;
using static System.Console;
using System.Linq;

namespace Contest
{
  class B
  {
    static void Main(string[] args)
    {
      string[] inputs = ReadLine().Split();
      int N = int.Parse(inputs[0]);
      int M = int.Parse(inputs[1]);
      int[] A = new int[M];

      for(int i=0; i<N; i++) {
        inputs = ReadLine().Split();
        for(int j = 1; j<=int.Parse(inputs[0]); j++)
          A[int.Parse(inputs[j])-1]++;
      }

      WriteLine(A.Where(x => x == N).ToArray().Length);
    }
  }
}


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

#define    ll     long long int

ll mod = 1000000007;

ll bigmod(ll a, ll b, ll mod)
{
    if (b == 0) return 1;
    ll x = bigmod(a, b / 2, mod);
    x = (x * x) % mod;
    if (b % 2) x = (x * (a % mod)) % mod;
    return x;
}

int main( )
{
    int n, i, j, k;
    map<int, int> mp;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> j;
        mp[j]++;
    }
    for (i = 1; i <= n; i++) {
        j = abs((i - 1) - (n - i));
        mp[j]--;
        if (mp[j] < 0) {
            cout << "0\n";
            return 0;
        }
    }
    cout << bigmod(2, n / 2, mod) << '\n';
    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
ll w[10000];
ll r[10000];
ll u[10000];
ll v[10000];
ll f[105];
ll x,y;
const ll mod=1e9+7;
ll ksm(ll x,ll n)
{
    ll s=1;
    while(n)
    {
        if(n&1)
            s=x*s%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return s;
}
int main()
{
   cin>>x>>y;
   ll a=(2*y-x)/3;
   ll b=(2*x-y)/3;
   if(3*b==2*x-y&&3*a==2*y-x&&a>=0&&b>=0)
   {
       ll x1=1,y1=1;
       for(ll i=1;i<=a+b;i++)
        x1=x1*i%mod;
       for(ll i=1;i<=a;i++)
        y1=y1*i%mod;
       for(ll i=1;i<=b;i++)
        y1=y1*i%mod;
       printf("%lld",x1*(ksm(y1,mod-2))%mod);
   }
   else
    printf("0");
}


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

using namespace std;

int n, k;
vector<vector<int> > edges;
vector<bool> hasVisited;
vector<int> edges_color;
map<pair<int, int>, int> edges_index;

void solve(int node, int color)
{
    int next_color = color;
    for(int i = 0; i < edges[node].size(); ++i)
    {
        int next_node = edges[node][i];
        if(!hasVisited[next_node])
        {
            next_color = (next_color + 1) % k;
            edges_color[edges_index[make_pair(node, next_node)]] = next_color;
            hasVisited[next_node] = true;
            solve(next_node, next_color);
        }
    }
}

int main()
{
    cin >> n;
    
    edges.resize(n + 1);
    hasVisited.resize(n + 1, false);
    edges_color.resize(n);

    for(int i = 1; i <= n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
        edges_index[make_pair(a, b)] = i;
        edges_index[make_pair(b, a)] = i;
    }

    k = 1;
    for(int i = 1; i <= n; ++i) {
        k = max(k, (int)edges[i].size());
    }

    hasVisited[1] = true;
    solve(1, -1);

    cout << k << endl;
    for(int i = 1; i <= n - 1; ++i) {
        cout << edges_color[i] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 18944
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    ll n,k;cin>>n>>k;
    vector<vector<int>> sum(3000,vector<int>(3000,0));
    for(int i=0;i<n;i++){
        ll x,y;char c;
        cin>>x>>y>>c;
        if(c=='W') y+=k;
        x%=(2*k);y%=(2*k);
        sum[x][y]++;sum[x+k][y]--;
        sum[x][y+k]--;sum[x+k][y+k]++;
        //cout<<x<<" "<<y<<endl;
    }
    for(int i=0;i<3*k;i++){
        for(int j=0;j<3*k;j++){
            if(i==0 && j==0) continue;
            else if(i==0){
                sum[i][j]+=sum[i][j-1];
            }
            else if(j==0){
                sum[i][j]+=sum[i-1][j];
            }
            else{
                sum[i][j]+= (sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]);
            }
        }
    }
    for(int i=0;i<k;i++){
        for(int j=0;j<2*k;j++){
            sum[i][j]+=sum[i+2*k][j];
        }
    }
    for(int i=0;i<2*k;i++){
        for(int j=0;j<k;j++){
            sum[i][j]+=sum[i][j+2*k];
        }
    }
    for(int i=0;i<k;i++){
        for(int j=0;j<k;j++){
            sum[i][j]+=sum[i+2*k][j+2*k];
        }
    }
    for(int i=0;i<k;i++){
        for(int j=0;j<k;j++){
            sum[i][j]+=sum[i+k][j+k];
        }
    }
    for(int i=0;i<k;i++){
        for(int j=k;j<2*k;j++){
            sum[i][j]+=sum[i+k][j-k];
        }
    }
    int res=0;
    for(int i=0;i<k;i++){
        for(int j=0;j<2*k;j++){
            res=max(res,sum[i][j]);
            //cout<<sum[i][j]<<" ";
        }
        //cout<<endl;

    }
    cout<<res<<endl;
}


Measured memory_bytes: 35584
#include<stdio.h>
int main(){
//	int n=100000;
	char s[15];
	int a=0;
	int b=0;
	scanf("%d %d",&a, &b);

	for(int i=0;i<15;i++){
		s[i]='x';
	}
	scanf("%s", s);
	int size=0;
	int hifn=0;
	for(int i=0;i<15;i++){
		if(s[i]!='x'){
//					printf("%d %c\n",i,s[i]);
 
			size++;
		}
	}
		for(int i=0;i<15;i++){
		if(s[i]=='-'){
//					printf("%d %c\n",i,s[i]);
 
			hifn++;
		}
	}
		size--;

	if(size==a+b+1&&hifn==1&&s[a]=='-'){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	//				printf("%d\n",size);
 

}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

typedef struct _dice {
    int surface[6];
} Dice;

void input(Dice *d);
void roll_N(Dice *d);
void roll_E(Dice *d);
void roll_S(Dice *d);
void roll_W(Dice *d);

int main(){
    Dice *dice;
    dice = (Dice *)malloc(sizeof(Dice *));
    input(dice);
    string str;
    cin >> str;
    for(int i=0;i<str.size();i++){
        if(str[i] == 'N') roll_N(dice);
        else if(str[i] == 'E') roll_E(dice);
        else if(str[i] == 'S') roll_S(dice);
        else if(str[i] == 'W') roll_W(dice);
    }
    cout << dice->surface[0] << endl;
}

void input(Dice *d){
    for(int i=0;i<6;i++) {
        cin >> d->surface[i];
    }
}

void roll_N(Dice *d){
    int tmp = d->surface[5];
    d->surface[5] = d->surface[4];
    d->surface[4] = d->surface[0];
    d->surface[0] = d->surface[1];
    d->surface[1] = tmp;
}

void roll_E(Dice *d){
    int tmp = d->surface[5];
    d->surface[5] = d->surface[2];
    d->surface[2] = d->surface[0];
    d->surface[0] = d->surface[3];
    d->surface[3] = tmp;
}

void roll_S(Dice *d){
    int tmp = d->surface[5];
    d->surface[5] = d->surface[1];
    d->surface[1] = d->surface[0];
    d->surface[0] = d->surface[4];
    d->surface[4] = tmp;
}

void roll_W(Dice *d){
    int tmp = d->surface[5];
    d->surface[5] = d->surface[3];
    d->surface[3] = d->surface[0];
    d->surface[0] = d->surface[2];
    d->surface[2] = tmp;
}


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

using namespace std;

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

  int sum = 0;
  int n = N;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }

  string answer = N % sum == 0 ? "Yes" : "No";

  cout << answer << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10; }
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid_pleaseAC_fast;

	string s;
	cin >> s;
	int a = s.size();
	bool ans = false;
	if (a == 2) {
		if (s == "hi" || s == "hi")ans = true;
	}

	if (a == 4) {
		if (s == "hihi" || s == "ihih")ans = true;

	}
		if (a == 6) {
			if (s == "hihihi" || s == "ihihih")ans = true;
		}

		if (a == 8) {
			if (s == "hihihihi" || s == "ihihihih")ans = true;
		}

		if (a == 10) {
			if (s == "hihihihihi" || s == "ihihihihih")ans = true;
		}
		Yes(ans == true);

		please AC;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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

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

int main() {
	string s;
	cin >> s;
	
	int ans;
	
	if (s == "SUN") {
		ans = 7;
	} else if (s == "MON") {
		ans = 6;
	} else if (s == "TUE") {
		ans = 5;
	} else if (s == "WED") {
		ans = 4;
	} else if (s == "THU") {
		ans = 3;
	} else if (s == "FRI") {
		ans = 2;
	} else if (s == "SAT") {
		ans = 1;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  //input
  int S, T,answer = 0;
  scanf("%d", &S);
  int Ss[S];
  for(int i=0; i<S; i++) scanf("%d", &Ss[i]);
  
  scanf("%d", &T);
  int Tt[T];
  for(int i=0; i<T; i++) scanf("%d", &Tt[i]);
  
  //calc
  for(int i=0; i<T; i++)
    {
      for(int j=0; j<S; j++)
	{
	  if(Tt[i] == Ss[j])
	    {
	      answer+=1;
	      break;
	    }
	}
    }
  printf("%d\n", answer);
  return 0;
  }



Measured memory_bytes: 2108
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    n = gets.chomp.to_i

    sn = Math.sqrt(n)

    min_dist = 1000000000000
    1.upto(sn) do |i|
      d, r = n.divmod(i)
      next if r != 0

      dist = i + d - 2
      if dist < min_dist
        min_dist = dist
      end
    end

    puts min_dist
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2428
n,m=list(map(int,input().split()))
ab=[]
for i in range(n):
  a=list(map(int,input().split()))
  ab.append(a)
ab=sorted(ab, key=lambda x:x[0])

cnt,ans,j=0,0,0

while cnt<m:
  if ab[j][1]>=m-cnt:
    ans+=ab[j][0]*(m-cnt)
    cnt=m
  else:
    ans+=ab[j][0]*ab[j][1]
    cnt+=ab[j][1]
  j+=1
print(ans)


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	t = 1;
	while(t--) {
	 cin >> n;
	 if(n % 2)
	  cout << (n / 2) * (n / 2 + 1) << endl;
     else
	  cout << (n / 2) * (n / 2) << endl;
	}
	return 0;
}



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

#define int long long
#define ll long long
#define pb push_back

main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int k1 = (a + d - 1) / d;
    int k2 = (c + b - 1) / b;
    if (k1 >= k2){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}


Measured memory_bytes: 3632
import sys

def main():
    _ = int(sys.stdin.readline())
    *B, = map(int, sys.stdin.readline().split())

    sumA = B[0] + B[-1]

    for b1,b2 in zip(B[:-1],B[1:]):
        sumA += min(b1,b2)

    print(sumA)

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back

int main(){

//	freopen("in.txt","r",stdin);

	int a,b,c,d,n;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&n);
	b=min(b,2 * a);
	c=min(c,2 * b);
	d=min(d,2 * c);
	ll ans=0;
	ans+=d * 1LL * (n / 2);
	ans+=c * 1LL * (n & 1);
	cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10000)


def main():
    # 入力処理
    N = int(input())

    # アルゴリズム本体
    x = 800 * N
    y = 200 * int(N / 15)

    # 出力
    print(x-y)


if __name__ == '__main__':
    main()


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

int sod(int N) {
  int sum = 0;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  return sum;
}

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

  if (N % sod(N) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
int main()
{
    int k; cin >> k;
    string s; cin >> s;
    if(s.size() <= k)cout << s << endl;
    else {
        cout << s.substr(0,k) << "..." << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
class Combination
{
    vector<long long> fact;
    vector<long long> factinv;
    long long MOD = 1e9 + 7;
    long long modpow(long long a, long long n)
    {
        if (n == 0)
            return 1;
        if (n % 2 == 0)
        {
            long long t = modpow(a, n / 2);
            return t * t % MOD;
        }
        return a * modpow(a, n - 1) % MOD;
    }

    long long modinv(long long a)
    {
        // mod is prime
        return modpow(a, MOD - 2);
    }

public:
    Combination(int n) : fact(n), factinv(n)
    {
        fact[0] = 1;
        for (int i = 1; i < n; i++)
        {
            fact[i] = fact[i - 1] * i % MOD;
        }
        factinv[n - 1] = modinv(fact[n - 1]);
        for (int i = n - 2; i >= 0; i--)
        {
            factinv[i] = factinv[i + 1] * (i + 1) % MOD;
        }
    }

    long long ncr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
    }

    long long npr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[n - r] % MOD;
    }

    long long nhr(long long n, long long r)
    {
        if (n == 0 && r == 0)
            return 1;
        return ncr(n + r - 1, r);
    }
};
int main(){
    ll x,y;
    cin >> x >> y;
    if((x+y)%3){
        cout << 0 << endl;
        return 0;
    }
    ll n = (x+y)/3;
    x-=n;
    Combination comb(1000000);
    cout << comb.ncr(n,x)<<endl;
}

Measured memory_bytes: 15872
#include <set>
#include <string>
#include <iostream>

using namespace std;

int main() {

	set<string> st;

	int n = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		st.insert(s);
	}

	cout << st.size() << '\n';

}
	

Measured memory_bytes: 19104
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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



int main(void)
{

	int n;

	cin >> n;

	vector<int> w(n);
	rep(i, n) cin >> w[i];

	vector<int> b(n+1);

	int ans = 10000000;
	b[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		b[i] = b[i - 1] + w[i-1];
	}

	
	rep(i, n+1) {
		int sa = abs(b[n] - 2 * b[i]);

		ans = min(sa, ans);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, M = mi()
    if N == M == 1:
        print(1)
    elif N == 1 or M == 1:
        print(max(N, M)-2)
    else:
        print((N-2)*(M-2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61484
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  vector<vector<P>> pv(n + 1);
  REP(i, n - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    pv[a].push_back(P(b, c));
    pv[b].push_back(P(a, c));
  }

  vector<bool> ans(n + 1);
  queue<tuple<int, int, bool>> que;

  ans[1] = true;
  que.push(make_tuple(1, -1, true));
  while(!que.empty()) {
    tuple<int, int, bool> t = que.front(); que.pop();
    int now = get<0>(t);
    int from = get<1>(t);
    bool c = get<2>(t);

    REP(i, pv[now].size()) {
      P p = pv[now][i];
      if(p.first != from) {
        if(p.second % 2 == 0) {
          ans[p.first] = c;
          que.push(make_tuple(p.first, now, c));
        } else {
          ans[p.first] = !c;
          que.push(make_tuple(p.first, now, !c));
        }
      }
    }
  }

  FOR(i, 1, n + 1) {
    cout << (ans[i] ? 0 : 1) << endl;
  }
}


Measured memory_bytes: 6528
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			boolean[] taro = new boolean[n*2];
			for(int i=0;i<n;i++) {
				taro[sc.nextInt()-1] = true;
			}
			TreeSet<Integer>[] hand = new TreeSet[2];
			for(int i=0;i<2;i++) {
				hand[i] = new TreeSet<Integer>();
			}
			for(int i=0;i<n*2;i++) {
				hand[taro[i] ? 0 : 1].add(i+1);
			}
			int pool = 0;
			int turn = 0;
			while(true) {
				Integer next = hand[turn].ceiling(pool);
				if (next == null) {
					pool = 0;
				}else{
					hand[turn].remove(next);
					pool = next;
					if (hand[turn].size() == 0) {
						break;
					}
				}
				turn = 1 - turn;
			}
			System.out.println(hand[1].size());
			System.out.println(hand[0].size());
		}
	}

}

Measured memory_bytes: 20484
#include<bits/stdc++.h>
#define pb push_back
#define fori(j,n) for(int i=j ; i<n ; i++)
#define forj(i,n) for(int j=i ; j<n ; j++)
#define fork(i,n) for(int k=i ; k<n ; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int
#define mod 1000000007

using namespace std;

void solve()
{
	int n,x,t;
	int cnt=0;
	cin>>n>>x>>t;
	while(n>0)
	{
		cnt+=t;
		n-=x;
	}
	cout<<cnt;
	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	// int t;cin>>t;
	// while(t--)
	// {
		solve();
		// cout<<endl;
	// }

	return 0;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
//ll min(ll a, ll b){
//    if(a>b){
//        return b;
//    }
//    return a;
//}
// 
//ll max(ll a, ll b){
//    if(a>b){
//        return a;
//    }
//    return b;
//}
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 

ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 
//cout<<setprecision(9)<<fixed<<sum<<endl; --- precision for double numbers
//copy(v.beg,v.en,outp);

int main()
{
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	string s="";
	forl(i,0,n)
	{
		s+=a[i];
		s+=b[i];
	}
	cout<<s<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 100000;

int main() {
  int N, pt = 0, px = 0, py = 0;
  bool ans = true;
  cin >> N;
  for (int i=0; i<N; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t-pt < abs(x-px)+abs(y-py)) {
      ans = false;
    } else if (abs(x-px)+abs(y-py)<t-pt && ((abs(x-px)+abs(y-py))&1)!=((t-pt)&1)) {
      ans = false;
    }
    pt = t; px = x; py = y;
  }

  cout << (ans?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

		int[] cnt = new int[61];
		for (int i = 0; i < n; i++) {
			int j = 0;
			long x = a[i];
			while (x > 0) {
				cnt[j] += x % 2;
				x /= 2;
				j++;
			}
		}

		long ans = 0;
		for (int i = 0; i < cnt.length; i++) {
			long val = (long) cnt[i] * (n - cnt[i]);
			val %= 1000000007;
			long val2 = (1L << i);
			val2 %= 1000000007;
			val *= val2;
			val %= 1000000007;
			ans += val;
			ans %= 1000000007;
		}
		System.out.println(ans);
	}
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

int spf[N];
vector<int> p;
void sieve()
{
    for(int i=2;i<N;i++)
    {
        if(!spf[i])
        {
            spf[i]=i;
            p.pb(i);
            for(int j=i*i;j<N;j+=i)if(!spf[j])spf[j]=i;
        }
    }
}

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    sieve();
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        vector<int> pr;
        for(int i:p)
        {
            int cnt = 0;
            while(n%i == 0)cnt++,n/=i;
            if(cnt)pr.pb(cnt);
        }
        if(n > 1)pr.pb(1);
        int ans = 0;
        for(int c:pr)
        {
            int add = 0;
            for(int i=1;;i++)
            {
                if(((i*(i+1))/2) > c)break;
                add = i;
            }
            ans += add;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 12036