akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

vector<string> ans;
void dfs(int n, string s, char e) {
	if (n == 0) {
		ans.push_back(s);
		return;
	}
	for (char c = 'a'; c <= e; c++) {
		dfs(n-1, s+c, e);
	}
	dfs(n-1, s+(char)(e+1), e+1);
}

void Main() {
	int N; cin >> N;
	dfs(N, "", 'a'-1);
	for (auto &s : ans) cout << s << el;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

VVI road;
VI visited;

int main() {
  int n, m;
  cin >> n >> m;
  road.resize(n);
  visited.resize(n);
  fill(visited.begin(), visited.end(), -1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    road.at(a).push_back(b);
    road.at(b).push_back(a);
  }

  queue<int> que;
  visited.at(0) = 0;
  que.push(0);
  while (!que.empty()) {
    int city = que.front();
    que.pop();
    for (int next : road.at(city)) {
      if (visited.at(next) == -1) {
        visited.at(next) = city;
        que.push(next);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << visited.at(i) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 10176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n;
    cin >> n;
    vector<ll> A(n);
    int f= 0;
    ll min= INF;
    REP(i,n){
        cin >> A[i];
        
        if(A[i]<0) f^= 1;
        A[i]= abs(A[i]);
        if(min>A[i]) min= A[i];
    }
    ll sum= accumulate(A.begin(), A.end(), 0LL);
    // cout << f << endl;
    cout << ((f)?sum-2*min:sum) << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    int l = s.length()/2;
    int count = 0;
    for(int i=0;i<l;i++){
        if(s[i]!=s[s.length()-1-i]){
            //cout << s[i] << s[s.length()-1-i] << endl;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
n = input()

if(n[len(n) - 1] == "2" or n[len(n) - 1] == "4" or n[len(n) -1] == "5" or n[len(n) - 1] == "7" or n[len(n) - 1] == "9"):
    print("hon")
elif(n[len(n) - 1] == "3"):
    print("bon")
else:
    print("pon")

Measured memory_bytes: 9060
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) 
{
	int a, b;
	char op;

	for (;;) 
	{
		scanf("%d %c %d", &a, &op, &b);

		if (op == '?') break;
		if ((0 > a || a > 20000) || (0 > b || b > 20000))
			continue;

		switch (op)
		{
		case '+':printf("%d\n", a + b);  break;
		case '-':printf("%d\n", a - b);  break;
		case '*':printf("%d\n", a * b);  break;
		case '/':
		{
			if (b != 0) {
				printf("%d\n", a / b);
			}  break;
		}
		}
	}
		return 0;
}


Measured memory_bytes: 2076
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

typedef long long ll;

int main() {
    int n[4];

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

    bool flag[4] = { false, false, false, false };

    for (int i = 0; i < 4; i++) {
        if ( n[i] == 1  ) {
            flag[0] = true;
        } else if ( n[i] == 9  ) {
            flag[1] = true;
        } else if ( n[i] == 7  ) {
            flag[2] = true;
        } else if ( n[i] == 4  ) {
            flag[3] = true;
        }
    }

    for (int i = 0; i < 4; i++) {
        if (!flag[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[10][10],c[10][10];
int main() {
	ll h,w;
	cin>>h>>w;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin>>a[i][j];
		}
	}
	for(int k=0;k<10;k++){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
			}
		}
	}
	ll ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			ll now;
			cin>>now;
			if(now==-1){
				continue;
			}
			ans+=a[now][1];
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for( int i = a; i <= b; ++i ){
		string s = to_string(i);
		if( s[0] == s[4] && s[1] == s[3] ){
			++ans;
		} 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        System.out.println(Math.max(C-(A-B),0));


    }
}


Measured memory_bytes: 22996
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    S_ = input()
    T = input()
    save = []

    for i in range(len(S_)-len(T)+1):
        target = S_[i:i+len(T)]

        flag = True
        for j in range(len(T)):
            if target[j]=='?':
                continue
            elif target[j]==T[j]:
                continue
            else:
                flag = False
                break

        if flag:
            S = S_[:i] + T + S_[i+len(T):]
            S = S.replace('?', 'a')
            save.append(S)

    if len(save)>0:
        save.sort()
        print(save[0])
    else:
        print('UNRESTORABLE')


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(void){

	char s[12],r[12];
	int i,j;
	int l;


	i = 0;

	r[i] = '\0';

	scanf("%s",s);

	l = strlen(s);

	for(j=0;j<12;j++){
		r[j] = '\0';
	}

	for(j = 0; j < l ;j++){
		switch(s[j]){
		case '0' :
			    r[i] = '0';
				i++;
				break;

		case '1':
			    r[i] = '1';
				i++;
				break;

		default :
			if(i != 0){
				i--;
				r[i] = '\0';
			}
			break;
				
		}

	}

	printf("%s\n",r);

	return 0;

}

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

#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl

void solve() {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  for (auto &it : arr) {
    cin >> it;
  }
  sort(arr.begin(), arr.end());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (arr[i] == arr[j])
        continue;
      for (int k = j + 1; k < n; k++) {
        if (arr[i] == arr[k] || arr[j] == arr[k])
          continue;
        if (arr[i] + arr[j] > arr[k])
          ans++;
      }
    }
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3684
#!/usr/bin/env python3
import itertools
import math
n = int(input())
x = [0] * n
y = [0] * n
a = list(range(n))
ans = 0
for i in range(n):
    x[i], y[i] = map(int, input().split())
for v in itertools.permutations(a, 2):
    ans += math.sqrt((x[v[0]] - x[v[1]])**2 + (y[v[0]] - y[v[1]])**2)
print(ans/n)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    ll r, d, x;
    cin>>r>>d>>x;
    f(i, 10){
        ll tx = r * x - d;
        cout<<tx<<"\n";
        x = tx;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))
ans = 'Yes'
pre = -999

for i in range(n):
  if pre <= L[i] - 1:
    pre = L[i] - 1
  elif pre <= L[i]:
    pre = L[i]
  else:
    print('No')
    exit()
print('Yes')



Measured memory_bytes: 20764
#include<iostream>
using namespace std;
int main(){
    int i,X,Y,c=0;
    cin >> X >> Y;
    for(i=0;i<=X;++i){
        if((2*i+4*(X-i))==Y){
            ++c;
        }
    }
    if(c>0){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

}

Measured memory_bytes: 3620
#! /usr/bin/env python3

N, T = map(int, input().split())
A = list(map(int, input().split()))
pu = -1
SPU = set([])
SPD = []
b = 0
c = 0
for i in A[:-1][::-1]:
    if i > A[pu]:
        pu = -c-2
    elif i < A[pu] and A[pu]-i >= b:
        SPU.add(pu)
        b = A[pu]-i
        SPD += [b]
    c += 1

print(min(len(SPU), SPD.count(b)))

Measured memory_bytes: 14680
import sys
readline = sys.stdin.readline
import math

def count_factor(n, d=2):
    if n % d != 0:
        return 0
    for i in range(n):
        if n & 2<<i:
            return i + 1

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))

    ans = sum([count_factor(a) for a in A])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4148
#include<iostream>
#include<map>
#include<vector>

using namespace std;
const int maxn=1e5+7;
int p[maxn],fa[maxn];

int find(int x){
	return x==fa[x] ? x : fa[x]=find(fa[x]);
}

int tog(int x,int y){
	int _x=find(x),_y=find(y);
	if (_x!=_y){
		fa[_y]=_x;
	}
}

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	for (int i=1;i<=n;i++){
		cin>>p[i];
		fa[i]=i;
	}
	for (int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		int _x=find(x),_y=find(y);
		if (_x!=_y){
			tog(_x,_y);
		}
		
	}
	int ans=0;
	for (int i=1;i<=n;i++){
		int _x=find(p[i]),_y=find(i);
		if (_x==_y){
			ans++;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		sc.close();
		double sum = 0;

		for (int i = 0; i <= a; i++) {
			if (i % 2 == 1) {
				sum += 1;
			}
		}
		System.out.println(sum / a);
	}
}

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

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	const T init;
	const F f;
	int sz;
	vector<T> seg;
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

int main() {
	int64_t n; cin >> n;
	int a[n]; for(int i = 0; i < n; ++i) cin >> a[i];
	int ok = 0, ng = 1e9 + 10;
	while(abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		int sum[n + 1] = {};
		for(int i = 1; i <= n; ++i) {
			sum[i] = (a[i - 1] >= mid ? +1 : -1);
			sum[i] += sum[i - 1];
		}
		constexpr int MAX = 200010;
		constexpr int BASE = 100000;
		SegmentTree<int64_t> seg(200010, 0, [](int64_t l, int64_t r) {
			return l + r;
		});
		int64_t ans = 0;
		for(int i = 0; i <= n; ++i) {
			ans += seg.get(0, sum[i] + BASE + 1);
			seg.replace(sum[i] + BASE, seg.get(sum[i] + BASE, sum[i] + BASE + 1) + 1);
		}
		if(ans < (n * (n + 1) / 2 + 1) / 2) {
			ng = mid;
		} else {
			ok = mid;
		}
		// cout << mid << " " << ans << '\n';
	}
	// cout << (n * (n - 1) + 3) / 4 << '\n';
	cout << ok << '\n';
	return 0;
}

Measured memory_bytes: 5244
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
    double n,a,b,sum=0,k,l;
    cin>>a>>b;
    for (int i=0;i<100*20;i++)
    {
        if (floor(i*0.08)==a and floor(i*0.1)==b)
        {
            cout<<i;
            exit(0);
        }

    }
    cout<<-1;
}

Measured memory_bytes: 256
N, M, P = gets.chomp.split(" ").map(&:to_i)
E = Array.new(N + 1)
E.map!{Array.new}
M.times{|i|
  a, b, c = gets.chomp.split(" ").map(&:to_i)
  E[a] << [b, c - P]
}

INF = 'inf'
tmp = 0
d = Array.new(N + 1, -(N * 10 ** 5))
d[1] = 0
bef = [1]
(2 * N).times{|cnt|
  nxt = []
  bef.each{|from|
    E[from].each{|to, cost|
      if d[to] < d[from] + cost then
        d[to] = d[from] + cost
        d[to] += (N * 10**5) if to != N && cnt == N
        nxt << to
      end
    }
  }
  bef = nxt.uniq
  break if bef.empty?
  tmp = d[N] if cnt == N - 1
  (d[N] = INF; break) if cnt >= N && d[N] > tmp
}

if d[N] == INF then
  puts -1
elsif d[N] < 0 then
  puts 0
else
  puts d[N]
end


Measured memory_bytes: 35196
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int k, x;
	cin >> k >> x;
	if(k * 500 >= x)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

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

int main(void) {
	char b[10];

  if(scanf("%s", b) == 1);

	if(b[0] == 'A') {
		printf("T");
	} else if(b[0] == 'T') {
		printf("A");
	} else if(b[0] == 'C') {
		printf("G");
	} else {
		printf("C");
	}

  return 0;
}


Measured memory_bytes: 128
import java.math.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    static final int modnum = 1000000007;

    public static void main(String[] args) {
        ArrayList<Node> node = new ArrayList<Node>();
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        for (int i = 1; i <= N; i++) {
            node.add(new Node(node, i));
        }

        for (int i = 1; i < N; i++) {
            int p1 = sc.nextInt();
            int p2 = sc.nextInt();
            int length = sc.nextInt();
            node.get(p1 - 1).addEdge(p2, length);
            node.get(p2 - 1).addEdge(p1, length);
        }

        for (int i = 0; i < N; i++) {
            if (node.get(i).isLeaf) {
                node.get(i).setParent(0, 0);
                break;
            }
        }

        for (int i = 0; i < N; i++) {
            System.out.println(node.get(i).isBlack ? 1 : 0);
        }
    }
}

class Node {
    final int number;
    boolean isLeaf = true;
    boolean isBlack = false;
    int parent = 0;

    ArrayList<Node> node;

    ArrayList<Integer> edge = new ArrayList<Integer>();
    ArrayList<Boolean> even = new ArrayList<Boolean>();

    Node(ArrayList<Node> node, int number) {
        this.node = node;
        this.number = number;
    }

    void addEdge(int n, int length) {
        edge.add(n);
        even.add(length % 2 == 0);

        if (edge.size() == 1)
            isLeaf = true;
        else
            isLeaf = false;
    }

    void setParent(int p, int odds) {
        parent = p;
        if (odds % 2 != 0)
            isBlack = true;
        for (int i = 0; i < edge.size(); i++) {
            if (edge.get(i) == p)
                continue;
            int nextodds = even.get(i) ? odds : odds + 1;
            node.get(edge.get(i) - 1).setParent(number, nextodds);
        }
    }

}

Measured memory_bytes: 123820
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  string s;
  cin >> s;
  rep(i,3) cout << s[i];
  cout << endl;
  return 0;
}

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

long long N, A[109], S[109], dp[109][309][9][4], nr[509][509], mod = 10007;

int COUNTRY = 0, ORDINARY = 0, DANGER = 0, DANGER1 = 0, DANGER2 = 0, PLUS = 0, BASE = 0;

void init() {
	for (int i = 0; i <= 500; i++) {
		for (int j = 0; j <= 500; j++) {
			if (i == 0 || j == 0) nr[i][j] = 1;
			else nr[i][j] = (nr[i - 1][j] + nr[i][j - 1]) % mod;
		}
	}
}

int ncr(int n, int r) {
	if (n < r || r < 0) return 0;
	return nr[r][n - r];
}

void calc(int num, int danger2, int multi) {
	for (int i = 0; i <= num; i++) {
		for (int j = 0; i + j <= num; j++) {
			for (int k = 0; i + j + k <= num; k++) {
				for (int l = 0; i + j + k + l <= num; l++) {
					int m = num - i - j - k - l;

					int v1 = ncr(ORDINARY, i);
					int v2 = ncr(DANGER, j);
					int v3 = ncr(DANGER1, k);
					int v4 = ncr(DANGER2, l);
					int v5 = ncr(PLUS, m);
					int product = (((v1 * v2 % mod) * v3 % mod) * v4 % mod) * v5 % mod;
					if (product == 0) continue;

					int T1 = COUNTRY;
					int T2 = DANGER - j + (DANGER1 - k) + (DANGER2 - l);
					int T3 = k + l * 2 + m;
					int T4 = danger2;
					dp[T1][T2][T3][T4] += BASE * product * multi;
					dp[T1][T2][T3][T4] %= mod;
				}
			}
		}
	}
}

void solve(int country, int danger, int danger1, int danger2) {
	COUNTRY = country + 1;
	DANGER = danger;
	DANGER1 = danger1;
	DANGER2 = danger2;
	PLUS = 2 * A[country] - DANGER1 - 2 * DANGER2;
	ORDINARY = S[country] + 1 - DANGER - DANGER1 - DANGER2 - PLUS;
	BASE = dp[country][danger][danger1][danger2];

	if (A[country + 1] == 1) {
		calc(1, 0, 1); // (1)
	}
	if (A[country + 1] == 2) {
		calc(1, 1, 1); // (2)
		calc(2, 0, 1); // (1, 1)
	}
	if (A[country + 1] == 3) {
		calc(1, 2, 1); // (3)
		calc(2, 1, 2); // (2, 1)
		calc(3, 0, 1); // (1, 1, 1)
	}
	if (A[country + 1] == 4) {
		calc(1, 3, 1); // (4)
		calc(2, 2, 3); // (3, 1), (2, 2)
		calc(3, 1, 3); // (2, 1, 1)
		calc(4, 0, 1); // (1, 1, 1, 1)
	}
}

int checker() {
	vector<int>vec;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < A[i]; j++) vec.push_back(i);
	}
	int cnts = 0;
	do {
		bool flag = true;
		for (int i = 0; i < vec.size() - 1; i++) {
			if (abs(vec[i] - vec[i + 1]) <= 1) flag = false;
		}
		if (flag == true) {
			/*for (int i = 0; i < N; i++) {
				if (i) cout << " "; cout << a[i];
			}
			cout << endl;*/
			cnts++;
		}
	} while (next_permutation(vec.begin(), vec.end()));
	return cnts % mod;
}

