akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IN(type, n) type n; cin >> n

ll solve(int N, int K, vector<int> P, vector<int>C) {
  vector<vector<int> > loops = {};
  vector<ll> sum = {};
  bitset<5000> flag_check;
  ll max_score = LLONG_MIN;

  REP (i, N) {
    if (flag_check[i]) continue;
    int next = P.at(i) - 1;
    ll tmp_sum = 0;
    vector<int> tmp_vec = {};
    while (true) {
      if (flag_check[next]) break;
      flag_check.set(next);
      tmp_vec.push_back(next);
      tmp_sum += C.at(next);
      next = P.at(next) - 1;
    }
    loops.push_back(tmp_vec);
    sum.push_back(tmp_sum);
  }

  REP (i, loops.size()) {
    vector<int> v = loops.at(i);
    int size = v.size();
    ll max_all = LLONG_MIN;
    ll max_limit = LLONG_MIN;
    REP (j, size) {
      ll tmp_sum = 0;
      int next = v.at(j);
      REP (k, size) {
        tmp_sum += C.at(next);
        if (k < K % size) {
          max_limit = max(max_limit, tmp_sum);
        }
        max_all = max(max_all, tmp_sum);
        next = P.at(next) - 1;
      }
    }
    ll sum_v = sum.at(i);
    ll max_v;
    if (sum_v > 0) {
      max_v = max(sum_v * (K / size) + max_limit, sum_v * (K / size - 1) + max_all);
    } else {
      max_v = max(max_limit, max_all);
    }
    max_score = max(max_score, max_v);
  }

  return max_score;
}

