akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector< vector<int> > table;
int main()
{
    int n,W;
    cin>>n>>W;
    vector<int> v(n+1),w(n+1);
    table dp(n+1,vector<int>(W+1));
    for (int i = 1; i < n+1; i++) cin>>v[i]>>w[i];
    v[0]=w[0]=0;

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

    return 0;
}


Measured memory_bytes: 6836
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>

int main() {
    ll N, Y;
    cin >> N >> Y;

    bool b = false;
    rep(i,N+1){
        rep(j,N - i + 1){
                if(!b && 10 * i + 5 * j + (N - i - j) == Y / 1000){
                    b = true;
                    cout << i << " " << j << " " << N - i - j << endl;
            }
        }
    }
    if(!b){
        cout << "-1 -1 -1" << endl;
    }
}

Measured memory_bytes: 3604
use proconio::input;

fn main() {
    input! {
        n: i64,
    }

    let primes = prime_sieve(n as usize);

    let mut v = vec![1i64; n as usize + 1];
    for p in primes {
        for i in 1.. {
            let a = p * i;
            if a > n {
                break;
            }

            let mut b = a;
            let mut count = 0;
            while b % p == 0 {
                count += 1;
                b /= p;
            }
            v[a as usize] *= count + 1;
        }
    }

    // dbg!(&v);

    let mut ans = 0;
    for i in 1..=n {
        ans += i * v[i as usize];
    }
    println!("{}", ans);
}

fn prime_sieve(n: usize) -> Vec<i64> {
    let mut table: Vec<i64> = vec![0; n + 1];
    let mut primes: Vec<i64> = Vec::new();

    for i in 2..=n {
        if table[i] == 0 {
            primes.push(i as i64);
            for j in 2..n {
                if i * j > n {
                    break
                }
                table[i * j] = 1
            }
        }
    }

    primes
}


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

int main()
{
  int ant[5];
  for(int i = 0; i < 5; i++)
  {
    cin >> ant[i];
  }
  int k;
  cin >> k;
  int J = 1;
  for(int j = 0; j < 4; j++)
  {
    for(int l = 1; l < 5; l++)
    {
      if(ant[l] - ant[j] > k)
      {
        J = 0;
      }
    }
  }
  if(J)
  {
    cout << "Yay!";
  }
  else
  {
    cout << ":(";
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256
function main(lines) {
    const input = lines.split('\n')
    const K = input[0]-0
    const S = input[1].split('')
    
    if(S.length <= K){
        console.log(S.join(''))
    } else {
        S.splice(K)
        console.log(S.join('') + '...')
    }
    
}

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


Measured memory_bytes: 29588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
int a,b,c,x,y;
cin>>a>>b>>c>>x>>y;
if(a+b<=2*c)cout<<x*a+y*b;
else {
    int ans=min(x,y)*2*c;
    int aa=min(x,y);
    x-=aa;y-=aa;
    if(x>0){
        if(a<2*c)ans+=x*a;
        else ans+=2*c*x;
    }
    if(y>0){
        if(b<2*c)ans+=y*b;
        else ans+=2*c*y;
    }
    cout<<ans;
}

}

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

int main() {
	// your code goes here
            string s;
            cin>>s;
            string ss="CF";
            int j=0;
            int clock=0;
            for(int i=0;i<s.length();i++){
            	if(s[i]==ss[j]){
            		clock++;
            		j++;
            	}
            }
            if(clock>=2) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

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

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            String input = br.readLine();
            List<String> splitNumberString = Arrays.asList(input.split(""));
            int targetNumber = Integer.parseInt(input);
            int fX = 0;
            for (String str : splitNumberString) {
                fX += Integer.parseInt(str);
            }

            String ans = "No";
            if (targetNumber % fX == 0) {
                ans = "Yes";
            }

            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;


int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n) cin>>a[i];
    int ans = 0;

    rep(i,n){
        bool jud = true;
        if ((i+1)%2 == 0) jud = false;
        if (a[i]%2 == 0) jud = false;
        if (jud == true) ans++;
    }
    cout << ans;
}

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