int main() {
	cin >> N; init();
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; S[i] = S[i - 1] + A[i];
	}
	dp[0][0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3 * N; j++) {
			for (int k = 0; k <= 8; k++) {
				for (int l = 0; l <= 3; l++) {
					if (dp[i][j][k][l] == 0) continue;
					solve(i, j, k, l);
				}
			}
		}
	}
	long long ret = dp[N][0][0][0];
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= A[i]; j++) { ret *= j; ret %= mod; }
	}
	cout << ret << endl;
	//cout << checker() << endl;
	return 0;
}


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

namespace ABC139D
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());

            long ans = (N - 1) * N / 2;

            Console.WriteLine(ans);


            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

double R;

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

    cin >> R;

    cout << setprecision(6) << R * 2 * M_PI << endl;
    
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  for (int i = 1; i < s.size(); ++i) {
    if (s[i-1]==s[i]) {
      cout<<"no"<<endl;
      return 0;
    }
  }
  cout<<"yes"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
main()
{
    int b, c, d, n, m;
    cin >> n >> d;
    double a[n][d];
    for( int i = 0; i < n; i++ )for( int j = 0; j < d; j++ ) cin >> a[i][j];
    int cnt= 0;
    for( int i = 0; i < n; i++ )
    {
        for( int j = i + 1; j < n; j++ )
        {
            double dist = 0;
            for( int k = 0; k < d; k++ )
            {
                dist += ( a[i][k] - a[j][k] ) * ( a[i][k] - a[j][k] );
            }
            dist = sqrt( dist );
            if( floor( dist ) == dist ) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int> pque;


    vector<pair<int,int>> que;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        pque.push(a);
    }

    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        que.push_back({y,x});
    }
    sort(que.begin(), que.end());


    int ind = 0;
    while(ind < n && que.size()){
        auto cur = que.back(); que.pop_back();


        for(int i = 0; i < cur.second; i++){
            pque.push(cur.first);
        }
        //cerr << cur.second << " " << cur.first << endl;
        ind += cur.second;
    }

    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += pque.top();
        //cerr << pque.top() << endl;
        pque.pop();
    }
    cout << sum << endl;

}

