akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
	int a,b,c,d,e,flag=0;
	scanf("%d",&a);
	e=a%10;
	a=a/10;
	d=a%10;
	a=a/10;
	c=a%10;
	a=a/10;
	b=a%10;
	if(b-c+d+e==7){
	printf("%d-%d+%d+%d=7\n",b,c,d,e);
	flag=1;
	}
	else if(b+c+d+e==7&&flag==0){
	printf("%d+%d+%d+%d=7\n",b,c,d,e);
	flag=1;
}
else if(b+c-d+e==7&&flag==0){
	printf("%d+%d-%d+%d=7\n",b,c,d,e);
	flag=1;
}
else if(b+c+d-e==7&&flag==0){
	printf("%d+%d+%d-%d=7\n",b,c,d,e);
	flag=1;
}
else if(b-c+d-e==7&&flag==0){
	printf("%d-%d+%d-%d=7\n",b,c,d,e);
	flag=1;
}
else if(b-c-d-e==7&&flag==0){
	printf("%d-%d-%d-%d=7\n",b,c,d,e);
	flag=1;
}
else if(b-c-d+e==7&&flag==0){
	printf("%d-%d-%d+%d=7\n",b,c,d,e);
	flag=1;
}
else if(b+c-d-e==7&&flag==0){
	printf("%d+%d-%d-%d=7\n",b,c,d,e);
	flag=1;
}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main( void )
{
    int N, K;
    cin >> N >> K;

    string S;
    cin >> S;
    if(S[K-1] == 'A'){
        S[K-1] = 'a';
    }else if(S[K-1] == 'B'){
        S[K-1] = 'b';
    }else if(S[K-1] == 'C'){
        S[K-1] = 'c';
    }

    cout << S;


	return 0;
}

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

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s = reader.readLine();
				
			int n = Integer.parseInt(s);
			String t = reader.readLine();
			String[] u = t.split(" "); 
			
			int[] m = new int[n];
			
			for (int i = 0; i < n; i++) {
				m[i] = Integer.parseInt(u[i]);
			}
			
			for (int j = n - 1; j > -1; j--) {
				System.out.print(m[j]);
				if (j != 0) {
					System.out.print(" ");
				}
			}
			System.out.println();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Measured memory_bytes: 24084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define x first
#define y second
vector<vector<char>> arr;
vector<vector<ll>> dp;
int n, m;
int main() {
    fast;
    cin>>n>>m;
    arr.resize(n);
    dp.resize(n);
    for (int i = 0; i < n; ++i) {
        arr[i].resize(m);
        dp[i].resize(m);
        for (int j = 0; j < m; ++j) {
            cin>>arr[i][j];
            dp[i][j] = 0;
        }
    }
    int temp = n;
    while(temp--)
    {
        if(arr[temp][m - 1] == '#')
            break;
        dp[temp][m - 1] = 1;
    }
    temp = m;
    while(temp--)
    {
        if(arr[n - 1][temp] == '#')
            break;
        dp[n - 1][temp] = 1;
    }
    for (int i = n - 2; i >= 0; i--) {
        for (int j = m - 2; j >= 0; j--) {
            if(arr[i][j] == '.')
                dp[i][j] = (dp[i+1][j] + dp[i][j+1]) % 1000000007;
        }
    }
    cout<<dp[0][0];
}

Measured memory_bytes: 9088
<?php
$count_employee = trim(fgets(STDIN));
$staffs = explode(" ", trim(fgets(STDIN)));
foreach($staffs as $staff){
	$boss_count[$staff]++;
}
for($i=1; $i<=$count_employee; $i++){
  if($boss_count[$i]){
    fputs(STDOUT, $boss_count[$i]."\n");
  }else{
    fputs(STDOUT, "0\n");
  }
}
?>

Measured memory_bytes: 39684
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  lvector A(n);rep(i,n) cin>>A[i];
  ll l=0,r=*max_element(ALL(A)),len,num;
  while(r-l>1) {
    len=(r+l)/2,num=0;
    for(ll a:A) num+=(a-1)/len;
    if(num<=k) r=len;else l=len;
  }
  print(r);
  return 0;
}

Measured memory_bytes: 4664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

string s1, s2;
map<char, int> cnt;

