akhauriyash/Code-Regression huggingface dataset:
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	string S;
	cin >> S;
	vector<char>v(S.size());
	for (int i = 0; i < S.size(); i++) {
		v[i] = S[i];
	}
	sort(v.begin(), v.end());
	int c = 97;
	for (int i = 0; i < S.size(); i++) {
		if ((char)c == v[i]) {
			c++;
		}
	}
	if (c == 123) {
		cout << "None" << endl;
	}
	else {
		cout << (char)c << endl;
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int a[3],t=0,c=0,e=0,d=0;
    for (int i=0;i<1000;i++){
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        if (a[2]>=a[0]+a[1])break;
        else if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1]){
            t+=1;
            c+=1;
        }
        else if(a[2]*a[2]>a[0]*a[0]+a[1]*a[1]){
            t+=1;
            d+=1;
        }
        else if(a[2]*a[2]<a[0]*a[0]+a[1]*a[1]){
            t+=1;
            e+=1;
        }
    }
    cout<<t<<" "<<c<<" "<<e<<" "<<d<<endl;
    return 0;
}



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

using namespace std;
#define BUF (1000)
#define ll long long 

int n;

#define MOD 1001

typedef int key;
key make_key(int i, int j){
	int a,b;
	if(i<j){
		a=i;b=j;
	}else{
		a=j;b=i;
	}
	return  a*MOD+b;
}

typedef struct node{
	key index;
	int pointed_count;
	std::vector<key> to;
	bool is_new; 
	bool is_exist;
} NODE;

std::vector<NODE> NODES(MOD*MOD);

std::vector<bool> is_used(MOD*MOD);
std::vector<int> cache(MOD*MOD, -1);



bool is_dag(key k){
	if(cache[k]==0) return false;
	if(cache[k]==1) return true;
	//cout << k << " ";
	is_used[k]=true;
	for(auto x : NODES[k].to){
		if(is_used[x]){
			cache[k] = 0;
			return false;
		}
		if(!is_dag(x)){
			cache[k] = 0;
			return false;
		}
	}
	is_used[k]=false;
	cache[k] = 1;
	return true;
}

int main(void){
	cin >> n;
	for(int i=1;i<=n;i++){
		int prev = 0;
		for(int j=1;j<=n-1;j++){
			int tmp;
			cin >> tmp;

			NODES[make_key(i,tmp)].is_exist = true;
			NODES[make_key(i,tmp)].index = make_key(i,tmp);

			//cout << tmp << i << " " <<  make_key(i,tmp) << " "   << endl;
			if(prev!=0){
				//cout << prev << endl;
				NODES[make_key(i,tmp)].pointed_count++;
				NODES[make_key(i,prev)].to.push_back(make_key(i,tmp));
			}
			prev = tmp;
		}
	}


	std::vector<key> root_nodes;
	for(auto nd : NODES){
		if(nd.is_exist&& nd.pointed_count==0){
			root_nodes.push_back(nd.index);
			//cout << nd.index << endl;
		}
	}
	
	if(root_nodes.empty()){
		cout << -1 << endl;
		return 0;
	}

	// check dag or not
	for(auto nd : root_nodes){
		if(!is_dag(nd))
		{
			cout << -1 << endl;
			return 0;
		}
	}



	int ret = 1;
	while(1){
		vector<int> tmp;
		for(auto nd : root_nodes){
			for(auto x : NODES[nd].to){
				NODES[x].pointed_count--;
				if(0==NODES[x].pointed_count) tmp.push_back(x);
			}
			NODES[nd].is_exist = false;
		}
		if(tmp.empty()) break;
		ret++;
		root_nodes.clear();
		root_nodes.resize(tmp.size());
		int l=0;
		for(auto x : tmp){
			root_nodes[l]=x;
			l++;
		}
	}

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


Measured memory_bytes: 59264
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppll pair <pll, pll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
int main(){
	ll s; cin >> s;
	const ll v = 1e9;
	ll x = (v - s % v) % v;
	ll y = (s + x) / v;
	cout << "0 0 1000000000 1 " << x << " " << y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define X ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


long long p = 1e9+7;
typedef pair<int, int> pi;
typedef unordered_map<int, int> UMP;
typedef long long ll;
typedef vector<ll> VI;
#define FOR(i,b) for(i=0;i<b;i++)
#define pb push_back


void printa(VI x,ll n){
    ll i;
    FOR(i, n){
        cout<<x[i]<<" ";
    }
    cout<<endl;
}

int main(){

    ll r,s,p,n,k,i;
    string a;
    cin>>n>>k;
    cin>>r>>s>>p;
    cin>>a;
    map<char, int> co;
    co['r']=r; co['s']=s;co['p']=p;
    map <char, char> mp;
    mp['s'] = 'r';mp['r']='p';mp['p']='s';
    string x;
    FOR(i,n){x+="?";}
    ll ans =0 ;
    FOR(i, n){
        if(i>=k){
            if(mp[a[i]]==x[i-k]){continue;}
        }
        x[i] = mp[a[i]];
        ans += co[mp[a[i]]];
    }
    cout<<ans;

}

// 2017634310362021

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[] arr = new int[10];
        for (int i =0; i< 10; i++){
            int a = scan.nextInt();
            arr[i] = a;
        }
        Arrays.sort(arr);
        System.out.println(arr[9]);
        System.out.println(arr[8]);
        System.out.println(arr[7]);

    }
}