Measured memory_bytes: 2288
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int a, b, m;
    scanf("%d%d%d", &a, &b, &m);
    vector<int> aa(a), bb(b);
    int mina = INF, minb = INF;
    int i;
    for (i = 0; i < a; i++) {
        scanf("%d", &aa[i]);
        mina = MIN(mina, aa[i]);
    }

    for (i = 0; i < b; i++) {
        scanf("%d", &bb[i]);
        minb = MIN(minb, bb[i]);
    }
    ll ans = mina + minb;
    for (i = 0; i < m; i++) {
        int x, y, c;
        scanf("%d%d%d", &x, &y, &c); x--; y--;
        ll tmp=(ll)aa[x] + bb[y] - c;
        ans = MIN(ans, tmp);
    }
    printf("%lld\n", ans);
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


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

const int N = 1e5 + 8;
int f[10][10];
int n, m;
int main()
{
	cin.sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 0; i < 10; ++i)
		for (int j = 0; j < 10; ++j)
			cin >> f[i][j];
	for (int k = 0; k < 10; ++k)
		for (int i = 0; i < 10; ++i)
			for (int j = 0; j < 10; ++j)
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
		{
			int x; cin >> x;
			if (x != -1) ans += f[x][1];
		}
	cout << ans << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a[N];
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  bool iro[8] = {false};
  int jiyuu = 0;
  for(int i=0; i<N; i++){
    if(0 <= a[i] && a[i] <= 399){iro[0] = true;}
    if(400 <= a[i] && a[i] <= 799){iro[1] = true;}
    if(800 <= a[i] && a[i] <= 1199){iro[2] = true;}
    if(1200 <= a[i] && a[i] <= 1599){iro[3] = true;}
    if(1600 <= a[i] && a[i] <= 1999){iro[4] = true;}
    if(2000 <= a[i] && a[i] <= 2399){iro[5] = true;}
    if(2400 <= a[i] && a[i] <= 2799){iro[6] = true;}
    if(2800 <= a[i] && a[i] <= 3199){iro[7] = true;}
    if(3200 <= a[i] && a[i] <= 4800){jiyuu += 1;}
  }
  int shurui = 0;
  for(int i=0; i<8; i++){
    shurui += iro[i];
  }
  cout << max(1,shurui) << " " << shurui+jiyuu << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