int main()
{
    int n;
    cin>>n>>s1>>s2;
    REP(i,n) {
        if (i == 0) {
            cnt[s1[0]] = 3;
            if (s1[0] == s1[1]) {
                cnt[s2[0]] = 2;
                i++;
            }
        } else {
            if (s1[i] == s2[i]) {
                cnt[s1[i]] = s1[i-1] == s2[i-1] ? 2 : 1;
            } else {
                if (s1[i-1] == s2[i-1]) {
                    cnt[s1[i]] = 2;
                    cnt[s2[i]] = 1;
                } else {
                    cnt[s1[i]] = 1;
                    cnt[s2[i]] = 3;
                }
                i++;
            }
        }
    }
    ll ans = 1ll;
    for (auto itr : cnt) {
        ans = ans * itr.second % MOD;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
#define ENDL printf("\n");
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using I = int;
using VI = V<I>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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

bool linear_search(VI a , int key){
    int n = a.size();
    rep(i ,n){
        if(a[i] == key) return true;
    }
    return false;
}

signed main(){
    int n; cin >> n;
    VI s(n);
    rep(i ,n) cin >> s[i];
    int q; cin >> q;
    VI t(q);
    rep(i ,q) cin >> t[i];
    //-----------------------------//
    int counter = 0;
    rep( i ,q) {
        if(linear_search(s ,t[i] )) ++counter;
    }
    PRINT(counter);
}


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

vvi dp;
vi s;

int rec(int l, int r) {
    if (dp[l][r] != inf) return dp[l][r];
    if (l == r) return dp[l][r] = 0;

    int res = inf;
    for (int i = l; i < r; i++) {
        chmin(res, rec(l, i) + rec(i + 1, r));
    }

    return dp[l][r] = res + s[r + 1] - s[l];
}

void solve(long long N, std::vector<long long> a) {
    dp = vvi(N + 1, vi(N + 1, inf));
    s = vi(N + 1);
    rep(i, N) s[i + 1] = s[i] + a[i];

    cout << rec(0, N - 1) << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    string x, y;
    cin >> x >> y;

    if (x > y)
        cout << ">" << endl;
    if (x < y)
        cout << "<" << endl;
    if (x == y)
        cout << "=" << endl;

    return 0;
}


Measured memory_bytes: 256
/*
Main AC Solution(map<pair<str, str>, int>)
*/

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
const int MN = 20;

mt19937 gen;
void reseed(ll seed) {
    gen = mt19937(seed);
    for (int i = 0; i < 10000; i++) {
        gen(); // skip
    }
}

ll rand_int(ll l, ll r) { //[l, r]
    using D = uniform_int_distribution<ll>;
    assert(l <= r);
    return D(l, r)(gen);
}

string rand_lower_string(int n, int up = 26) {
    string s = "";
    for (int i = 0; i < n; i++) {
        s += 'a' + rand_int(0, up-1);
    }
    return s;
}

template<class T> void myshuffle(T &v) {
    shuffle(begin(v), end(v), gen);
}
int main() {
    int n; string s;
    cin >> n >> s;
    string l = s.substr(0, n);
    string r = s.substr(n, 2*n);
    reverse(begin(r), end(r));

    map<pair<string, string>, int> mp;
    for (int f = 0; f < (1<<n); f++) {
        string x, y;
        for (int i = 0; i < n; i++) {
            if (f & (1<<i)) {
                x += l[i];
            } else {
                y += l[i];
            }
        }
        mp[make_pair(x, y)]++;
    }

    ll ans = 0;

    for (int f = 0; f < (1<<n); f++) {
        string x, y;
        for (int i = 0; i < n; i++) {
            if (f & (1<<i)) {
                x += r[i];
            } else {
                y += r[i];
            }
        }
        ans += mp[make_pair(x, y)];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 91904
#include <iostream>
#include <algorithm>
#include <string>

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

	long long ans = 9999999999;
	for (int i = 0, end = s.size() - 2; i < end; ++i)
		ans = std::min(ans, std::abs(std::stoll(s.substr(i, 3)) - 753));

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


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

int main() {
  int N;
  cin >> N;
  vector<double> x(N), y(N);
  for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

  vector<vector<double>> table(N, vector<double>(N, 0));
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      double tmp = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
      table[i][j] = tmp;
      table[j][i] = tmp;
    }
  }
  
  int route = 1;
  for (int i = 2; i <= N; i++) route *= i;

  double length = 0;
  vector<int> town;
  for (int i = 1; i <= N; i++) town.push_back(i);
  do {
    for (int i = 0; i < N - 1; i++) {
      length += table[town[i] - 1][town[i + 1] - 1];
    }
  } while (next_permutation(town.begin(), town.end()));

  printf("%.10f\n", length / route);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

	int len = (int)s.size();
	int ans = 0;
	int n = 0;
	REP(i, len){
		n *= 10;
		n += s[i] - '0';
		ans += s[i] - '0';
	}

	cout << (n % ans == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import itertools

def main():
    n = int(input())
    P=tuple(map(int,input().split()))
    Q=tuple(map(int,input().split()))

    permutations = list(itertools.permutations(range(1,n+1)))
    a = permutations.index(P)
    b = permutations.index(Q)
    print(abs(a-b))    

if __name__=="__main__":
    main()

Measured memory_bytes: 13904
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int N;
    cin >> N;
    vector<long long> A(N);
    rep(i,N) cin >> A[i];

    if (N == 2) {
        cout << max(A[0], A[1]) << endl;
        return 0;
    }

    vector< vector<long long> > dp(N, vector<long long>(3, (-1) * LINF));
    dp[0][0] = A[0];
    dp[1][1] = A[1];
    dp[2][0] = A[0] + A[2];
    dp[2][2] = A[2];
    for (int i = 3; i < N; i++) {
        dp[i][0] = dp[i - 2][0] + A[i];
        dp[i][1] = max(dp[i - 2][1] + A[i], dp[i - 3][0] + A[i]);
        dp[i][2] = max(dp[i - 2][2] + A[i], max(dp[i - 3][1] + A[i], i > 3 ? dp[i - 4][0] + A[i] : (-1) * LINF));
    }

    if (N % 2 == 0) cout << max(dp[N - 2][0], dp[N - 1][1]) << endl;
    else cout << max(dp[N - 3][0], max(dp[N - 2][1], dp[N - 1][2])) << endl;
    
    return 0;
}

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

#define ll long long
#define mx  300005
#define mod 1000000009
#define lim 10000000
#define N 18
using namespace std;
vector<pair<int,int> >seg;
int main(){
	ios_base::sync_with_stdio(false);
	int n;cin>>n;
	int a[n+5],last[25];
	memset(last,0,sizeof(last));

	for(int i=1;i<=n;i++)cin>>a[i];
	int l=0;

	for(int i=1;i<=n;i++)
	{
		int le=l;
		for(int bit=0;bit<=20;bit++)
		{
			if(a[i]>>bit & 1)
			{
				l=max(l,last[bit]);
				last[bit]=i;
			}
		}
		if(le!=l)
			seg.push_back({le+1,i-1});

	}
	seg.push_back({l+1,n});
	ll lh=seg[0].first;
	ll rh=seg[0].second;

	ll ans=(rh-lh+1)*(rh-lh+2)/2;
	ll pr=rh;

	for(int i=1;i<seg.size();i++)
	{
		ll se=seg[i].second-seg[i].first+1;
		ll in=(pr-seg[i].first)+1;
		pr=seg[i].second;
		ans+=(se+1)*se/2;
		ans-=(in+1)*in/2;
	}
	cout<<ans<<"\n";
	return 0;
}


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

using namespace std;

int main() {
  int N, ans = INT8_MAX;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
    if (A.at(i) % 2) {
      ans = 0;
      break;
    } else {
      int tmp = 0;
      while (!(A.at(i) % 2)) {
        tmp++;
        A.at(i) /= 2;
        if (tmp > ans) break;
      }
      if (tmp < ans) ans = tmp;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <utility>

using namespace std;

const int UNIONFIND_MAX = 1e6;

int par[2][UNIONFIND_MAX];

void unionfind_init(int n){
	for (int i = 0; i < n; i++){
		par[0][i] = i;
		par[1][i] = i;
	}
}

// return the root
int unionfind_root(int x, int index){
	if(par[index][x] == x){
		// x is root
		return x;
	} else {
		// compress the path
		return par[index][x] = unionfind_root(par[index][x], index);
	}
}

// check two set is the same
bool unionfind_same(int x, int y, int index){
	return unionfind_root(x, index) == unionfind_root(y, index);
}

// unite two set
void unionfind_unite(int x, int y, int index){
	x = unionfind_root(x, index);
	y = unionfind_root(y, index);
	if(x == y){
		return;
	}
	par[index][x] = y;
}

int main(){
	int N, K, L;
	cin >> N >> K >> L;

	unionfind_init(N);

	for (int i = 0; i < K; i++){
		int p, q;
		cin >> p >> q;
		p--;
		q--;
		unionfind_unite(p, q, 0);
	}
	for (int i = 0; i < L; i++){
		int r, s;
		cin >> r >> s;
		r--;
		s--;
		unionfind_unite(r, s, 1);
	}

	map<pair<int, int>, int> m;
	for (int i = 0; i < N; i++){
		m[{unionfind_root(i, 0), unionfind_root(i, 1)}]++;
	}
	for (int i = 0; i < N; i++){
		cout << m[{unionfind_root(i, 0), unionfind_root(i, 1)}] << " ";
	}
	return 0;
}


Measured memory_bytes: 16896
#define ll				long long
#define MOD				1000000007

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

typedef struct data {
	int a;
	int b;
} data;

FILE *in, *ans;
int tno;


int out(const char *s) {
#ifdef TEST
	char buf[8192];
	fgets(buf, sizeof(buf), ans);
	if (strcmp(buf, s)) {
		printf("err\n");
	}
#else
	printf(s);
#endif
	return 0;
}

int outi(int i) {
	char s[128];
	sprintf(s, "%d\n", i);
	out(s);
	return 0;
}

int outll(ll l) {
	char s[128];
	sprintf(s, "%lld\n", l);
	out(s);
	return 0;
}

int geti() {
	int i;
	fscanf(in, "%d", &i);
	return i;
}

ll getll() {
	ll l;
	fscanf(in, "%lld", &l);
	return l;
}

int getstr(char *s) {
	fscanf(in, "%s", s);
	return 0;
}

int fnc() {

	int a = geti();
	int b = geti();
	int c = geti();
	if (a < c && c < b || b < c && c < a) {
		out("Yes\n");
	}
	else {
		out("No\n");
	}

	return 0;
}

int main() {
#ifdef TEST
	for (tno = TEST_SNO; tno <= TEST_ENO; tno++) {
		char str[128];
		sprintf(str, "test%d.txt", tno);
		in = fopen(str, "r");
		sprintf(str, "ans%d.txt", tno);
		ans = fopen(str, "r");
		fnc();
		fclose(in);
		fclose(ans);
	}
	printf("end\n");
#else
	in = stdin;
	fnc();
#endif

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

template<typename T>
T gcd(T a,T b)
{
	if(a==0 || b==0)return 0;
	T r;
	while(1)
	{
		r=a%b;
		if(r==0)break;
		a=b;
		b=r;
	}
	return b;
}	

int main()
{
	int N;
	int A;
	int ans;
	
	cin >> N;
	cin >> ans;
	for(int i=0;i<N-1;i++)
	{
		cin >> A;
		ans=gcd(ans,A);
	}
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int x,sum=0,mx=0,mn=1000;
		for(int i=0;i<n;i++){
			cin>>x; sum+=x;
			if(x>mx) mx=x;
			if(x<mn) mn=x;
		}
		cout<<(sum-mn-mx)/(n-2)<<endl;
	}
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
using ll = long long int;

using namespace std;

vector<int> l;
int N, A, B, C;

int dfs(int mp, int a, int b, int c, int n) {
  int tmp = numeric_limits<int>::max() >> 1;
  if (n == (int)l.size()) {
    if ((a == 0) || (b == 0) || (c == 0)) {
      return tmp;
    } else {
      return mp + abs(A - a) + abs(B - b) + abs(C - c) - 30;
    }
  }
  tmp = min(tmp, dfs(mp + 10, a + l[n], b, c, n + 1));
  tmp = min(tmp, dfs(mp + 10, a, b + l[n], c, n + 1));
  tmp = min(tmp, dfs(mp + 10, a, b, c + l[n], n + 1));
  tmp = min(tmp, dfs(mp, a, b, c, n + 1));
  return tmp;
}

int main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  REP(i, N) cin >> l[i];
  cout << dfs(0, 0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

const int MAX_V = 10;

int d[MAX_V][MAX_V];
int V = 10;

void warshall_floyd() {
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
  }
}

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, 10) {
    rep(j, 10) {
      cin >> d[i][j];
    }
  }

  warshall_floyd();

  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      int v;
      cin >> v;
      if (v == -1) continue;
      ans += d[v][1];
    }
  }

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


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class NotDivisible {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();
            }
            Arrays.sort(nums);

            int max = nums[n - 1];
            int[] count = new int[max + 1];
            boolean[] divs = new boolean[max + 1];

            for (int i = 0; i < n; i++) {
                count[nums[i]] += 1;
                divs[nums[i]] = true;
            }

            for (int i = 0; i < n; i++) {
                int base = nums[i];
                int loop = base + base;
                while (loop <= max) {
                    divs[loop] = false;
                    loop += base;
                }
            }

            int result = 0;
            for (int i = 0; i < n; i++) {
                if (divs[nums[i]] == true && count[nums[i]] == 1) {
                    result++;
                }
            }
            out.append(String.valueOf(result));
        }

    }
}