int main() {
  
  long long a, b, c;
  cin >> a >> b >> c;
  
  long long x;
  x =c-a-b;
  
  if(x<=0){
    cout << "No" << endl;
  }
  
  else if(x*x<=4*a*b){
    cout << "No" << endl;
  }
  
  else {
    cout << "Yes" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3596
n,m=int(input()),list(map(int,input().split()))
m.sort()
c=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if m[i]+m[j]>m[k]:
                if m[i]!=m[j] and m[i]!=m[k] and m[j]!=m[k]:
                    c+=1
            else:
                break
print(c)

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;

const LL MOD = 1000000007;

const int DEG = 2100;
const int BASE = 4100;

void add(LL &x, LL y){
	x += y;
	if(x >= MOD){ x -= MOD; }
}

LL powmod(LL x, LL y){
	LL a = 1;
	while(y){
		if(y & 1){ a = a * x % MOD; }
		x = x * x % MOD;
		y >>= 1;
	}
	return a;
}

LL invs[DEG + 1];

void solve(int n, int m){
	vector<vector<pii>> G(n);
	for(int i = 0; i < m; ++i){
		int s, t, d;
		cin >> s >> t >> d;
		G[s - 1].emplace_back(t - 1, d);
	}

	vector<vector<LL>> cnts(n, vector<LL>(BASE + DEG + 1));
	cnts[0][0] = 1;
	for(int u = 0; u < n; ++u){
		auto &from = cnts[u];
		for(int i = 0; i < BASE + DEG; ++i){
			add(from[i + 1], from[i]);
		}
		for(const auto &p : G[u]){
			auto &to = cnts[p.first];
			for(int i = 0; i + p.second <= BASE + DEG; ++i){
				add(to[i + p.second], from[i]);
			}
		}
	}

	vector<LL> ltmul(DEG + 2), rtmul(DEG + 2);
	int q;
	cin >> q;
	for(int qnum = 0; qnum < q; ++qnum){
		int e;
		LL t;
		cin >> e >> t;
		--e;

		LL res = 0;
		if(t <= BASE + DEG){
			res = cnts[e][t];
		}
		else{
			LL s = (t - BASE) % MOD;
			ltmul[0] = 1;
			for(int i = 0; i <= DEG; ++i){
				ltmul[i + 1] = ltmul[i] * (s - i) % MOD;
			}
			rtmul.back() = 1;
			for(int i = DEG; i >= 0; --i){
				rtmul[i] = rtmul[i + 1] * (s - i) % MOD;
			}
			for(int i = 0; i <= DEG; ++i){
				LL x = ltmul[i] * rtmul[i + 1] % MOD * invs[i] % MOD;
				res = (res + x * cnts[e][i + BASE]) % MOD;
			}
		}
		
		res = (res % MOD + MOD) % MOD;
		cout << res << '\n';
	}
}

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

	LL f = 1;
	for(int i = 1; i <= DEG; ++i){
		f = f * -i % MOD;
	}
	for(int i = 0; i <= DEG; ++i){
		invs[i] = powmod(f, MOD - 2);
		f = f * (i + 1) % MOD;
		f = f * powmod(i - DEG, MOD - 2) % MOD;
	}

	int n, m;
	while(cin >> n >> m && n){
		solve(n, m);
	}
}



Measured memory_bytes: 100020
list = (2..55555).to_a
prime = []
sqrt = Math.sqrt(55555).floor

while val = list.shift
  prime << val
  break if val > sqrt
  list.delete_if{|i| i%val == 0}
end
prime = prime.concat(list)

prime.delete_if{|i| i%5 != 1}

n = gets.chomp.to_i
printf("%s\n",prime[0,n].join(" "))

Measured memory_bytes: 2556
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int [] s = new int[n];
		long d = 0;
		for(int i = 0;i < n;i ++) {
			s[i] = in.nextInt();
			s[i] -= i + 1;
		}
		Arrays.sort(s);
		for(int i = 0;i < n;i ++) {
			d += Math.abs(s[i] - s[n / 2]);
		}
		System.out.println(d);
	}
}


Measured memory_bytes: 87732
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  ll a,b,x;
  cin >> a >> b >> x;

  ll s;
  if(a==0) s = 0;
  else s = (a - 1) / x + 1;

  ll t = b / x + 1;

  cout << t - s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <string>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  ll a[LIMIT2]={0};
  std::map<ll,ll> dp[LIMIT1];
  char s[LIMIT1];
  
  scanf("%lld",&n);
  rep(i,n) scanf("%lld",&a[i]);
  
  dp[0][0]=0;
  dp[1][0]=0;
  dp[1][1]=a[0];
  for(i=2;i<=n;i++){
    dp[i][(i/2)-1]=max(dp[i-1][(i/2)-1],dp[i-2][(i/2)-2]+a[i-1]);
    dp[i][(i/2)]=max(dp[i-1][(i/2)],dp[i-2][(i/2)-1]+a[i-1]);
    dp[i][(i/2)+1]=dp[i-2][(i/2)]+a[i-1];
  }
  result = dp[n][n/2];
  printf("%lld",result);
  
  return 0;
}



