akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_N = 1e4;
ll n;
ll a[MAX_N + 1];
Vi list_of_primes(ll n){
  // return list of primes p <= n
  //primes[i] != 0 iff i is prime.
  Vi primes(n);
  FOR(i, 2, n){
   primes[i] = i;
  }
  for (ll i = 2; i*i < n; ++i)
   if (primes[i])
     for (ll j = i*i; j < n; j+=i)
       primes[j] = 0;
  primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
  return primes;
}
Vi prime_factors(ll n){
  // return list of prime factors of n.
  if(n == 1) return {};
  for(ll i = 2; i * i <= n; i++){
    if(n % i == 0){
      Vi ans = prime_factors(n / i);
      ans.pb(i);
      sort(ans.begin(), ans.end());
      ans.erase(unique(ans.begin(), ans.end()), ans.end());
      return ans;
    }
  }
  return {n};
}
bool hantei(ll p){
//  cout << "p = " << p << endl;
  if(a[0] % p != 0) return false;
  Vi a_red(p - 1, 0);
  REP(i, n + 1){
    a_red[i % (p - 1)] += a[i];
  }
  REP(i, p - 1){
//    printf("a_red[%d] == %d\n", i, a_red[i]);
    if (a_red[i] % p != 0) return false;
  }
  return true;
}
int main(){
  cin >> n;
  ll d = 0;
  REP(i, n + 1){
    cin >> a[n - i];
    d = gcd(d, abs(a[n - i]));
  }
  Vi P1 = prime_factors(d); //係数全ての最大公約数は必ず条件を満たす.
  Vi P2 = list_of_primes(n + 1);
  for(auto &p : P2){
    if(hantei(p)) P1.pb(p);
  }
  SORT(P1);
  for(auto &p : P1){
    cout << p << endl;
  }
}


Measured memory_bytes: 512
// abc143_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

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

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
    int N;
    cin >> N;
    string S;
    cin >> S;

    int ans = 0;
    REP(i, N){
        if (S[i] == S[i+1]){
            while (i < N && S[i] == S[i+1]){
                i++;
            }
        }
        ans++;
    }
    
    print(ans);

    return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;
import static java.lang.Double.parseDouble;

