akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
struct node{
    int u,v;
}x[N];
int f[N];
int num[N];
bool vis[N];
int g[N];
int sf(int x){
    return x==f[x]?x:f[x]=sf(f[x]);
}

void Union(int x,int y){
    if(x&1)f[sf(x)]=sf(y);
    else f[sf(y)]=sf(x);
}
int ssf(int x){
    return x==g[x]?x:g[x]=ssf(g[x]);
}
void Union1(int x,int y){
    int fx=ssf(x),fy=ssf(y);
    if(fx==fy) return ;
    num[fx]+=num[fy];
    g[fy]=fx;
}
int main(){
    ll n,m,q;
    scanf("%lld%lld%lld",&n,&m,&q);
    int u,v,F,cnt=0;
    for(int i=0;i<=n;i++){
        f[i]=i;
        num[i]=1;
    }
    for(int i=0;i<q;i++){
        scanf("%d %d %d",&u,&v,&F);
        ++u,++v;
        if(F==0) {
            if(sf(u)!=sf(v)){
                Union(u,v);
                --m;
            }

        }
        else {
            x[cnt].u=u;
            x[cnt++].v=v;
        }
    }
    F=0;
    ll c=0;
    for(int i=1;i<=n;i++){
        if(!vis[sf(i)]){
            vis[sf(i)]=1;
            ++c;
        }
    }
    for(int i=0;i<=n;i++) {
        vis[i]=0;
        g[i]=f[i];
    }
    for(int i=0;i<cnt;i++){
        int fx=sf(x[i].u),fy=sf(x[i].v);
        if(fx==fy) {
            F=1;
            break;
        }
        else {
            Union1(fx,fy);
        }
    }
    if(F==1){
        printf("No\n");
        return 0;
    }
    ll mi=0,mx=0;
    int ff=0;
    for(int i=1;i<=n;i++){
        int x=ssf(i);
        if(!vis[x]){
            vis[x]=1;
            if(num[x]==2) F=1;
            if(num[x]==1) continue;
            mi+=num[x];
            ff++;
        }
    }
    //cout<<c<<endl;
    mx=1ll*c*(c-1)/2;
    //cout<<m<<" "<<mi<<" "<<mx<<endl;
    if(c>2) {
        if(F==1&&ff<2) mi++;
        if(m>=mi&&m<=mx) printf("Yes\n");
        else printf("No\n");
    }
    else if(F) printf("No\n");
    else if(m>=mi&&m<=mx) printf("Yes\n");
    else printf("No\n");
}


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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i=0;i<N;i++){
        cin >> vec[i];
    }
    vector<int> ans(N);
    for(int i=0;i<N;i++){
        ans[vec[i]-1] = i+1;
    }
    for(int i=0;i<N;i++){
        cout <<ans[i] << " ";
    }
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

void temp(int *x, int *y)
{
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

int main(void)
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	int counter = 0;
	bool flag = true;
	for (int i = 0; i < n && flag; ++i)
	{
		flag = false;
		int min = a[i];
		int min_n = i;
		for (int j = i+1; j < n; ++j)
		{
			if(min > a[j])
			{
				min = a[j];
				min_n = j;
			}
			if(a[j-1] > a[j])
				flag = true;
		}
		if(i != min_n)
		{
			temp(&a[i],&a[min_n]);
			counter++;
		}
	}
	for (int i = 0; i < n-1; ++i)
		cout << a[i] << " ";
	cout << a[n-1] << endl;
	cout << counter << endl;

	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y,fr;
}a[1000001];
int n,m,t1,tot,ans[1000001],e[1000001],nt[1000001],hd[1000001],mx[1000001];
void add(int x,int y){
	tot++;
	e[tot]=y;
	nt[tot]=hd[x];hd[x]=tot;
}
void dfs(int x,int dep,int col){
	if(!ans[x])ans[x]=col;
	if(mx[x]>=dep)return;
	mx[x]=dep;
	int i;
	for(i=hd[x];i;i=nt[i])dfs(e[i],dep-1,col);
}
int main(){
	int i,x,y;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&t1);
	for(i=1;i<=t1;i++)scanf("%d%d%d",&a[i].fr,&a[i].x,&a[i].y);
	for(i=t1;i;i--)dfs(a[i].fr,a[i].x,a[i].y);
	for(i=1;i<=n;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 19456
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main()
{
  int A, B, K;
  cin >> A >> B >> K;
  set<int> st;
  for (int i = A; i <= min(A + K - 1, B); i++)
    st.insert(i);
  for (int i = B; i >= max(B - K + 1, A); i--)
    st.insert(i);
  for (auto a : st)
    cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
const double pie = 3.14159265358979;

int main(){
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double a = H*30+M*0.5;
    double b = M*6;
    double c = abs(a-b);
    if(c==90){
        cout << sqrt(A*A+B*B) << endl;
    }
    else{
        cout << setprecision(100) << sqrt(A*A+B*B-2*A*B*cos(c*pie/180)) << endl;
    }
}

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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    string s,t;
    cin>>s>>t;
    int ans=INT_MAX;
    for(int i=0;i<sz(s);i++) {
        int cnt=0;
        if(i+sz(t)>sz(s)) break;
        for(int j=0;j<sz(t);j++) {
            if(s[i+j]!=t[j]) {
                cnt++;
            }
        }

        ans=min(ans,cnt);
    }

    cout<<ans;

}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 3640
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e5 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}