int main() {
  IN(int, N);
  IN(int, K);
  vector<int> P(N);
  vector<int> C(N);
  vector<int> sumv(N);
  long long sum = 0;
  REP(i, N) {
    cin >> P.at(i);
  }
  REP(i, N) {
    cin >> C.at(i);
    sum += C.at(i);
  }

  cout << solve(N, K, P, C) << endl;;

  return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for(int i=0; i<M; i++) cin >> A[i];

    int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    string dp[10001];
    for(int i=1; i<=N; i++) dp[i] = "!";
    dp[0] = "";

    for(int i=2; i<=N; i++){
        for(int a : A){
            if(i-num[a] < 0 || dp[i-num[a]] == "!") continue;
            string d2 = dp[i-num[a]];
            d2.push_back('0'+a);
            if(d2.size() > dp[i].size() || (d2.size() == dp[i].size() && d2 > dp[i])){
                dp[i] = d2;
            }
        }
    }

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 41600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    public class Program

    {
        const int MOD = (int)1e9 + 7;



        public static void Main(string[] args)
        {
            int n = RInt();
            string s = RSt();

            int[] frec = new int[26];
            for (int i = 0; i < s.Length; i++)
            {
                frec[s[i] - 'a']++;
            }

            long res = 1;
            for (int i = 0; i < frec.Count(); i++)
            {
                res = res % MOD * (frec[i] + 1) % MOD;
            }


            Console.WriteLine((res-1) % MOD);
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


Measured memory_bytes: 13408
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


vector<int> ss[200000];

int a[200000], b[200000];

ll ans[200000]={};

int p[200000], x[200000];

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

    for(int i=0; i<N-1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        
        ss[a[i]].push_back(b[i]);
    }
    

    for(int i=0; i<Q; i++){
        cin >> p[i] >> x[i];
        p[i]--;
        
        ans[p[i]]+=x[i];
    }
    
    
    
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int temp=que.front();
        que.pop();
        
        for(int i : ss[temp]){
            ans[i] += ans[temp];
            que.push(i);
        }
    }
    
    for(int i=0; i<N; i++){
        cout<<ans[i];
        if(i==N-1){
            cout<<endl;
        }else{
            cout<<" ";
        }
    }
    
    return 0;
}


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

long long int N, K, x[101010], ans = 1125899906842624LL;

int main(){
    scanf("%lld%lld", &N, &K);
    --K;
    for(int i = 0; i < N; ++i){
        scanf("%lld", x + i);
        if(i >= K){
            if(x[i] * x[i - K] >= 0){
                ans = min(ans, max(abs(x[i]), abs(x[i - K])));
            }else{
                ans = min(ans, abs(x[i]) + abs(x[i - K]) + min(abs(x[i]), abs(x[i - K])));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll kai[2000001], inv[2000001];
int n, k;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= 2000000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[2000000] = mod_pow(kai[2000000], MOD - 2LL, MOD);
  for (ll i = 1999999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}

ll calc(ll x, ll y) {
  if (y == 0LL) {
    return 1LL;
  }
  ll res = comb(x + y, x) * mod_pow(25, y, MOD);
  res %= MOD;
  res += calc(x + 1LL, y - 1LL);
  return res % MOD;
}

int main() {
  string s;
  cin >> k >> s;
  n = s.length();
  init();
  cout << calc(n, k) << endl;
}

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

namespace AtCoder
{
    class Program
    {
        public static void Main()
        {
          var count = int.Parse(Console.ReadLine());
          var ans = Enumerable.Range(0, count).Select(_=>Console.ReadLine()).Distinct().Count();
   	      Console.WriteLine(ans);
        }
    }
}



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

#ifndef ONLINE_JUDGE
#define debarr(a,x,y)cerr<<#a<<":";for(int i=x;i<=y;i++)cerr<<a[i]<<" ";cerr<<endl;
#define deb(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S, class T>ostream &operator<<(ostream &os, const pair<S, T> &p) {return os << "(" << p.first << "," << p.second << ")";}
template<class T>ostream &operator<<(ostream &os, const vector<T> &p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const set<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const multiset<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class S, class T>ostream &operator<<(ostream &os, const map<S, T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>void dbs(string str, T t) {cerr << str << ":" << t << "\n";}
template<class T, class...S>void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#endif
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

#define int              long long
#define ll               long long
#define ld               long double
#define fi               first
#define se               second
#define mp               make_pair
#define pb               push_back
#define sz(x)            (int)x.size()
#define all(x)           x.begin(),x.end()
#define ini(x,y)         memset(x,y,sizeof(x))
#define rep(i,n)         for(int i=0;i<n;i++)
#define fr(i,a,b)          for(int i=a;i<=b;i++)
#define fb(i,a,b)        for(int i=a;i>=b;i--)
#define tr(a,x)          for(auto& a:x)
typedef pair<int, int>   pii;
typedef vector<int>      vi;
typedef vector<pii>      vii;
typedef map<int, int>    mii;
typedef set<int>         si;
const ll inf = 1e18;
const int N = 2e5 + 10;

void solve(int tc)
{
	int n;
	cin >> n;
	vi cnt(1000000 + 1, 0);
	rep(i, n)
	{
		int x;
		cin >> x;
		cnt[x]++;
	}
	int ans = 0;
	vi vis(1000000 + 1, 0);
	fr(i, 1, 1000000)
	{
		if (cnt[i] == 0 || vis[i]) continue;
		if (cnt[i] == 1 && !vis[i]) ans++;
		for (int j = i; j <= 1000000; j += i) vis[j] = 1;
	}
	cout << ans << endl;

}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;

	fr(i, 1, t) solve(t);

	return 0;
}

Measured memory_bytes: 18768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int D = in.Int();
            int N = 26;
            int[] c = in.Int(N);
            int[][] s = new int[D][N];
            for (int i = 0; i < D; i++) {
                s[i] = in.Int(N);
            }

            int[] last = new int[N];
            for (int d = 0; d < D; d++) {
                int t = 0;
                int max = Integer.MIN_VALUE;
                for (int tt = 0; tt < N; tt++) {
                    int tmp = s[d][tt];
                    for (int i = 0; i < N; i++) {
                        if (tt != i) {
                            tmp -= c[i] * ((d + 1) - last[i]);
                        }
                    }
                    if (tmp > max) {
                        max = tmp;
                        t = tt;
                    }
                }
                last[t] = d + 1;
                out.println(t + 1);
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

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

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 36552
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/

const int mod = 998244353;

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

    int n, k; cin >> n >> k;
    vector <pair<int,int>> A(k);
    for (auto &i: A) cin >> i.first >> i.second;

    vector <ll> dp(n+1, 0), diff(n+1, 0);
    dp[1] = 1;
    for (int i = 1; i <= n; ++i) {
        diff[i] += diff[i-1];
        dp[i] += diff[i];
        dp[i] %= mod;
        diff[i] %= mod;
        // watch(dp[i]);
        for (int j = 0; j < k; ++j) {
            int l = i + A[j].first, r = i + A[j].second;
            if (l <= n) (diff[l] += dp[i]) %= mod;
            if (r < n) diff[r+1] = (diff[r+1] - dp[i] + mod) % mod;
            // watch()
        }
    }

    cout << dp[n];

    return 0;
}



Measured memory_bytes: 6332
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{
		int N = nextInt();
		int A = nextInt();
		int B = nextInt();
		long[] X = nextLongs();
		long[] S = new long[N-1];
		for(int i=0;i<N-1;i++) {
			S[i]=(X[i+1]-X[i])*A;
		}
		long ans = 0;
		for(int i=0;i<S.length;i++) {
			if(S[i]<B) {
				ans+=S[i];
			}else {
				ans+=B;
			}
		}
		pw.println(ans);

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 46932
/*                    ___          |\    /|           ____   ____   ____  ____
   |     |    /\    /    \ |     | | \  / |    /\    |    \ |    \ |     |    \
   |_____|   /__\   \____  |_____| |  \/  |   /__\   |____/ |____/ |__   |____/
   |     |  /    \       \ |     | |      |  /    \  |      |      |     |   \
   |     | /      \ \____/ |     | |      | /      \ |      |      |____ |    \
*/
#include<bits/stdc++.h>
using namespace std;
#define lb lower_bound
#define ub upper_bound
#define pf push_front
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pi pair<int,int>
#define pl pair<long,long>
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define endl '\n'
#define loop(i,n) for(ll i=0;i<n;i++)
#define mod 1e9+7
#define in(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define vl vector<ll>
#define mp make_pair

int main()
{
    ll n,k,ans=0;
    cin>>n>>k;
    while(n--) {
        ll a;
        in(a);
        if(a>=k) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    ans = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if a*500 + b*100 + c*50 == X:
                    ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long k=sc.nextLong();
		long[] a=new long[n];
		long[] f=new long[n];
		for(int i=0;i<n; i++){
			a[i]=sc.nextLong();
		}
		Arrays.sort(a);
		for(int i=0; i<n; i++){
			f[i]=sc.nextLong();
		}
		Arrays.sort(f);
		long left=-1;
		long right=1000000000000L;
		while(right-left>1){
			long mid=(right+left)/2;
			long count=k;
			for(int i=0; i<n; i++){
				long cost=a[i]*f[n-i-1];
				if(cost>mid){
					count-=a[i]-(mid/f[n-i-1]);
				}
			}
			if(count<0){
				left=mid;
			}else{
				right=mid;
			}
		}
		System.out.println(right);
	}
}


Measured memory_bytes: 101496
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

	vector< vector<int> > dp(s.length() + 1, vector<int>(t.length() + 1, 0));

	for(int i = 0; i < s.length(); i++) {
		for(int j = 0; j < t.length(); j++) {
			int is_same_char = 0;
			if(s[i] == t[j]) is_same_char = 1;
			dp[i+1][j+1] = max({dp[i][j] + is_same_char, dp[i][j+1], dp[i+1][j]});
		}
	}

	string out = "";
	int i = s.length() - 1, j = t.length() - 1;
	while(i >= 0 && j >= 0) {
		int n = 0;
		if(dp[i][j] < dp[i+1][j]) n = 1;
		else if(dp[i][j] < dp[i][j+1]) n = 2;
		else if(dp[i][j] == dp[i+1][j+1]) n = 3;

		switch(n) {
			case 0:
			out += s[i];
			case 3:
			i--, j--;
			break;
			case 1:
			j--;
			break;
			case 2:
			i--;
			break;
		}
	}

	reverse(out.begin(), out.end());
	cout << out << endl;
}


Measured memory_bytes: 35584
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
ll T,n,m;
int a[maxn];
int dp1[11][11][11];
int dp2[11][11][11]; 
int main() {
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n;i++){
		a[i+1] = s[i]-'0';
	}
	dp1[a[1]][a[2]][a[3]] = 1;
	dp2[a[1]][a[2]][a[3]] = 1;
	for(int i=4;i<=n;i++){
		for(int x=0;x<=9;x++)
			for(int y=0;y<=9;y++)
				for(int z=0;z<=9;z++){
					if(dp1[x][y][z]){
						dp2[x][y][a[i]] = 1;
						dp2[x][z][a[i]] = 1;
						dp2[y][z][a[i]] = 1;
					}
				}
		for(int x=0;x<=9;x++)
			for(int y=0;y<=9;y++)
				for(int z=0;z<=9;z++){
					dp1[x][y][z] =dp2[x][y][z];
				} 
	}
	int cnt = 0;
	for(int x=0;x<=9;x++)
		for(int y=0;y<=9;y++)
			for(int z=0;z<=9;z++){
				if(dp1[x][y][z]){
					cnt++;
				//	cout<<x<<" "<<y<<" "<<z<<endl;
				}
			}
				
	cout<<cnt<<endl;
	return 0;
	
}



Measured memory_bytes: 384
package main

import (
	"fmt"
)

// A - Frog 1
// https://atcoder.jp/contests/dp/tasks/dp_a

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &h[i])
	}
	var dp = make([]int, n)
	dp[0] = 0
	var num = n
	if k+1 < n {
		num = k + 1
	}
	for i := 1; i < num; i++ {
		dp[i] = Abs(h[i] - h[0])
	}
	var tmp = 0
	for i := k; i < n; i++ {
		dp[i] = dp[i-1] + Abs(h[i]-h[i-1])
		for j := 2; j <= k; j++ {
			tmp = dp[i-j] + Abs(h[i]-h[i-j])
			if tmp < dp[i] {
				dp[i] = tmp
			}
		}
	}
	fmt.Printf("%d\n", dp[n-1])
}


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

namespace WelcomeAtcordet
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long a = long.Parse(input[0]);
            long b = long.Parse(input[1]);
            long x = long.Parse(input[2]);

            long from = a / x;
            if (a % x > 0)
            {
                from++;
            }

            long to = b / x;

            Console.WriteLine(to - from + 1);
        }
    }
}