Measured memory_bytes: 26332
n = int(input())
s = input()
if n % 2 == 0:
    half_s = n // 2
    s1 = s[:half_s]
    s2 = s[half_s:n]
    if s1 == s2:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, a, b;
	cin >> n >> a >> b;
	if(a > b){
		cout << 0 << endl;
	} else if(n == 1){
		cout << int(a==b) << endl;
	} else {
		ll mn = (n-1)*a + b, mx = (n-1)*b + a;
		cout << mx-mn+1 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.text","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll mx=200009;	
ll tree[mx*4]; 
ll lazy[mx*4]; 
vector<pair<ll,ll> >l[mx],r[mx]; 
void pushdown(ll node,ll b, ll e)
{
	if(lazy[node])
	{
		tree[node]+=lazy[node]; 
		if(b!=e)
		{
			lazy[node*2]+=lazy[node]; 
			lazy[node*2+1]+=lazy[node]; 
		}
		lazy[node]=0; 
	}
}
void update(ll node, ll b, ll e, ll i, ll j, ll val )
{
	pushdown(node,b,e);
	if(b>j or e<i) return ; 
	if(b>=i and e<=j)
	{
		lazy[node]+=val; 
		pushdown(node,b,e);
		return ;
	}
	ll mid=(b+e)>>1;
	update(node*2,b,mid,i,j,val);
	update(node*2+1,mid+1,e,i,j,val);
	tree[node]=max(tree[node*2],tree[node*2+1]);
}
ll query(ll node, ll b,ll e, ll i, ll j)
{
	pushdown(node,b,e);
	if(b>j or e<i) return LLONG_MIN; 
	if(b>=i and e<=j) return tree[node]; 
	ll mid=(b+e)>>1; 
	return max(query(node*2,b,mid,i,j),query(node*2+1,mid+1,e,i,j));
}
int main()
{
	ll n,m; 
	cin>>n>>m; 
	for(ll i=0;i<m;i++)
	{
		ll a,b,c; 
		cin>>a>>b>>c;
		l[a].pb(mp(a,c));
		r[b].pb(mp(a,c));
	}
	ll ans=0; 
	for(ll i=1;i<=n;i++)
	{
		for(auto x: l[i])
		{
			update(1,0,n,0,x.first-1,x.second);; 
		}
		ll curval=query(1,0,n,0,i-1);
		ans=max(ans,curval);
		update(1,0,n,i,i,curval);
		for(auto x: r[i])
		{
			update(1,0,n,0,x.first-1,-x.second);
		}
	}
	cout<<ans<<endl; 
}



Measured memory_bytes: 33152
import sys
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Ii()
a = Li()
x = [0]*n
ans = 0
for i in range(n): 
  if a[i]+i < n:
    x[a[i]+i] += 1
  if i-a[i] >= 0:
    ans += x[i-a[i]]
      
print(ans)

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

struct UF {
    UF *p;
    int s;
    UF() : p(nullptr), s(1) {}
    UF *Find() {
        if(p == nullptr)
            return this;
        return p = p->Find();
    }
    int Union(UF &n) {
        auto *r = Find(), *nr = n.Find();
        if(r == nr)
            return 0;
        if(r->s < nr->s)
            swap(r, nr);
        nr->p = r, r->s += nr->s;
        return 1;
    }
} u[111111];
int x[111111];
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    for(int i = 0; i < m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        x[a]--, x[b]--;
        u[a].Union(u[b]);
    }
    for(int i = 0; i < n; i++)
        x[i + 1] += u[i + 1].Find()->s;
    for(int i = 0; i < k; i++) {
        int c, d;
        scanf("%d%d", &c, &d);
        if(u[c].Find() == u[d].Find())
            x[c]--, x[d]--;
    }
    for(int i = 0; i < n; i++)
        cout << x[i + 1] - 1 << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
function main()
  
  N = parse(Int,readline())
  
  ans = 0
  
  for i in 1:N
    
    (x,u) = split(chomp(readline())," ")
    
    if u == "BTC"
      ans += 380000.0 * parse(Float64,x)
    else
      ans += parse(Float64,x)
    end
    
  end
  
  println(ans)
  
end

main()

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

#define N 505

int n, a[N][N];
typedef long long ll;
ll pos[N][N], neg[N][N];

const ll inf = 1ll<<62;

ll dp[N][N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j ++) {
			if (j == i) continue;
			scanf("%d", &a[i][j]);
		}
	}
	for (int i = 1; i <= n; i ++) {
		pos[i][i] = 0;
		for (int j = i - 1; j >= 1; j --) pos[i][j] = pos[i][j+1] + a[j][i];
		neg[i][i] = 0;
		for (int j = i - 1; j >= 1; j --) neg[i][j] = neg[i][j+1] + a[i][j];
	}
	for (int i = 0; i <= n; i ++) for (int j = 0; j <= i; j ++) dp[i][j] = inf;
	dp[0][0] = 0;
	for (int j = 0; j <= n; j ++) {
		for (int k = 0; k <= j; k ++) {
			ll cur = 0;
			for (int i = j + 1; i <= n; i ++) {
				cur += pos[i][j+1] - neg[i][k+1];
				dp[i][j] = min(dp[i][j], dp[j][k] + cur);
			}
		}
	}
	ll ans = inf;
	for (int i = 0; i < n; i ++) ans = min(ans, dp[n][i]);
	for (int i = 1; i <= n; i ++) for (int j = i - 1; j >= 1; j --) ans += a[i][j];
	cout<<ans<<endl;
}