Measured memory_bytes: 54072
def solve(n, y):
    for a in range(n + 1):
        for b in range(n - a + 1):
            if a * 10 + b * 5 + (n - a - b) == y / 1000:
                print("{} {} {}".format(a, b, n - a - b))
                return

    print("-1 -1 -1")
    return

n, y = map(int, input().split())
solve(n, y)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;


void solve(){
	string s; cin>>s;
	bool f=true;
	rep(i, s.size()/2){
		if(s[i]!=s[s.size()-1-i]) f=false;
	}
	string k;
	k=s.substr(0,s.size()/2);
	rep(i, k.size()/2){
		if(k[i]!=k[k.size()-1-i]) f=false;
	}
	k=s.substr(s.size()/2+1,s.size()/2);
	rep(i, k.size()/2){
		if(k[i]!=k[k.size()-1-i]) f=false;
	}
	if(f) cout<<"Yes";
	else cout<<"No";

}

int main(){
	fast_io
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

Measured memory_bytes: 380
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}


void main() {
    int n;
    R(n);
    LL ans=0;
    REP(i,n) ans+=(LL)(i+1)*(n-i);
    REP(i,n-1) {
        int u,v;
        R(u,v);
        --u; --v;
        if ( u>v ) swap(u,v);
        ans-=(LL)(u+1)*(n-v);
    }
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

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

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back

int main()
{
    int n; cin >> n;
    vector<int> w(n);

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

    int mid = sum / 2;
    int current = 0, mx = 0;
    while(current < mid)
    {
        current = current + w[mx];
        mx++;
    }
    mx = mx - 1;
    int res = min(abs(current - (sum - current)), abs((current - w[mx]) - (sum - current + w[mx])));
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
struct cg
	{
		int num;
		string s;//city
		int p;//point
	};
	cg t[107];
	int N;
void swap(cg*a,cg*b)
{
	cg t=*a;
	*a=*b;
	*b=t;
}
void bubble_sort()
{
	for(int m=N-1;m>=0;m--)
	{
		int flag=0;
		for(int i=1;i<=m;i++)
		{
			if(t[i].s>t[i+1].s)
			{
				swap(&t[i],&t[i+1]);
				flag=1;
				//break;
			}
			else if(t[i].s==t[i+1].s)
			{
				if(t[i].p<t[i+1].p)
				{
					swap(&t[i],&t[i+1]);
					flag=1;
					//break;
				}
			}
		}
		if(flag==0)
			break;
	}	
	return;
}
int main(){
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>t[i].s>>t[i].p;
		t[i].num=i;
	}
	bubble_sort();
	for(int i=1;i<=N;i++)
	{
		cout<<t[i].num<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXH 1000000001
#define MAXW 1000000007
#define INF 1000000007
#define MAXN 200001
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main(){
    char A[15], B[15];
    char op;
    scanf("%s %c %s", A, &op, B);

    if(op == '+'){
        ll anum = atoi(A);
        ll bnum = atoi(B);
        printf("%lld\n", anum + bnum);
    }else{
        ll anum = atoi(A);
        ll bnum = atoi(B);
        printf("%lld\n", anum - bnum);
    }

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	bool ans = true;
	for (int i = s.length(); i > 0;)
	{
		if (i - 7 >= 0)
		{
			if (s.substr(i - 7, 7) == "dreamer")
			{
				i -= 7;
				continue;
			}
		}
		if (i - 6 >= 0)
		{
			if (s.substr(i - 6, 6) == "eraser")
			{
				i -= 6;
				continue;
			}
		}

		if (i - 5 >= 0)
		{
			if (s.substr(i - 5, 5) == "dream" || s.substr(i - 5, 5) == "erase")
			{
				i -= 5;
				continue;
			}
		}


		ans = false;
		break;
	}

	cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll idx = 2;

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for(ll r = 2; r * r <= n; r++) {
        idx = r;
        while(n % r == 0) {
            res[r]++;
            n /= r;
        }
    }
    if(n != 1) res[n] = 1;
    return(res);
}

int main(void) {
    ll num; cin >> num;
    map<ll, ll> prime = prime_factor(num);
    cout << num << ": ";
    map<ll, ll>::iterator ite;
    map<ll, ll>::iterator temp;
    for(ite = prime.begin(); ite != prime.end(); ite++) {
        for(int r = 0; r < ite->second; r++) {
            cout << ite->first;
            temp = ite; temp++;
            if(temp != prime.end() || r != ite->second - 1) cout << " ";
        }
    }
    
    cout << endl;
    return(0);
}

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

int n, m, q;
int a[55], b[55], c[55], d[55];
ll ans = 0;
int v[15];

void dfs(int i){
	if(i==n){
		ll now = 0;
		for(int j=0;j<q;j++){
			if(v[b[j]]-v[a[j]]==c[j]){
				now += d[j];
			}
		}
		ans = max(ans, now);
		return;
	}
	int w = 1;
	if(i!=0) w = v[i-1];
	for(int j=w;j<=m;j++){
		v[i] = j;
		dfs(i+1);
	}
}

int main() {
	cin >> n >> m >> q;
	for(int i=0;i<q;i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
N = int(input())
S = input()

tmp = ""

first_indexes = []
last_indexes = []
rev_S = list(reversed(S))
for i in range(10):
    try:
        first_indexes.append(S.index(str(i)))
        last_indexes.append(N-1-rev_S.index(str(i)))
    except ValueError:
        first_indexes.append(N+1)
        last_indexes.append(-1)

ans = 0
for i in first_indexes:
    if N<i:
        continue
    for j in last_indexes:
        if j<0:
            continue
        for k in range(10):
            for p in range(i+1,j):
                if S[p] == str(k):
                    ans += 1
                    break

print(ans)       

Measured memory_bytes: 3316
n = int(input())
s = input()

m = 0
for i in range(1, n):
    sub1 = set(s[:i])
    sub2 = set(s[i:])
    count = 0
    for c in sub1:
        if c in sub2:
            count += 1
    if m < count:
        m = count


print(m)


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<iomanip>
#include <utility>

using namespace std;

//using Point = pair<double,double>;

void koch(int n,pair<double,double> P1,pair<double,double> P2)
{
    if(n==0) return;
    double th = M_PI * 60 / 180;
    double s_x = P1.first * 2 / 3 + P2.first * 1 / 3;
    double s_y = P1.second * 2 /3 + P2.second * 1 / 3;
    double t_x = P1.first * 1 / 3 + P2.first * 2 / 3;
    double t_y = P1.second * 1 / 3 + P2.second * 2 / 3;
    double u_x = (t_x - s_x) *cos(th) - (t_y - s_y) * sin(th) + s_x;
    double u_y = (t_x - s_x) *sin(th) + (t_y - s_y) * cos(th) + s_y;

    pair<double,double> S = make_pair(s_x,s_y);
    pair<double,double> T = make_pair(t_x,t_y);
    pair<double,double> U = make_pair(u_x,u_y);

    koch(n-1,P1,S);
    cout << S.first << " " << S.second <<endl;
    koch(n-1,S,U);
    cout << U.first << " " << U.second << endl;
    koch(n-1,U,T);
    cout << T.first << " " << T.second << endl;
    koch(n-1,T,P2); 
}
int main()
{
    int n;cin >>n;
    
    pair<double,double>P1 = make_pair(0.0,0.0);
    pair<double,double>P2 = make_pair(100.0,0.0);
    cout<<fixed;
    cout << setprecision(8);

    cout << P1.first << " " <<P1.second <<endl;
    koch(n,P1,P2);
    cout << P2.first << " " << P2.second<<endl;
    return 0;
    
}


Measured memory_bytes: 3240
import numpy as np
d=int(input())
c=[0]+[int(j)for j in input().split()]
s=[[0]+[int(j)for j in input().split()]for i in range(d)]
t=[int(input())for i in range(d)]
l=[0]*27
ans=0
for i,j in enumerate(t,1):
    ans+=s[i-1][j]
    l[j]=i
    for k in range(1,27):
        ans-=(i-l[k])*c[k]
    print(ans)

Measured memory_bytes: 27436
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll D;
	cin >> D;

	ll N = 26;
	vector <ll> c(N);
	for (ll ii = 0; ii < N; ++ii){
		cin >> c[ii];
	}
	vector<vector<ll>> s(D, vector <ll> (N));
	for (ll ii = 0; ii < D; ++ii){
		for (ll jj = 0; jj < N; ++jj){
			cin >> s[ii][jj];
		}
	}

	//貪欲法
	vector <int> ans(D, 0);
	vector <int> last(N, -1);
	vector < set<int> > select(N);
	for (int ii = 0; ii < N; ++ii){
		select[ii].insert(-1);
	}
	for (ll d = 0; d < D; ++d){
		//d日目の最適解を選ぶ
		ll val = 0;
		ll idx = 0;
		for (int ii = 0; ii < N; ++ii){
			ll tmp = s[d][ii] + c[ii]*(d - last[ii]);
			if (tmp > val){
				val = tmp;
				idx = ii;
			}
		}
		ans[d] = idx;
		last[idx] = d;
		select[idx].insert(d);
	}

	//ランダムに値を変更する
	// int trial = 100;
	int trial = 1801001;
	for (int t = 0; t < trial; ++t){
		int d = rand() % D;
		int prevType = ans[d];
		int newType = rand() % N;
		while(prevType == newType) {
			newType = rand() % N;
		}
		ll dif = s[d][newType] - s[d][prevType];

		auto nitr = upper_bound(select[newType].begin(), select[newType].end(), d);
		ll newDist = (nitr != select[newType].end()) ? (*nitr - d) : (D - d);
		ll newVal = d - *(--nitr);
		dif += newVal * newDist;

		auto pitr = upper_bound(select[prevType].begin(), select[prevType].end(), d);
		ll prevDist = (pitr != select[prevType].end()) ? (*pitr - d) : (D - d);
		ll prevVal = d - *(--pitr);
		dif -= prevVal * prevDist;

		if (dif > 0){
			select[prevType].erase(d);
			select[newType].insert(d);
			ans[d] = newType;
		}
	}


	for (ll d = 0; d < D; ++d){
		cout << ans[d] + 1 << "\n";
	}

	return 0;
}


Measured memory_bytes: 3752
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main{
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    int l = sc.nextInt() - 1;
    int r = sc.nextInt();
    int d = sc.nextInt();

    System.out.println(r/d - l/d);

    





}
}

Measured memory_bytes: 35488
from collections import defaultdict

N = int(input())
S=[input() for _ in range(N)]
D = defaultdict(int)
for s in S:
    D[s]+=1

max_val = max(D.values())
D = sorted(D.items(),key=lambda x:(-x[1],x[0]))
for key,val in D:
    if val==max_val:
        print(key)
    else:
        exit()


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n;
    while (cin >> n, n) {
        vi s(n);
        REP(i, n) cin >> s[i];
        auto minmax = minmax_element(ALL(s));
        cout << (accumulate(ALL(s), 0) - *minmax.first - *minmax.second) / (n-2) << endl;
    }
}

Measured memory_bytes: 3036
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import Control.Monad
import Control.Monad.ST
import Control.Applicative


main :: IO ()
main = do
  n <- read <$> getLine
  ls <- VU.unfoldrN n (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  print $ binSearch 0 n ls

binSearch :: Int -> Int -> VU.Vector Int -> Int
binSearch ng ok ls | ok - ng <= 1 = ok
binSearch ng ok ls =
  if isPossibleWith mid ls then
    binSearch ng mid ls
  else
    binSearch mid ok ls
  where
    mid = (ng + ok) `shiftR` 1


isPossibleWith :: Int -> VU.Vector Int -> Bool
isPossibleWith 1 ls = VU.and $ VU.zipWith (<) ls (VU.tail ls)
isPossibleWith numChars ls
  = VU.foldr loop (\_ _ -> True) ls 0 Nil
  where
    loop !reqLen cont wordLen charList
      | reqLen > wordLen = cont reqLen charList
      | otherwise = loop1 (cont reqLen)
                    (cutOff charList reqLen) (reqLen - 1)
    loop1 _ !xs ind | ind < 0 = False
    loop1 cont xs@(Snoc xs' i e) ind = case compare i ind of
      LT -> cont $! Snoc xs ind 1
      EQ | e < numChars - 1 -> cont $! Snoc xs' i (e+1)
         | otherwise        -> loop1 cont xs' (ind-1)
    loop1 cont Nil ind = cont $! Snoc Nil ind 1

data List = Nil | Snoc !List {-# UNPACK #-} !Int {-# UNPACK #-} !Int
 deriving Show


cutOff :: List -> Int -> List
cutOff (Snoc xs i e) till | till <= i = cutOff xs till
cutOff xs !till = xs


Measured memory_bytes: 7036
//??¨??????????????????

#include <cstdio>
#include <iostream>
using namespace std;

int f(int n, int k){
	if(n==1) return 0;	
	return (f(n-1,k)+k)%n;
}

int main(){
	while(1){
		int n, k, m;
		scanf(" %d %d %d", &n, &k, &m);
		if(n==0) break;
			
		printf("%d\n", (f(n-1,k)+m)%n+1);
	}
}

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

using namespace std;

int main(void)
{
    int N, K;
    int h;

    cin >> N >> K;

    int c = 0;
    for (int i = 0; i < N; i++) {
        cin >> h;
        if (h >= K) c++;
    }
    
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
public class Main{
/// functions
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
// end
static long[] f;
// taking inputs
static BufferedReader s;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
// ends
//......................................@uthor_Alx..............................................
static boolean check(String s){
	int i=0,j=s.length()-1;
	while(i<j){
		if(s.charAt(i)!=s.charAt(j)){return false;}
		i++;j--;
	}
	return true;
}
public static void main(String[] args) throws  IOException{
       assign();
       String ss=read();
       boolean b1=check(ss);
       int n=ss.length();
       boolean b2=check(ss.substring(0,(n-1)/2));
       boolean b3=check(ss.substring((n-1)/2+1));
       //out.write(ss.substring(0,(n-1)/2)+"  ");
       //out.write(ss.substring((n-1)/2+1,ss.length()));       
       if(b1&&b2&&b3){out.write("Yes");}
       else{out.write("No");}
             
        out.flush();
  }
}


Measured memory_bytes: 21076
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
W=[]
total=0
for i in range(N):
    W.append(V[i]-C[i])
    W=sorted(W)
for i in W:
    if i>0:
        total+=i
print(total)


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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  
  int count = 1;
  vector<int> v;
  for(int i = 1; i < s.size(); i++){
    if(s.at(i - 1) == s.at(i)){
      count++;
    }
    else{
      v.push_back(count);
      count = 1;
    }
  }
  v.push_back(count);
  
  int happy = 0;
  for(int i = 0; i < v.size(); i++) happy += v.at(i) - 1;
  
  cout << min(n - 1, happy + 2 * k) << endl;
}

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--) 

int main(){

    int n,out;
    cin >> n;

    DEFOR(i,n,0){
        
        FOR(j,2,sqrt(i)+1){
        int k = 2;
            while((out=pow(j,k))<=i){
                
                if(i==out){
                    goto outOFloop;
                }
                k++;
        
            }
        }
    }
    out = 1;

    outOFloop:
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  
  if(n==1)
  {
  cout<<"Yes";
  return 0;
  }
  
  int h[n];
  
 for(int i=0;i<n;i++)
  {
   cin>>h[i];
 }
  if(h[n-1]<h[n-2])
   {
     h[n-2]--;
     if(h[n-1]<h[n-2]){
   cout<<"No";
     return 0;}
   }
  
  for(int i=n-3;i>0;i--)
  {
   if(!( h[i]<=h[i+1]))
   {
     h[i]--;
       if(!(h[i]<=h[i+1] ))
       {cout<<"No";
        return 0;}
   }
  }
 if(h[0]>h[1])
  { h[0]--;
if(h[0]>h[1]){
   cout<<"No";
   return 0;}
   } 
   
   
  
  cout<<"Yes";
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <limits>
#include <type_traits>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

int main()
{
	int a, b;
	cin >> a >> b;
	if (abs(a - b) >= 2)
	{
		cout << max(a, b) * 2 - 1 << endl;
	}
	else
	{
		cout << a + b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	var N = parseInt(input.split('\n')[0]);
	var a = input.split('\n')[1].split(' ');
	a = a.map(val => parseInt(val));
	var ave = 0;
	for ( var i = 0; i < N; i++ ) {
		ave += a[i];
	}
	ave = ave / N;
	var def = [];
	for ( var j = 0; j < N; j++ ) {
		def.push(Math.abs(a[j] - ave));
	}
	var min = Math.min(...def);
	console.log(def.indexOf(min));
}

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

signed main() {
  int N;
  cin>>N;
  vector<string>v(N);
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  int e=0;
  for(int i=0;i<N;i++){
    cin>>v[i];
    if(v[i][0]=='M')a++;
    if(v[i][0]=='A')b++;
    if(v[i][0]=='R')c++;
    if(v[i][0]=='C')d++;
    if(v[i][0]=='H')e++;
    }
    cout<<a*b*(c+d+e)+a*c*(d+e)+a*d*e+b*c*(d+e)+b*d*e+c*d*e<<endl;
}


Measured memory_bytes: 6144
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    cout << fixed << setprecision(10) << (n-n/2) /(double)n << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int n;
    cin>>n;
    int arr[N];
    forn(i,1,n)cin>>arr[i];
    
    forn(i,1,n)arr[i] = (arr[i]==i)?1:0;
    //forn(i,1,n)cout<<arr[i]<<" ";nl;
    int ans = 0;
    forn(i,1,n)
    {
        if(i<n and arr[i] and arr[i+1])
        {
            ans++;
            i++;
        }
        else if(arr[i])ans++;
    }

    cout<<ans;

    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = Integer.parseInt(scanner.nextLine());

        Dice[] dices = new Dice[num];
        boolean flag = true;

        loop:
        for (int i = 0; i < num; i++) {
            dices[i] = new Dice(scanner.nextLine());
            for (int j = 0; j < i; j++) {
                /*System.out.println(Arrays.toString(dices[i].a) + " -> "
                        + Arrays.toString(dices[j].a));*/
                if (dices[i].equals(dices[j])) {
                    flag = false;
                    break loop;
                }
            }
        }
        System.out.println(flag ? "Yes" : "No");
    }
}

class Dice {

    int[] a = new int[6];

    Dice(String s) {
        String[] b = s.split(" ");
        for (int i = 0; i < 6; i++) {
            a[i] = Integer.parseInt(b[i]);
        }
    }

    public void roll(char c) {
        int temp;
        switch (c) {
            case 'E':
                temp = a[0];
                a[0] = a[3];
                a[3] = a[5];
                a[5] = a[2];
                a[2] = temp;
                break;
            case 'N':
                temp = a[0];
                a[0] = a[1];
                a[1] = a[5];
                a[5] = a[4];
                a[4] = temp;
                break;
            case 'W':
                temp = a[0];
                a[0] = a[2];
                a[2] = a[5];
                a[5] = a[3];
                a[3] = temp;
                break;
            default:
                temp = a[0];
                a[0] = a[4];
                a[4] = a[5];
                a[5] = a[1];
                a[1] = temp;
                break;
        }
    }

    public boolean equals(Dice d) {
        char[] c = {'E', 'E', 'E', 'N', 'W', 'W', 'W', 'S'};
        boolean flag = false;
        loop:
        for (int i = 0; i < 24; i++) {
            /*System.out.println(Arrays.toString(a) + "========"
                    + Arrays.toString(d.a));*/
            if (Arrays.equals(a, d.a)) {
                flag = true;
                break loop;
            }
            d.roll(c[i % 8]);
        }
        return flag;
    }

}



Measured memory_bytes: 27996
public class Hello{
    public static void Main(){
        string[] str = System.Console.ReadLine().Split(' ');
        int max = 0, min = 0;

        // 入力
        int N = int.Parse(str[0]);
        int a = int.Parse(str[1]);
        int b = int.Parse(str[2]);
        
        // 処理
        if(a<b)
        {
            max = a;
        }
        else
        {
            max = b;
        }
        
        min = (a + b) - N;
        if(min < 0)
        {
            min = 0;
        }
        
        // 出力
        System.Console.WriteLine(max + " " + min);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	int sum = 0;
	int digit = n;
	while (digit > 0)
	{
		int temp = digit % 10;
		sum += temp;
		digit /= 10;
	}
	if(n % sum == 0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  while(n--) {
    cin >> v[n];
  }
  vector<int> ans(6);
  FOR(it,v) {
    if (*it<165)ans[0]++;
    REP(i,5)
      if (165+i*5<=*it && *it<170+i*5)
        ans[i+1]++;
  }
  REP(i,6) {
    cout << i+1 << ":";
    REP(j,ans[i])
      cout << '*';
    cout << endl;
  }
}

Measured memory_bytes: 0
H,W = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
d = [0]*10
for i in range(H):
    A = list(map(int,input().split()))
    for j in range(W):
        if A[j]!=-1:
            d[A[j]] += 1

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])
for i in range(10):
    c[i][i] = 0

ans = 0
for i in range(10):
    ans += c[i][1]*d[i]
print(ans)


Measured memory_bytes: 40428
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if(500*a + 100*b + 50*c == X):
                counter += 1
print(counter)


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

int main(void){
	int N;
	cin >> N;
	vector<int> A(N);

	bool isTwo = false;
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(A[i] == 2 && i != 0)isTwo = true;
	}

	
	long long ret = 0, p = 1;
	for(int i=0;i<N;i++){
		if( A[i] > p ){
			if( p == 1 ){
				ret += A[i] - 1;
				p++;
			}else if( A[i] % p == 0 ){
				A[i] -= ( p + 1 );
				ret += 1 + A[i] / p;
			}else{
				ret += A[i] / p;
			}
		}else if( A[i] == p )p++;
	}

	cout << ret << endl;
	return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		p[--a] = i + 1;
	}
	for (int x : p){
		cout << x << " ";
	}
	return 0;
} 

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main(){
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	ll ans = 0;
	rep(i,n-1){
		if(a[i]+a[i+1]<=x) continue;
		int p = a[i+1];
		a[i+1] = max(0, x-a[i]);
		ans += p - a[i+1];
		if(x==a[i+1]+a[i]) continue;
		else{
			ans += a[i] - x;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s == "Sunny")cout << "Cloudy" << endl;
	else if (s == "Cloudy")cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
	return 0;
}

//がんばるぞーーー

Measured memory_bytes: 256
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
int a[100005];
int t[100005];
int main(){
	ios_base::sync_with_stdio(false);
	int i,j,n;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<n;i++){
		if(a[i]%4==0) t[i]=2;
		else if(a[i]%2==0) t[i]=1;
		else t[i]=0;
	}
	sort(t,t+n);
	for(i=0;i<n/2;i++) if(t[i]+t[n-1-i]<2){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0; 
}



Measured memory_bytes: 1024
#include <iostream>

using std::cin;
using std::cout;

int arr[110];

int main() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> arr[i];
	bool fst = 1;
	while(n >= 1) {
		if(fst) fst = 0;
		else cout << ' ';
		cout << arr[n] , n--;
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, P;
	cin >> N >> P;

	ll dp[51][2] = {};
	dp[0][0] = 1;
	rep(i, N) {
		int a;
		cin >> a;
		if (a % 2) {
			dp[i + 1][1] += dp[i][0];
			dp[i + 1][0] += dp[i][0];
			dp[i + 1][0] += dp[i][1];
			dp[i + 1][1] += dp[i][1];
		}
		else {
			dp[i + 1][0] += 2 * dp[i][0];
			dp[i + 1][1] += 2 * dp[i][1];
		}
	}
	co(dp[N][P]);

	Would you please return 0;
}

Measured memory_bytes: 256
from math import floor
n = int(input())
nodes = list(map(int, input().split()))
for i, node in enumerate(nodes, start=1):
    parent = floor(i / 2)
    left = i * 2
    right = i * 2 + 1
    print('node {}: key = {}, '.format(i, node), end='')
    if parent > 0:
        print('parent key = {}, '.format(nodes[parent - 1]), end='')
    if left <= n:
        print('left key = {}, '.format(nodes[left - 1]), end='')
    if right <= n:
        print('right key = {}, '.format(nodes[right - 1]), end='')
    print()



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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define LL              long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

int main()
{
    int n;
    cin >> n;
    bool f=true;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        if(x%2==0 and (x%3!=0 and x%5!=0)) f=false;
    }
    if(f) cout << "APPROVED";
    else cout << "DENIED";
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)

def erase(x, y):
    c[y][x] = '0'
    for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)):
        nx, ny = x + dx, y + dy
        if 0 <= nx < w and 0 <= ny < h and c[ny][nx] == '1':
            erase(nx, ny)

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    c = [[i for i in input().split()] for _ in range(h)]
    ans = 0
    for y in range(h):
        for x in range(w):
            if c[y][x] == '1':
                ans += 1
                erase(x, y)
    print(ans)

Measured memory_bytes: 9512