Measured memory_bytes: 63888
use std::io;
use std::io::prelude::*;

fn d(mut n: usize) -> usize {
    let mut d = 0;
    while n > 0 {
        d += 1;
        n >>= 1;
    }
    return d;
}

fn main () {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iter.next().unwrap().parse().unwrap()).collect();

    let mut bits: usize = 0;
    for s in (0..d(k)).rev() {
        let cnt = a.iter().map(|&x| x & (1 << s) != 0).filter(|&x| x == true).count();
        if cnt <= n / 2 {
            bits += 1 << s;
            if bits > k {
                bits -= 1 << s;
            }
        }
    }
    let ans:usize = a.iter().map(|&x| x ^ bits).sum();
    println!("{}", ans);
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

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

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


Measured memory_bytes: 256
S=input()
ans="Yes"
for i in range(0,len(S),2):
    if S[i]!="R" and S[i]!="U" and S[i]!="D":
        ans="No"
for j in range(1,len(S),2):
    if S[j]!="L" and S[j]!="U" and S[j]!="D":
        ans="No"
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX = 2000 + 10;
long long arr[MAX];
int from[MAX];
int main() {
  int n;
  long long x;
  long long last = 0, ans;
  scanf("%d %lld", &n, &x);
  for(int i = 0 ; i < n ; i++){
    scanf("%lld", &arr[i]);
    last += arr[i];
    from[i] = i;
  }
  ans = last;
  for(int i = 1 ; i < n ; i++){
    last += x;
    for(int j = 0 ; j < n ; j++){
      int target = (j - i + n) % n;
      if(arr[target] < arr[from[j]]){
        last -= arr[from[j]] - arr[target];
        from[j] = target;
      }
    }
    ans = min(ans, last);
  }
  printf("%lld\n", ans);
  return 0;
}


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