ll ara[Max+10];

ll n,k;
bool ok(ll val)
{
    ll cnt=0;
    for(ll i=0; i<n; i++)
    {
       // if(ara[i])




       if(val<ara[i])
       cnt+=((ara[i])/val);


    }

    //cout<<ara[0]<<" "<<cnt<<" "<<val<<endl;

   // cout<<cnt

    return (cnt<k+1);
}
int main()
{

   fastread();

   ll i,j,m,p,a,sum=0,t,b,c,d,cnt=0,q,l,r;


     string str;

   bool flag=true;

   ll low=1,high=1e9,ans=0;

   cin>>n>>k;

   for(i=0; i<n; i++)
   {
       cin>>ara[i];
       ans=max(ara[i],ans);
   }

   if(k==0)
   {
       cout<<ans<<endl;

       return 0;
   }

  // cout<<ans<<endl;

  high=ans;

     while(low<=high)
     {
         ll mid=(high+low)/2;

        // cout<<mid<<endl;

         if(ok(mid))
         {
             ans=mid;
            high=mid-1;
         }
         else low=mid+1;
     }

     cout<<ans<<endl;




}



Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
const long double EPS = 1e-14;
const int maxn = 100500;
const int mod = 1e9 + 7;
vector < pair < int, int > > g[maxn];
vector < pair < int, pair < int, bool > > > gr[maxn];
int paths[2][maxn], d[2][maxn];
bool vis[maxn];
int n, m, s, t;

set < pair < int, int > > in;

void dij(int idx, int st){
    for(int i = 0 ; i < n ; ++i) d[idx][i] = 1e18;
    d[idx][st] = 0;
    priority_queue < pair < int, int > > pq;
    pq.push({0, st});
    while(!pq.empty()){
        auto u = pq.top();
        pq.pop();
        if(d[idx][u.second] > -u.first) continue;
        for(auto v : g[u.second])
            if(d[idx][v.first] > d[idx][u.second] + v.second){
                d[idx][v.first] = d[idx][u.second] + v.second;
                pq.push({-d[idx][v.first], v.first});
            }
    }
}

long long add(long long x, long long y) { 
    return (x + y + mod) % mod;
}
long long mul(long long x, long long y) { return (add(x, mod) * add(y, mod)) % mod; }