Measured memory_bytes: 13140
def dijkstra(s):
    d=[inf]*V
    used=[False]*V
    d[s]=0
    while True:
        v=-1
        for u in range(V):
            if used[u]==False and(v==-1 or d[u]<d[v]):
                v=u
        if v==-1:
            break
        used[v]=True
        for u in range(V):
            d[u]=min(d[u],d[v]+cost[v][u])
    return d



V, E=map(int,input().strip().split(' '))
inf=10**9
cost=[[inf]*V for i in range(V)]
edge=[]
for i in range(E):
    fr, to, co=map(int,input().strip().split(' '))
    cost[fr-1][to-1]=co
    cost[to-1][fr-1]=co
    edge.append([fr-1,to-1])
    
d=[]
for i in range(V):
    d.append(dijkstra(i))

cand=E
for i in range(E):
    fl=False
    for s in range(V):
        if d[s][edge[i][0]]+cost[edge[i][0]][edge[i][1]]==d[s][edge[i][1]]:
            cand-=1
            fl=True
            break

print(cand)

Measured memory_bytes: 3504
N = int(input())
slime = list(map(int, input().split()))

time = 0

change = 0
k = 100000
for i in range(N):
  if k == slime[i]:
    change += 1
  else:
    time += (change+1) // 2
    change = 0
  k = slime[i]