using namespace std;

int my_max(int a, int b) {
    return a > b ? a : b;
}

int my_abs(int x) {
    return x < 0 ? -x : x;
}

int main() {

    double r;
    cin >> r;

    printf("%lf\n", r * 2 * 3.14159265359);

    return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(),greater<char>());
	if (s < t)
		cout << "Yes";
	else
		cout << "No";
}

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

using namespace std;

const int MD = 1000000007;

int main() {
	long long n, k; cin >> n >> k;
	long long x = n - (k - 1) + 1;
	// cout << x * (k * 3 * (k - 2 + x) + x * (x - 3) + 2) / 6 << '\n';
	/*
	n * x
	(n - 1) * x
	...
	(n - k + 1) * x
	(n - k - 0) * (x - 1) = n * x - 1n - k(x - 1) - 0x + 0 + 0
	(n - k - 1) * (x - 2) = n * x - 2n - k(x - 2) - 1x + 1 + 1
	(n - k - 2) * (x - 3) = n * x - 3n - k(x - 3) - 2x + 4 + 2
	(n - k - 3) * (x - 4) = n * x - 4n - k(x - 4) - 3x + 9 + 3
	...
	*/
	/*
	x(3nx + 6nk - 3n - 3kk + 3k - xx + 2x - 3xk + x - 2 + 3k - 3kk + 6k - 3xk - xx - 2 + 3x)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
                                        6


																				*/
	// cout << x * (3 * (n * (n + x) - (n - k) * (n - k + 1)) + (x - 1) * (-x + 2 - 3 * k)) / 6 << '\n';
	// cout << x * (3 * n * x + 6 * n * k - 3 * n - 3 * k * k + 3 * k - x * x + 2 * x - 3 * x * k + x - 2 + 3 * k - 3 * k * k + 6 * k - 3 * x * k - x * x - 2 + 3 * x) / 6 << '\n';
	cout << x * (3 * n * x + 6 * k * n - 3 * n - 6 * k * k + 12 * k - 2 * x * x + 6 * x - 6 * k * x + 2) / 6 % MD << '\n';
	// cout << x * (((x - k * (x + n - k + 2)) * 2 + n * (x - 1)) * 3 - (x * x - 5) * 2) / 6 << '\n';
	return 0;
}