int tot_w;
void build_paths(int idx, int st){
    paths[idx][st] = 1;
    set < pair < int, int > > s;
    s.insert({0, st});
    while(!s.empty()){
        auto u = *s.begin();
        s.erase(u);
        for(auto v : g[u.second])
            if(d[idx][u.second] + v.second + d[1 - idx][v.first] == tot_w){
                paths[idx][v.first] = add(paths[idx][v.first], paths[idx][u.second]);
                in.insert({min(u.second, v.first), max(u.second, v.first)});
                s.insert({d[idx][v.first], v.first});
            }
    }
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    cin >> s >> t;
    --s; --t;
    for(int i = 0 ; i < m ; ++i){
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    dij(0, s);
    dij(1, t);
    tot_w = d[1][s];
    build_paths(0, s);
    build_paths(1, t);
    assert(paths[0][t] == paths[1][s]);
    int ans = mul(paths[0][t], paths[0][t]);
    for(int u = 0 ; u < n ; ++u){
        assert(paths[0][u] >= 0);
        assert(paths[1][u] >= 0);
        if(d[1][u] + d[0][u] == tot_w && d[1][u] == d[0][u]){
            ans = add(ans, -mul(paths[0][u], paths[1][u]) * mul(paths[0][u], paths[1][u]));
            continue;
        }
        set < pair < int, int > > ed;
        for(auto v : g[u])
            if((d[0][u] + v.second + d[1][v.first]) == tot_w){
                if(in.find({min(u, v.first), max(u, v.first)}) == in.end())
                    continue;
                in.erase({min(u, v.first), max(u, v.first)});
                int t1 = d[0][u];
                int t2 = d[1][v.first];
                if(abs(t1 - t2) < v.second) 
                    ans = add(ans,
                     -mul(mul(paths[0][u], paths[1][v.first]), mul(paths[0][u], paths[1][v.first])));
        }
    }
    cout << ans << '\n';
    return 0;
}

//201260731

Measured memory_bytes: 30784
n,m = map(int,input().split())
cnt_lst = [0] * (m+1)
lst = [list(map(int,input().split()))[1:] for _ in range(n)]
ans = 0

for i in range(len(lst)):
    for j in range(len(lst[i])):
        cnt_idx = lst[i][j]
        cnt_lst[cnt_idx] += 1

for cnt in cnt_lst:
    if cnt == n:
        ans += 1
print(ans)


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

int powmod(int x, int y, int mod)
{
    int res = 1;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

void solve()
{
}

int main()
{
    // freopen("filename.in","r",stdin);
    // freopen("filename.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (x > 0 && (x / d) >= k)
    {
        ll temp = x / d;
        x = x - (k)*d;
        cout << x << "\n";
        return 0;
    }

    ll y = x / d;
    x = x - y * d;
    k = k - y;

    if (k % 2 == 0)
        cout << abs(x) << "\n";
    else
        cout << min(abs(x - d), abs(x + d)) << "\n";

    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>

#define div1 1000000007

using namespace std;

int main(void)
{
    int H, W, N, sum=0, count=0;

    cin >> H >> W >> N;

    while(sum < N){
        if(H<W){
            sum += W;
            H--;
        }
        else{
            sum += H;
            W--;
        }
        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a,b,c,d;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);

    if(a*b>=c*d){
        printf("%d",a*b);
    }
    else printf("%d",c*d);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using namespace std;

int main() {
    long long n, d, a;
    cin >> n >> d >> a;

    vector<pair<long long, long long>> xh(n, make_pair(0, 0));
    for (int i = 0; i < n; i++) {
        cin >> xh[i].first >> xh[i].second;
    }

    sort(xh.begin(), xh.end());

    long long res = 0, cur = 0;
    map<long long, long long> dr;
    for (int i = 0; i < n; i++) {
        for (map<long long, long long>::iterator j = dr.begin();
                j != dr.end() && j->first < xh[i].first; j = dr.begin()) {
            cur -= j->second;
            dr.erase(j);
        }

        if (cur < xh[i].second) {
            long long r = (xh[i].second - cur + a - 1) / a;
            res += r;
            cur += r * a;
            dr[xh[i].first + 2 * d] = r * a;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
//
bool negative=true;
struct edge{int from;int to;int cost;};
struct bellman{
	//
	int v,e;
	vector<edge> G;
	vector<ll> D;
	//
	bellman(int n,int m){
		v=n;e=m;
		D.resize(v);
	}
	//
	void add_edge(int from,int to,int cost){
		G.push_back((edge){from,to,cost});
	}
	//
	vector<ll> dist(int s){
		fill(D.begin(),D.end(),1e18+7);
		D[s]=0LL;
		for(int i=0;i<v;i++){
			bool f=false;
			for(int j=0;j<e;j++){
				edge &e=G[j];
				if(D[e.from]!=1e18+7&&D[e.to]>D[e.from]+e.cost){
					D[e.to]=D[e.from]+e.cost;
					f=true;
					if(i==v-1){
						negative=false;
						break;
					}
				}
			}
			if(!negative){
				break;
			}
			if(!f){
				break;
			}
		}
		return D;
	}
	//
};
//
int main(){
	int V,E;
	cin>>V>>E;
	bellman be(V,E);
	for(int i=0;i<E;i++){
		int s,t,d;
		cin>>s>>t>>d;
		be.add_edge(s,t,d);
	}
	vector<ll> ans=be.dist(0);
	if(!negative){
		cout<<"NEGATIVE CYCLE"<<endl;
		return 0;
	}
	for(int i=0;i<V;i++){
		vector<ll> ans=be.dist(i);
		for(int j=0;j<V;j++){
			if(j!=0){
				cout<<" ";
			}
			if(ans[j]==1e18+7){
				cout<<"INF";
			}else{
				cout<<ans[j];
			}
		}
		cout<<endl;
	}
	return 0;
}


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

int dx[]={1,1,0,-1,-1,-1,0,1};
int dy[]={0,1,1,1,0,-1,-1,-1};
string board[60];
int main(){
  int X,Y;
  cin>>X>>Y;
  rep(i,X)cin>>board[i];
  rep(i,X){
    rep(j,Y){
      if(board[i][j]=='.'){
        int cnt=0;
        rep(k,8){
          int x=i+dx[k];
          int y=j+dy[k];
          if (x>=0 && x<X && y>=0 && y<Y && board[x][y]=='#'){
            cnt++;
          }
        }
        board[i][j]='0'+cnt;
      }
    }
  }
  rep(i,X) cout<<board[i]<<endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=0
b_n=-2
for i in range(n):
  num=a[i]-1
  ans+=b[num]
  if num==b_n+1:
    ans+=c[b_n]
  b_n=a[i]-1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using P = pair<int, int>;
using ll = long long;
const int INF = 1001001001;

int main() {
    int n; cin >> n;
    int now = 1000;
    for(int i = 1;;i++){
        if(n <= now) break;
        now += 1000;
    }
    cout << now - n << endl;

    return 0;
}

Measured memory_bytes: 3628
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

ans = 'Yes'

for i in range(2):
    a0 = c[0][i] - c[0][i + 1]
    a1 = c[1][i] - c[1][i + 1]
    a2 = c[2][i] - c[2][i + 1]
    if not (a0 == a1 == a2):
        ans = 'No'
        break

print(ans)

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

class Program {
  static void Main(string[] args) {
    var sc = new Scanner();
    int N = sc.NextInt();
    int[] v = new int[N];
    foreach (int i in Enumerable.Range(0, N)) v[i] = sc.NextInt();
    for (int i = N - 1; i > 0; i--) Console.Write(v[i] + " ");
    Console.WriteLine(v[0]);
  }

  class Scanner {
    string[] inp;
    int ptr;

    public Scanner() {
      inp = new string[0];
      ptr = 0;
    }

    private void Fetch() {
      if (ptr >= inp.Length) {
        inp = Console.ReadLine().Split(' ');
        ptr = 0;
      }
    }

    public int NextInt() {
      Fetch();
      return int.Parse(inp[ptr++]);
    }

    public string Next() {
      Fetch();
      return inp[ptr++];
    }

    public double NextDouble() {
      Fetch();
      return double.Parse(inp[ptr++]);
    }
  }

}

Measured memory_bytes: 5796
<?php
  fscanf(STDIN, "%d", $n);
  $s = [];
  for ($i=0; $i<$n; $i++) {
    $s[] = trim(fgets(STDIN));
  }
  array_unique($s);

  $cnt = [];
  for ($i=0; $i<count($s); $i++) {
    $cnt[$s[$i][0]]++;
  }

  $ans = 0;
  $chars = ['M','A','R','C','H'];
  for ($i=0; $i<5; $i++)
  for ($j=$i+1; $j<5; $j++)
  for ($k=$j+1; $k<5; $k++) {
    $ans += $cnt[$chars[$i]] * $cnt[$chars[$j]] * $cnt[$chars[$k]];
  }
  echo $ans;
?>

Measured memory_bytes: 18804
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	vector<int> Height(10);
	for(int i = 0; i < 10; ++i)
	{
		cin >> Height[i];
	}
	sort(Height.begin(), Height.end());
	for(int i = 9; i > 6; --i)
	{
		cout << Height[i] << endl;
	}
}

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

Measured memory_bytes: 0
import bisect
a, b, q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(a)] + [INF]
t = [-INF] + [int(input()) for j in range(b)] + [INF]
start = [int(input()) for i in range(q)]
for i in range(len(start)):
    tmp = start[i]
    s_w = bisect.bisect_right(s, tmp)
    t_w = bisect.bisect_right(t, tmp)
    a_1 = abs(s[s_w]- tmp) + abs(t[t_w-1]-s[s_w]) 
    a_2 = abs(s[s_w]- tmp) + abs(t[t_w] - s[s_w])
    a_3 = abs(s[s_w-1]-tmp) + abs(t[t_w-1]-s[s_w-1])
    a_4 = abs(s[s_w-1]-tmp) + abs(t[t_w]-s[s_w-1])
    a_5 = abs(t[t_w-1]- tmp) + abs(s[s_w]-t[t_w-1]) 
    a_6 = abs(t[t_w] - tmp) + abs( s[s_w]-t[t_w] )
    a_7 = abs(t[t_w-1]-tmp) + abs(s[s_w-1]-t[t_w-1])
    a_8 = abs(t[t_w]-tmp) + abs(s[s_w-1]-t[t_w])
    print(min(a_1,a_2,a_3,a_4,a_5,a_6,a_7,a_8))

Measured memory_bytes: 16144
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
	int n, i;
	int a[1000] = { 0 };
	double ave, sum, ans;

	while (1) {
		cin >> n;

		if (n == 0)break;

		i = 0;
		sum = 0;
		while (i < n) {
			cin >> a[i];

			sum += a[i];

			i++;
		}
		ave = sum / n;

		i = 0;
		ans = 0;
		while (i < n) {
			ans += pow(a[i] - ave, 2) / n;
			i++;
		}

		cout << setprecision(10) << sqrt(ans) << endl;
	}
	
    return 0;
}



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


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

    int n;
    int w;
    int i;
    cin>>n>>w;

    ll val[n+1];
    ll wgt[n+1];

    for(i=1;i<=n;i++)
    {
        cin>>wgt[i]>>val[i];
    }

    ll ans[n+1][w+1];
    int j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
          if(i==0||j==0)
          {
              ans[i][j]=0;
          }
          else if((j-wgt[i])>=0)
          {
              ans[i][j]=max(val[i]+ans[i-1][j-wgt[i]],ans[i-1][j]);
          }
          else ans[i][j]=ans[i-1][j];
        }
    }
    cout<<ans[n][w];
}

Measured memory_bytes: 79232
using System;
using System.Collections.Generic;
using System.Linq;
class ilds1_2_d{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    int[] num = new int[n];
    for(int i=0; i<n; i++){
      num[i] = int.Parse(Console.ReadLine());
    }
    List<int> list = new List<int>();
    int cur = 1;
    while(cur <= n){
      list.Add(cur);
      cur = cur*3+1;
    }
    list.Reverse();
    int ans = 0;
    foreach(int i in list){
      ans += InsertionSort(num,n,i);
    }
    Console.WriteLine(list.Count);
    Console.WriteLine(string.Join(" ",list));
    Console.WriteLine(ans);
    for(int i=0; i<n; i++){
      Console.WriteLine(num[i]);
    }
  }
  public static int InsertionSort(int[] a, int n, int g){
    int cnt=0;
    for(int i=g; i<n; i++){
      int v = a[i];
      int j = i-g;
      while(j >= 0 && a[j] > v){
        a[j+g] = a[j];
        j = j-g;
        cnt++;
      }
      a[j+g] = v;
    }
    return cnt;
  }
}



Measured memory_bytes: 23540
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int INF=1e9;

struct UnionFind{
    vector<int> par,rank;
    int c;
    UnionFind(int n):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=1;
        c=n;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]){
            par[rx]=ry;
        }
        else{
            par[ry]=rx;
            if(rank[rx]==rank[ry]) rx++;
        }
        c--;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
    
};