//-------------------------------------------------------------------
struct segtree{
  ll M=1, INIT;
  vector<ll> dat;
  segtree(ll N, ll num){
    INIT = num;
    while(M<N) M*=2;
    for(int i=0;i<M*2-1;i++)  dat.push_back(num);
  }
  void update(ll x, ll k, ll l=0, int r=-1){
    if(r==-1) r = M;
    k+=M-1;
    dat[k] = x;
    while(k>0) k = (k-1)/2, dat[k] = dat[k*2+1] + dat[k*2+2];
  }
  ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return INIT;
    if(a<=l && r<=b) return dat[k];
    ll A = query(a, b, k*2+1, l, (l+r)/2);
    ll B = query(a, b, k*2+2, (l+r)/2, r);
    return A + B;
  }
};
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  string s;std::cin >> s;
  ll q;std::cin >> q;
  vector<segtree> seg(26, segtree(n+100, 0));

  re(i, n){
    ll now = s[i]-'a';
    seg[now].update(1, i);
  }

  re(i, q){
    ll a, b;scanf("%lld %lld",&a, &b);
    if(a==1){
      char c;std::cin >> c;
      ll pre = s[b-1]-'a';
      ll to = c-'a';
      s[b-1] = c;
      seg[pre].update(0, b-1);
      seg[to].update(1, b-1);
    }else{
      ll c, ans = 0;std::cin >> c;
      re(j, 26){
        ll q = seg[j].query(b-1, c);
        if(q>0) ans++;
      }
      std::cout << ans << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 222568
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final String[] s = new String[3];
    s[0] = scanner.nextLine();
    s[1] = scanner.nextLine();
    s[2] = scanner.nextLine();

    final int[] idx = new int[3];
    int nextTurn = 0;
    while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    }

    System.out.println(Character.toUpperCase((char) (nextTurn + 'a')));
  }
}