Measured memory_bytes: 3616
def insertionSortForShell(lst, n, g):
    cnt = 0
    for i in range(g, n):
        v = lst[i]
        j = i - g
        while j >= 0 and lst[j] > v:
            lst[j+g] = lst[j]
            j = j - g
            cnt += 1
        lst[j+g] = v
    return cnt


def cleate_split_lst(n):
    lst = []
    while 1:
        n = int(n/2)
        if n <= 1:
                lst.append(1)
                break
        else:
                lst.append(n)
    return lst


def shellSort(lst, n):
    cnt = 0
    G = cleate_split_lst(n)

    for i in range(0, len(G)):
        cnt += insertionSortForShell(lst, n, G[i])

    print(len(G))
    print(" ".join([str(g) for g in G]))
    print(cnt)
    for n in lst:
        print(n)


if __name__ == "__main__":
    n = int(input())
    lst = []
    for i in range(0, n):
        lst.append(int(input()))
    shellSort(lst, n)

Measured memory_bytes: 47500
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;
struct Edge { int from, to; long long cost; };
using Graph = vector<vector<Edge>>;

struct Combination {
    vector<long long> fac, inv, finv;
    long long md = 0;
    Combination(int n, long long m): fac(n + 1), inv(n + 1), finv(n + 1) {
        md = m;
        fac[0] = fac[1] = 1;
        inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(int i = 2; i <= n; i++) {
            fac[i] = fac[i - 1] * i % md;
            inv[i] = md - inv[md % i] * (md / i) % md;
            finv[i] = finv[i - 1] * inv[i] % md;
        }
    }
    long long P(int n, int r) {
        if(r < 0 || n < r) return 0;
        return fac[n] * finv[n - r] % md;
    }
    long long C(int n, int r) {
        if(r < 0 || n < r) return 0;
        return fac[n] * (finv[r] * finv[n - r] % md) % md;
    }
    long long H(int n, int r) {
        if(n < 0 || r < 0) return 0;
        return (r == 0 ? 1 : C(n + r - 1, r));
    }
};

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

    int n,k;
    cin>>n>>k;
    Combination c(2020,MOD);
    cout<<c.H(k,n)<<endl;
}