time += (change+1) // 2
print(time)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include "boost/multiprecision/cpp_int.hpp"
using ll = long long;
using ull = unsigned long long;
namespace mp = boost::multiprecision;

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

	int A, B, C; std::cin >> A >> B >> C;

	if (A == B)std::cout << C;
	else if (B == C)std::cout << A;
	else if (C == A)std::cout << B;

	return 0;

}

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

struct UnionFind {
    vector<int> data;
    int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

int main() {
    int h, w; cin >> h >> w;
    vector<string> field(h);
    for (string &s: field) cin >> s;
    UnionFind uf(h * w);
    auto idx = [&](int i, int j) { return i * w + j; };
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        for (int di: {-1, 0, 1}) for (int dj: {-1, 0, 1}) {
            if (di * di + dj * dj != 1) continue;
            int ni = i + di, nj = j + dj;
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (field[i][j] != field[ni][nj]) uf.unionSet(idx(i, j), idx(ni, nj));
        }
    }
    vector<vector<int>> cnt(h * w, vector<int>(2, 0));
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        cnt[uf.root(idx(i, j))][field[i][j] == '.']++;
    }
    long long ans = 0;
    for (auto &v: cnt) ans += 1LL * v[0] * v[1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9856
#include<iostream>
#include<numeric>
using namespace std;
 
int main(){
  int A,B,K,sum=0,ans;
  cin>> A >> B >> K;
  for(int i=min(A,B);i>0;i--){
    if(A%i==0 && B%i==0){
      sum++;
    if(sum==K){
      cout << i <<endl;
      return 0;
    }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n=0, k=0, a[100000] = {}, sam, b[100000] = {}, roop = 0, save[100000] = {0}, ans[100000] = {}, w = 0;
int main(void){
	while (1){
		int n=0, k=0, a[100000] = {}, sam, b[100000] = {}, roop = 0, save[100000] = {0}, ans[100000] = {}, w = 0;
		cin >> n >> k;
		if (n == 0 && k == 0)
			break;
		for (int i = 0; i<k; i++){
			cin >> a[i];
		}
		sort(a, a + k);
		for (int i = 0; i<k; i++){
			if (a[i + 1] - a[i] == 1){
				sam++;
			}
			else if (a[i + 1] - a[i] != 1){
				b[roop] = sam+1;
				if(a[0]==0){
					if (a[i + 1] - a[i] == 2){
						save[w] = roop;
						w++;
					}
				}
				sam = 0;
				roop++;
			}
		}
		for (int i = 0; i <= roop; i++){
			if (save[i] != 0){
				ans[i] = b[save[i]];
				ans[i]+= b[save[i] + 1] + 1;
			}
		}
		sort(b, b + roop+1);
		sort(ans, ans + roop+1);
		if (ans[roop]>b[roop])
		cout << ans[roop] << endl;
		if (ans[roop] <= b[roop]){
			if(a[0]==0){
				cout << b[roop]+1 << endl;
			}
			else{
			cout << b[roop] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2744
using System;
namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){
            int[,] map=new int[14,14];
            string str;
        while((str=Console.ReadLine())!=null){
            string[] strArray=str.Split(',');
            int x=int.Parse(strArray[0])+2;
            int y=int.Parse(strArray[1])+2;
            int s=int.Parse(strArray[2]);
            if(s==1){
                map[y-1,x]++;
                map[y,x-1]++;
                map[y,x]++;
                map[y,x+1]++;
                map[y+1,x]++;
            }
            if(s==2){
                for(int i=y-1;i<=y+1;i++){
                    for(int j=x-1;j<=x+1;j++){
                        map[i,j]++;
                    }
                }
            }
            if(s==3){
                for(int i=y-1;i<=y+1;i++){
                    for(int j=x-1;j<=x+1;j++){
                        map[i,j]++;
                    }
                }
                map[y-2,x]++;
                map[y,x-2]++;
                map[y,x+2]++;
                map[y+2,x]++;
            }
        }
        int count=0;
        int max=0;
        for(int i=2;i<12;i++){
            for(int j=2;j<12;j++){
                if(map[j,i]==0){
                    count++;
                }
                if(map[j,i]>max){
                    max=map[j,i];
                }
            }
        }
        Console.WriteLine(count);
        Console.WriteLine(max);
        }
    }
}

Measured memory_bytes: 5620
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
 
int main(void){
	int n, m;
	std::cin >> n >> m;
	std::vector<int> cnt(n+1);
	int lmax=1, rmin=n;
	for(int i=0;i<m;i++){
		int l, r;
		std::cin >> l >> r;
		lmax=std::max(l, lmax);
		rmin=std::min(r, rmin);
	}
	int ans = rmin - lmax+1;
	if(ans<0)ans=0;
	std::cout << ans << std::endl;

}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int n; cin>>n;
  string a,b; cin>>a>>b;
  for(int i=0;i<n;i++){
    if(b[0]==a[i]) b.erase(b.begin());
  }
  cout<<(a+b).length()<<endl;
  return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<VI> r(n+1);
	rep(i, n-1){
		int a, b; cin >>a >>b;
		r[a].push_back(b);
		r[b].push_back(a);
	}
	VI dst(n+1, -1);
	auto f=[&](auto f,int c)->void{
		for(auto v: r[c]) if(dst[v] ==-1){
			dst[v] = (dst[c] + 1) %2;
			f(f, v);
		}
	};
	f(f, 1);
	vector<VI> gk(2), kj(3);
	rep2(i, 1, n+1){
		gk[dst[i]%2].push_back(i);
		kj[i%3].push_back(i);
	}
	
	//for(auto xl: gk){for(auto x :xl) cerr<<x<<":";dbg("gk");}
	//for(auto xl: kj){for(auto x :xl) cerr<<x<<":";dbg("kj");}
	VI ans(n);
	int zz = (sz(gk[0]) < sz(gk[1]))? 0: 1; 
	if(sz(gk[zz]) <= sz(kj[0]) ){
		for(auto v: gk[zz]){
			ans[v-1] = kj[0].back();
			kj[0].pop_back();
		}
		int j=0;
		for(auto& v: ans){
			if(v > 0) continue;
			while(sz(kj[j]) <1) j++;
			assert(j <=2);
			v = kj[j].back();
			kj[j].pop_back();
		}
	} else {
		for(auto v: gk[zz]){
			if(sz(kj[1]) <=0) break;
			ans[v-1] = kj[1].back();
			kj[1].pop_back();
		}
		for(auto v: gk[zz^1]){
			if(sz(kj[2]) <=0) break;
			ans[v-1] = kj[2].back();
			kj[2].pop_back();
		}
		int j=0;
		for(auto& v: ans){
			if(v > 0) continue;
			while(sz(kj[j]) <1) j++;
			assert(j <=2);
			v = kj[j].back();
			kj[j].pop_back();
		}
	}

	for(auto x :ans) cout<<x<<" "; cout<<"\n";
	return 0;
}


Measured memory_bytes: 17396
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if (a <= 8 && b <= 8){
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string>
#include <memory.h>
#include <bitset>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <utility>
#include <functional>
#include <ctime>
using namespace std;

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

long long dfs(long long a, long long b, long long sum, string s) {
	if(a == s.size()) return sum;
	long long x = 0;
	int tmp = s[a] - '0';
	if(a + 1 != s.size()) x += dfs(a + 1, b * 10 + tmp, sum, s);
	x += dfs(a + 1, 0, sum + b * 10 + tmp, s);
	return x;
}

void solve() {
	string s;
	cin >> s;
	cout << dfs(0, 0, 0, s) << endl;
}

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


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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

	string a, b;

	cin >> a >> b;

	int ans = 0;

	REP(i, 3)
	{
		if (a[i] == b[i]) ++ans;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,count=0,x;
    while (scanf("%d %d",&a,&b)!=EOF) {
        x=a+b;
        while (1) {
            x=x/10;
            count++;
            if (x<1) {
                break;
            }
    }
//    for (i=0; i<200; i++) {
//        x=dataset[0][i]+dataset[1][i];
//        while (1) {
//            x=x/10;
//            count++;
//            if (x<1) {
//                break;
//            }
//            
//        }
        
        
        
        printf("%d\n",count);
        count=0;
    }
    
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////


struct tower{
    ll w,s,v;
};
bool comp(tower t1,tower t2){
    if(t1.w+t1.s<t2.w+t2.s)return true;
    else return false;
}

int main(){
    
    ll N=20001;
    ll n;cin>>n;
    tower t[n];
    rep(i,0,n-1){
        cin>>t[i].w>>t[i].s>>t[i].v;
    }
    sort(t,t+n,comp);
    ll dp[n+1][N];
    memset(dp,0,sizeof(dp));
    rep(i,0,n-1){
        rep(j,0,N-1){
            dp[i+1][j]=dp[i][j];
            if(0<=j-t[i].w&&j-t[i].w<=t[i].s)Max(&dp[i+1][j],dp[i][j-t[i].w]+t[i].v);
        }
    }
    /*rep(i,0,n){
        rep(j,0,20){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    ll ans=0;rep(i,0,N-1)Max(&ans,dp[n][i]);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 156672
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int X,N; cin >> X >> N;
    vector<int> p;
    if(N == 0) {
        cout << X << endl; 
        return 0;
    }
    
    for(int i=0;i<N;i++) {
        int pp;
        cin >> pp;
        p.push_back(pp);
    }
    sort(p.begin(),p.end());
    if(!binary_search(p.begin(), p.end(), X)) { //その数自身
        cout << X << endl;
        return 0;
    }
    
    int x1 = X, x2 = X;
    
    while(binary_search(p.begin(), p.end(), --x1)) ;
    while(binary_search(p.begin(), p.end(), ++x2)) ;
    if(abs(X-x1) == abs(X-x2)) cout << x1 << endl; 
    else if(abs(X-x1) < abs(X-x2)) cout <<  x1 << endl;
    else cout <<  x2 << endl;
}

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

typedef long long ll;
const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> X(N),L(N);
    for (int i=0;i<N;i++) cin >> X[i] >> L[i];
    vector<pair<int,int>> r(N);
    for (int i=0;i<N;i++){
        r[i].first = X[i] + L[i];
        r[i].second = X[i] - L[i];
    }
    sort(r.begin(),r.end());
    int pos = - INF;
    int ans = 0;
    for (int i=0;i<N;i++){
        if (r[i].second >= pos) {
            ans++;
            pos = r[i].first;
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = 0
b = 0
for _ in range(n):
    word = input().split()
    if word[0] == word[1]:
        a += 1
        b += 1
        continue
    word_sort = sorted(word)
    if word == word_sort:
        b += 3
    else:
        a += 3
print(a, b)


Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

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

    i64 sum = 0;
    for (int i = 0; i <= n; ++i) {
        sum += iabs(a[i] - a[i + 1]);
    }

    for (int i = 1; i <= n; ++i) {
        i64 ans = sum - iabs(a[i - 1] - a[i]) - iabs(a[i] - a[i + 1]) + iabs(a[i - 1] - a[i + 1]);
        cout << ans << '\n'; 
    }
    return 0;
}

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

using namespace std;

int num[200001];

bool gt(int a, int b){
	return a > b;
}

int main(){
	int n, k;
	cin >> n >> k;
	
	vector<int> nums;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		num[a] += 1;
	}
	for(int i = 1;i <= n;i++){
		if(num[i] > 0){
			nums.push_back(num[i]);
		}
	}
	
	sort(nums.begin(), nums.end(), gt);
	
	int sum = 0;
	for(int i = k;i < nums.size();i++){
		sum += nums[i];
	}
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 2168
using System;

namespace MF
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ');
            var a = double.Parse(x[0]);
            var b = double.Parse(x[1]);
            var c = double.Parse(x[2]);
            var d = c * Math.PI / 180;
            Console.Write("{0}\n{1}\n{2}\n",
            a * b * Math.Sin(d) / 2,
            a + b + Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(d)),
            b * Math.Sin(d));
        }
    }
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,m;
  cin >> n >> m;
  ll t = 1;
  REP(i,n) t *= 2;
  vl ss(m);
  REP(i,m){
    ll k;
    cin >> k;
    REP(j,k){
      ll tmp,tp;
      cin >> tmp;
      tp = 1;
      while(--tmp>0)tp *= 2;
      ss[i] += tp;
    }
  }
  vl p(m);
  REP(i,m) cin >> p[i];
  ll ans = 0;

  REP(i,t){
    bool ok = true;
    REP(j,m){
      ll count = 0;
      ll d = ss[j]&i;
      while(d>0){
        if(d%2==1) count++;
        d /= 2;
      }
      if(count%2!=p[j]){
        ok = false;
        break;
      }
    }
    if(ok) ans++;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int dp[100100];

int main()
{
    int n; cin >> n;
    double a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    double ans = 0.0;
    double div = 1.0;
    for(int i = 0; i < n-1; i++){
        div *= 2.0;
        ans += (a[i]/div);     
    }
    ans += a[n-1]/div;
    printf("%.3lf\n",ans);
}


Measured memory_bytes: 256
n = int(input())
a = input()
a2 = [int(a[i]) for i in range(n)]
n2 = bin(n)
b = [0] * n
c = [1] * (2 ** (len(n2) - 3))
for i in range(len(c)):
    b[i] += c[i]
temp = len(n2) - 4
count = len(c)
while temp>= 0:
    if n2[-1-temp] == "1":
        c = [b[i] for i in range(count)]
        for i in range(count):
            b[i + 2 ** temp] += c[i]
        count += 2 ** temp
    temp -= 1
e = [b[i] % 2 for i in range(len(b))]
d = 0
for i in range(n):
    if e[i] % 2 == 1:
        d += a2[i]
if d % 2 == 1:
    print(1)
else:
    a3 = [abs(a2[i] - a2[i + 1]) for i in range(n - 1)]
    if 1 in a3:
        print(0)
    else:
        n3 = bin(n - 1)
        b = [0] * (n - 1)
        c = [1] * (2 ** (len(n3) - 3))
        for i in range(len(c)):
            b[i] += c[i]
        temp = len(n3) - 4
        count = len(c)
        while temp>= 0:
            if n3[-1-temp] == "1":
                c = [b[i] for i in range(count)]
                for i in range(count):
                    b[i + 2 ** temp] += c[i]
                count += 2 ** temp
            temp -= 1
        e = [b[i] % 2 for i in range(len(b))]
        d = 0
        for i in range(n - 1):
            if e[i] % 2 == 1:
                d += a3[i]
        if d % 4 == 0:
            print(0)
        else:
            print(2)

Measured memory_bytes: 158768
#include<cstdio>
#include<cstring>
int main(){
	int a,b,c,d,i,j;
	int n[6];
	c=0;d=0;
	for(i=0;i<3;i++)
	{
		scanf("%d",&n[i]);
		if(n[i]==5)
		c+=1;
		else if(n[i]==7)
		d+=1;
	}
	if(c==2&&d==1)
	printf("YES\n");
	else
	printf("NO\n");

}

Measured memory_bytes: 760
/*
　　　　　／＞　 フ
　　　　　| 　^　 ^|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int P = 1e9+7;
const int N = 4008;
int A, B, C[N][N];
int g[N][N], f[N][N]; 
int add(int x) { return x >= P ? x - P : x; }
int main() {
	read(A), read(B); int lim = max(A, B);
	C[0][0] = 1;
	for (int i = 1;i <= lim; C[i++][0] = 1)
		for (int j = 1;j <= i; j++)
			C[i][j] = add(C[i-1][j] + C[i-1][j-1]);
	for (int i = 0;i <= lim; i++) {
		g[i][0] = C[i][0];
		for (int j = 1;j <= lim; j++)
			g[i][j] = add(C[i][j] + g[i][j-1]);
	}
	for (int i = 0;i <= lim; i++) {
		f[i][0] = g[i][0];
		for (int j = 1;j <= lim; j++)
			f[i][j] = add(g[i][j] + f[i][j-1]);
	}
	ll ans = A + 1;
	for (int i = 1;i <= A + 1; i++) 
		for (int j = 1;j < i; j++) 
			ans = (ans + (ll)C[B-1][j] * f[j-1][i-j-1]) % P;
	write(ans);
	return 0;
}

Measured memory_bytes: 65916
//<MIHIR KHAMBHATI/>
#include <bits/stdc++.h>
#include <chrono>
using namespace std::chrono;
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// // Declaring ordered_set
// typedef tree<ll, null_type, less<ll>, rb_tree_tag,
//             tree_order_statistics_node_update>
//    ordered_set;

#define _start_ auto __start__ = high_resolution_clock::now();
#define _stop_ cerr << "\n" \
                    << duration_cast<microseconds>(high_resolution_clock::now() - __start__).count() / (double)1000000 << " sec\n";
#define mod 998244353
#define _                             \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define ideb \
    int _p_; \
    cin >> _p_;
typedef long long int ll;
typedef unsigned long long int ull;
long long power(long long x, long long n)
{
    long long result = 1;
    while (n > 0)
    {
        if (n % 2 == 1)
            result = (result % mod * x % mod) % mod;
        x = (x % mod * x % mod) % mod;
        n = n / 2;
    }
    return result % mod;
}

bool comp(pair<ll, ll> a, pair<ll, ll> b)
{
    return (double)a.second / (double)a.first > (double)b.second / (double)b.first;
}

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

    pair<ll, ll> p[n];

    for (ll i = 0; i < n; i++)
    {
        cin >> p[i].first >> p[i].second;
    }

    ll dp[n + 1][m + 1];

    memset(dp, 0, sizeof(dp));

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= m; j++)
        {
            if (p[i - 1].first > j)
            {
                dp[i][j] = dp[i - 1][j];
            }
            else
            {
                dp[i][j] = max(p[i - 1].second + dp[i - 1][j - p[i - 1].first], dp[i - 1][j]);
            }
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        ans = max(ans, dp[i][m]);
    }
    cout << ans;
}

Measured memory_bytes: 79104
#include<queue>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  const int mod=1000000007;
  int k,j,i,n,a[1010];
  long long ans=1;
  scanf("%d\n",&n);
  if(n==1){
    printf("1\n");
    return 0;
  }
  for(i=1;i<=n;i++){
    a[i]=0;
  }
  for(i=2;i<=n;i++){
    k=i;
    for(j=2;j*j<=i;j++){
      if(k%j==0){
        while(k%j==0){
          a[j]++;
          k=k/j;
        }
      }
    }
    if(k!=1){
      a[k]++;
    }
  }
  for(i=2;i<=n;i++){
    ans=ans*(a[i]+1)%mod;
  }
  printf("%lld\n",ans);
  return 0;
}

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

using ll = long long;

const ll mod = 1e+9 + 7;

int main() {

    int n, k;

    cin >> n >> k;

    set<int> dangerStep;

    vector<ll> stepCount(n + 10, 0);

    for(int i = 0; i < k; ++i) {
        int step;
        cin >> step;
        stepCount[step] = -1;

    }

    stepCount[0] = 1;

    if(stepCount[1] != -1)
        stepCount[1] = 1;

    for(int i = 2; i <= n; ++i) {

        if(stepCount[i] == -1)
            continue;

        if(stepCount[i - 1] != -1)
            stepCount[i] = (stepCount[i] + stepCount[i - 1]) % mod;
        if(stepCount[i - 2] != -1)
            stepCount[i] = (stepCount[i] + stepCount[i - 2]) % mod;

    }

    cout << stepCount[n] << endl;

    return 0;
}

Measured memory_bytes: 1024
let () =
  let (n, k) = Scanf.scanf "%d %d " (fun n k -> (n, k)) in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  Array.fast_sort (fun a b -> b - a) a;
  let ans = ref 0 in
  for i = 0 to k - 1 do
    ans := !ans + a.(i);
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
  int a;
  int b;
  int c;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  
  a=a-b;
  a=a%c;
  
  printf("%d",a);
  
  return 0;
 
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

ll calc(ll A, ll B) {
	ll ans = 1 << 21;
	rep(a, 1, A) {
		ll S1 = a * B;
		ll S2 = (A - a) * (B / 2);
		if (B % 2 == 0) {
			ans = min(ans, abs(S1 - S2));
		}
		else {
			ll S3 = (A - a) * (B / 2 + 1);
			ll maxS = max(S1, max(S2, S3));
			ll minS = min(S1, min(S2, S3));
			ans = min(ans, maxS - minS);
		}
	}
	return ans;
}

int main() {
	ll H, W; cin >> H >> W;
	ll ans = 0;
	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	else {
		ans = ((H > W) ? W : H);
	}

	ans = min(ans, calc(H, W));
	ans = min(ans, calc(W, H));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256