akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
int n;
int k;
int dp[1000000];
vector< int> v;
int f(int x)
{
	if(x==n-1)
		return 0;
	if(x==n-2)
		return abs(v[n-1]-v[n-2]);
	if(dp[x]!=-1)
		return dp[x];
	int ans=1e18;
	for(int i=1;i<=k;i++)
	{
		if(i+x>n-1)
			break;
		ans=min(ans,abs(v[x+i]-v[x])+f((x+i)));
	}
	return dp[x]=ans;
}
int32_t  main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
	}
	cout<<f(0)<<endl;
	return 0;
}

Measured memory_bytes: 16756
A, B, C, X, Y = map(int, input().split())
value = float('inf')
D = max(X,Y)
for i in range(D+1):
  E = max((X-i)*A, 0)
  F = max((Y-i)*B, 0)
  valueX = 2*i*C+E+F
  if valueX < value:
    value  = valueX
print(str(value))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using pii = pair<int,int>;

int n,arr[1001][1001];
int idx[1001];

int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) for(int j=0;j<n-1;j++) scanf("%d",&arr[i][j]);
    
    queue<pii> que;
    int ans = 0, cnt=0;
    for(int i=1;i<=n;i++) if(arr[arr[i][0]][0] == i && i < arr[i][0]) {
        que.push({i,arr[i][0]});
    }
    
    for(;cnt < n*(n-1)/2; ans++) {
        if(que.empty()) {
            puts("-1");
            return 0;
        }

        int s=que.size();
        while(s--) {
            int a=que.front().fi, b=que.front().se;
            que.pop();
            idx[a]++;
            if(arr[arr[a][idx[a]]][idx[arr[a][idx[a]]]] == a) {
                que.push({a, arr[a][idx[a]]});
            }
            idx[b]++;
            if(arr[arr[b][idx[b]]][idx[arr[b][idx[b]]]] == b) {
                que.push({b, arr[b][idx[b]]});
            }
            cnt++;
        }
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 4224
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int p[100100];
ll ans;
int n, m;
pair<ll, int> a[100100];
bool group_used[100100];
bool used[100100];
int root(int x) { return x == p[x] ? x : p[x] = root(p[x]); }
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
	{
		ll cost;
		scanf("%lld", &cost);
		a[i] = make_pair(cost, i);
	}
	for (int i = 1; i <= n; i++) p[i] = i;
	for (int i = 1; i <= m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		u++; v++;
		p[root(u)] = root(v);
	}
	int g = 0;
	for (int i = 1; i <= n; i++) if (p[i] == i) g++;
	// need to group g supernodes into a tree. need to have:
	//   sum of degree = 2(g-1) <= number of nodes = n
	if (2 * (g - 1) > n)
	{
		printf("Impossible\n");
		return 0;
	}
	// select smallest cost from each group first
	// then select smallest from rest
	sort(&a[1], &a[n + 1]);
	int dsum = 0;
	for (int i = 1; i <= n && dsum < 2 * (g - 1); i++)
	{
		int x = a[i].second;
		int r = root(x);
		if (group_used[r] || used[x]) continue;
		group_used[r] = used[x] = true;
		ans += a[i].first;
		dsum++;
	}
	for (int i = 1; i <= n && dsum < 2 * (g - 1); i++)
	{
		int x = a[i].second;
		if (used[x]) continue;
		ans += a[i].first;
		dsum++;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 100005;

class TaskB {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int n , k;
		cin >> n >> k;
		set<int> s;
		for(int i = 0; i < k; i++){
			int x;
			cin >> x;
			for(int j = 0; j < x; j++){
				int val;
				cin >> val;
				s.insert(val);
			}
		}
		cout << n - s.size() << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskB solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string a, b;
        cin >> a;
        cin >> b;
    int counter=0;
    for(int i=0;i<3;i++){
        if(a[i]==b[i])counter++;
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
(stdin => {
  // Define Function
  const Num = (array, array2) => array * array2
  const Num2 = (array, array2) => (array + array2) * 2
  // Declare Variable
  const inputs = stdin.toString().trim().split(' ')
  const array = parseInt(inputs[0], 10)
  const array2 = parseInt(inputs[1], 10)

  console.log(Num(array, array2), Num2(array, array2))
})(require('fs').readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 15136
{-
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1136&lang=jp
?????????: Polygonal_Line_Search
20:34 AC
-}
import Data.Complex
import Control.Applicative
import Control.Monad

data Zigzag = Zigzag [Complex Double] -- ????????????????????????

instance Eq Zigzag where
 c@(Zigzag a) == d@(Zigzag b)
  | a==b = True
  | (fromZigzag . zigzag . reverse . fromZigzag)c == fromZigzag d = True
  | otherwise = False


instance Show Zigzag where
 show a = "zigzag " ++ show (fromZigzag a)

zigzag :: [Complex Double] -> Zigzag
zigzag [] = undefined
zigzag (a:xs) = Zigzag $ map (/signum(head b)) b
 where b = map (subtract a) xs


fromZigzag :: Zigzag -> [Complex Double]
fromZigzag (Zigzag a) = 0:a

main = do
 n <- read <$> getLine
 unless (n==0) $ do
  zigzags <- replicateM (n+1) getZigzag
  let ans = tail{-0?????????-}. map fst . filter ((==head zigzags) . snd) $ zip [0..] zigzags --index?????£??????zigzag????????????????????????filter
  mapM_ print ans
  putStrLn "+++++"
  main

getZigzag :: IO Zigzag
getZigzag = do
 m <- read <$> getLine
 zigzag <$> replicateM m (fmap lire getLine)


lire :: String -> Complex Double
lire str = let[a,b] = map read $ words str in a:+b

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

int main(){
  int N;
  cin >> N;
  
  vector<int> d(N);
  for(int i=0;i<N;i++)
    cin >> d.at(i);
  
  int count = 0;
  sort(d.begin(),d.end());
  count = d.at(N/2) - d.at(N/2-1);
  
  cout << count << endl;
}



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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll l(int d){
    ll ret=(1LL << d+2)-3LL;
    return ret;
}

ll p(int d){
    ll ret=(1LL << d+1)-1LL;
    return ret;
}

ll solve(ll rest,int d){

    if(d==0){
        //puts("1");
        return 1;
    }

    ll b1=l(d-1)+2;
    ll b2=2*l(d-1)+ 3;
    ll b3;

    if(rest==1){

        //puts("0");
        return 0;

    }else if(b1 > rest  && rest>1){

        return solve(rest-1,d-1);

    }else if(b1 == rest){

        //cout <<p(d-1)+1LL<<endl;
        return p(d-1)+1LL;

    }else if( b2 > rest  && rest > b1){

        //cout <<p(d-1)+1LL<<endl;
        return p(d-1)+1LL+solve(rest - b1,d-1);

    }else{
        //cout <<2*p(d-1)+1LL<<endl;
        return 2*p(d-1)+1LL;
    }
}

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    ll n,x;
    cin >>n>>x;
    //cout <<fixed<<setprecision(16)<< << endl;

    //for(int i = 0; i < n; i++)cout <<l(i)<< " " << p(i)<<endl;

    cout << solve(x,n) << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


/*

ln = 
bn = 
pn = 


*/

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{ int n,c=0;
  cin>>n;
  int arr[n];
   for(int i=0 ;i<n ;i++) cin>>arr[i];
    for(int i=1;i<n-1;i++) if(((arr[i]>arr[i-1])&&(arr[i]<arr[i+1]))||((arr[i]<arr[i-1])&&(arr[i]>arr[i+1]))) c++;
    cout<<c;
    return 0;
}


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

const int step[5] = {5, 7, 5, 7, 7};

int N;
string S[40];

int solve() {
    for (int i = 0; i < N; ++i) {
        bool ok = true;
        int idx = i;
        for (int t = 0; t < 5; ++t) {
            int acc = 0;
            while (acc < step[t]) acc += S[idx++].size();
            if (acc != step[t]) {
                ok = false;
                break;
            }
        }
        if (ok)
            return i+1;
    }

    return -1;
}

int main(void) {
    while (true) {
        cin >> N;
        if (N == 0) break;
        for (int i = 0; i < N; ++i)
            cin >> S[i];

        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
k = int(input())
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
      1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(li[k-1])


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;


int main(){
    vector<vector<pair<int,int> > > a(3,vector<pair<int,int> >(3)) ;
    for (size_t i = 0; i < 3; i++)
    {
        for (size_t j = 0; j < 3; j++)
        {
            cin >> a.at(i).at(j).first ;
            a.at(i).at(j).second = 0 ;
        }
        
    }
    int n ;
    cin  >> n ;
    vector<int> b(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> b.at(i) ;
        for (size_t k = 0; k < 3; k++)
        {
            for (size_t j = 0; j < 3; j++)
            {
                if (b.at(i) == a.at(k).at(j).first)
                {
                    a.at(k).at(j).second = 1 ;
                }
                
            }
            
        }
        
    }
    int sum = 0 ;
    bool ans = false ;
    for (size_t i = 0; i < 3; i++)
    {
        for (size_t j = 0; j < 3; j++)
        {
            sum += a.at(i).at(j).second ;
            
        }
        if (sum == 3)
        {
            ans = true ;
            break ;
        }else
        {
            sum = 0 ;
        }
        for (size_t j = 0; j < 3; j++)
        {
            sum += a.at(j).at(i).second ;
        }
        if (sum == 3)
        {
            ans = true;
            break ;
        }else
        {
            sum = 0 ;
        }
        
        
        
        
    }
    if (ans == false)
    {
        for (size_t i = 0; i < 3; i++)
        {
            sum += a.at(i).at(i).second ;
        }
        if (sum == 3)
        {
            ans = true ;
        }else
        {
            sum = 0 ;
        }
        
        for (size_t i = 0; i < 3; i++)
        {
            sum += a.at(i).at(2-i).second ;
        }
        if (sum == 3)
        {
            ans = true ;
        }
        
        
    }
    if (ans == true)
    {
        cout << "Yes" << endl ;
    }else
    {
        cout << "No" << endl ;
    }
    
    
    
}    

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());//int型
		int K = Integer.parseInt(sc.next());
		double ans = 0;
		// サイコロの段階で勝ち確定
		ans = Math.max((double)(N-K+1)/N, 0);
		int co=0;
		if(N<K) co = N;
		else if(N>=K) co=K-1;
		
		for( int i=1; i<=co;i++) {
			int countpow=0;
			for(int j=1; j<18;j++){
			    int p = (int) (i*Math.pow(2, j));
				if(p>=K) {
					countpow=j;
					break;
				}
			}
			double tmp=(double)1/(N * Math.pow(2, countpow));
			ans += tmp;
			
		}
		
		System.out.println(String.format("%.12f",ans));
		
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B; cin >> A >> B;
  cout << 6 - A - B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  unsigned long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = (ll)1e9+7;
const double PI = 3.141592653589793238463;
const int MAXN = 1000030;
int s;
int dp[2005];
int dfs(int sum){
    if(sum==s)
    return 1;

    
    if(~dp[sum])
    return dp[sum];
    ll ans=0;
    for(int i=3;;i++){
        if(sum+i<=s){
            ans=(ans%MOD+dfs(sum+i)%MOD)%MOD;
        }else{
            break;
        }
        
    }
    return dp[sum]=ans%MOD;
    
}
int main() {
    cin>>s;
    memset(dp,-1,sizeof dp);
    cout<<dfs(0)%MOD;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10,mod=1e9+7;
vector<int> G[maxn];
vector<int> dp[maxn][2];
int f[maxn],Pw[maxn],rt[maxn],cnt,Max[maxn],dep[maxn];
inline void add(int &x,int y){
	x+=y;
	if(x>=mod) x-=mod;
}
inline void mul(int &x,int y){
	x=(ll)x*y%mod;
}
void dfs(int x,int d){
	++dep[d];
	int ms=0;
	REP(i,0,G[x].size()-1){
		dfs(G[x][i],d+1);
		if(chkmax(Max[x],Max[G[x][i]])) ms=G[x][i];
	}
	++Max[x];
	if(ms==0) rt[x]=++cnt;
	else rt[x]=rt[ms];
	dp[rt[x]][0].push_back(1),dp[rt[x]][1].push_back(1);
//	REP(i,0,Max[x]-1) cout<<x<<' '<<i<<' '<<dp[rt[x]][0][iend-i]<<' '<<dp[rt[x]][1][iend-i]<<endl;
	int Md=0;
	REP(j,0,G[x].size()-1){
		int v=G[x][j];
		if(v==ms) continue;
		chkmax(Md,Max[v]+1);
		REP(i,1,Max[v]){
			mul(f[Max[x]-i-1],dp[rt[v]][1][iend-i]+dp[rt[v]][0][iend-i]);
			add(f[Max[x]-i-1],(ll)dp[rt[x]][1][Max[x]-i-1]*dp[rt[v]][1][iend-i]%mod);
			mul(dp[rt[x]][1][Max[x]-i-1],dp[rt[v]][0][iend-i]);
			add(dp[rt[x]][1][Max[x]-i-1],(ll)dp[rt[v]][1][iend-i]*dp[rt[x]][0][Max[x]-i-1]%mod);
			mul(dp[rt[x]][0][Max[x]-i-1],dp[rt[v]][0][iend-i]);
		}
	}
//	REP(i,0,Max[x]-1) cout<<x<<' '<<i<<' '<<dp[rt[x]][0][iend-i]<<' '<<dp[rt[x]][1][iend-i]<<' '<<f[iend-i]<<endl;
	DREP(i,Max[x]-1,Max[x]-Md) add(dp[rt[x]][0][i],f[i]),f[i]=0;
//	cerr<<x<<' '<<Max[x]<<' '<<Md<<endl;
}
int main(){
	int n=read()+1;
	REP(i,2,n){
		int x=read()+1;
		G[x].push_back(i);
	}
	dfs(1,0);
	int ans=0;
	Pw[0]=1;
	REP(i,1,n) Pw[i]=(Pw[i-1]<<1)%mod;
	REP(i,0,Max[1]-1) ans=(ans+(ll)Pw[n-dep[i]]*dp[rt[1]][1][iend-i])%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 45036
#include <iostream>
#include <stdint.h>

using namespace std;
#define SIZE 100
static char bitmap[SIZE][SIZE];

int32_t main()
{
  uint32_t H, W;
  cin >> H >> W;
  for(uint32_t i = 0; i < H; i++){
    for(uint32_t j = 0; j < W; j++){
      cin >> bitmap[i][j];
      cout << bitmap[i][j];
    }
    cout << endl;
    for(uint32_t j = 0; j < W; j++){
      cout << bitmap[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
struct Queue {
	int l, r,len;
	T a[100000];
	Queue() :l(0), r(0),len(100000) {}
	void enqueue(T x) {
		a[r++] = x;
		r %= len;
	}
	T dequeue() {
		T ret = a[l++];
		l %= len;
		return ret;
	}
	bool empty() {
		return l == r;
	}
};
struct Job {
	string name;
	int time;
	Job() {}
	Job(string name, int time) :name(name), time(time) {}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	int now(0);
	Queue<Job> pro;
	rep(i, 0, n) {
		string s; int a; cin >> s >> a;
		pro.enqueue(Job(s, a));
	}
	while (!pro.empty()) {
		Job f = pro.dequeue();
		int x = min(q, f.time);
		now += x;
		f.time -= x;
		if (f.time <= 0) {
			cout << f.name << " " << now << endl;
		}
		else pro.enqueue(f);
	}
	return 0;
}

Measured memory_bytes: 6992
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		List<Long> hi = new ArrayList<Long>();
		for(int i=0; i<n; ++i) {
			hi.add((long) scan.nextInt());
		}

		if(n <= k) {
			System.out.println("0");
		} else {
			Collections.sort(hi, Collections.reverseOrder());

			for(int i=0; i<k; ++i) {
				hi.set(i, (long) 0);
			}
			long sum = 0;
			for(int i=k; i<n; ++i) {
				sum += hi.get(i);
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 95944
/*
問題文
高橋君は，いつも頭の中に整数を 1 つ思い浮かべています．

はじめ，高橋君が思い浮かべている整数は 0 です． これから，高橋君は + または - の記号を，あわせて 4 つ食べようとしています． 高橋君が + を食べると，思い浮かべている整数は 1 大きくなります． 一方，高橋君が - を食べると，思い浮かべている整数は 1 小さくなります．

高橋君が食べようとしている記号は，文字列 S で与えられます． S の i 文字目は，高橋君が i 番目に食べる記号です．

すべての記号を食べ終わった後，高橋君が思い浮かべている整数を求めてください．

制約
S の長さは 4
S の各文字は + または -

*/

#include <iostream>


using namespace std;


int main()
{
	int n = 0;

	char s[4];

	cin >> s;

	for (int i = 0 ; i < 4 ; i++){
		if (s[i] == '+')	n++;
		if (s[i] == '-')	n--;
	}

	cout << n << "\n";

	return 0;
}


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

int main(){
    int n; cin >> n;
    map<string, int> ma;
    rep(i,n){
        string str; cin >> str;
        ma[str]++;
    }
    int m; cin >> m;
    rep(i,m){
        string str; cin >> str;
        ma[str]--;
    }
    int res = 0;
    for(auto itr = ma.begin(); itr!=ma.end(); itr++){
        res = max(res, itr->second);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
struct Edge {
	int s, d; Weight w;
	Edge() {};
	Edge(int s, int d, Weight w) : s(s), d(d), w(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

auto dijkstra = [&](const Graph &g, int s, Array &dist) {
	int n = g.size();
	vector<bool> vis(n);
	vector<int> prev(n, -1);
	dist.assign(n, INF);
	dist[s] = 0;
	using State = tuple<Weight, int, int>;
	priority_queue<State, vector<State>, greater<State>> pq;
	pq.emplace(0, s, -1);
	while (pq.size()) {
		Weight d; int v, p; tie(d, v, p) = pq.top(); pq.pop();
		if (dist[v] < d)continue;
		vis[v] = true;
		prev[v] = p;
		for (auto &e : g[v]) {
			if (vis[e.d])continue;
			if (dist[e.d] > dist[v] + e.w) {
				dist[e.d] = dist[v] + e.w;
				pq.emplace(dist[e.d], e.d, v);
			}
		}
	}
	return prev;
};


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	Graph g(N);
	vector<int> a(N - 1), b(N - 1), c(N - 1); rep(i, 0, N - 1) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--, b[i]--;
		addEdge(g, a[i], b[i], c[i]);
	}
	int Q, K; cin >> Q >> K; K--;
	Array dist;
	dijkstra(g, K, dist);
	rep(i, 0, Q) {
		int x, y; cin >> x >> y; x--, y--;
		cout << dist[x] + dist[y] << endl;
	}
	return 0;
}

Measured memory_bytes: 17584
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    long long A;
    long long B;
    
    bool operator<( const Data& right ) const {
        return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    int N, M;
    long long result = 0;

    float f;
    string s;
    
    //cin >> N;
    //for (int i=0;i<N;i++) cin >> A[i];
    
    cin >> N >> M;
    vector<Data> C(N);
    for (int i=0;i<N;i++) cin >> C[i].A >> C[i].B;
    
    sort(C.begin(), C.end());
//    for (int i=0;i<N;i++) {
//        cout << C[i].A << endl;
//    }
    
    int count = 0;
    while (M!=0) {
        int now = 0;
        if (M>=C[count].B) {
            now = C[count].B;
        }
        else {
            now = M;
        }
        result += now*C[count].A;
        M -= now;
        count += 1;
    }
    
    cout << result << endl;
    
//    Card C1[100], C2[100];
//    //for (int i=0;i<N;i++) cin >> C1[i].suit >> C1[i].value;
//    //for (int i=0;i<N;i++) C2[i] = C1[i];
//
//    vector<int> v{5,4,3,2}; // g++ -std=c++11
//    v.push_back(1);
//    for (int i=0;i<v.size();i++) cout << v[i] << " " ; cout << endl;
//    sort(v.begin(), v.end());
//    for (int i=0;i<v.size();i++) cout << v[i] << " " ; cout << endl;

    
    return 0;
}

Measured memory_bytes: 1792
/*
....................../´¯/)
....................,/¯../
.................../..../
............./´¯/'...'/´¯¯`·¸
........../'/.../..../......./¨¯\
........('(...´...´.... ¯~/'...')
.........\.................'...../
..........''...\.......... _.·´
............\..............(
..............\.............\...
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define pi 3.14159265358979323846
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
	return (x % m + m) % m;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

	//cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

		cin >> n >> x >> temp;
		//ll arr[n]; for (i = 0; i < n; i++) {cin >> arr[i];}

		maxx = n / x;
		if (n % x)
			maxx++;

		cout << maxx*temp;




		ln
	}
	return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner

fun main(args :Array<String>){
    val cin = Scanner(System.`in`)
    var x = cin.nextInt()
    var y = cin.nextInt()
    var z = cin.nextInt()
    var t :Int

    if(x > y){
	t = x
	x = y
	y = t
    }

    if(x > z){
	t = x
	x = z
	z = t
    }

    if(y > z){
	t = y
	y = z
	z = t
    }

    println("$x $y $z")
}



Measured memory_bytes: 25596
#include <stdio.h>
int  pop();
void push(int);
int d[11],top=0,n,i;
int main(){
  while(scanf("%d",&n)!=EOF){
    
    if(n==0){
	printf("%d\n",pop());
      }
      else{
        push(n);
      }
    
  }
  
  return 0;
}
void push(int x){
  top++;
  d[top]=x;
}
int pop(){
  top--;
  return d[top+1];
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b && b == c) printf("Yes\n");
	else printf("No\n");
}


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

int main() {
    
    while (1) {
        int x;
        cin >> x;
        if (!(x)) break;
        
        int min, max, avg = 0;
        for (int i = 0; i < x; i++) {
            int num;
            cin >> num;
            if (!(i)) {
                min = num;
                max = num;
            } else {
                if (num < min) min = num;
                if (num > max) max = num;
            }
            avg += num;
        }
        
        avg -= (min + max);
        avg /= (x - 2);
        cout << avg << endl;
    }
}


Measured memory_bytes: 3072
c = []
for i in range(3):
    c.append([int(i) for i in input().split()])

flag = True
if c[0][0]-c[0][1] != c[1][0]-c[1][1] or c[0][0]-c[0][1] != c[2][0]-c[2][1]:
    flag = False
elif c[0][1]-c[0][2] != c[1][1]-c[1][2] or c[0][1]-c[0][2] != c[2][1]-c[2][2]:
    flag = False
elif c[0][0]-c[1][0] != c[0][1]-c[1][1] or c[0][0]-c[1][0] != c[0][2]-c[1][2]:
    flag = False
elif c[0][0]-c[2][0] != c[0][1]-c[2][1] or c[0][0]-c[2][0] != c[0][2]-c[2][2]:
    flag = False

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#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 amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll x;
	cin >>x;
	for(ll i=1;;i++){
		if( i * (i+1) >= 2*x){
			cout << i <<"\n"; return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
/*********
深さ優先探索
**********/

#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 100

//入力
int n,m;
char field[MAX][MAX]={-1};//庭

//プロトタイプ宣言
void bfs(int x,int y);
void slove();



int main(){
  int i,j,flag;

  while(1){

    for(i=0;i<12;i++){
      flag=0;
      if(scanf("%s",field[i])==EOF) flag=-1;
    }

    if(flag==-1) break;
    slove();
  }

  return 0;
}



void bfs(int i,int j){
  //今いるところを、.に置き換える
  field[i][j]='0';

  //移動する4方向を調べる
  if(0<=j && j<12 && 0<=i-1 && i-1<12 && field[i-1][j]=='1') bfs(i-1,j);
  if(0<=j-1 && j-1<12 && 0<=i && i<12 && field[i][j-1]=='1') bfs(i,j-1);
  if(0<=j+1 && j+1<12 && 0<=i && i<12 && field[i][j+1]=='1') bfs(i,j+1);
  if(0<=j && j<12 && 0<=i+1 && i+1<12 && field[i+1][j]=='1') bfs(i+1,j);

 return ;
}

void slove(){
  int res=0;
  for(int i=0;i<12;i++){
    for(int j=0;j<12;j++){
      if(field[i][j]=='1'){
	//wが残っているならそこからbfsを始める
	bfs(i,j);
	res++;
      }
    }
  }
  printf("%d\n",res);
}

Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
  return b == 0 ? a : gcd(b, a % b);
}

int main(void){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a = abs(c - a);
  b = abs(d - b);
  ll g = gcd(a, b);
  a /= g;
  b /= g;
  cout << g * (a + b - 1) << endl;
}


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

int main()
{
    int monsterHealth, attacksDone, specialAttack;
    long attackPower = 0;
    long specialAttacks[100000];
    scanf("%d %d",&monsterHealth, &attacksDone);

    for (int i = 0; i < attacksDone; i++)
    {
        scanf("%d", &specialAttack);
        specialAttacks[i] = specialAttack;
        attackPower += specialAttacks[i];
    }

    if (attackPower >= monsterHealth)
    {
        printf("Yes \n");
    }
    else
    {
        printf("No \n");
    }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    double X[n];
    string S[n];
    for(int i = 0; i < n; i++){
        cin >> X[i] >> S[i];
    }
    double sum = 0;
    int money = 0;
    double bit = 0;
    for(int i = 0; i < n; i++){
        if(S[i] == "JPY"){
            money += X[i];
        }else if(S[i] == "BTC"){
            bit += X[i];
        }
    }
    //cout  << money << " " << bit*380000 << " ";
    sum = money + bit * 380000;
    cout << sum << endl;

    return 0;
}




Measured memory_bytes: 256
S=input()
T=input()

slist,sdic=[],{}
tlist,tdic=[],{}
for i in range(len(S)):
  if not S[i] in sdic:
    sdic[S[i]]=len(sdic)+1
  slist.append(sdic[S[i]])
  
  if not T[i] in tdic:
    tdic[T[i]]=len(tdic)+1
  tlist.append(tdic[T[i]])

#print(slist)
#print(tlist)
if slist==tlist:
  print("Yes")
else:
  print("No")

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}

const int MAX_N=1005;
const int MAX_V=MAX_N*(MAX_N-1)/2;
vii G(MAX_V);
int id[MAX_N][MAX_N];
bool vis[MAX_V];
bool fin[MAX_V];
int dp[MAX_V];

int dfs(int v){
    if(vis[v]){
        if(!fin[v]) return -1;
        else return dp[v];
    }
    vis[v]=true;
    dp[v]=1;
    for(auto &nv : G[v]){
        int res=dfs(nv);
        if(res == -1) return -1;
        dp[v]=max(dp[v], res+1);
    }
    fin[v]=true;
    return dp[v];
}

int main(){
    int n; cin >> n;
    vii a(n, vi(n-1));
    for(int i=0; i<n; i++){
        for(int j=0; j<n-1; j++){
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int num=0;
    for(int i=0; i<n-1; i++) for(int j=i+1; j<n; j++) id[i][j]=num++;
    for(int i=0; i<n; i++){
        for(int j=0; j<n-1; j++){
            if(i > a[i][j]) a[i][j]=id[a[i][j]][i];
            else a[i][j]=id[i][a[i][j]];
        }
        for(int j=0; j<n-2; j++){
            G[a[i][j]].push_back(a[i][j+1]);
        }
    }
    int ans=0;
    for(int i=0; i<num; i++){
        int res=dfs(i);
        if(res == -1){
            ans=-1;
            break;
        }
        chmax(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 41472
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

int main()
{
  int N,T=0;
  string S;
  
  cin >> S;
  REP(i,S.size()){
    if(i%2 == 1){
      if(S[i] == 'g'){
        T++;
      }else
        continue;
    }else{
      if(S[i] == 'g'){
        continue;
      }else{
        T--;
      }
    }
  }
  cout << T << endl;
  return 0;
}



Measured memory_bytes: 512
#include <cstdio>

int main(){
  int kensu = 0;
  int nyukyosya[4][3][10];
  int b, f, r, v;
  for ( int tou = 0; tou < 4; tou++ ){
    for ( int huroa = 0; huroa < 3; huroa++ ){
      for ( int heya = 0; heya < 10; heya++ ){
        nyukyosya[tou][huroa][heya] = 0;
      }
    }
  }
  scanf ( "%d", &kensu );
  for ( int i = 0; i < kensu; i++ ){
    scanf ( "%d %d %d %d", &b, &f, &r, &v);
    nyukyosya[b-1][f-1][r-1] = nyukyosya[b-1][f-1][r-1] + v;
  }
  for ( int tou = 0; tou < 4; tou++ ){
    for ( int huroa = 0; huroa < 3; huroa++ ){
      for ( int heya = 0; heya < 10; heya++ ){
        printf(" %d", nyukyosya[tou][huroa][heya] );
      }
      printf("\n");
    }
    if ( tou < 3 ) printf("####################\n" );
  }
}

Measured memory_bytes: 2684
import java.lang.reflect.Array;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();                
		
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			if (i % 2 == 0) {
				continue;
			}
			int count = 0;
			for (int j = 1; j <= i; j++) {
				if (i % j == 0) {
					count++;
				}
				if (count > 8) {
					break;
				}
			}
			if (count == 8) {
				ans++;
			}
		}
		System.out.println(ans);			
	}	
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

int main() {
  long long N, D;
  cin >> N >> D;
  long long ans = 0;
  long long key = D * D;
  rep(i, N) {
    long long x, y;
    cin >> x >> y;
    if(key >= x * x + y * y) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int N;

    cin >> N;

    int a[N];

    int cnt = 0;

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    bool flg = true;
    do{ 
        for (int i = 0; i < N; i++) {
            if(a[i] % 2 == 0){
                a[i] = a[i] / 2;

            }else{
                flg = false;
            }
        }
        if(flg){
            cnt++;
        }
    }while (flg);

    cout << cnt << endl;

    return 0;

}





Measured memory_bytes: 3644
package main

import (
	"fmt"
)

var N int
var a [3000]int64
var result [3000]int64
var SMALL = -int64(1000000000) * 3000 * 2

func max(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
		result[i] = a[i]
	}

	for n := 1; n < N; n++ {
		for i := 0; i < N-n; i++ {
			r := SMALL
			r = max(r, a[i+n]-result[i])
			r = max(r, a[i]-result[i+1])
			result[i] = r
		}
		// fmt.Println(result[:N-n])
	}
	fmt.Println(result[0])
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
bool check(vector <ii> p, int n, int m) {
    if (p[0] != mp(0, 0))
        return 0;
    if (p.back() != mp(n - 1, m - 1))
        return 0;
    for (int i = 0; i + 1 < p.size(); ++i) {
        if (p[i + 1] != mp(p[i].f + 1, p[i].s) && p[i + 1] != mp(p[i].f, p[i].s + 1))
            return 0;
    }   
    return 1;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, m;
    cin >> n >> m;
    vector <ii> p;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            char c; cin >> c;
            if (c == '#')
                p.app(mp(i, j));
        }   
    }   
    if (check(p, n, m))
        cout << "Possible" << endl;
    else 
        cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi d(N);
    rep(i,N) cin>>d.at(i);
    sort(d.begin(),d.end());
    int a=d.at(N/2-1);
    int b=d.at(N/2);
    int answer=b-a;
    cout<<answer<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define pb(v) push_back(v)
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using P = pair<int ,int>;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    vi v(1000), w(1000);
    vector<vi> dp(105, vi(10050, -1));

    int n, k; cin >> n >> k;
    rep(i, n) cin >> v[i] >> w[i];
    rep(i, n) dp[i][0] = 0;

    rep(i, n) rep(j, k+1) {
        int vv = v[i], ww = w[i];
        if (j>=ww) dp[i+1][j] = max(dp[i+1][j-ww]+vv, dp[i][j]);
        else dp[i+1][j] = dp[i][j];
    }

    int ans = 0;
    rep(i, k+1) ans = max(ans, dp[n][i]);
    cout << ans << endl;
}


Measured memory_bytes: 7012
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    void merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return;
        if (-par[x] < -par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
};
    
int main() {
    int N; cin >> N;
    vector<long long> x(N), y(N);
    for (int i = 0; i < N; ++i) cin >> x[i] >> y[i];

    // Kruskal 法に使う枝 (絞られたもの)
    using pint = pair<int,int>;
    using Edge = pair<long long, pint>;
    vector<Edge> edges;

    // x 軸方向について隣接二点のみ
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });
    for (int i = 0; i+1 < ids.size(); ++i) {
        int u = ids[i], v = ids[i+1];
        edges.push_back(Edge(x[v] - x[u], pint(u, v)));
    }

    // y 軸方向について隣接二点のみ
    sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });
    for (int i = 0; i+1 < ids.size(); ++i) {
        int u = ids[i], v = ids[i+1];
        edges.push_back(Edge(y[v] - y[u], pint(u, v)));
    }

    // Kruskal 法
    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    long long res = 0;
    for (auto e : edges) {
        int u = e.second.first, v = e.second.second;
        long long cost = e.first;
        if (uf.issame(u, v)) continue;
        uf.merge(u, v);
        res += cost;
    }
    cout << res << endl;
}


Measured memory_bytes: 8432
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";
 
ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {     
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}
 
 
int main()
{
    fastio
	
	ll i,n,k,a,b;
	cin>>k>>a>>b;
	int f=0;
	for(i=a;i<=b;i++)
	{
	    if(i%k==0)
	    {
	        f=1;
	        break;
	    }
	}
	if(f) cout<<"OK";
	else cout<<"NG";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    ll ans = 0;
    rep(i,n-1){
        cin >> b[i];
    }
    if(b.size() == 1){
        cout << b[0]*2 << endl;
        return 0;
    }
    ans += b[0];
    for(int i = 1; i < n-1; i++){
        ans += min(b[i-1],b[i]);
    }
    ans += b[n-2];
    cout << ans << endl;
}

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

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ll INF = 1e15;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}

ll pow(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	if (b == 1) {
		return a;
	}
	ll ans = pow(a, b / 2);
	ans *= ans;
	ans *= b % 2 == 1 ? a : 1;
	return ans;
}

namespace SOLVE {
	void main() {
		ll a, b, x, y;
		cin >> a >> b;
		
		extgcd(a, b, x, y);
		cout << x << ' ' << y << endl;
	}
}


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

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int h, w; cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];

    vector<vector<int>> turn(h, vector<int>(w, 0));
    queue<T> que;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if('1' <= s[i][j] && s[i][j] <= '8'){
                int num = s[i][j] - '0';
                int sum = 0;
                for(int k=0; k<8; k++){
                    int ny = i + dy[k];
                    int nx = j + dx[k];

                    if(s[ny][nx] == '.' && turn[ny][nx] == 0) sum++;
                }

                if(num <= sum){
                    s[i][j] = '.';
                    turn[i][j] = 1;
                    que.emplace(i, j, 1);
                }
            }
        }
    }

    int ans = 0;
    while(que.size()){
        int cy, cx, cnt;
        tie(cy, cx, cnt) = que.front();
        que.pop();

        //cout << cy << " " << cx << " " << cnt << endl;

        ans = max(ans, cnt);

        for(int i=0; i<8; i++){
            int ny = cy + dy[i];
            int nx = cx + dx[i];

            if('1' <= s[ny][nx] && s[ny][nx] <= '8'){
                int num = s[ny][nx] - '0';
                int sum = 0;
                for(int j=0; j<8; j++){
                    int nny = ny + dy[j];
                    int nnx = nx + dx[j];

                    if(s[nny][nnx] == '.' && turn[nny][nnx] <= cnt) sum++;
                }

                if(num <= sum){
                    s[ny][nx] = '.';
                    turn[ny][nx] = cnt + 1;
                    que.emplace(ny, nx, cnt + 1);
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 7876