Measured memory_bytes: 3256
#include <stdio.h>
#define N 100
int main(){
  int i,j,k=0,n,tmp,min,flag;
  int A[N];
  scanf("%d",&n);
  for(j=0;j<=n-1;j++){
    scanf("%d",&A[j]);
  }
  for(i=0;i<=n-1;i++){
    flag=0;
    min=i;
    for(j=i;j<=n-1;j++){
      if(A[j]<A[min]){
	min=j;
	flag=1;
      }
    }
    if(flag==1){
      tmp=A[i];
      A[i]=A[min];
      A[min]=tmp;
      k++;
    }
  }
  for(j=0;j<=n-1;j++){
    printf("%d",A[j]);
    if(j<n-1)
      printf(" ");
  }
  printf("\n");
  printf("%d\n",k);
  return 0;
}



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int res = 0;
        for (int i = 1 ; i <= N ; i++ ) {
            int sum = 0;
            int temp = i;
            while (temp > 0) {
                sum += temp % 10;
                temp /= 10;
            }
            if (sum >= A && sum <= B) {
                res += i;
            }
        }
        System.out.println(res);
    }

}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

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

	int N; cin >> N;
	vector<int> a(N, 0);
	rep (i, N) cin >> a[i];

	ll res = (ll)(a[0] - 1LL);

	int minv = 2;
	for (int i = 1; i < N; ++i){
		if (a[i] < minv) continue;

		if (a[i] == minv){
			++minv;
			continue;
		} // end if
		res += (ll)((a[i] - 1) / minv);
	} // end rep

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main(){
	int n,m,t;
	cin>>n>>m;
	int a=0;
	for(int i=0;i<m;i++){
		cin>>t;
		a+=t;
	}
	if(a>n)cout<<-1;
	else cout<<n-a;
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

int main(void){
    
	while(1){
	int H, W;
	scanf("%d %d", &H, &W);
	if(H == 0 && W == 0) break;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
		    if(i == 0 || i == H -1 || j == 0 || j == W - 1) printf("#");
			else printf(".");
		}
		printf("\n");
	}
	printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2036
#include <iostream>
using namespace std;
#define ll long long

ll dp[100001][101]={};

int main()
{
    int n,W; cin>>n>>W;
    ll w[n],v[n];
    for(int i=0;i<n;i++) cin>>w[i]>>v[i];

    for(int i=1;i<=W;i++)
    {
        for(int j=1;j<=n;j++)
        {
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            if(w[j-1]<=i){
                dp[i][j]= max(dp[i][j], v[j-1] + dp[i-w[j-1]][j-1] );
            }
        }
    }
    cout<<dp[W][n];

//    for(int i=1;i<=W;i++)
//    {
//        for(int j=1;j<=n;j++)
//        cout<<dp[i][j]<<" ";
//        cout<<endl;
//    }

    return 0;
}

Measured memory_bytes: 79104
using System;
class Hello{
static void Main(){
string [] str;
int a;
int b;

for(int i=0;;i++)
{
str=Console.ReadLine().Split(' ');
a=int.Parse(str[0]);
b=int.Parse(str[1]);
if(a==0&&b==0)break;
if(a>b)Console.WriteLine("{0} {1}",b,a);
else if(a<b)Console.WriteLine("{0} {1}",a,b);
else Console.WriteLine("{0} {1}",a,b);

}

}
}


Measured memory_bytes: 15876
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353
using namespace std;

ll R[4001];
ll G[4001];
ll B[4001];

int main() {
    

    ll n;
    string s;
    cin >> n >> s;
    ll r = 0, g = 0, b = 0;
    for(ll i=n-1;i>=0;i--){
        if(s[i] == 'R'){
            r++;
        }else if(s[i] == 'G'){
            g++;
        }else{
            b++;
        }
        R[i] = r;
        G[i] = g;
        B[i] = b;
    }
    ll ans = 0;
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<n;j++){
            if(s[i] == s[j]){
                continue;
            }
            if((s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R')){
               if(j+1<n){
                   ans += B[j+1];
               }
               if(2*j - i < n){
                   if(s[2*j-i] == 'B'){
                       ans--;
                   }
               }
            }
            if((s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G')){
                if(j+1<n){
                    ans += R[j+1];
                }
                if(2*j - i < n){
                    if(s[2*j-i] == 'R'){
                        ans--;
                    }
                }
            }
            if((s[i] == 'B' and s[j] == 'R') or (s[i] == 'R' and s[j] == 'B')){
                if(j+1<n){
                    ans += G[j+1];
                }
                if(2*j - i < n){
                    if(s[2*j-i] == 'G'){
                        ans--;
                    }
                }
            }

        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3640
integer N
integer,allocatable,dimension(:,:)::A
integer,allocatable,dimension(:)::B,Anum
integer aite
logical nogame
read*,N
allocate(A(N,N-1),B(N),Anum(N))
Anum=1
do i=1,N
  read*,A(i,:)
end do
do i=1,N*N
  nogame=.true.
  B=0
  do j=1,N
    if(B(j)==0.and.Anum(J)/=N)then
      aite=A(J,Anum(J))
      if(A(aite,Anum(aite))==J.and.B(aite)==0)then
        Anum(j)=Anum(j)+1
        Anum(aite)=Anum(aite)+1
        nogame=.false.
        B(j)=1;B(aite)=1
      endif
    endif
  end do
  if(minval(Anum)==N)then
    print"(i0)",i
    stop
  endif
  if(nogame)then
    print"(i0)",-1
    stop
  endif
end do
end

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
double N,K,c=1,n;
int main(){
	cin>>N;
	cin>>K;
	for(n=0;n<N;n++){
		if(c<K){
			c=c*2;
		}
		else{
			c=c+K;
		}
	}
	cout<<c<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	while (cin>>n)
	{
		int a[n];
		for (int i=0;i<n;i++)
			cin>>a[i];
		double s=1,x=0;
		for (int i=0;i<n;i++)
//			x+=a[i];
			x+=(1.0/a[i]);
//		for (int i=0;i<n;i++)
//		{
//			s*=a[i];
////			x+=a[i];
//			while (s%2==0&&x%2==0)
//			{
//				s/=2;
//				x/=2;		
//			} 
//		}
//		cout<<s<<" "<<x<<endl;
		cout<<1/x<<endl;
			
	}
	
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>pi;
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vouble vector<double>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mis map<int,str>
#define msi map<str,int>
#define mid map<int,double>
#define mod 100000007
#define elif else if
#define str string
int digitsum(int a){
  int b=0;
  while(a){
    b+=a%10;
    a/=10;
  }
  return b;
}
signed main(){
  int n,k,m,c=0,c2=0;
  string S,t;
  char C;
  double d;
  cin>>n>>k;
  int a[n]={};
  rep(0,k){
    cin>>m;
    REP(0,m){
      cin>>c2;
      a[c2-1]++;
    }
  }
  rep(0,n)if(a[i]==0)c++;
  cout<<c<<endl;
}


Measured memory_bytes: 3624
w,h,n=map(int,input().split())
li=[[0 for i in range(w)] for j in range(h)]

for i in range(n):
    x,y,a=map(int,input().split())

    for j in range(h): #縦(y)
        for k in range(w): #横(x)
        
            if a==1:
                if k<x:
                    li[j][k]=1
            elif a==2:
                if k>=x:
                    li[j][k]=1
            elif a==3:
                if j<y:
                    li[j][k]=1
            else:
                if j>=y:
                    li[j][k]=1

ans=0
for tm in li:
    ans+=tm.count(0)

print(ans)
                

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#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;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m, k;std::cin >> n >> m >> k;
  vll a(n), b(m);
  re(i, n) std::cin >> a[i];
  re(i, m) std::cin >> b[i];

  for(int i=1;i<n;i++) a[i] += a[i-1];
  for(int i=1;i<m;i++) b[i] += b[i-1];
  ll ans = 0;

  for(int i=0;i<=n;i++){
    if(i!=0&&a[i-1]>k) break;
    ll l = 0, r = m+1;
    while(r-l>1){
      ll mid = (l+r)/2;
      if(b[mid-1]+(i==0?0:a[i-1])>k) r = mid;
      else l = mid;
    }
    ans = max(ans, i+l);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 5988
program vjudge149349E;
const maxn=300000+10;
      maxm=100000+10;
var l,r,next:array[0..maxn] of longint;
    last,ans,bits:array[0..maxm] of longint;
    n,m,i,j:longint;
function ask(x:longint):longint;
var ans:longint;
begin
  ans:=0;
  while x>0 do
  begin
    ans:=ans+bits[x];
    x:=x-x and (-x);
  end;
  exit(ans);
end;
procedure add(x,d:longint);
begin
  while(x<=m+1) do
  begin
    bits[x]:=bits[x]+d;
    x:=x+x and (-x);
  end;
end;
begin
  readln(n,m);
  fillchar(last,sizeof(last),0);
  for i:=1 to n do
  begin
    readln(l[i],r[i]);
    next[i]:=last[r[i]-l[i]+1];
    last[r[i]-l[i]+1]:=i;
    inc(ans[1]);
    dec(ans[r[i]-l[i]+2]);
  end;
  for i:=1 to m do ans[i]:=ans[i]+ans[i-1];
  fillchar(bits,sizeof(bits),0);
  for i:=1 to m do
  begin
    ans[i]:=ans[i]+bits[1];
    for j:=1 to m div i do
      ans[i]:=ans[i]+ask(j*i+1);
    j:=last[i];
    while j>0 do
    begin
      add(l[j]+1,1);
      add(r[j]+2,-1);
      j:=next[j];
    end;
  end;
  for i:=1 to m do writeln(ans[i]);
end.


Measured memory_bytes: 5504
#include "bits/stdc++.h"
    using namespace std;
     
     
    int n;
    int m;
     
     
    vector<int> v[802];
     
     
    vector<int> g[802];
     
    int ng[802];
    int us;
     
    vector<int> lb[2];
    bool use[820];
    bool zz[820];
    inline void dfs(int b, int fl) {
    	use[b] = true;
    	zz[b] = fl;
    	lb[fl].push_back(b);
    	for (int go : g[b]) {
    		if (use[go] == false) {
    			dfs(go, fl ^ true);
    		}
    		else {
    			if (zz[go] == fl) {
    				puts("-1");
    				exit(0);
    			}
    		}
    	}
    }
    vector < pair < vector<int>, vector<int> > > V;
    vector<int> vv[2];
    bool con[1002][1002];
    int be[820];
     
    bool dp[1000][1000];
    int pr[1000][1000];
     
    int main() {
    	cin >> n >> m;
    	for (int i = 0; i < m; i++) {
    		int a, b;
    		scanf("%d%d", &a, &b);
    		a--;
    		b--;
    		v[a].push_back(b);
    		v[b].push_back(a);
    		con[a][b] = true;
    	}
    	for (int i = 0; i < n; i++) {
    		us++;
    		for (int go : v[i]) {
    			ng[go] = us;
    		}
    		for (int j = 0; j < n; j++) {
    			if (ng[j] != us) {
    				if (i == j)continue;
    				g[i].push_back(j);
    			}
    		}
    	}
    	for (int i = 0; i < n; i++) {
    		if (use[i] == false) {
    			dfs(i,false);
    			V.push_back(make_pair(lb[0], lb[1]));
    			lb[0].clear();
    			lb[1].clear();
    		}
    	}
    	dp[0][0] = true;
    	for (int i = 0; i < V.size(); i++) {
    		for (int j = 0; j < 810; j++) {
    			if (dp[i][j]) {
    				dp[i + 1][j + V[i].first.size()] = true;
    				dp[i + 1][j + V[i].second.size()] = true;
    				pr[i + 1][j + V[i].second.size()] = true;
    			}
    		}
    	}
    	int mint = INT_MAX;
    	int pos = -1;
    	for (int j = 0; j < 810; j++) {
    		if (dp[V.size()][j]) {
    			int a = j;
    			int b = n - j;
    			int z = a*(a - 1) / 2 + b*(b - 1) / 2;
    			mint = min(mint, z);
    		}
    	}
    	cout << mint << endl;
    	return 0;	return 0;
    }


Measured memory_bytes: 8704
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	int N;
	int[] C,S,F;

	private void solve(){
		N = nextInt();
		C = new int[N];
		S = new int[N];
		F = new int[N];
		for(int i = 0;i < N-1;i++) {
			C[i] = nextInt();
			S[i] = nextInt();
			F[i] = nextInt();
		}

		for(int i = 0;i < N - 1;i++) {
			int ans = S[i];
			for(int j = i;j < N - 1;j++) {
				if (ans <= S[j]) {
					ans = S[j];
				}
				if (ans % F[j] != 0) {
					ans += F[j] - ans % F[j];
				}
				ans += C[j];
			}

			out.println(ans);
		}

		out.println(0);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	private boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	private String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	private long nextLong() {
		return Long.parseLong(next());
	}

	private double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> que;
    for(int i=0; i<N; ++i) {
        int a; cin >> a;
        que.push(a);
    }

    while(M--) {
        int price = que.top();
        que.pop();
        que.push(price / 2);
    }

    long long res = 0;
    for(int i=0; i<N; ++i) {
        res += que.top();
        que.pop();
    }
    cout << res << endl;
}

Measured memory_bytes: 892
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int, int);

int main()
{
  int i,q;

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

  q = partition(0, n-1);

  for(i = 0; i < n; i++){
    if(i > 0)printf(" ");
    if(i == q)printf("[");
    printf("%d",A[i]);
    if(i == q)
      printf("]");
  }
  printf("\n");
  
  return 0;
}

int partition(int p, int r)
{
  int x,i,j,t;

  x = A[r];
  i = p-1;

  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}



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

int main()
{
	while (true){
		int n;
		cin >> n;
		if (!n) break;
		for (int i = 0; i < n; i++){
			int pm, pe, pj;
			cin >> pm >> pe >> pj;
			if (pm == 100 || pe == 100 || pj == 100 || (pm + pe) / 2 >= 90 || (pm + pe + pj) / 3 >= 80) cout << "A" << endl;
			else if ((pm + pe + pj) / 3 >= 70 || ((pm + pe + pj) / 3 >= 50) && (pm >= 80 || pe >= 80)) cout << "B" << endl;
			else cout << "C" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

int main()
{
    string s;
    
    cin >> s;
    
    bool isEven = s.length() % 2 == 0;
    bool isSame = s[0] == s[s.length() - 1];
    
    // XOR
    if (isEven != isSame)
    {
        printf("Second\n");
    }
    else
    {
        printf("First\n");
    }
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e16;
typedef long long ll;
ll mod = 1e9+7;
long double fast_exp(long double a, long long b)
{
    if(b == 0)
	   return 1;
    else
    {
	   long double res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res);
	   if(b%2 == 1)
		  res = (res*a);
	   return res;
 
    }
}
const int N = 1e5+10;
map <pair<int,int>, int> edgecol;
vector<int> edge[N];
void dfs_assign(int v, int par , int forb)
{
	int curcol = 1;
	for(auto e: edge[v])
	{
		if(e!=par)
		{
			
				if(forb == curcol)
					curcol++;
			
				int v1 = v , v2 = e;
				if(v1<v2)
					swap(v1,v2);
				edgecol[mp(v1,v2)] = curcol;
				dfs_assign(e,v,curcol);
			curcol++;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,a,b;
	cin>>n;
	vector<pair<int,int>> ed;
	for(int i =0; i<n-1 ; i++)
	{
		cin>>a>>b;
		if(a<b)
			swap(a,b);
		edge[b].pb(a);
		edge[a].pb(b);

		ed.pb(mp(a,b));
	}
	int k = 0;
	for(int i = 1 ; i<=n ; i++)
	{
		k = max(k,(int)edge[i].size());
	}
	dfs_assign(1,-1,-1);
	cout<<k<<endl;
	for(auto e: ed)
		cout<<edgecol[e]<<endl;

	return 0;
	
}

Measured memory_bytes: 14076
s = gets.to_i
fn, i = s, 1
if s == 4 || s== 2 || s== 1
  puts 4
  exit
end
arr = [fn]
loop do
  if arr[i-1] % 2 == 0
    arr << arr[i-1]/2
  else
    arr << 3*(arr[i-1])+1
  end
  if arr[i] == 4 || arr[i] == 2 || arr[i] == 1
    puts i+4
    break
  end
  i+=1
end

Measured memory_bytes: 3836
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
char r[600][600],b[600][600],a[600][600];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i+=2)
    	for(int j=1;j<=m;j++)
    		r[i][j]='#';
    for(int i=2;i<=n;i+=2)
    	for(int j=1;j<=m;j++)
    	{
			r[i][j]='.';
    	}
    for(int i=2;i<=n;i+=2)
    	for(int j=1;j<=m;j++)
    		b[i][j]='#';
    for(int i=1;i<=n;i+=2)
    	for(int j=1;j<=m;j++)
    	{
			b[i][j]='.';
    	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char cur;
			cin>>cur;
			if(cur=='#')
			{
				r[i][j]='#';
				b[i][j]='#';
			}
		}
	}
	for(int i=1;i<=n;i++)
		r[i][1]='#',b[i][1]='.';
	for(int i=1;i<=n;i++)
	    r[i][m]='.',b[i][m]='#';
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		  cout<<r[i][j];
		cout<<endl;
	}
	cout<<endl;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		  cout<<b[i][j];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
           

            while (true)
            {
                string[] s = Console.ReadLine().Split(' ');

                int x = int.Parse(s[0]);
                int y = int.Parse(s[1]);

                if (x == 0 && y == 0)
                { break; }
               
                if (x > y) 
                {
                    Console.WriteLine(y+" "+x);

                }
            else 
                {
                    Console.WriteLine(x+" "+y);
                }
            

            }
        }
    }
}

Measured memory_bytes: 5836
#include <iostream>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;

    bool flag = false;
    for (int i = 1; i <= b; ++i)
    {
        if (a * i % b == c)
        {
            flag = true;
            break;
        }
    }

    if (flag)
    {
        std::cout << "YES";
    }
    else
    {
        std::cout << "NO";
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
	string s1,s2;
	int s=0;
	while(getline(cin,s1)){
		getline(cin,s2);
		for(int i=0;i<s1.size();i++){
			if(s1[i]!=s2[i]) s++;
		}
		cout<<s<<endl;	
		s=0;
	}
	return 0;
}

Measured memory_bytes: 3892