/**
 * Baby Tree
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n, m;
			n = parseInt(line.substring(0, line.indexOf(' ')));
			m = parseInt(line.substring(line.indexOf(' ') + 1));
			if (n == 0 && m == 0) break;

			double[][] vs = new double[n][n];
			double[][] dp = new double[m][n];

			for (int i = 0; i < n; i++) {
				String[] words = br.readLine().split(" ");
				for (int j = 0; j < n; j++) {
					vs[i][j] = parseDouble(words[j]);
				}
			}

			// solve
			Arrays.fill(dp[0], 1);

			for (int i = 1; i < m; i++) {
				for (int j = 0; j < n; j++) {
					for (int k = 0; k < n; k++) {
						dp[i][k] = Math.max(dp[i][k], dp[i - 1][j] * vs[j][k]);
					}
				}
			}

			double max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, dp[m - 1][i]);
			}
			System.out.println(String.format("%.2f", max));

		} //ene while
	}//end main
}

Measured memory_bytes: 36644
D, G = map(int, input().split())
pcs = [[i] + list(map(int, input().split())) for i in range(1, D + 1)]
from itertools import product
ans = 10 ** 10
for bonus in product(range(2), repeat=D):
    sum_b = 0
    cnt = 0
    for b, (i, p, c) in zip(bonus, pcs):
        if b:
            sum_b += c + i * 100 * p
            cnt += p

    if sum_b >= G:
        ans = min(ans, cnt)

    else:
        for b, (i, p, c) in reversed(list(zip(bonus, pcs))):
            if b:
                continue

            rem = -(-(G - sum_b) // (i * 100))
            sum_b += min(rem, p) * i * 100
            cnt += min(rem, p)
            if sum_b >= G:
                break

        ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int m = 10000;
  for(int i = 2; i < s.size(); ++i) {
    m = min(m, abs(753 - ((s[i] - '0') + (s[i - 1] - '0') * 10 + (s[i - 2] - '0') * 100)));
  }
  cout << m << endl;
  return 0;
}

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

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;

int main() {
	cin.tie();	ios::sync_with_stdio(false);
	int n,buf,count=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>buf;
		if(buf%2) count++;
	}
	cout<<((count%2==0)?"YES":"NO")<<en;
	return 0;
}


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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn print_vec_split_whitespace<T: std::fmt::Display>(a: &Vec<T>) {
    let len = (*a).len();
    for i in 0..len-1 {
        print!("{} ", (*a)[i]);
    }
    print!("{}\n", (*a)[len-1]);
}

fn selection_sort(a: &mut Vec<u32>, n: usize) -> u32 {
    let mut counter = 0;
    for i in 0..n {
        let mut minj = i as usize;
        for j in i..n {
            if (*a)[j] < (*a)[minj] {
                minj = j;
            }
        }
        if i != minj {
            counter += 1;
            let tmp = a[i];
            a[i] = a[minj];
            a[minj] = tmp;
        }
    }
    counter
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<u32>();

    let counter = selection_sort(&mut a, n);
    print_vec_split_whitespace(&a);
    println!("{}", counter);
}


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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  int N;
  vector<int> b(N);
  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      cin >> A.at(i).at(j);
    }
  }
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> b.at(i);
    for (int j=0; j<3; j++) {
      for (int k=0; k<3; k++) {
        if (A[j][k] == b.at(i)) {
          A[j][k] = -1;
        }
      }
    }
  }
  vector<int> a1={A[0]};
  vector<int> a2={A[1]};
  vector<int> a3={A[2]};
  vector<int> a4={A[0][0], A[1][0], A[2][0]};
  vector<int> a5={A[0][1], A[1][1], A[2][1]};
  vector<int> a6={A[0][2], A[1][2], A[2][2]};
  vector<int> a7={A[0][0], A[1][1], A[2][2]};
  vector<int> a8={A[0][2], A[1][1], A[2][0]};
  vector<int> t={-1,-1,-1};
  if (a1==t || a2==t || a3==t || a4==t || a5==t || a6==t || a7==t || a8==t) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto c:v) cout<<" "<<c; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
const int MX=2e5+5;
int vis[MX]={0};
vector<int>a[MX];
int cnt;
void dfs(int n){
	if(!vis[n]){
		vis[n]=1;
		cnt++;
		for(auto x:a[n]){
			dfs(x);
		}
	}
}
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		a[x].pb(y);
		a[y].pb(x);
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(!vis[i]){
			cnt=0;
			dfs(i);
			ans=max(ans,cnt);
		}
	}
	cout<<ans<<endl;
}

int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}



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

int main(){

    long long int x,y;
    int cnt=0;
    cin >> x;
  	cin >> y;

    while(x <= y){
        cnt++ ;
      	x *= 2;
    }

    cout << cnt;
    return 0;
}

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

int main(void){
  char str[30];
  long int x,i,N,sum;
  
  fgets(str,sizeof(str),stdin);
  N=atol(str);
  
  if(N%2==1){
    printf("0");
  }else{
    N=N/2;
    sum=0;
    for(i=1;(long int)powl(5,i)<=N;i++){
      x=(long int)powl(5,i);
      sum+=N/x;
    }
    printf("%ld\n",sum);
  }
  return 0;
}
    

Measured memory_bytes: 128
using System;
class Program
{
  static void Main(string[] args)
  {
    int M = 0;
    int D = 0;
    M = ReadInt();
    D = ReadInt();
    int count = 0;
    for (int m = 4; m <= M; ++m)
    for (int i = 2; i <= D / 10; ++i) {
      var a = m / i;
      if (2 <= a && a <= 9 && i * a == m && 10*i + a <= D) {
        //Console.WriteLine($"{m}/{i}{a}");
        count++;
      }
    }
    Console.WriteLine(count);
  }
  static int ReadInt()
  {
    int M = 0;
    while (true)
    {
      var r = Console.Read();
      if (r < '0' || '9' < r) break;
      M = 10 * M + (r - '0');
    }
    return M;
  }
}

Measured memory_bytes: 11092
import bisect

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

C = 0

for t in T:
    index = bisect.bisect_left(S, t)
    if index < n and S[index] == t:
        C += 1
print(C)




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

int main() {
    int n, k;
    cin >> n >> k;

    ll ans = k * pow(k - 1, n - 1);

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int a, b, prod;
    
    cin >> a >> b;
    
    prod = a * b;
    
    if(prod % 2 != 0) cout << "Odd" << endl;
    else cout << "Even" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>

using namespace std;
typedef long long int lint;

void AOJ0119()
{
	int m, n, x, y;
	cin >> m >> n;

	//??£??\?????????
	vector< vector< int > >	list(m + 1);

	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		list[x].push_back(y);
	}

	//L ??? ??????????????????????????????????????????????????????????????????
	vector< int > L;
	//S ??? ??\???????????????????????????????????????????????????
	vector< int > S;

	//??\???????????¨??????????????°
	bool* flag = new bool[m + 1];
	for (int i = 1; i <= m; i++) {
		flag[i] = true;
	}

	for (int i = 1; i <= m; i++) {
		for (auto itr = list[i].begin(); itr != list[i].end(); itr++) {
			flag[*itr] = false;
		}
	}

	for (int i = 1; i <= m; i++) {
		if (flag[i]) {
			S.push_back(i);
		}
	}

	while (!S.empty()) {
		int a = S.back();
		L.push_back(a);
		S.pop_back();
		//foreach a ???????????? e ??¨????????????????????? b do
		while (!list[a].empty()) {
			int b = list[a].back();
			list[a].pop_back();
			bool found = false;
			for (int i = 1; i <= m; i++) {
				if (find(list[i].begin(), list[i].end(), b) != list[i].end()) {
					found = true;
					break;
				}
			}
			if (!found) {
				S.push_back(b);
			}
		}
	}

	for (auto itr = L.begin(); itr != L.end(); itr++) {
		cout << *itr << endl;
	}

	delete[] flag;

	return;
}

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

Measured memory_bytes: 3144
import bisect as bc

N = int(input())
A = list(map(int,input().split()))
A.sort()

dp = [True for _ in range(A[-1]+1)]

for i in range(N):
    ai = A[i]
    for j in range(2,A[-1]+1):
        if ai*j > A[-1]:
            break
        if dp[ai*j]:
            dp[ai*j] = False

ans = 0
finish = [True for _ in range(A[-1]+1)]
for i in range(N):
    if dp[A[i]] and finish[A[i]]:
        if bc.bisect_right(A,A[i]) - bc.bisect_left(A,A[i]) == 1:
            ans += 1
            finish[A[i]] = False

print(ans)




Measured memory_bytes: 167560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

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

  int n, w;
  cin >> n >> w;

  vector<pair<ll, ll>> items;
  rep(i, n) {
    ll w, v;
    cin >> w >> v;
    items.emplace_back(w, v);
  }

  vector<vector<ll>> dp(101, vector<ll>(100001, 0));

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= w; j++) {
      chmax(dp[i][j], dp[i-1][j]);
      ll ww = items[i-1].first;
      ll v = items[i-1].second;
      if (j < ww) continue;
      chmax(dp[i][j], dp[i-1][j-ww] + v);
    }
  }

  cout << dp[n][w] << endl;

  return 0;
}


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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
#define INF 1000000000

int main(){
    int N; cin >> N;
    vector<int> a, b, c;
    rep(i, N) {
        int temp_a, temp_b, temp_c;
        cin >> temp_a >> temp_b >> temp_c;
        a.push_back(temp_a);
        b.push_back(temp_b);
        c.push_back(temp_c);
    }
    vector<vector<int> > A;
    A.push_back(a);
    A.push_back(b);
    A.push_back(c);
    vector<vector<int> > dp(3, vector<int>(N, 0));
    // view(dp);
    for (int i = 0; i < N; i++) {
        // cout << i << endl;
        for (int k = 0; k < 3; k++) {
            // cout << k << endl;
            int cand;
            int temp_max = 0;
            if (i == 0) dp[k][i] = A[k][i];
            for (int kk = 0; kk < 3; kk++){
                if (k == kk) continue;
                // cout << "kk:" << kk << endl;
                cand = dp[kk][i - 1] + A[k][i];
                if (cand > temp_max) temp_max = cand;
            }
            dp[k][i] = temp_max;
        }
        // // view(dp[0][i]);
    }
    // view(dp);
    view(max(dp[0][N - 1], max(dp[1][N - 1], dp[2][N - 1])));

}

Measured memory_bytes: 4460
import math
from functools import reduce
n = int(input())
xy = []
for i in range(n):
    x, y = [int(item) for item in input().split()]
    xy.append([x, y, i])

def convex_hull_graham(points):
    TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0)

    def cmp(a, b):
        return (a > b) - (a < b)

    def turn(p, q, r):
        return cmp((q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1]), 0)

    def _keep_left(hull, r):
        while len(hull) > 1 and turn(hull[-2], hull[-1], r) == TURN_RIGHT:
            hull.pop()
        if not len(hull) or hull[-1] != r:
            hull.append(r)
        return hull

    points = sorted(points)
    l = reduce(_keep_left, points, [])
    u = reduce(_keep_left, reversed(points), [])
    return l.extend(u[i] for i in range(1, len(u) - 1)) or l

ret = convex_hull_graham(xy)
ret.append(ret[0])
ret.append(ret[1])
thetas = [0.0] * n
for i in range(1, len(ret)-1):
    v1 = [-ret[i][1] + ret[i-1][1], ret[i][0] - ret[i-1][0]]
    v2 = [-ret[i+1][1] + ret[i][1], ret[i+1][0] - ret[i][0]]
    v1_norm = math.sqrt(v1[0]**2.0 + v1[1]**2.0)
    v2_norm = math.sqrt(v2[0]**2.0 + v2[1]**2.0)
    thetas[ret[i][2]] = math.acos((v1[0]*v2[0] + v1[1]*v2[1]) / (v1_norm * v2_norm))
for item in thetas:
    print(item / (math.pi * 2.0))

Measured memory_bytes: 3808
import sys
input = sys.stdin.readline
def main():
    N, M = map(int, input().split())
    # C = [list(map(int, input().split())) for i in range(N)]
    V, W = [0]*N, [0]*N
    for i in range(N):
        W[i], V[i] = map(int, input().split())
    dp = [[0]*(M+1) for i in range(N+1)]
    # print(dp)
    # print(W)
    
    for i in range(N):
        for w in range(M+1):
            if w - W[i] >= 0:
               dp[i+1][w] = max(dp[i+1][w], dp[i][w-W[i]] + V[i]) 
            dp[i+1][w] = max(dp[i+1][w], dp[i][w])
    print(dp[N][M])    


if __name__ == '__main__':
    main()

Measured memory_bytes: 118768
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define MIN(a,b) ((a) < (b) ? (a) : (b))
struct node {
  int id;
  int cap;
  struct node *next;
};
struct node **list;
int **flow, *visit, *delta, *prev, *stack;
void Insert(int, int);
int Maxflow(int, int, int);
int main(void)
{
  int i, x, y, v, e, s, t, maxflow = 0;
  scanf("%d %d %d", &x, &y, &e);
  v = x + y + 2;
  list = (struct node**)malloc(sizeof(struct node*) * v);
  flow = (int**)malloc(sizeof(int*) * v);
  visit = (int*)malloc(sizeof(int) * v);
  delta = (int*)malloc(sizeof(int) * v);
  prev = (int*)malloc(sizeof(int) * v);
  stack = (int*)malloc(sizeof(int) * v);
  for (i = 0; i < v; i++) {
    list[i] = NULL;
    flow[i] = (int*)calloc(v, sizeof(int));
  }
  for (i = 0; i < e; i++) {
    scanf("%d %d", &s, &t);
    Insert(0, s + 1);
    Insert(x + t + 1, v - 1);
    Insert(s + 1, x + t + 1);
  }
  while (Maxflow(0, v - 1, v)) {
    int n = v - 1;
    do {
      flow[prev[n]][n] += delta[v-1];
      flow[n][prev[n]] -= delta[v-1];
      n = prev[n];
    } while(n);
    maxflow += delta[v-1];
  }
  printf("%d\n", maxflow);
  for (i = 0; i < v; i++) {
    free(list[i]);
    free(flow[i]);
  }
  free(list);
  free(flow);
  free(visit);
  free(delta);
  free(prev);
  free(stack);
}
void Insert(int a, int b)
{
  struct node *p = (struct node*)malloc(sizeof(struct node));
  p->id = b;
  p->cap = 1;
  p->next = list[a];
  list[a] = p;
  p = (struct node*)malloc(sizeof(struct node));
  p->id = a;
  p->cap = 0;
  p->next = list[b];
  list[b] = p;
}
int Maxflow(int s, int t, int size)
{
  struct node *n;
  int i, reached = 0, tail = 0;
  for (i = 0; i < size; i++) {
    visit[i] = 0;
    delta[i] = INT_MAX;
    prev[i] = -1;
  }
  visit[s] = 1;
  stack[tail++] = s;
  do {
    i = stack[--tail];
    for (n = list[i]; n != NULL; n = n->next) {
      int v = n->id;
      if (!visit[v] && flow[i][v] < n->cap) {
        stack[tail++] = v;
        visit[v] = 1;
        prev[v] = i;
        delta[v] = MIN(delta[i], n->cap - flow[i][v]);
        if (v == t) reached = 1;
      }
    }
  } while (tail && !reached);
  return reached;
}


Measured memory_bytes: 3768
#include<iostream>
using namespace std;
typedef long long ll;

const int MAX_N = 2002;
const ll INF = 1LL << 50;

ll A[MAX_N], min_time[MAX_N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll X;
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        min_time[i] = A[i];
    }
    ll ans = INF;
    for (ll i = 0; i < N; i++) {
        ll now_ans = i * X;
        for (int j = 0; j < N; j++) {
            min_time[j] = min(min_time[j], A[(j - i + N) % N]);
            now_ans += min_time[j];
        }
        ans = min(ans, now_ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long A, long long B){
	cout << max(0LL, A-B*2) << endl;
}

int main(){	
	long long A;
	long long B;
	scanf("%lld",&A);
	scanf("%lld",&B);
	solve(A, B);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<functional>
#define len(a) sizeof(a)/sizeof(a[0])
#define sort_asc(a,b) sort(a,a+b)
#define sort_dsc(a,b,dataType) sort(a,a+b,greater<dataType>())
#define IN cin>>
#define OUT cout<<
#define PI 3.14159265358979323846D
#define forr(i,b,e) for(int (i)=(b); (i) <= (e); (i)++)
#define pb push_back
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define vi vector<int>
#define nl endl
typedef long long int ll;
using namespace std;
void f();
int main()
{
    int t=1;
    //IN t;
    for(int i=0;i<t;++i) {f(); if(i!=t-1) OUT endl; else continue;}
    //{OUT "Case "<<i<<":"<<f(); if(i!=t-1) OUT endl; else continue;}
    return 0;
}
void f()
{
   int x;
   IN x;
   ll res=x;
   res+=(ll)pow(x,2)+(ll)pow(x,3);
   OUT res;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  //int n; cin>>n;
  //string s; cin>>s;
  int l,r,d;
  cin>>l>>r>>d;
  int c=0;
  for(int i=l;i<=r;i++){
    if(i%d==0) c++;
  }
  cout<<c;
}


Measured memory_bytes: 3584
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    S = iss()
    T = iss()
    G = math.gcd(N, M)

    for g in range(G):
        if S[g * N // G] != T[g * M // G]:
            print(-1)
            exit()
    else:
        print(lcm(N, M))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10472
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007


void solve()
{
	ll n,sum=0;
	cin>>n;
	vector<ll> a(n);
	for(ll i=0;i<n;i++)
		cin>>a[i],sum+=a[i];;
	ll sum1=0,ans=1000000007;
	for(ll i=0;i<n-1;i++)
	{
		sum1+=a[i];
		sum-=a[i];
		ans=min(ans,abs(sum-sum1));
	}
	cout<<ans;
    return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


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

int main() {

  int N,K;
  cin >> N >> K;
  int X = 1;
  
  for (int i = 0; i < N; i++) {
    
    if (X * 2 < X + K) {
      X *= 2;
    }
    else {
      X += K;
    }  
    
  }
  
  cout << X << endl;

}


Measured memory_bytes: 3628
#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 <climits>
#include <ctime>
#include <cassert>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}
 
signed main() {
    int n; string s;
    while(cin >> n, n) {
        int l = 0, r = 0;
        int cnt = 0;
        rep(i,0,n) {
            cin >> s;
            if(s == "lu" || s == "ld") l++;
            else r++;
            
            if(l - r > 1) l = r;
            else if(r - l > 1) r = l;
            else if(l == r) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s,t;
    cin >> s >> t;
    int count = 0;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == t[i])
        {
            count++;
        }
    }
    cout << count;

    return 0;
}

Measured memory_bytes: 256
n=int(input())

t = list(map(int,input().split()))

for i in range(n-1, 0, -1):
    #print(t)
    if t[i] < t[i-1]-1:
        print('No')
        exit()
    elif t[i] == t[i-1]-1:
        t[i-1] -= 1
print('Yes')

Measured memory_bytes: 63984
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      int N=int.Parse(Console.ReadLine());
      int M=int.Parse(Console.ReadLine());
      
      if((N==1&&M==2)||(N==2&&M==1)){
        Console.WriteLine(3);
      }else if((N==2&&M==3)||(N==3&&M==2)){
        Console.WriteLine(1);}
      else{
        Console.WriteLine(2);}
    
  }
  }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,b,p,q,s[50],g;
vector<ll> v[2];

void dfs(int f,ll pos,ll ss,ll e){
  if(pos==e){
    v[f].push_back(ss);
    return;
  }
  ll ns=s[pos]+ss;
  dfs(f,pos+1,ss,e);
  dfs(f,pos+1,ns,e);
}

int main(){
  cin>>n>>m>>a>>b>>p>>q;
  if(b==1&&a==1){
    if(m/(p+q)>=n)cout<<m-(p+q)*n<<endl;
    else cout<<min(p+q-(m%(p+q)),m%(p+q))<<endl;    
  }
  else{
    for(ll i=0,x=p,y=q;i<n;i++,x*=a,y*=b){
      ll ss=x+y;
      s[g++]=ss;
      if(ss>m)break;
    }
    v[0].push_back(0);
   v[1].push_back(0);
   v[1].push_back(1e16);
    dfs(0,0,0,g/2);
    dfs(1,g/2,0,g);
    ll ans=m;
    sort(v[1].begin(),v[1].end());
    for(int i=0;i<v[0].size();i++){
      int l=0,M,r=v[1].size();
      while(l<r){
	M=(l+r)/2;
	if(v[0][i]+v[1][M]<=m)l=M+1;
	else r=M;
      }
      ans=min(ans,m-v[0][i]-v[1][r-1]);
      ans=min(ans,v[0][i]+v[1][r]-m);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
//ll MOD = 1000000007;
ll MOD = 998244353;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  string s; cin >> s;
  int n = s.size();
  vl a(3);
  rep(i,n){
      a[s[i]-'a']++;
  }
  ll max = a[0],min = a[0];
  rep1(i,3){
    chmax(max,a[i]);
    chmin(min,a[i]);
  }
  if(max - min <= 1)out("YES");
  else out("NO");
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int dfs(int u, int t, vector<vector<int>>& adj, vector<int>& d,
        vector<int>& parent, vector<int>& low)
{
  ++t;
  d[u] = low[u] = t;

  int ret = 0;
  for (int v : adj[u]) {
    if (d[v] == -1) {
      parent[v] = u;
      ret += dfs(v, t, adj, d, parent, low);
      low[u] = min(low[u], low[v]);
      if (d[u] < low[v]) { ++ret; }
    }
    else if (v != parent[u]) {
      low[u] = min(low[u], d[v]);
    }
  }
  return ret;
}

int main()
{
  int N, M; scanf("%d %d", &N, &M);
  vector<vector<int>> adj(N + 5);
  int a, b;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  vector<int> d(N + 5, -1), low(N + 5, -1), parent(N + 5, -1);
  int ans = dfs(1, 0, adj, d, parent, low);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i, j;
    char c[3][4];

    for (i=0; i<3; i++) {
        scanf("%s", c[i]);
    }

    printf("%c%c%c\n", c[0][0], c[1][1], c[2][2]);

    return 0;
}

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

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

void solve(){
	string s, t;
	cin >> s >> t;

	int changes = t.size();

	for(int i = 0; i <= s.size() - t.size(); ++i){
		int here = 0;

		for(int j = 0; j < t.size(); ++j)
			here += s[i + j] != t[j];

		changes = min(changes, here);
	}

	cout << changes << "\n";
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 3644
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int c = saori.saori_hayami();
		int d = saori.saori_hayami();
		if(a*b >= c*d){
			System.out.println(a*b);
		} else {
			System.out.println(c*d);
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
from collections import deque
s = list(input())
d = deque(s)
q = int(input())
flag = True
for i in range(q):
  l = list(map(str,input().split()))
  if l[0] == '1':
    if flag:
      flag = False
    else:
      flag = True
  else:
    if l[1] == '1':
      if flag:
        d.appendleft(l[2])
      else:
        d.append(l[2])
    else:
      if flag:
        d.append(l[2])
      else:
        d.appendleft(l[2])
if flag:
  ll = list(d)
  print(''.join(ll))
else:
  d.reverse()
  ll = list(d)
  print(''.join(ll))
  

Measured memory_bytes: 9964
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	string S,T,U;
	cin>>S>>T;
	int A,B;
	cin>>A>>B;
	cin>>U;
	if(U==S){
		A--;
	}
	else{
		B--;
	}
	cout<<A<<' '<<B<<endl;
	return 0;
}


Measured memory_bytes: 256
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, n) {cin >> a[i];}
#define readmat(a, n, m) int a[(n) + 1][(m) + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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

    #ifndef ONLINE_JUDGE 
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        freopen ("OUTPUT_ERROR.txt" , "w" , stderr);
    #endif

    //start from here

    readb(n, W) 
    int v[n+1], w[n+1];

    fori (i, 1, n) cin >> w[i] >> v[i];

    int V = 1000*n;
    int dp[n+1][1000*n + 1];
    dp[0][0] = 0;

    fori (i, 1, V) dp[0][i] = INF;

    fori (i, 1, n)
    {
        fori (j, 1, V) 
            if(j - v[i] >= 0) dp[i][j] = min(dp[i-1][j], w[i] + dp[i-1][j - v[i]]);
            else dp[i][j] = dp[i-1][j]; 
    }

    ford (i, V, 0) if(dp[n][i] <= W) {print(i) return 0;}

    return 0;
}


Measured memory_bytes: 82504
n, m = gets.split.map(&:to_i)
# ac = Array.new(n, 0)
# wa = Array.new(n, 0)
ac = Hash.new(0)
wa = Hash.new(0)
ng = 0
m.times do
  p, s = gets.chomp.split
  if s == 'AC'
    if ac[p] == 0
      ng += wa[p]
    end
    ac[p] = 1    
  else
    wa[p] += 1
  end
end

puts "#{ac.values.inject(:+).to_i} #{ng}"

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

int main()
{
	int x, y;
	

	while (1)
	{
		cin >> x>> y;
		if (x == 0 && y == 0)break;

		if (x >= y)
		{
			cout << y << " " << x << endl;
		}

		if (x < y)
		{
			cout << x << " " << y << endl;
		}
		
	}

	return 0;
}


Measured memory_bytes: 2972
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;

long long MOD = 1000000007;
long long dp[100005][4];

P channel[30];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

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

	vector<T>vec(N);
	for (int i = 0; i < N;++i) {
		cin >> get<0>(vec[i]) >> get<1>(vec[i]) >> get<2>(vec[i]);
	}
	sort(vec.begin(), vec.end());

	for (int i = 0; i < 30; ++i)channel[i] = make_pair(0,0);

	for (int i = 0; i < N;++i) {
		T t = vec[i];
		for (int i = 0; i < 30;++i) {
			if (channel[i].second <= get<0>(t) && (channel[i].first == get<2>(t) || channel[i].first == 0)) {
				channel[i].first = get<2>(t);
				channel[i].second = get<1>(t);
				break;
			}
			else if (channel[i].second <= get<0>(t)-1) {
				channel[i].first = get<2>(t);
				channel[i].second = get<1>(t);
				break;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < N;++i) {
		if (channel[i].first != 0)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define si( x ) scanf("%d", &x)
#define sll( x ) scanf("%lld", &x)
#define mp make_pair
#define pb push_back
using namespace std;

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

int n, k, a[100001], res = 1e9;

int main( int argc, char *argv[] )
{
	si(n), si(k);
	for(int i = 0 ; i < n ; i++) si(a[i]);
	
	for(int i = 0 ; i <= n-k ; i++){
		res = min(res, abs(0 - a[i]) + abs(a[i] - a[i+k-1]) );
		res = min(res, abs(0 - a[i+k-1]) + abs(a[i] - a[i+k-1]) );
	}
	
	cout << res << endl;
}

Measured memory_bytes: 640
"""
n = int(sys.stdin.readline())
a, b = map(int, sys.stdin.readline().split())
c = c
s = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

a = 100
b = 0.987654321
print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)


mod = 1000000007

if __name__ == "__main__":
    N, M = map(int, sys.stdin.readline().split())
    list_2d = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
    list_2d = sorted(list_2d)
    bought = 0
    total = 0
    for l in list_2d:
        for i in range(l[1]):
            bought += 1
            total += l[0]
            if bought == M:
                print(total)
                exit()


Measured memory_bytes: 30672
#include<stdio.h>
int main(){
    char s[3];
    int i;
    scanf("%s", s);
    for (int i = 0; i < 3; ++i)
    {
    if(s[i]=='7'){
        printf("Yes");
        return 0;
        }
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 1700
#include<iostream>
#include<vector>
#include<string>
#include<numeric>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M);
    for (auto& a : A) {
        cin >> a;
    }
    ll sum = accumulate(all(A), 0LL);
    if (sum > N) {
        cout << -1 << endl;
    } else {
        cout << N - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
open List
let gcd (a, b) =
  let rec gcd' (a, b)= 
    if b = 0 then a else gcd' (b, a mod b)
  in if a > b then gcd' (a, b)
     else gcd' (b, a)

let i_inp_list : unit -> int list = fun () ->
  let inp_split = Str.split (Str.regexp " ") (input_line stdin) in
  map (fun x -> int_of_string x) (inp_split)

let () =
  let [a;b;c;d] = i_inp_list () in
  let enum_can_div k =
    b / k - (a - 1) / k in
  let y_c = enum_can_div c in
  let y_d = enum_can_div d in
  let y_cd = enum_can_div (c / gcd (c, d) * d) in
  let ans = (b - a + 1) - (y_c + y_d - y_cd) in
  print_int ans;
  print_newline ()
    

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

int main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	vector<int> water;
	vector<int> sugar;
	vector<int> add;
	for (int i =0;i*a*100<=f;i++){
		water.push_back(i*100*a);
	}
	for (int w : water){
		for (int i=0;i*b*100+w<=f;i++){
			add.push_back(i*b*100+w);
		}	
	}
	for (int i : add) water.push_back(i);
	add.clear();
	for (int i=0;i*c<=f;i++){
		sugar.push_back(i*c);
	}
	for (int s : sugar){
		for (int i=0;i*d+s<=f;i++){
			add.push_back(i*d+s);
		}	
	}
	for (int i : add) sugar.push_back(i);
	add.clear();
	double maxProcent = -1;
	int ans1,ans2;
	for (int i : water){
		for (int j : sugar){
			if(100*j>=(i+j)*maxProcent&&i>0&&100*double(j)/i<=e&&i+j<=f){
				maxProcent=double(100*j)/(i+j);
				ans1 = i;
				ans2 = j;
			}
		}
	}
	cout<<ans1+ans2<<" "<<ans2;
	
   	return 0;	
}


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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    ll ma,mi,mai,mii;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        if(i==0){
            ma = a[i];
            mai = i;
            mi = a[i];
            mii = i;
        }else{
            if(a[i]>ma){
                ma = a[i];
                mai = i;
            }
            if(a[i]<mi){
                mi = a[i];
                mii = i;
            }
        }
    }

    std::cout << 2*n-1 << std::endl;
    for (int i = 0; i < n; i++) {
        if(abs(ma) >= abs(mi)){
            std::cout << mai+1 <<" "<<i+1 << std::endl;
        }else{
            std::cout << mii+1 <<" "<<i+1 << std::endl;
        }
    }
    
    
    if(abs(ma) >= abs(mi)){
        for (int i = 0; i < n-1; i++) {
            std::cout << i+1<<" "<<i+2 << std::endl;
        }
    }else{
        for (int i = n-1; i > 0; i--) {
            std::cout << i+1<<" "<<i << std::endl;
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[100001];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    vector<bool> ischecked(n + 1, false);
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(ischecked[i]) continue;
        ischecked[i] = true;
        if(i == a[a[i]]){
            ischecked[a[i]] = true;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640