Measured memory_bytes: 7168
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        Job[] a = new Job[n];
        for(int i=0;i<n;i++) {
            a[i] = new Job(sc.nextLong(), sc.nextLong());
        }
        Arrays.sort(a);

        long cur = 0;
        for(int i=0;i<n;i++) {
            if(a[i].dur + cur > a[i].t) {
                pw.println("No");
                pw.close();
                return;
            }
            cur += a[i].dur;
        }

        pw.println("Yes");
        pw.close();
    }

    static class Job implements Comparable<Job> {
        long dur;
        long t;
        public Job(long dur, long t) {
            this.dur = dur;
            this.t = t;
        }
        @Override
        public int compareTo(Job other) {
            return (int)(this.t - other.t);
        }

    }
}

Measured memory_bytes: 56912
from scipy.sparse.csgraph import dijkstra
h, w = map(int, input().split())
c = [ list(map(int, input().split())) for _ in range(10) ]
D = dijkstra(c)
C = D[:, 1].astype(int).tolist()
ans = 0
for _ in range(h):
  for i in map(int, input().split()):
    if i != -1:
      ans += C[i]
print(ans)

Measured memory_bytes: 13712
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;

ll choose2(ll n) {
  return n*(n-1)/2;
}
int main() {
    int N;
    cin >> N;
    map<int, int>mp;
    vector<int>A(N);
    
    rep(i, 0, N){
        cin >> A[i];
        mp[A[i]]++;
    }
    ll total = 0;
    for(auto & p:mp){
        total += choose2(p.second);
    }
    rep(i, 0, N){
        ll ans = total;
        ans -= choose2(mp[A[i]]);
        ans += choose2(mp[A[i]]-1);
        cout << ans<< endl;
    }
    return 0;
}


Measured memory_bytes: 8320
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

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

/* see https://github.com/pllk/cphb/
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;
 **/

typedef long long ll;
#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

//typedef __int128 lll;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

