akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int a, b, c, d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		if (a < c) {
			a = c;
		}
		if (b > d) {
			b = d;
		}
		if (b - a < 0) {
			System.out.println(0);
		} else {
			System.out.println(b - a);
		}
	}
}


Measured memory_bytes: 23124
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

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

    int cnt = 0;
    bool up = false, down = false;
    for(int i = 1; i < n; ++i){
        int dif = a[i] - a[i-1];
        if(dif > 0) up = true;
        if(dif < 0) down = true;
        if(up && down){
            ++cnt;
            up = down = false;
        }
    }

    cout << cnt+1 << endl;

return 0;
}

Measured memory_bytes: 3732
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
  int n;
  cin>>n;
  double b,sum=0;
  rep(i,n){
      cin>>b;
      sum+=1/b;
  }
  cout<<fixed<<setprecision(10)<<1/sum<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
int n, m, c;

int main(){
	IOS
	cin >> n >> m >> c;
	ll ans=0;
	int b[m+5], a[m+5];
	for(int i=0;i<m;i++){
		cin >> b[i];
	}
	while(n--){
		for(int i=0;i<m;i++){
			cin >> a[i];
		}
		ll jawab=0;
		for(int i=0;i<m;i++){
			jawab+=a[i]*b[i];
		}
		jawab+=c;
		if(jawab>0){
			ans++;
		}
	}
	cout << ans << '\n';
}

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

int main(int argc, char const *argv[]) {
  int a[3],k;
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  sort(a,a+3);
  cin>>k;
  for(int i=0;i<k;i++){
    a[2]=a[2]*2;
  }
  cout<<a[0]+a[1]+a[2]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
   int N;
   cin >> N;
   vector<string> W;
   for(int i=0; i<N; i++){
      string w;
      cin >> w;
      W.push_back(w);
   }

   for(int i=0; i < N-1; i++){
      if(W[i].back() != W[i+1][0]){
         cout << "No" << endl;
         return 0;
      }
      for(int j=i+1; j < N; j++){
         if(W[i] == W[j]){
            cout << "No" << endl;
            return 0;
         }
      }
   }
   cout << "Yes" << endl;

   return 0;
}

Measured memory_bytes: 256
// use proconio::input;
use std::io;

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

fn main() {
    let vec = read_vec::<i64>();
    let a = vec[0];
    let b = vec[1];

    println!("{} {} {:.5}", a / b, a % b, a as f64 / b as f64);
}


Measured memory_bytes: 5052
#include <stdio.h>
#include <stdlib.h>

#define SWAP(x, y) {int z = x; x = y; y = z;}
#define MARU 0
#define BATU 1