Measured memory_bytes: 21844
import math,itertools as it
M = 256
while 1:
    N = int(raw_input())
    if N == 0: break
    H = 1e10
    I = map(int,raw_input().split())
    for S,A,C in it.product(range(16),repeat=3):
        R = S
        O = [0]*M
        for i in I:
            R = (A*R+C)%M
            O[(i+R)%M] += 1
        tmp = -sum(1.0*x/N*math.log(1.0*x/N,2) for x in O if x > 0)
        if tmp < H:
            H = tmp
            ans = [S,A,C]
    print " ".join(map(str,ans))

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

int main() {
  int t, a, b;
  cin >> t >> a >> b;

  int ta = t * a;

  if (ta > b) {
    cout << b << endl;
  }else if(ta < b){
    cout << ta << endl;
  }else{
    cout << b << endl;
  }
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long int
#define endl "\n"
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = (int)3e5+5;

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN;
//    cout << (2019 / 3) << endl;
//    for(int i = 2; i*i <= 673; i++){
//        if(673 % i == 0){ cout << ", " ; break; }
//    }
//    cout << (18171 % 673) << endl;
    string s;
    cin >> s;
    vector< ll > V(s.size());
    ll cur = 1LL;
    for(int i = s.size()-1; i >= 0; i--){
        int res =  (cur * (s[i]-'0') ) % 2019;
        V[i] = res;
        cur*=10;
        cur%=2019;
    }
    int res = 0;
    vector< int > lol(2020,0);
    for(int i = s.size()-1; i >= 0; i--){
        res+=V[i];
        res%=2019;
        lol[ res ]++;
    }
    ll ans = 0LL;
    for(int i = 0; i < 2019; i++){
        ans+=(1LL * lol[i] * (lol[i]-1)/2);
    }
    ans+=lol[0];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5156
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] s = in.readLine().split(" ");
    boolean yellow_flg = false;
    for(int i=0; i<n; i++) {
      if(s[i].charAt(0)=='Y')
        yellow_flg = true;
    }
    System.out.println(yellow_flg == true?"Four":"Three");
  }
}