int main()
{
    int a,b,c;cin>>a>>b>>c;
    int ans=0;
    while(true){
        if(a&1||b&1||c&1) break;
        if(a==b&&b==c){
            ans=-1;break;
        }
        int p,q,r;
        p=a/2;q=b/2;r=c/2;
        a=q+r;b=p+r;c=p+q;
      ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <bitset>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define RPA(i,s,e) for(int i=s; i<=e; i++)
#define RPD(i,s,e) for(int i=s; i>=e; i--)
#define PB(a) push_back(a)
#define MP(i,s) make_pair(i,s)
#define ALL(a) (a).begin(), (a).end()
#define PRT(a) cout << (a) << endl

typedef pair<int,int> P;

struct edge { int to, cost; };

const int INF = 1000000009;
const int MAX_V = 111;
const int MAX_C = 15;
vector<edge> G[MAX_V];

int c, n, m, s, d;
int p, q, r;
int dp[MAX_C][MAX_V];

void add_edge(int from, int to, int cost) {
	edge e1 = { to, cost };
	edge e2 = { from, cost };
	G[from].PB(e1);
	G[to].PB(e2);
}

void dijkstra(int f, int t, int k) {
	REP(j,n) dp[k][j] = INF;

	priority_queue<P, vector<P>, greater<P> > que;
	que.push(MP(0, f));
	dp[k][f] = 0;

	while(!que.empty()) {
		P p = que.top();
		que.pop();

		int v = p.second;
		REP(i,G[v].size()) {
			edge& e = G[v][i];
			int minval = dp[k][v] + e.cost;
			if(k > 0) minval = min(minval, dp[k-1][v] + e.cost / 2);
			if(dp[k][e.to] > minval) {
				dp[k][e.to] = minval;
				que.push(P(minval, e.to));
			}
		}
	}
}

void solve() {
	RPA(i,0,c) {
		dijkstra(s, d, i);
	}
	PRT(dp[c][d]);
}

void coding() {
	while(scanf("%d%d%d%d%d", &c, &n, &m, &s, &d) != EOF) {
		if(c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;

		s--; d--;
		REP(i,n) G[i].clear();

		REP(i,m) {
			scanf("%d%d%d", &p, &q, &r);
			p--; q--;
			add_edge(p, q, r);
		}
		solve();
	}
}

//#define _LOCAL_TEST

int main() {
#ifdef _LOCAL_TEST
	freopen("a.in", "r", stdin);
#endif

	coding();

#ifdef _LOCAL_TEST
	cout << endl;
	cout << "This is local test" << endl;
	cout << "Do not forget to comment out _LOCAL_TEST" << endl;
#endif
}

Measured memory_bytes: 1256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int X; cin >> X;

	int ans = 0;
	ans += (X / 500) * 1000;
	X %= 500;
	ans += (X / 5)*5;
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    print(YES if S == T[0:len(T)-1] else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


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

int main(void){
	long long n, W, w_0, w_, v_;
	cin >> n >> W;
	vector<long long> v[4];
	for(int i = 0; i < 4; ++i){
		v[i].resize(n+10);
	}
	cin >> w_0 >> v[0][0];
	for(int i = 1; i < n; ++i){
		cin >> w_ >> v_;
		v[w_-w_0].push_back(v_);
	}

	for(int i = 0; i < 4; ++i){
		sort(v[i].rbegin(), v[i].rend());
	}
	for(int i = 0; i < 4; ++i){
		for(int j = 1; j < v[i].size(); ++j){
			v[i][j] += v[i][j-1];
		}
	}

	long long value = 0;
	for(int i = 0; i <= v[0].size(); ++i){
		for(int j = 0; j <= v[1].size(); ++j){
			for(int k = 0; k <= v[2].size(); ++k){
				for(int l = 0; l <= v[3].size(); ++l){
					if(w_0*i+(w_0+1)*j+(w_0+2)*k+(w_0+3)*l>W) continue;
					value = max(value, 
						(i==0?0LL:v[0][i-1]) +
						(j==0?0LL:v[1][j-1]) +
						(k==0?0LL:v[2][k-1]) +
						(l==0?0LL:v[3][l-1]) );
				}
			}
		}
	}
	cout << value << endl;




	return 0;

	// vector<int> w(n), v(n), dp[n+1];
	// for(int i = 0; i < n; ++i){
	// 	cin >> w[i] >> v[i];
	// 	dp[i].resize(W+10);
	// }
	// dp[n].resize(W+10);
	// for(int i = 0; i < n; ++i){
	// 	for(int j = 0; j <= W; ++j){
	// 		if(j >= w[i]){
	// 			dp[i+1][j] = max(dp[i][j-w[i]]+v[i], dp[i][j]);
	// 		}else{
	// 			dp[i+1][j] = dp[i][j];
	// 		}
	// 	}
	// }
	// cout << dp[n][W] << endl;
}

Measured memory_bytes: 256
mod = (1e9 + 7).to_i
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
sum = arr.inject(:+) % mod
res = 0
n.times do |i|
  sum -= arr[i]
  res += arr[i] * sum
  res %= mod
end
puts res.to_i


Measured memory_bytes: 36000
T = int(input())
for _ in range(T):
	n = int(input())
	if n < 5:
		print(0)
	elif n % 2 == 0:
		x = n // 2 - 2
		ans = (37476432000*(x) + 187243792560*(x**2) + 399117903732*(x**3) + 485269948800*(x**4) + 379718819935*(x**5) + 204017288475*(x**6) + 78161197114*(x**7) + 21814113750*(x**8) + 4477585255*(x**9) + 675269595*(x**10) + 73895276*(x**11) + 5705700*(x**12) + 294560*(x**13) + 9120*(x**14) + 128*(x**15))//163459296000
		print(ans % 1000000007)
	else:
		x = n // 2 - 1
		ans = ((-4490640000) * (x) - 9469891440 * (x**2) + 5980311612 * (x**3) + 38927921760 * (x**4) + 55757252005 * (x**5) + 44011832865 * (x**6) + 22464496054 * (x**7) + 7902767730 * (x**8) + 1972993165 * (x**9) + 353017665 * (x**10) + 45000956 * (x**11) + 3991260 * (x**12) + 234080 * (x**13) + 8160 * (x**14) + 128 * (x**15))//163459296000
		print(ans % 1000000007)

Measured memory_bytes: 9252
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int N;
    cin >> N;
    for(int i=0;4*i<=N;++i)
    {
        for(int j=0;j*7<=N;++j)
        {
            if(i*4+7*j==N)
            {
                cout << "Yes";
                return 0;
            }      
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
using ll = long long;

string s;

void dfs(string op,int now,int i)
{
	if(i==4)
	{
		if(now==7)
		{
		for(int i =0 ;i<3;i++)cout<<s[i]<<op[i+1];
		cout<<s.back();
		cout<<"=7"<<endl;
		exit(0);
		}
		return;
	}
	dfs(op+'+',now+s[i]-'0',i+1);
	if(i)dfs(op+'-',now-s[i]+'0',i+1);
}

int main()
{
	cin >> s;
	dfs("",0,0);
}


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

int main()
{
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h+2, vector<char>(w+2));
  vector<vector<int>> num(h+2, vector<int>(w+2));
  int i, j, ii, jj;
  for(i = 0; i < h+2; i++)
  {
    for(j = 0; j < w+2; j++)
    {
      if(i == 0 || i == h+1 || j == 0 || j == w+1)
      {
        s.at(i).at(j) = '.';
      }
      else
      {
        cin >> s.at(i).at(j);
      }
    }
  }
  for(i = 0; i < h; i++)
  {
    for(j = 0; j < w; j++)
    {
      if(s.at(i+1).at(j+1)=='#')
      {
        num.at(i+1).at(j+1) = 255;
      }
      else
      {
        for(ii = i; ii <= i+2; ii++)
        {
          for(jj = j; jj <= j+2; jj++)
          {
            if((ii != i+1 || jj != j+1)&& s.at(ii).at(jj) == '#')
            {
              num.at(i+1).at(j+1)++;
            }
          }
        }
      }
    }
  }
  for(i = 0; i < h; i++)
  {
    for(j = 0; j < w; j++)
    {
      if(num.at(i+1).at(j+1) >= 255)
      {
        cout << '#';
      }
      else
      {
        cout << num.at(i+1).at(j+1);
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import sys
x, k, d = map(int, input().split())
if x>0 and x-k*d>=0:
  print(x-k*d)
  sys.exit()
if x<0 and x+k*d<=0:
  print(-x-k*d)
  sys.exit()
a=0
b=0
for i in range(1,k+1):
  if abs(x)-i*d<=0:
    a=i
    b=i-1
    break
if (k-a)%2 ==0:
  print(-abs(x)+a*d)
else:
  print(abs(x)-b*d)

Measured memory_bytes: 62680
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
    ll siz;
    string S;
    cin >> S;
    siz = S.size();

    for(ll i = 0;i<siz;i++){
        cout << "x";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define watch(x) cout<<"->"<<#x<<": "<<x<<endl;
// #define int long long
const int INF = 1000000000;
const int MOD = 1000000007;
const long long INFLL = 1e18;
const double PI = 2*acos(0.0);
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	int res = 0;
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int lo = j;
			int hi = n-1;
			while(lo<=hi)
			{
				int mid = (lo+hi)/2;
				if(a[i]+a[j]>a[mid])
					lo = mid + 1;
				else
					hi = mid - 1;
			}
			res+=lo-j-1;
		}
	}
	return cout<<res<<endl,0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N; cin >> N;
    vector<int> p(N+1);
    p[N] = 0;
    int count = 0;
    int seq = 0;
    for(int i=0;i<N+1;i++){
        if(i!=N)cin >>p[i]; p[i]--;
        if(p[i]==i) seq++;
        else {count += (seq+1)/2; seq=0;}
    }
    cout << count << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long int n , m , c = 0;
    cin >> n >> m;
    if ( m >= n * 2 ) {
        c += n;
        m -= n * 2;
        c += m / 4;
    } else {
        c += m / 2;
    }
    cout << c;
}

Measured memory_bytes: 256
from itertools import product
from collections import Counter
 
n, c = map(int, input().split())
color_costs = [list(map(int, input().split())) for _ in range(c)]
matrix = [list(map(int, input().split())) for _ in range(n)]

colord = {(i, j):cost for i, row in enumerate(color_costs)
                      for j, cost in enumerate(row)}
 
res = []
for n in range(3):
  color_count = Counter(c-1 for i, row in enumerate(matrix) 
                            for j, c in enumerate(row) 
                            if (i + j) % 3 == n)
  def color_cost(color):
    return sum(colord[ccolor, color] * ccount for ccolor, ccount in color_count.items())
  cx = [(color, color_cost(color)) for color in range(c)]
  sorted_by_cost = sorted(cx, key=lambda x:x[1])
  cheapest3 = sorted_by_cost[:3]
  res.append(cheapest3)

color_pickss = product(*res)
filtered_unique = (picks for picks in color_pickss if len(set(x[0] for x in picks)) == 3)
costs = (sum(x[1] for x in picks) for picks in filtered_unique)
print(min(costs))

Measured memory_bytes: 5996
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

func check(i int) bool {
	if i%2 != 0 {
		return true
	}
	if i%3 == 0 || i%5 == 0 {
		return true
	}
	return false
}
func checks(ints []int) bool {
	for _, v := range ints {
		if !check(v) {
			return false
		}
	}
	return true
}

func main() {
	n := nextInt()
	ints := nextInts(n)

	var result string
	if checks(ints) {
		result = "APPROVED"
	} else {
		result = "DENIED"
	}
	fmt.Println(result)
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

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

    bool ok = false;
    int len = s.length();
    string k;

    for(int i=0;i<7;i++){
        string k;
        for(int j=0;j<i;j++) k += s[j];
        for(int j=0;j<7-i;j++) k += s[len-7+i+j];
        if(k == "keyence") ok = true;
    }

    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  REP(i,s.size()-1){
    if(s[i]=='A' && s[i+1]=='C'){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
 
struct pt {
    LL x, y;
    pt(): x(0), y(0) {}
    pt(LL x, LL y): x(x), y(y) {}
};
pt operator-(pt A, pt B) { return {A.x-B.x, A.y-B.y}; }
 
bool above(pt A, pt B, pt C) {
    B = B-A, C = C-A;
    return B.x * C.y - B.y * C.x >= 0;
}
 
 
int main() {
    int N;
    cin >> N;
    vector<LL> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
 
    int it = 0;
    for (int i = 0; i < N; i++) if (A[i] > A[it]) it = i;
    rotate(A.begin(), A.begin() + it, A.end());
    rotate(B.begin(), B.begin() + it, B.end());
    A.push_back(A[0]);
    B.push_back(B[0]);
    vector<LL> C(N+1, 0);
    for (int i = 2; i <= N; i++) C[i] = 2*(C[i-1]+B[i-1]) - C[i-2];
    
    vector<pt> hull = {{0, A[0]-C[0]}};
    for (int i = 1; i <= N; i++) {
        pt P = {i, A[i]-C[i]};
        while (hull.size() >= 2 and above(hull[hull.size()-2], hull.back(), P)) hull.pop_back();
        hull.push_back(P);
    }
    
    LL twice_res = 0;
    for (int i = 1; i < (int)hull.size(); i++) {
        LL dx = hull[i].x - hull[i-1].x;
        LL area = hull[i-1].y * (dx+1) + hull[i].y * (dx-1);
        twice_res += area;
    }
    for (int i = 0; i < N; i++) twice_res += 2*C[i];
 
    double res = twice_res;
    res /= 2*N;
    cout.precision(12);
    cout << fixed << res << endl;
}

Measured memory_bytes: 14128
H,N = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]

INF = float('inf')
dp = [INF]*(H+1)
dp[H] = 0
for a,b in AB:
    for i in range(H,0,-1):
        if i-a <= 0:
            dp[0] = min(dp[0], dp[i]+b)
        else:
            dp[i-a] = min(dp[i-a], dp[i]+b)
print(dp[0])

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

int main() {
int n;
int r;
int x;
cin >> n;
cin >> r;
x = 100*(10-n)+r;
if (n >= 10) {
  cout << r;
} else {
 cout << x; 
}
	return 0;
}


Measured memory_bytes: 3640
fn main() {
    let alphas = [
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
        'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
    ];

    let alphas_len = 26;
    let mut n: usize = read();

    let mut mods = Vec::new();
    while n > 0 {
        // スライスに合わせるためにn-1する
        n -= 1;
        
        let m = n % alphas_len;
        mods.push(m);

        n = n / alphas_len;
    }

    let name = mods
        .iter()
        .rev()
        .map(|v| (alphas[*v]).to_string())
        .collect::<Vec<String>>()
        .join("");
    println!("{}", name);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


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

using namespace std;

int main(void) {
  int H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K;
  int t = H2*60 + M2;
  t -= H1*60 + M1;
  t -= K;

  cout << t << endl;

  return 0;
}

Measured memory_bytes: 3672
from math import sqrt, floor

n, q = map(int, input().split())

A = [0] * (n + 1)

# sqrt-decomposition
b = floor(sqrt(n + 1))
k = (n + b) // b
# Aをbごとに分割して、総和をBで管理する
# B[i] represents sum of A[i*b: (i+1)*b]
B = [0] * k


def add(x, y):
    A[x] += y
    B[x//b] += y


def get_sum(x, y):
    res = 0
    # xから bの倍数になるまで足す
    while x % b and x < y:
        res += A[x]
        x += 1
    # yから bの倍数になるまで、添字が減る方向に足す
    while y % b and x < y:
        res += A[y]
        y -= 1
    res += A[y]
    # 残りの間の区間を足す
    res += sum(B[x//b:y//b])

    print(res)


for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        add(x, y)
    else:
        get_sum(x, y)



Measured memory_bytes: 7228
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;

    while(k>0)
    {
        if(c<=b||c<=a) c*=2;

        else if(b<=a) b*=2;

        if(a<b&&b<c)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        k--;
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 3132
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cctype>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int n[3] = {a, b, c};
  sort(n, n+3);
  cout << n[0] + n[1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = c;
	rep(i, a) {
		int put;
		cin >> put;
		ans += (b-1) / put+1;
	}
	cout << ans << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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 long long INF = 100100100100100;
const long long MOD = 1000000007;
typedef pair<long long,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int parent[100005];
int tall[100005];

int searchRoot(int v){
    if(parent[v] == v) return v;
    return parent[v] = searchRoot(parent[v]);
}
 
void unite(int x,int y){
    int rootX = searchRoot(x);
    int rootY = searchRoot(y);
    if(rootX == rootY) return;
    if(tall[x] > tall[y]){
        parent[rootY] = rootX;
    }
    else if(tall[x] < tall[y]){
        parent[rootX] = rootY;
    }
    else {
        tall[y]++;
        parent[rootY] = rootX;
    }
}
 
bool same(int x,int y){
    if(searchRoot(x) == searchRoot(y)) return true;
    else return false;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N,M;cin >> N >> M;
    vector<int> retu(N);
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
        retu.at(i)--;
    }
    for(int i = 0;i<N;i++){
        parent[i] = i;
        tall[i] = 0;
    }
    //連結しているグループ内に番号と一致する値があったら揃えられる
    for(int i = 0;i<M;i++){
        int a,b;cin >> a >> b;a--;b--;
        unite(a,b);
    }
    //連結しているグループごとに入れ替えられる値を保存する
    vector<set<int>> group(N);
    for(int i = 0;i<N;i++){
        int root = searchRoot(i);
        group.at(root).insert(retu.at(i));
    }
    int ans = 0;
    //属しているグループ内に同じ値があるか調べる
    for(int i = 0;i<N;i++){
        int Root = searchRoot(i);
        if(group.at(Root).count(i)) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 13764
#include<iostream>
#include<cstdio>
#include<string>
#include<set>
using namespace std;
int main()
{
    string a, b;
    set<string> S;
    int point = -1, i, j, k = 0;
    cin >> a >> b;
    for(i = 0; i < a.length(); i++)
    {
        int sum = 0;
        k = 0;
        for(j = i; j < b.length()+i; j++)
        {
            if(a[j] == b[k] || a[j] == '?') sum++;
            k++;
        }
        if(sum == b.length()) point = i;

    }
    k = 0;
    if(point == -1) cout << "UNRESTORABLE" << endl;
    else
    {
        for(j = point; j < point+b.length(); j++)
        {
            a[j] = b[k++];
        }
        for(i = 0; i <a.length(); i++)
        {
            if(a[i] == '?') a[i] = 'a';
        }
        cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	string s;
	cin >> s;
	int n = s.size();
	int ans = n/2;
	for(int i=0;i<n;i++){
		if( s[i] == 'p' ) ans--;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void)
{
  int x;
  cin >> x;
  int ans=1;
  for(int i=0;i<340;i++)
    {
      if(i*i<=x&&ans<i*i)
	{
	  ans=i*i;
	}
      if(i*i>x)
	break;
    }
   for(int i=0;i<340;i++)
    {
      if(i*i*i<=x&&ans<i*i*i)
	{
	  ans=i*i*i;
	}
      if(i*i*i>x)
	break;
    }
  for(int i=0;i<340;i++)
    {
      if(i*i*i*i<=x&&ans<i*i*i*i)
	{
	  ans=i*i*i*i;
	}
      if(i*i*i*i>x)
	break;
    }
  for(int i=0;i<340;i++)
    {
      if(i*i*i*i*i<=x&&ans<i*i*i*i*i)
	{
	  ans=i*i*i*i*i;
	}
      if(i*i*i*i*i>x)
	break;
    }
  for(int i=0;i<340;i++)
    {
      if(i*i*i*i*i*i<=x&&ans<i*i*i*i*i*i)
	{
	  ans=i*i*i*i*i*i;
	}
      if(i*i*i*i*i*i>x)
	break;
    }
  for(int i=0;i<340;i++)
    {
      if(i*i<=x&&ans<i*i)
	{
	  ans=i*i;
	}
      if(i*i>x)
	break;
    }
  for(int i=0;i<340;i++)
    {
      if(i*i*i*i*i*i*i<=x&&ans<i*i*i*i*i*i*i)
	{
	  ans=i*i*i*i*i*i*i;
	}
      if(i*i*i*i*i*i*i>x)
	break;
    }
  for(int i=0;i<340;i++)
    {
      if(i*i*i*i*i*i*i*i<=x&&ans<i*i*i*i*i*i*i*i)
	{
	  ans=i*i*i*i*i*i*i*i;
	}
      if(i*i*i*i*i*i*i*i>x)
	break;
    }
  for(int i=0;i<340;i++)
    {
      if(i*i*i*i*i*i*i*i*i<=x&&ans<i*i*i*i*i*i*i*i*i)
	{
	  ans=i*i*i*i*i*i*i*i*i;
	}
      if(i*i*i*i*i*i*i*i*i>x)
	break;
    }
  cout << ans <<endl;
  return 0;
}


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

int main() {
  	int n, x, t;
  	cin >> n >> x >> t;
  
	if(n % x != 0) cout << ((n/x)+1)*t << endl;
  	else cout << (n/x)*t << endl;
  	return 0;  
}


Measured memory_bytes: 3604