int main(void)
{
	int n, i;
	int *check;
	int swap_num = 0;

	scanf("%d", &n);
	check = malloc(sizeof(int) * (n + 1));

	for(i = 1; i <= n; i++)
	{
		int num;

		scanf("%d", &num);
		if(i != num)
		{
			check[i] = MARU;
		}
		else
		{
			check[i] = BATU;
		}
	}

	for(i = 1; i <= n; i++)
	{
		if(i != n && check[i] == BATU)
		{
			SWAP(check[i],check[i+1]);
			check[i] = MARU;
			check[i + 1] = MARU;
			swap_num++;
		}
		else if(i == n && check[i] == BATU)
		{
			SWAP(check[i], check[i - 1]);
			check[i] = MARU;
			check[i - 1] = MARU;
			swap_num++;
		}
	}
	printf("%d\n", swap_num);

	return 0;
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            Map<Integer, Integer> countMap = ArrayUtils.getCountMap(a);
            List<Integer> list = new ArrayList<>();
            Set<Integer> set = countMap.keySet();
            for (int x : set) {
                int cnt = countMap.get(x);
                if (cnt >= 4) {
                    list.add(x);
                    list.add(x);
                } else if (cnt >= 2) {
                    list.add(x);
                }
            }
            Collections.sort(list, Collections.reverseOrder());

            if (list.size() < 2) {
                out.println(0);
            } else {
                out.println((long) list.get(0) * list.get(1));
            }
        }

    }

    static class ArrayUtils {
        public static Map<Integer, Integer> getCountMap(int[] array) {
            Map<Integer, Integer> map = new TreeMap<>();
            for (int x : array) map.merge(x, 1, Integer::sum);
            return map;
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 43600
#include <stdio.h>

int main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);
	while (b-- > 0) {
		int temp;
		scanf("%d", &temp);
		if (a - temp < 0) {
			printf("-1\n");
			return 0;
		}
		a -= temp;
	}
	printf("%d\n", a);
	return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

const ll MOD = 1e9+7;

ll Pow(ll  x, ll n){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return Pow(x * x % MOD, n / 2);
  else
    return x * Pow(x, n - 1) % MOD;
}


const ll INF = 1e15;

int main(){
    ll n, m; cin >> n >> m;
    ll po = pow(2, n);
    vector<vector<ll> > dp(m+1, vector<ll>(po, INF));
    dp[0][0] = 0;
    REP(i, 0, m){
        int a, b; cin >> a >> b;
        ll k = 0;
        vector<int> ch(n, 0);
        REP(i, 0, b){
            int c; cin >> c;
            ch[c-1] = 1;
        }
        REP(l, 0, po){
            if(dp[i][l] == INF){
                continue;
            }
            ll c = l;
            vector<int> ch1(n, 0);
            REP(k, 0, n){
                if((c & 1) == 1){
                    ch1[k] = 1;
                }
                c /= 2;
            }
            int f = 0;
            REP(k, 0, n){
                if(ch1[k] == 0 && ch[k] == 1){
                    f = 1;
                }
                ch1[k] = max(ch1[k] , ch[k]);
            }
            ll mid = 0;
            ll kk = 1;
            REP(k, 0, n){
                mid += kk * ch1[k];
                kk *= 2;
            }
            //cout << l <<  mid << endl;
            if(f == 1){
                dp[i+1][mid] = min(dp[i][l] + a, dp[i+1][mid]);
            }
        }
        REP(l, 0, po){
            dp[i+1][l] = min(dp[i+1][l], dp[i][l]);
        }
    }
    if(dp[m][po-1] == INF){
        cout << -1 << endl;
        return 0;
    }
    cout << dp[m][po-1] << endl;
}

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

#pragma optimize("O3")

#define int long long

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int a, b, c;
    cin >> a >> b >> c;

    for (; b <= c; ++b) {
        if (b % a == 0) {
            cout << "OK";
            return 0;
        }
    }

    cout << "NG";

    return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int, in){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}

struct union_find {
	struct node {int p, r = 0;};
	vector<node> nodes;