ll fak(ll v) {
    if(v==1)
        return 0;

    if(v==2)
        return 1;
    else 
        return v-1+fak(v-1);
}

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    cinas(s, n);
    map<string, int> m;
    for(int i=0; i<n; i++) {
        sort(s[i].begin(), s[i].end());
        m[s[i]]++;
    }

    
    ll ans=0;
    for(auto ent : m) {
        ans+=fak(ent.second);
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 16640
#include<stdio.h>

int main()
{
	double weight;

	while(scanf("%lf",&weight)!=EOF)
	{
		if(weight<=48.00)
		{
			puts("light fly");
		}
		else if(weight<=51.00)
		{
			puts("fly");
		}
		else if(weight<=54.00)
		{
			puts("bantam");
		}
		else if(weight<=57.00)
		{
			puts("feather");
		}
		else if(weight<=60.00)
		{
			puts("light");
		}
		else if(weight<=64.00)
		{
			puts("light welter");
		}
		else if(weight<=69.00)
		{
			puts("welter");
		}
		else if(weight<=75.00)
		{
			puts("light middle");
		}
		else if(weight<=81.00)
		{
			puts("middle");
		}
		else if(weight<=91.00)
		{
			puts("light heavy");
		}
		else
		{
			puts("heavy");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL << 60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int H,A;
  cin >> H >> A;
  int sum = 0;
  for(int i=0; i<A; i++){
    int x;
    cin >> x;
    sum += x;
  }
  if(sum >= H){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>

using namespace std;
#define int long long
/*                      */    #undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int h, w, A[220][220];
struct edge
{
    int to, cost;
};
vector<edge> G[220];
int d[220];
PQG que;

signed main()
{
    cin >> h >> w;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            int a;
            cin >> a;
            if(i == j) continue;
            G[j].pb({i, a});
        }
    }
    fill(d, d + 219, INF);
    d[1] = 0;
    que.push(mk(0, 1));
    while(!que.empty()){
        int dis = que.top().first;
        int pos = que.top().second;
        que.pop();
        if(d[pos] < dis) continue;
        for(int i = 0; i < (int)G[pos].size(); i++){
            edge e = G[pos][i];
            if(d[e.to] > dis + e.cost){
                d[e.to] = dis + e.cost;
                que.push(mk(d[e.to], e.to));
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int a;
            cin >> a;
            if(a == -1 || a == 1)continue;
            ans += d[a];
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>

const int N = 3000 + 10;

char s[N], t[N];
int dp[N][N], from[N][N];

int main() {
  scanf("%s%s", s, t);
  int n = strlen(s);
  int m = strlen(t);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
        from[i][j] = 0;
      } else {
        dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
        if (dp[i][j] == dp[i - 1][j]) from[i][j] = 1;
        else from[i][j] = 2;
      }
    }
  }
  int x = n, y = m;
  std::vector<char> ret;
  while (x && y) {
    if (from[x][y] == 0) {
      ret.push_back(s[x - 1]);
      --x, --y;
    } else if (from[x][y] == 1) {
      --x;
    } else {
      --y;
    }
  }
  std::reverse(ret.begin(), ret.end());
  for (auto &&c: ret) putchar(c);
  puts("");
  return 0;
}


Measured memory_bytes: 70912
#include <iostream>
using namespace std;
int S;
int Partial[15], Power[15];
int ans;
const int MOD = 1000000007;
inline void Add(int& x, int y)
{
    x += y;
    if(x >= MOD) x -= MOD;
}
void precalcPartial()
{
    Partial[1] = 9;
    Power[0] = 1;
    for(int i = 1; i <= 8; i++)
        Power[i] = Power[i - 1] * 10;
    int power = 10;
    for(int i = 2; i <= 8; i++)
    {
        power *= 10;
        Partial[i] = Partial[i - 1] + (power - power / 10) * i;
    }
}

void Solve(int a, int b)
{
    int sum = 0;
    sum += Partial[b - 1] - Partial[a];
    sum = S - sum;
    if(sum < 0)
        return;
    int point = Power[a - 1], point2 = (sum - a * (Power[a] - Power[a - 1])) / b;
    for(; point < Power[a]; point++)
    {
        point2 = (sum - a * (Power[a] - point)) / b;
        if(point2 >= 1 && point2 <= Power[b] - Power[b - 1] && (sum - a * (Power[a] - point)) % b == 0)
            Add(ans, 1);
    }
}

void Solve2(int k)
{
    int sum = S - k - k - 1;
    if(sum < 0)
        return;
    int moda = (k + 1) - (sum) % (k + 1);
    if(moda == k + 1)
        moda = 0;
    int lim = sum / k;
    if(lim < moda)
        return;
    Add(ans, (lim - moda) / (k + 1) + 1);
}

void getAns()
{
    int pw = 1;
    for(int i = 1; i <= 7; i++)
    {
        if(S % i == 0)
        {
            int number = S / i;
            int next = pw * 10;
            next = next - pw;
            if(next >= number - 1)
            {
                next -= (number - 1);
                Add(ans, next);
            }
        }
        for(int j = i + 1; j <= 8; j++)
            Solve(i, j);
        pw = pw * 10;
    }

    for(int i = 8; i <= S; i++)
    {
        Solve2(i);
        if(S % i == 0)
        {
            int number = S / i;
            int next = (1LL * pw * 10) % MOD;
            next = next - pw;
            if(next < 0)
                next += MOD;
            next -= (number - 1);
            if(next < 0)
                next += MOD;
            Add(ans, next);
        }
        pw = (1LL * pw * 10) % MOD;
    }
    cout << ans << "\n";
}
int main()
{
    cin >> S;
    precalcPartial();
    getAns();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;	
int main(){
	int n,i;
	long long a[1000];
	while(~scanf("%d",&n)){
		a[0]=2;
		a[1]=1;
	for(i=2;i<=n;i++){
	a[i]=a[i-2]+a[i-1];
	}
	printf("%lld\n",a[n]);
	}
}


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

int a,b,d;
struct P
{
  int x,y;
  P(int x=-1,int y=-1):x(x),y(y){}
  bool operator < (const P &p)const
  {
    if(x+y != p.x+p.y)return x+y < p.x+p.y;
    if(a*x+b*y != a*p.x+b*p.y)return a*x+b*y < a*p.x+b*p.y;
    if(x != p.x)return x < p.x;
    return y < p.y;
  }
};

int main()
{

  while(cin >> a >> b >> d,a|b|d)
    {
      assert(0 <= a && a <= 10000);
      assert(0 <= b && b <= 10000);
      assert(0 <= d && d <= 50000);
      int ans_x = (1<<28),ans_y = (1<<28);
      P p = P(ans_x,ans_y);
      for(int x = 0;x <= 50000;x++)
	{
	  int y;
	  if((a*x+d)%b == 0)
	    {
	      y = (a*x+d)/b;	     
	      P pp = P(x,y);
	      p = min(p,pp);
	    }

	  if(x*a-d >= 0 && (x*a-d)%b == 0)
	    {
	      y = (x*a-d)/b;
	      P pp = P(x,y);
	      p = min(p,pp);
	    }

	  if(d-x*a >= 0 && (d-x*a)%b == 0)
	    {
	      y = (d-x*a)/b;
	      P pp = P(x,y);
	      p = min(p,pp);
	    }
	}

      ans_x = p.x,ans_y = p.y;
      cout << ans_x << " " << ans_y << endl;

    }
  return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  int n;cin>>n;
  vector<ll>a(n+10);
  ll sum[n+100]={};
  for(int i=0;i<n+100;i++)sum[i]=0;
  ll dp[n+100][n+100]={};
  for(int i=0;i<n+100;i++)for(int j=0;j<n+100;j++)dp[i][j]=llINF;
  try{
    for(int i=1;i<=n;i++){cin>>a[i];dp[i][i]=0;sum[i]+=sum[i-1]+a[i];}
    for(int i=2;i<=n;i++){
      for(int j=1;j<=n-i+1;j++){
	for(int k=1;k<i;k++){
	  dp[j][j+i-1]=min(dp[j][j+i-1],min(dp[j][j+k-1]+dp[j+k][j+i-1],dp[j][j+i-1-k]+dp[j+i-k][j+i-1]));
	}
	dp[j][j+i-1]+=(sum[j+i-1]-sum[j-1]);
      }
    }
    cout<<dp[1][n]<<endl;
  }catch(exception e){
    cout<<dp[1][n]<<endl;
  }
  return 0;
}


Measured memory_bytes: 2304
package main
 
import (
  "fmt"
)
 
func main() {
 
  var n int
  fmt.Scanln(&n)
  d := scanFloats(n)
 
  var reciprocals float64
  for i := 0; i < n; i++ {
    reciprocals += 1 / d[i]
  }
  
  fmt.Print(1 / reciprocals)
}
 
func scanFloats(len int) (nums []float64) {
    var num float64
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

Measured memory_bytes: 512
from collections import defaultdict
N = int(input())
alst = []
slst = defaultdict(list)
for i in range(N):
    k, v = map(str, input().split())
    slst[k].append(v)
    alst.append(k + ',' + v)

tmp = sorted(slst)
xlst = []
for i in tmp:
    x = slst[i]
    xx = []
    for j in x:
        xx.append(int(j))
    xtmp = sorted(xx, reverse=True)
    for j in xtmp:
        xlst.append(i + ',' + str(j))

anslst = [0] * N
anstmp = 0
for i in xlst:
    for j in range(len(alst)):
        if alst[j] == i:
            anslst[anstmp] = j + 1
            anstmp += 1
            break

for i in anslst:
    print(i)

Measured memory_bytes: 3316
import sys
import math

N = int(sys.stdin.readline())
x = []
y = []
for i in range(N):
    tempx, tempy = map(int, sys.stdin.readline().split())
    x.append(tempx)
    y.append(tempy)


sum_dist = 0
for i in range(N):
    for j in range(i+1, N):
        dist = math.sqrt(math.pow(x[i]-x[j], 2) + math.pow(y[i]-y[j], 2) )
        sum_dist += dist*2
print(sum_dist/N)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  ll n = s.size();
  rep(i, (n + 1) / 2) {
    if(s[i] != s[n - 1 - i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
long long INF=1234567890123456789;
long long a,b,c,d;
map<long long, long long> m;
long long cost(long long n){
  long long t,res=INF;
  decltype(m)::iterator it;
  it=m.find(n);
  if(it!=m.end())
    return m.at(n);
  if(n<INF/d)
    res=n*d;
  t=n/2;
  res=min(res,cost(t)+a+(n%2)*d);
  if(n%2>0)
    res=min(res,cost(t+1)+a+(2-(n%2))*d);
  t=n/3;
  res=min(res,cost(t)+b+(n%3)*d);
  if(n%3>0)
    res=min(res,cost(t+1)+b+(3-(n%3))*d);
  t=n/5;
  res=min(res,cost(t)+c+(n%5)*d);
  if(n%5>0)
    res=min(res,cost(t+1)+c+(5-(n%5))*d);
  m.emplace(n,res);
  return res;
}
int main()
{
  int t,i;
  long long n,j,res;
  cin >> t;
  for(i=0;i<t;i++){
    cin >> n >> a >> b >> c >> d;
    m.clear();
    m.emplace(0,0);
    m.emplace(1,d);
    res=cost(n);
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define DEB 0

int dp[1<<10][331];

int main(){
  int n,s,comb,x,y;
  while(~scanf("%d%d",&n,&s)){
    memset(dp,0,sizeof(dp));
    if( s>330 ){
      puts("0");
      continue;
    }
    rep(k,10)dp[1<<k][k] = 1;

    REP(i,1,n-1){  // n --> n-1
      comb = (1<<i)-1;
      while( comb < 1<<10 ){
	rep(j,s+1)if( dp[comb][j] ){
	  rep(k,10)if( !(comb&(1<<k)) ){
	    if( j+(i+1)*k>s )break;
	    dp[comb|(1<<k)][j+(i+1)*k] += dp[comb][j];
	  }
	}
	x = comb & -comb;
	y = comb + x;
	comb = ((comb&~y)/x>>1)|y;
      }
    }
    /*
    int ans = 0;
    comb = (1<<n)-1;
    while( comb < 1<<10 ){
      ans += dp[comb][s];
      x = comb & -comb;
      y = comb + x;
      comb = ((comb & ~y)/x>>1)|y;
    }
    */
    int ans = 0;
    if( n>1 ){
      comb = (1<<(n-1))-1;
      while( comb < 1<<10 ){
	rep(i,s+1)if( dp[comb][i] && (s-i)%n==0 ){
	  int b = (s-i)/n;
	  if( b<10 && !(comb&(1<<b)) ){
	    ans += dp[comb][i];
#if DEB
	    printf("comb:%d  i:%d  b:%d\n",comb,i,b);
#endif
	  }
	}
	x = comb & -comb;
	y = comb + x;
	comb = ((comb & ~y)/x>>1)|y;
      }
    }else{
      if( s<10 ){
	ans = 1;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 0
n, m, l = map(int, input().split())

a = []
for i in range(0, n):
  e = list(map(int, input().split()))
  a.append(e) 

b = []
for i in range(0, m):
  e = list(map(int, input().split()))
  b.append(e)

for i in range(0, n):
  e = []
  for j in range(0, l):
    ab = 0
    for k in range(0, m):
      ab += a[i][k] * b[k][j]
    e.append(ab)
  print(' '.join(map(str, e)))



Measured memory_bytes: 6308
#include<iostream>

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
using namespace std;
int main()
{
    int n;

    cin >> n;

    int c = 0, m = 0, mm = 0, mmm = 0;

    rep (i, n) {
        cin >> m;
        if (i > 0 && mm >= m) {
            ++c;
        }
        if (mmm < c) {
            mmm = c;
        }
        if (i > 0 && !(mm >= m)) {
            c = 0;
        }
        mm = m;
    }

    cout << mmm << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	char arr[n][n];
	char arr1[m][m];
	for(int i=0;i<n;i++)
	scanf("%s",arr[i]);
		for(int i=0;i<m;i++)
		scanf("%s",arr1[i]);
			for(int i=0;i<n;i++){
					for(int j=0;j<n;j++){
						int cnt=0;
							for(int a=0;a<m;a++){
									for(int b=0;b<m;b++){
										if(arr1[a][b]==arr[i+a][j+b])
										cnt++;
									}
							}
							if(cnt==(m*m)){
								return(cout<<"Yes",	0);
							}
					}
			}
			printf("No\n");
			return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

// http://drken1215.hatenablog.com/entry/2019/05/28/124300
// けんちょんさんのUnion Find
struct UnionFind {
    vector<int> par, w;

    UnionFind(int n) : par(n, -1), w(n, 0) { }
    void init(int n) { par.assign(n, -1); w.assign(n, 0); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) {
            ++w[x];
            return false;
        }
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        w[x] += w[y];
        ++w[x];
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }

    int wei(int x) {
        return w[root(x)];
    }
};


int main(){
  int N,M,K;
  cin >> N >> M >> K;
  UnionFind uf(N);
  vector<vector<int>> G(N);
  for(int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
    uf.merge(a,b);
  }
  vector<vector<int>> B(N);
  for(int i=0; i<K; i++){
    int c,d;
    cin >> c >> d;
    c--;
    d--;
    B[c].push_back(d);
    B[d].push_back(c);
  }
  for(int i=0; i<N; i++){
    int res = uf.size(i);
    res -= G[i].size();
    for(int nv: B[i]){
      if(uf.issame(nv,i)) res--;
    }
    res--;
    cout << res << (i!=N-1 ? " " : "\n");
  }
  return 0;
}

Measured memory_bytes: 12536
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&

//#define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&

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

/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
// find_by_order(), order_of_key() 

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#define int long long int 
#define ld long double
#define X first
#define Y second
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
const ld PI  = 3.141592653589793238463;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&

void solve(){
	string s, t;
	cin >> s >> t;
	t.pop_back();
	if(s == t){
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    //cin >> T;
    for(int i = 1; i <= T; ++i){
        solve();
    }
    return 0;
}
/*
Sample inp
*/

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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n,a,cnt=1;
    cin >> n;
    vector<ll> table(1e6+1,0);
    rep(i,n){
        cin >> a;
        for(ll j=2; j*j<=a; j++){
            if(a%j==0){
                while(a%j==0) a/=j;
                table[j]++;
                cnt=max(cnt,table[j]);
            }
        }
        if(a!=1){
            table[a]++;
            cnt = max(cnt,table[a]);
        }
    }
    if(cnt==1) print("pairwise coprime");
    else if(cnt!=n) print("setwise coprime");
    else print("not coprime");
    return 0;
}

Measured memory_bytes: 11048
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static final int INF = (int) 1e9 + 5;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);
        solve(scanner, writer);
        scanner.close();
        writer.close();
    }

    public static void solve(Scanner scanner, PrintWriter writer) {
        int n = scanner.nextInt();
        int w = scanner.nextInt();
        int[] weights = new int[n];
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            weights[i] = scanner.nextInt();
            values[i] = scanner.nextInt();
        }

        // dp[i][j] denote maximum sum of values using first i items and total weights is j
        // recurrence: dp[i][j] = max(dp[i-1][j-weight[i]] + values[i], dp[i-1][j])
        long[][] dp = new long[n+1][];
        for (int i = 0; i <= n; i++) {
            dp[i] = new long[w + 1];
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= w; j++) {
                if (j - weights[i-1] >=0 ){
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - weights[i-1]] + values[i-1]);
                }
                dp[i][j] = Math.max(dp[i][j], dp[i - 1][j]);
            }
        }

        long ans = 0;
        for (int i = 0; i <= w; i++) {
            ans = Math.max(ans, dp[n][i]);
        }

        writer.println(ans);
    }
}


Measured memory_bytes: 129492
#include<string>
#include<cstdio>
#include<iostream>

using namespace std;
 
int main(){
    string a;
 
    while(getline(cin, a)){
		  for(int i = 0; i < a.length(); ++i)
	    if('a'<=a[i] && a[i]<='z') a[i]-=('a'-'A');
		cout << a<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 1172
#include<iostream>
using namespace std;
int main(){
	int a[100][100], b[100],c,n,m,p,q;
	cin >> n >> m;
	p = n; q = m;
	for (n = 0; n < p; n = n + 1) {
		for (m = 0; m < q; m = m + 1) {
			cin >> a[n][m];
		}
	}
	for (m = 0; m < q; m = m + 1) {
		cin >> b[m];
	}
	c = 0;
	for (n = 0; n < p; n = n + 1) {
		for (m = 0; m < q; m = m + 1) {
			c = c + a[n][m] * b[m];
		}
		cout << c << endl;
		c = 0;
	}
}


Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

using namespace std;

#define REP(i,s,e) for(int i=(s);i<(e);i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef unsigned long long ull;

int N, T, A;

int main(void) {
  cin >> N >> T >> A;

  int h, t, ans, diff = (1 << 30);
  rep(i, N) {
    cin >> h;
    t = T * 1000 - h * 6;
    if (abs(t - 1000 * A) < diff) {
      diff = abs(t - 1000 * A);
      ans = i;
    }
  }

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


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 2826.cc: Game Balance
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int ss[MAX_N];

/* subroutines */

int calc(int n, int x) {
  int l = 1, c = 0;
  for (;;) {
    c++;
    if (ss[n - 1] < l + x) break;

    int k = lower_bound(ss, ss + n, l) - ss;
    int d0 = (k < n && ss[k] < l + x) ? ss[k] - l : INF;
    int d1 = (k > 0) ? l - ss[k - 1] : INF;
    int d = min(d0, d1);
    if (d >= INF) return INF;

    l += max(1, x - d);
  }
  return c;
}

/* main */

int main() {
  for (;;) {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n == 0) break;

    for (int i = 0; i < n; i++) scanf("%d", ss + i);

    int x0 = 0, x1 = ss[n - 1] - 1;
    while (x0 + 1 < x1) {
      int x = (x0 + x1) / 2;
      int c = calc(n, x);
      //printf("calc(%d)=%d\n", x, c);

      if (c < m) x1 = x;
      else x0 = x;
    }

    int c0 = calc(n, x0);
    printf("%d\n", (c0 < m || c0 >= INF) ? -1 : x0);
  }
  return 0;
}



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

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


			var inputArray = retreiveLongArray();
			var inputCount = 4;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long A = inputArray[0];
			long B = inputArray[1];
			long C = inputArray[2];
			long K = inputArray[3];

			if( K <= A) {
				Console.WriteLine(K);
				return;

			}
			if (K <= (A+B)) {
				Console.WriteLine(A);
				return;

			}
	
			Console.WriteLine(A-(K-A-B));
			return;


		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 28180
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<int>p(a),q(b),r(c);
    REP(i,a) cin>>p[i];
    REP(i,b) cin>>q[i];
    REP(i,c) cin>>r[i];
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    sort(r.rbegin(),r.rend());
    vector<int>ruip(a+1,0),ruiq(b+1,0),ruir(c+1,0);
    vector<int>d;
    for (int i = 0; i < x; i++)
    {
        d.push_back(p[i]);
    }
    for (int i = 0; i < y; i++)
    {
        d.push_back(q[i]);
    }
    for (int i = 0; i < c; i++)
    {
        d.push_back(r[i]);
    }
    int cnt=0;
    sort(d.rbegin(),d.rend());
    for (int i = 0; i < x+y; i++)
    {
        cnt+=d[i];
    }
    cout<<cnt<<endl;
        return 0;
    }

Measured memory_bytes: 11120
#include <vector>
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)

const ll MOD = (ll)(1000000007);
const int d = 13;
int main(void)
{
	string s;
	cin >> s;
	vector<vector<ll>> dp(s.size(), vector<ll>(d, 0));
	{
		char c = s[0];
		if (c != '?') {
			int b = c - '0';
			dp[0][b] = 1;
		}
		else {
			for (int b = 0; b < 10; b++) {
				dp[0][b] = 1;
			}
		}
	}
	for (int i = 1; i < s.size(); i++) {
		char c = s[i];
		if (c != '?') {
			int b = c - '0';
			for (int j = 0; j < d; j++) {
				ll m = ((j * 10) + b) % d;
				dp[i][m] += dp[i-1][j];
				dp[i][m] %= MOD;
			}
		}
		else {
			for (int b = 0; b < 10; b++) {
				for (int j = 0; j < d; j++) {
					ll m = ((j * 10) + b) % d;
					dp[i][m] += dp[i-1][j];
					dp[i][m] %= MOD;
				}
			}
		}
	}
	cout << dp[s.size()-1][5] << endl;
	return 0;
}

Measured memory_bytes: 13696
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
typedef long long ll;

int x;
int ans = 0;
int main()
{
	cin >> x;

	REP(i, 1, 1001) {
		REP(j, 2, 1001) {
			if ((int)pow(i, j) <= x) ans = max(ans, (int)pow(i, j));
			else break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll n; cin >> n;
    for (int i = 0; i < 100; i += 4) {
        for (int j = 0; j < 100; j += 7) {
            if (i + j > n) continue;
            if (i + j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3648