Measured memory_bytes: 32612
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    /*
    int a[n];
    std::vector<int> v;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[i] = tmp;
    }
    */
    int a = 1000-n%1000;
    if(a==1000) a = 0;
    cout << a << endl;
    //cout << "Yes" << endl;
    //cout << a << endl;
    
    return 0;
}

Measured memory_bytes: 3632
let n, q = Scanf.scanf " %d %d" @@ fun a b -> a, b
let g, ans = Array.(make n [], make n 0)
let rec f v p = List.iter (fun u -> if u <> p then (ans.(u) <- ans.(u) + ans.(v); f u v)) g.(v)
let _ = Scanf.(for _ = 1 to n - 1 do scanf " %d %d" @@ fun u v -> g.(u - 1) <- v - 1 :: g.(u - 1); g.(v - 1) <- u - 1 :: g.(v - 1) done;
  for _ = 1 to q do scanf " %d %d" @@ fun p x -> ans.(p - 1) <- ans.(p - 1) + x done);
  f 0 ~-1; Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) ans; print_newline ()

Measured memory_bytes: 36224
from sys import stdin

n=int(input())
count = 0

output = 'No'

for i in range(n):
  temp = stdin.readline().split()
  if temp[0] == temp[1]:
    if count == 2:
      output = 'Yes'
      break;
    elif count == 1:
      count = 2
    elif count == 0:
      count = 1
  else:
  	count = 0
    