	union_find(int n) : nodes(n) {
		int i = 0;
		for (node &n: nodes)
			n.p = i++;
	}
	int find(int x) {
		int &p = nodes[x].p;
		if (p != x)
			p = find(p);
		return p;
	}
	void unite(int a, int b) {
		int ar = find(a), br = find(b);
		node &an = nodes[ar], &bn = nodes[br];
		if (an.r > bn.r)
			bn.p = ar;
		else {
			an.p = br;
			if (an.r == bn.r)
				bn.r++;
		}
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
};

struct edge {
	int s, t, w;
	bool operator < (edge &a) {return w < a.w;}
};

int main() {
	union_find V(in());
	vector<edge> E(in());
	int r = 0;
	for (edge &e: E)
		e = {in(), in(), in()};
	sort(E.begin(), E.end());
	for (edge e: E)
		if (!V.same(e.s, e.t)) {
			r += e.w;
			V.unite(e.s, e.t);
		}
	outl(r);
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;
ll d[305][305];  /* 最短距離 */
vector<ll> d2[305]; /* 補給しなくてもいける点同士のつながり */ /* 幅優先探索をつかう */
ll ans[305][305];    /* 単一始点最小補給回数 */
bool isUsed[305];

int main(){
    ll n, m, l;
    cin >> n >> m >> l;

    REP(i, n) REP(j, n) {
        if(i == j) d[i][j] = 0;
        else d[i][j] = INF;
    }

    REP(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    REP(i, n) REP(j, n) REP(k, n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
    REP(i, n) REP(j, n) if(d[i][j] <= l && 0 < d[i][j]) d2[i].push_back(j);
    REP(i, n) REP(j, n) ans[i][j] = -1;

    int q;
    cin >> q;

    REP(query, q) {
        int s, t;
        cin >> s >> t;
        s--, t--;

        if(ans[s][t] != -1) {
            cout << ans[s][t] - 1 << endl;
            continue;
        }

        queue<int> que;
        que.push(s);
        ans[s][s] = 0;
        REP(i, n) isUsed[i] = false;

        while(que.size()) {
            REP(i, que.size()) {
                int k = que.front();
                que.pop();
                REP(j, d2[k].size()) {
                    int dst = d2[k][j];
                    if(!isUsed[dst]) {
                        isUsed[dst] = true;
                        ans[s][dst] = ans[s][k] + 1;
                        que.push(dst);
                    }
                }
            }
        }

        if(ans[s][t] == -1) cout << "-1" << endl;
        else cout << ans[s][t] - 1 << endl;
    } 

    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=100005;
ll dp[3003][3004]={};
void solve()
{
    int n,k=1,m=0,i=1,j,x,y,l,r,p,q,z,a[3000];
    ll ans=0;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    //Add sec subtract first
    for(i=n;i>0;i--)
    {
        for(j=i;j<=n;j++)
        {
            if(i==j) dp[i][j]=a[i];
            else
                dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
        }
    }
    cout<<dp[1][n];
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 49748
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define el '\n'
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define repd(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define large 1000000007
#define pb() push_back()
#define MAX 10e+7
void solve(int t)
{
int r=t%10;
if(r==2||r==4||r==5||r==7||r==9)
cout<<"hon"<<el;
else if(r==0||r==1||r==6||r==8)
cout<<"pon"<<el;
else
{
    cout<<"bon"<<el;
}


}
int main()
{
    
 long long int t;
 cin>>t;
solve(t);
  return 0;
}


Measured memory_bytes: 3636
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
 
class Program {
    static void Main(string[] args) {
        var ST = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
        
        var SX = ST[0];
        var SY = ST[1];
        var TX = ST[2];
        var TY = ST[3];
        
        //一往復目
        for(int i = SX;i < TX ; i++){
            Console.Write('R');
        }
        for(int i = SY;i < TY ; i++){
            Console.Write('U');
        }
        for(int i = SX;i < TX ; i++){
            Console.Write('L');
        }
        for(int i = SY;i < TY ; i++){
            Console.Write('D');
        }
        
        Console.Write('L');
        for(int i = SY;i <= TY ; i++){
            Console.Write('U');
        }
        for(int i = SX;i <= TX ; i++){
            Console.Write('R');
        }
        Console.Write('D');
        Console.Write('R');
        for(int i = SY;i <= TY ; i++){
            Console.Write('D');
        }
        for(int i = SX;i <= TX ; i++){
            Console.Write('L');
        }
        Console.Write('U');
     }
}


Measured memory_bytes: 11348
from collections import Counter
MOD = 998244353
N = int(input())
Ds = list(map(int, input().split()))

ct = Counter(Ds)
M = max(ct)
if Ds[0] != 0 or ct[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1, M+1):
    ans *= pow(ct[i-1], ct[i], MOD)
    ans %= MOD
print(ans)

Measured memory_bytes: 19928
#include <stdio.h>
int main(void){
  int a,b,c;
  int t;
    
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  
  t=a; 
  a=b;
  b=t;
  t=a;
  a=c;
  c=t;
  printf("%d %d %d\n",a,b,c);

  return 0;
}
  

Measured memory_bytes: 1728
import math

a, b, c, d = map(int, input().split())

lcm = c*d // math.gcd(c, d)

dif = b-a+1
div_c = b//c - (a-1)//c
div_d = b//d - (a-1)//d
div_cd = b//lcm - (a-1)//lcm

ans = dif - (div_c + div_d) + div_cd
print(int(ans))

Measured memory_bytes: 9092
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

const int N = 1e5 + 7;

int ans = 0;
int n;

int used[N];
int sz[N];

vector<pair<int, int>> g[N];

int fnd = -1;

void dfs(int cur) {
    used[cur] = 1;
    sz[cur] = 1;
    for (auto t : g[cur]) {
        if (!used[t.first]) {
            dfs(t.first);
            ans += 2 * min(sz[t.first], n - sz[t.first]) * t.second;
            sz[cur] += sz[t.first];
            if (2 * sz[t.first] == n) {
                fnd = t.second;
            }
        }
    }
}

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

    cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    dfs(0);
    if (fnd == -1) {
        for (int i = 0; i < n; i++) {
            int mx = -1;
            for (auto t : g[i]) {
                if (sz[t.first] > sz[i]) mx = max(mx, n - sz[i]);
                else mx = max(mx, sz[t.first]);
            }
            if (2 * mx < n) {
                int mnc = -1;
                for (auto t : g[i]) {
                    if (mnc == -1 || mnc > t.second) mnc = t.second;
                }
                cout << ans - mnc << endl;
                exit(0);
            }
        }
    } else {
        cout << ans - fnd << endl;
    }
}   


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

int main(){
	string sa;
	while(cin>>sa){
		int ans=0;
		
		for(int i=0;i<sa.size();i++){
			if(sa[i]=='M'){
				ans+=1000;
				}
			else if(sa[i]=='D'){
				if(i!=sa.size()-1&&sa[i+1]=='M')ans-=500;
				else ans+=500;
				}	
			else if(sa[i]=='C'){
				if(i!=sa.size()-1&&sa[i+1]=='D'||sa[i+1]=='M'){
					ans-=100;
					}
				else ans+=100;	
				}	
			else if(sa[i]=='L'){
				if(i!=sa.size()-1&&sa[i+1]=='D'||sa[i+1]=='M'||sa[i+1]=='C'){
					ans-=50;
					}
				else ans+=50;	
				}
			else if(sa[i]=='X'){
				if(i!=sa.size()-1&&sa[i+1]=='D'||sa[i+1]=='M'||sa[i+1]=='C'||sa[i+1]=='L'){
					ans-=10;
					}
				else ans+=10;	
				}	
			else if(sa[i]=='V'){
				if(i!=sa.size()-1&&sa[i+1]=='D'||sa[i+1]=='M'||sa[i+1]=='C'||sa[i+1]=='L'||sa[i+1]=='X'){
					ans-=5;
					}
					else ans+=5;
				}
			else{
				if(i!=sa.size()-1&&sa[i+1]!='I')ans-=1;
				else ans++;
				}			
			}
			cout<<ans<<endl;
		}
		return 0;
	}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int m, d;
	cin >> m >> d;

	int ans = 0;
	Rep(i, 1, m + 1) {
		Rep(j, 1, d + 1) {
			if (j < 10) continue;
			int d1, d10;
			d1 = j % 10;
			d10 = j / 10;
			if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) ans++;
		}
	}

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

Measured memory_bytes: 256
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
#define int long long
const int INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

signed main() {
    //input
    int n,k;cin>>n>>k;
    vi c(n);
    rep(i, k){
        int d;cin>>d;
        rep(j, d){
            int x;cin>>x;
            x--;
            c[x]++;
        }
    }

    int ans = 0;
    //solve
    rep(i, n) if (c[i]==0) ans++;
    cout << ans << endl;

    return 0; 
}


Measured memory_bytes: 3660
#include<stdio.h>
#include<inttypes.h>
 
int main(){
	long long int i,n,num;
	int digit;
	int min = 12;
 
	scanf("%"SCNd64"",&n);
 
	i = 1;
	while( i*i <= n ){
		if( n%i == 0 ){
			num = n/i;
			digit = 0;
			while( num != 0 ){
				num /= 10;
				digit++;
			}
 
			if( min > digit ) min = digit;
		}
		i++;
	}
 
	printf("%d\n",min);
		
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		double ans = 0.0;
		int tmp  = (n + 1) / 2;
		ans = (double)tmp / (double)n;
		System.out.println(ans);
	}
}


Measured memory_bytes: 20948
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m; cin >> n >> m;
    vi a(m); rep(i,m) cin >> a[i];
    ll tmp = 0;
    rep(i,m) tmp+=a[i];
    if (tmp>n) {
        ct(-1);
        return 0;
    } else {
        ct(n-tmp);
    }
}



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

public class Main {

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

	    int N=gi();
	    String s=gs();
	    
	    int r=0;
	    int b=0;
	    for (int i=0; i<N;i++) {
	    	char c=s.charAt(i);
	    	if(c=='R') {
	    		r++;
	    	}else {
	    		b++;
	    	}
	    }

	    if (r>b) {
	    	System.out.println("Yes");
	    } else {
	    	System.out.println("No");
	    }
	    //System.out.println(a);
	}


	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main(){string a;cin>>a;int b,c,sa,ans=1000;c=a.size();vector<int> n(c);
           for(int i=0;i<c;i++){
             if(a[i]=='1')n[i]=1;
             else if(a[i]=='2')n[i]=2;
             else if(a[i]=='3')n[i]=3;
             else if(a[i]=='4')n[i]=4;
             else if(a[i]=='5')n[i]=5;
             else if(a[i]=='6')n[i]=6;
             else if(a[i]=='7')n[i]=7;
             else if(a[i]=='8')n[i]=8;
             else{n[i]=9;}
           }
           
           for(int i=0;i<c-2;i++){
             b=(n[i]*100)+(n[i+1]*10)+n[i+2];
             if(b>753){
               sa=b-753;
             }
             else{
               sa=753-b;
             }
             if(sa<ans){
               ans=sa;
             }
           }
           cout<<ans;
          }

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

int     main() {
        long N, M, K;
        cin >>N >>M >>K;
        for (long n=0; n<=N; n++)
                for (long m=0; m<=M; m++)
                        if (K==m*N+n*M-2*n*m) {
                                cout <<"Yes" <<endl;
                                return 0;
                        }
        cout <<"No" <<endl;
        return 0;
};

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define ll long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bs binary_search
#define mp make_pair
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ld long double
#define meme(a,no)  memset(a,no,sizeof(a))


using namespace std; 

const int INF=1e9+7;
/*
const int N=2*100000+5;

const int mod=998244353;

vector<vector<int>>v(N);

int vis[N]={0};

int level[N];*/

long long binpow(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1){
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}

long long binpow_mod(ll a,ll b,ll c){
    ll res=1;
    while(b>0){
        if(b&1){
            res=res*a%c;
        }
        a=a*a%c;
        b>>=1;
    }
    return res;
}
/*void dfs(int a){
    vis[a]=1;
    for(auto x:v[a]){
        if(!vis[x]){
            dfs(x);
        }
    }
}*/
//vector<bool>v;
//vector<int>isfactor;

/*void Seive(int n){
    v.assign(n+1,true);
    isfactor.assign(n+1,0);
    v[0]=false; v[1]=false;
    for(int i=2;i<=n;i++){
        if(v[i]){
            isfactor[i]=i;
            for(int j=i*i;j<=n;j+=i){
                if(v[j]){
                    v[j]=false;
                    isfactor[j]=i;
                }
            }
        }
    }
    
}*/
int32_t main(){
    ios
    int T;
    //cin>>T;
    T=1;
    while(T--){
        int n,x,t;
        cin>>n>>x>>t;
        int num=(n+x-1)/x;
        cout<<num*t<<endl;
    }
    
    
    
    
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

bool solve()
{
    int n;
    cin >> n;

    vector<int> v = fetch_vec<int>(n);
    sort(v.begin(), v.end());

    int ans = 0;

    if (n % 2 == 0)
    {
        int low = v[n / 2 - 1];
        int high = v[n / 2];

        if (low != high) {
            ans = high - low;
        }
    }

    cout << ans << endl;

    return true;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    vector<int>IToV(int bit,int N){
        vector<int>S;
        rep(i,N){
            if(bit&(1<<i)){
                S.push_back(i);
            }
        }
        return S;
    }


    int main(){
        int n;cin>>n;
        vector<vector<P>>p(n);
        vector<int> box(n);
        rep(i,n)box[i] = i;
        rep(i,n){
            int a;cin>>a;
            while(a--){
                int x,y;cin>>x>>y;
              x--;y;
                p[i].emplace_back(x,y);
            }
        }

        int res = 0;
        for(int bit=0;bit<(1<<n);bit++){
            vector<int> S = IToV(bit,n);
            bool f = true;
            int k = S.size();
            for(auto s : S){
                for(auto m : p[s]){
                    if(m.second == 0 && m.first==*lower_bound(ALL(S),m.first))f = false;
                    if(m.second == 1 && m.first!=*lower_bound(ALL(S),m.first))f = false;
                }
            }
            if(f)res = max(res,k);
        }
      cout<<res;
    }
    


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>


constexpr int MAXLENGTH = 1000;
int C[MAXLENGTH + 1][MAXLENGTH + 1];
int lcs(std::string lhs, std::string rhs) {
    int lnum = lhs.length();
    int rnum = rhs.length();
    for (int i = 0; i <= lnum; i++) {
        C[i][0] = 0;
    }
    for (int i = 0; i <= rnum; i++) {
        C[0][i] = 0;
    }
    for (int il = 1; il <= lnum; il++) {
        for (int ir = 1; ir <= rnum; ir++) {
            if (lhs[il-1] == rhs[ir-1]) {
                C[il][ir] = C[il - 1][ir - 1] + 1;
            }else if(C[il - 1][ir] >= C[il][ir - 1]) {
                C[il][ir] = C[il-1][ir];
            }else{
                C[il][ir] = C[il][ir - 1];
            }
        }
    }
    return C[lnum][rnum];
}

int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::string l, r;
        std::cin >> l;
        std::cin >> r;
        std::cout << lcs(l, r) << std::endl;
    }
}


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

int main(){
  int N,M; cin >> N >> M;
  int card[100010];
  for(int i=0; i<N; i++) card[i]=0;
  
  for(int i=0; i<M; i++){
    int l,r; cin >> l >> r;
    card[l-1]++; card[r]--;
  }
  for(int i=0; i<N; i++){
    card[i+1]+=card[i];
  }
  
  int count=0;
  for(int i=0; i<N; i++)
    if(card[i]==M) count++;
  cout << count << endl;
}

Measured memory_bytes: 640
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a_list=list(map(int,input().split()))
b=[0]*n
for i in a_list:
    b[i-1]+=1
b.sort()
ans=0
for i in range(n-k):
    ans+=b[i]
print(ans)

            



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

int n, ans;
bool check(long long x)
{
	bool flag[3];
	rep(i, 3) flag[i] = false;
	if (x < 357)
		return false;
	while(x)
	{
		int y = x % 10;
		if (y == 3)
			flag[0] = true;
		else if (y == 5)
			flag[1] = true;
		else if (y == 7) 
			flag[2] = true;
		x /= 10;
	}
	rep(i, 3)
	{
		if (!flag[i])
			return false;
	}
	return true;
}
void dfs(long long x)
{
	if (x > n)
		return;
	else
	{
		if (check(x)) ans++;
		dfs(10 * x + 3);
		dfs(10 * x + 5);
		dfs(10 * x + 7);
	}
}

signed main(void)
{
	cin >> n;
	ans = 0;
	dfs(0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;

struct Node{
  int key;
  Node *p, *l, *r;
};

int n;

Node *NIL, *root;

void preorder(Node *u){
  if(u == NIL) return;
  cout << ' ' << u->key;
  preorder(u->l);
  preorder(u->r);
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->l);
  cout << ' ' << u->key;
  inorder(u->r);
}

/*void Postorder(int u){
  if(u == -1) return;
  Postorder(T[u].l);
  Postorder(T[u].r);
  cout << ' ' << u;
}
*/

void insert(int k){
  Node *y = NIL;
  Node *x = root;

  Node *z;

  z = new Node[1];

  z->key = k;
  z->p = NIL;
  z->r = NIL;
  z->l = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->l;
    else x = x->r;
  }

  z->p = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key) y->l = z;
  else y->r = z;

}


int main(){


  int x;

  string s;

  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> s;
    if(s ==  "insert"){

      cin >> x;

      insert(x);
    }

    else{
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }


/*  for(int k = 0; k < n; k++){

    cin >> x;

    for(int i = 0; i < 2; i++){
      cin >> y;
      T[y].parent = x;
      if(i == 0){
      T[x].l = y;
      }
      else{
        T[x].r = y;
      }
    }
  }

/*
  cout << "Inorder" << endl;
  Inorder(r);
  cout << endl;


  cout << "Preorder" << endl;
  Preparse(r);
  cout << endl;


  cout << "Postorder" << endl;
  Postorder(r);
  cout << endl;
*/

  return 0;
}



Measured memory_bytes: 26608
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
int n,a[maxn],b[maxn];
typedef long long ll;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n+1;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    ll res=0;
    for(int i=1;i<=n;i++){
        res+=min(a[i],b[i]);
        int minn=min(a[i],b[i]);
        a[i]-=minn;
        b[i]-=minn;
        minn=min(a[i+1],b[i]);
        res+=minn;
        a[i+1]-=minn;
        b[i]-=minn;
    }
    cout<<res<<endl;
    return 0;
}

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

typedef pair<int,int> P;

int nextInt() {
  int x; scanf("%d", &x); return x;
}

const int MAX_N = 100000 + 10;

map<P, vector<int> > g;
vector<P> es[MAX_N];

struct State {
  int pos;
  int pc;
  int cost; 
  State(int a, int b, int c) : pos(a), pc(b), cost(c) {}
};

int main() {
  int N = nextInt();
  int M = nextInt();

  for (int i = 0; i < M; i++) {
    int p = nextInt() - 1;
    int q = nextInt() - 1;
    int c = nextInt();
    es[p].emplace_back(q, c);
    es[q].emplace_back(p, c);
    g[P(p,c)].push_back(q);
    g[P(q,c)].push_back(p);
  }

  int ans = -1;
  map<P, int> memo; // 0なら存在しないノード、最小値は 1 
  deque<State> pq;
  pq.emplace_back(0, 0, 1); // 今いる駅, 最後に使った会社, コスト
  memo[P(0,0)] = 1;
  while (!pq.empty()) {
    const State state = pq.front();
    pq.pop_front();
    const int cost = memo[P(state.pos, state.pc)];
    if (state.cost != cost) continue;
    if (state.pos == N - 1 && state.pc == -1) {
      ans = cost - 1;
      break;
    }

    if (state.pc == -1) {
      for (P e : es[state.pos]) {
        int next_cost = cost + 1;
        auto f = memo.find(e);
        if (f == memo.end() || f->second > next_cost) {
          memo[e] = next_cost;
          pq.emplace_back(e.first, e.second, next_cost);
        }
      }
    }
    else
    {
      for (int next_pos : g[P(state.pos, state.pc)]) {
        P e(next_pos, state.pc);
        int next_cost = cost;
        auto f = memo.find(e);
        if (f == memo.end() || f->second > next_cost) {
          memo[e] = next_cost;
          pq.emplace_front(e.first, e.second, next_cost);
        }
      }
      {
        int next_pos = state.pos;
        int next_pc = -1;
        P e(next_pos, next_pc);
        int next_cost = cost ;
        auto f = memo.find(e);
        if (f == memo.end() || f->second > next_cost) {
          memo[e] = next_cost;
          pq.emplace_front(e.first, e.second, next_cost);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 75520
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>


struct Node {
    int id;
    int parent;
    int childs_num;
    int* childs;
    int depth;
};

static const char* GetType(const struct Node* p_node) {
    if ( p_node->parent == - 1 ) {
        return "root";
    }
    if ( p_node->childs_num == 0 ) {
       return "leaf";
    }

    return "internal node";
}

static int FindRoot(const struct Node nodes[], int n) {
    int i;

    for ( i = 0; i < n; i++ ) {
        if ( nodes[i].parent == -1 ) {
            return nodes[i].id;
        }
    }
    assert( 0 );

    return -1;
}

static void UpdateDepth(int root, struct Node nodes[], int n) {
    int i;

    if ( nodes[root].childs_num == 0 ) {
        return;
    }

    for ( i = 0; i < nodes[root].childs_num; i++ ) {
        int c = nodes[root].childs[i];
        nodes[c].depth = nodes[root].depth + 1;
        UpdateDepth(c, nodes, n);
    }

    return;
}

int main() {
    int i, j;
    int n;
    struct Node* nodes;

    scanf("%d\n", &n);

    nodes = malloc(sizeof(struct Node) * n);

    for (i = 0; i < n; i++) {
        nodes[i].parent = -1;
        nodes[i].depth = 0;
    }
    for (i = 0; i < n; i++) {
        int id, k;

        scanf("%d %d", &id, &k);
        nodes[id].id = id;
        nodes[id].childs_num = k;
        nodes[id].childs = malloc(sizeof(int) * k);

        for (j = 0; j < k; j++) {
            int c;
            scanf("%d", &c);

            nodes[id].childs[j] = c;
            nodes[c].parent = id;
        }
          /* new line */
        (void)fgetc(stdin);
    }

    int root = FindRoot(nodes, n);

    UpdateDepth(root, nodes,n);

    for ( i = 0; i < n; i++ ) {
        printf("node %d: parent = %d, depth = %d, %s, ", nodes[i].id, nodes[i].parent, nodes[i].depth, GetType(&nodes[i]));

        printf("[");
        for ( j = 0; j < nodes[i].childs_num; j++ ) {
            printf("%d", nodes[i].childs[j]);
            if ( j + 1 < nodes[i].childs_num ) {
                printf(", ");
            }
        }
        printf("]\n");
    }

    for ( i = 0; i < n; i++ ) {
        if ( nodes[i].childs_num > 0 ) {
            free(nodes[i].childs);
        }
    }

    free(nodes);

    return 0;
}



Measured memory_bytes: 7996
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();
		int c = t/a;
		int ans = c * b; 
		System.out.println(ans);
	}
}

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

int main(){
    int N, T;
    cin >> N >> T;

    vector<pair<int, int>> route(N);
    for(int i = 0; i < N; i++){
        cin >> route[i].second >> route[i].first;
    }

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

    int minc = 10000;
    int elaps = 0;
    int i = 0;
    while(route[i].first <= T){
        minc = min(minc, route[i].second);
        i++;
        if(i >= N) break;
    }

    if(minc == 10000){
        cout << "TLE" << endl;
    }else{
        cout << minc << endl;
    }
    
    return 0;

}

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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int64_t N, M, K;
    cin >> N >> M >> K;
    vector<int64_t> A(N + 1), B(M + 1);
    int64_t tmp;
    for (int64_t i = 1; i < N + 1; i++)
    {
        cin >> tmp;
        if (i != 1)
            A[i] = A[i - 1] + tmp;
        else
            A[i] = tmp;
    }
    for (int64_t i = 1; i < M + 1; i++)
    {
        cin >> tmp;
        if (i != 1)
            B[i] = B[i - 1] + tmp;
        else
            B[i] = tmp;
    }

    int64_t ans = 0;
    for (int i = 0; i < N + 1; i++)
    {
        tmp = K - A[i];
        if (tmp < 0)
            break;
        else
        {
            int64_t b = upper_bound(B.begin(), B.end(), tmp) - B.begin();
            ans = max(ans, i + b - 1);
        }
    }
    cout << ans;
}

Measured memory_bytes: 6432
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int k[12345];

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    if(!n)break;

    scn(n, k);

    rep(i, n)if(k[i] >= 2)break;
    if(i == n)puts("NA");
    else{
      int res = 0;
      rep(i, n)res += (k[i] != 0);
      pri(res + 1);
    }

//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3172