print(output)

Measured memory_bytes: 61928
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 1e16;

int main() {
  long long r;
  scanf("%lld", &r);
  long long D;
  scanf("%lld", &D);
  long long x;
  scanf("%lld", &x);

  rep(i, 0, 10) {
    x = r * x - D;
    print(x);
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
strings = sorted(''.join(sorted(input())) for _ in range(N))

ans = 0
cnt = 1
for i in range(N - 1):
    if strings[i] == strings[i + 1]:
        cnt += 1
    else:
        if cnt > 1:
            ans += cnt * (cnt - 1) // 2
        cnt = 1
print(ans) if cnt <= 1 else print(ans + cnt * (cnt - 1) // 2)


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

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

    for (int i = 0; i <= (n / 4); i++) {
        for (int j = 0; ; j++) {
            if (4 * i + 7 * j > n) {
                break;
            }

            if (4 * i + 7 * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int a, b, c;

	cin>> a >> b >> c;

	if(c<=b/a){
		cout<< c << endl;
	}else{
		cout<< b/a << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());
    int D = Integer.parseInt(sc.next());

    String result = (A + B) < (C + D)?"Right":(A + B) > (C + D)?"Left":"Balanced";

    System.out.println(result);

  }
}


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <utility>
#include <queue>
#include <stdio.h>
#define INF 1000000007
using namespace std;


int main(){
    int N,K,T,U,V,L;
    vector<int> d(N);
    cin >> N >> K >> T >> U >> V >> L;
    for (int i=0; i<N ;i++) {
        cin >> d[i];
    }
    int k=0;
    long double len=0;
    long double time=0;
    int flag=0;
    while (1) {
        if (k>0) {
            //cout << 1 << endl;
            k--;
            if (len + T*V >= L) {
                time += (L-len)/V;
                break;
            }else{
              //  cout <<2<<endl;
                time+=T;
                len+=T*V;
                for (int i=flag; i<N && d[i]< len; i++) {
                    k++;
                    flag=i+1;
                    if(k>K){
                        len -=T*V;
                        time = time -T + static_cast<double>(d[i]-len)/V;
                        len  = d[i];
                        break;
                    }
                //    cout << 3 <<endl;
                }
            }
        }
        if (k==0) {
            //cout << "("<<len<<","<<time<<")" << endl;
            if (flag<N){
                long double ll = static_cast<long double>(d[flag]-len);
                time += ll / static_cast<long double>(U);
                len = d[flag];
                flag++;
            }else{
                time += static_cast<long double>(L-len)/U;
                break;
            }
            if (len + T*V >= L) {
                time += (L-len)/V;
                break;
            }else{
              //  cout << 5 << endl;
                time+=T;
                len+=T*V;
                //cout << "("<<len<<","<<time<<")" << endl;
                for (int i=flag; i<N&&d[i]<len; i++) {
                  //  cout << 6<< endl;
                    k++;
                    flag=i+1;
                    if(k>K){
                        len -= T*V;
                        time = time -T + static_cast<double>(d[i]-len)/V;
                        len = d[i];
                        break;
                    }
                }
            }
        }
    }
    printf("%.9Lf\n",time);
    return 0;
}

Measured memory_bytes: 17432
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
count = 0
for i in range(n-1):
    if li[i] <= m:
        count += 1
        m -= li[i]
if li[-1] == m:
    count += 1
print(count)


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

int main() {
	int n;
	cin >> n;
	vector<int>w(n);
	int all(0);
	rep(i, n) {
		cin >> w[i];
		all += w[i];
	}
	//sort(w.begin(), w.end());
	int k = 105;
	//int sum(0);
	int ans(1e9);
	int sum(0);
	rep(i, n) {
		sum += w[i];
		int dist = abs(sum - (all - sum));
		ans = min(ans, dist);
	}
	cout << ans;
	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  vector<vector<int>>b(N,vector<int>(32));
  vector<int>c(32);
  for(int i=0;i<N;i++){
    for(int j=0;j<32;j++){
      b[i][j]=(a[i]>>j)&1;
      c[j]+=b[i][j];
    }
  }
  vector<vector<int>>ans(N,vector<int>(32));
  for(int i=0;i<N;i++){
    for(int j=0;j<32;j++){
      if(c[j]%2){
        ans[i][j]=!b[i][j];
      }
      else{
        ans[i][j]=b[i][j];
      }
    }
  }
  for(int i=0;i<N;i++){
    ll res=0;
    for(int j=0;j<32;j++){
      res+=pow(2,j)*ans[i][j];
    }
    cout<<res<<" ";
  }
  cout<<endl;
  return 0;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

long long int MOD = 1'000'000'007;

void solv(){
	int n;
	cin >> n;
	
	long long int ans = 0;
	long long int p = 1;

	rep(i, n){
		p *= 10;
		p %= MOD;
	}

	ans = p;
	p = 1;

	rep(i, n){
		p *= 8;
		p %= MOD;
	}

	ans += p;
	ans %= MOD;
	p = 1;

	rep(i, n){
		p *= 9;
		p %= MOD;
	}

	ans -= 2 * p;
	while(ans < 0) ans += MOD;
	ans %= MOD;

	cout << ans;
}

int main(){
	solv();

	return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>

const int FALSE = 0;
const int TRUE = 1;
int main(){
    int N;
    scanf("%d", &N);

    int d[100] = {-1};

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

    int cnt[110] = {-1};
    int pos = 0;
    int hit;
    for(int i = 0; i < 100; i++){
        if(i >= N){
            break;
        }
        hit = FALSE;
        for(int j = 0; j < pos; j++){
            if(d[i] == cnt[j]){
                hit = TRUE;
            }
        }
        if(!hit){
            cnt[pos++] = d[i];
        }

    }

    printf("%d\n", pos);
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    class Program
    {
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = vals[0];
            var M = vals[1];
            int[] array = null;
            foreach(var i in Enumerable.Range(0, N))
            {
                if(array == null)
                {
                    array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Skip(1).ToArray();
                }
                else
                {
                    array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Skip(1).Intersect(array).ToArray();
                }
            }
            Console.WriteLine(array.Length);
        }

    }
}
//A

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

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

    static class BTaxRate {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            for (int x = 0; x <= n; x++) {
                if ((x * 108) / 100 == n) {
                    out.println(x);
                    return;
                }
            }

            out.println(":(");
        }

    }

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

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

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

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

    }
}



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

int ans[501][501];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	if(H%h==0&&W%w==0)
		return cout<<"No\n",0;
	cout<<"Yes\n";
	for(int i=1;i<=H;i+=h)
		for(int j=1;j<=W;j+=w)
			ans[i][j]=999999999;
	for(int i=h;i<=H;i+=h)
		for(int j=w;j<=W;j+=w)
			ans[i][j]=-1e9;
	for(int i=1;i<=H;i++,cout<<'\n')
		for(int j=1;j<=W;j++)
			cout<<ans[i][j]<<' ';
}


Measured memory_bytes: 3968