akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, m;
char dat[190][190];
int dpr[190][190][190], dpd[190][190][190];
int cur[190];

int main()
{
	scanf("%d%d", &n, &m);
	rep(i, n) scanf("%s", dat[i]);
	for(int i = n - 1; i >= 0; i --) {
		int cur = m;
		for(int j = m - 1; j >= 0; j --) {
			if(j == m - 1 || dat[i][j] != dat[i][j + 1]) cur = j;
			
			dpd[i][j][i] = cur;
			for(int k = i + 1; k < n; k ++) if(dat[k][j] == dat[k - 1][j]) dpd[i][j][k] = min(dpd[i][j][k - 1], dpd[k][j][k]);
			else dpd[i][j][k] = j - 1;
		}
	}
	
	for(int j = m - 1; j >= 0; j --) {
		int cur = n;
		for(int i = n - 1; i >= 0; i --) {
			if(i == n - 1 || dat[i][j] != dat[i + 1][j]) cur = i;
			
			dpr[i][j][j] = cur;
			for(int k = j + 1; k < m; k ++) if(dat[i][k] == dat[i][k - 1]) dpr[i][j][k] = min(dpr[i][j][k - 1], dpr[i][k][k]);
			else dpr[i][j][k] = i - 1;
		}
	}
	
	rep(i, 20) {
		if(dpd[0][0][n - 1] == m - 1) {
			printf("%d\n", i);
			return 0;
		}
		
		rep(i, n) rep(j, m) for(int k = i; k < n; k ++)
		dpd[i][j][k] = dpd[i][min(dpd[i][j][k] + 1, m - 1)][k];
		
		rep(i, n) rep(j, m) for(int k = j; k < m; k ++)
		dpr[i][j][k] = dpr[min(dpr[i][j][k] + 1, n - 1)][j][k];
		
		rep(i, n) rep(j, m) {
			for(int k = j; k < m; k ++) dpd[i][j][dpr[i][j][k]] = max(dpd[i][j][dpr[i][j][k]], k);
			for(int k = n - 2; k >= i; k --) dpd[i][j][k] = max(dpd[i][j][k], dpd[i][j][k + 1]);
			for(int k = i; k < n; k ++) dpr[i][j][dpd[i][j][k]] = max(dpr[i][j][dpd[i][j][k]], k);
			for(int k = m - 2; k >= j; k --) dpr[i][j][k] = max(dpr[i][j][k], dpr[i][j][k + 1]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 53504
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	var t string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)

	if len(s) != n {
		fmt.Printf("No\n")
		return
	}

	t = s[:len(s)/2]
	if strings.Repeat(t, 2) != s {
		fmt.Printf("No\n")
	} else {
		fmt.Printf("Yes\n")
	}
}


Measured memory_bytes: 640
from typing import List, NamedTuple
import pprint

pp = pprint.PrettyPrinter()


class Baggage(NamedTuple):
    value: int
    weight: int


def knapsack(
    total_weight: int, n_baggages: int, baggages: List[Baggage]
) -> int:

    T: List[List[int]] = [
        [0] * (n_baggages + 1) for _ in range(total_weight + 1)
    ]

    for n in range(1, n_baggages + 1):
        for t in range(1, total_weight + 1):
            v = T[t][n - 1]
            b = baggages[n - 1]
            if t >= b.weight:
                v_use = T[t - b.weight][n - 1] + b.value
                v = max(v, v_use)
            T[t][n] = v
        # pp.pprint(T)

    return T[total_weight][n_baggages]


def main() -> None:
    N, W = [int(x) for x in input().split()]

    B: List[Baggage] = []
    for _ in range(N):
        v, w = (int(x) for x in input().split())
        B.append(Baggage(v, w))

    print(knapsack(W, N, B))


main()



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

int a[5][5];
bool mark[5][5] = {0};

int main()
{
	for(int i = 1;i<=3;++i){
		for(int j = 1;j<=3;++j){
			cin>>a[i][j];
		}
	}
	int n;
	cin>>n;
	for(int t = 0;t<n;++t){
		int k;
		cin>>k;
		for(int i = 1;i<=3;++i){
			for(int j = 1;j<=3;++j){
				if(k == a[i][j]){
					mark[i][j] = 1;
				}
			}
		}
	}
	
	for(int i = 1;i<=3;++i){
		if(mark[i][1]+mark[i][2]+mark[i][3] == 3){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	for(int i = 1;i<=3;++i){
		if(mark[1][i]+mark[2][i]+mark[3][i] == 3){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	if(mark[1][1]+mark[2][2]+mark[3][3] == 3){
		cout<<"Yes"<<endl;
		return 0;		
	}
	if(mark[1][3]+mark[2][2]+mark[3][1] == 3){
		cout<<"Yes"<<endl;
		return 0;		
	}
	
	cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#![allow(unused_imports)]
use proconio::input;
use std::cmp;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        K: usize,
        H: [i64; N],
    }

    let mut dp = vec![0; N];
    for i in 1..N {
        let min = cmp::max(0, i as i64 - K as i64) as usize;

        dp[i] = dp[min..i]
            .iter()
            .enumerate()
            .map(|(j, &c)| c + (H[i] - H[j + min]).abs())
            .min()
            .unwrap();
    }

    println!("{}", dp[N - 1]);
}


Measured memory_bytes: 4064
#include <iostream>
using namespace std;
int main(void)
{
	char str[101];
	while(cin >> str){
		int i = 0;
		do{
			if(str[i] ==  '@'){
				i += 2;
				int num = str[i-1] - '0';
				for(int j=0; j < num; j++){
					putchar(str[i]);
				}
			}else{
				putchar(str[i]);
			}
			i++;
		}while(str[i]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 0
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s;
int a[5];

void dfs(int pos,int res,string t)
{
	if(pos==3)
	{
		if(res==7)
		{
			cout<<t<<"=7\n";
			exit(0);
		}
		return;
	}
	res+=a[pos+1];
	t.pb('+');
	t.pb(s[pos+1]);
	dfs(pos+1,res,t);
	res-=a[pos+1]*2;
	t[t.size()-2]='-';
	dfs(pos+1,res,t);
}

int main()
{
	cin>>s;
	rep(i,4) a[i]=s[i]-'0';
	dfs(0,a[0],s.substr(0,1));
	rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline void chmin(T &a, T b){if(a>=b)a=b;}
template<class T> inline void chmax(T &a, T b){if(a<=b)a=b;}
typedef long long ll;
const int INF = 1e9;

string S;

int main()
{
    cin >> S;
    if(S[0]!='A'){
        cout << "WA" << endl;
        return 0;
    }
    int cnt = 0;
    bool isAC = true;
    for(int i=1;i<S.size();++i){
        if(isupper(S[i])){
            if(i==1 || i==S.size()-1 || S[i]!='C'){
                isAC = false;
            }
            ++cnt;
        }
    }
    if(cnt==1 && isAC) cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<string>
using namespace std;
#include <stdio.h>
#include <limits.h>
#include "bits/stdc++.h"
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
int a, b, c, d, e, ans1;
string str;
int main() {
	cin >> a >> b ;
    c=a+b;
    d=a-b;
    e=a*b;
	if(c>=d && c>=e){
        ans1=c;
    }else if(d>=e){
        ans1=d;
    }else{
        ans1=e;
    }
	cout << ans1;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int r;

int main() {
    cin >> r;
    cout << r * r << endl;
}


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

bool comp(string a,string b){
  if(a.size()!=b.size()){
    return a.size()>b.size();
  }
  return a>b;
}

int main(){
  string A,B;
  cin >> A >> B;
  if(A==B){
    cout << "EQUAL" << endl;
  }else if(comp(A,B)){
    cout << "GREATER" << endl;
  }else{
    cout << "LESS" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n,d;
    cin >> n>>d;
    int x[n+1][d+1];
    rep1(i,n){
        rep1(j,d){
            cin >> x[i][j];
        }
    }
    int count =0;
    rep1(i,n) {
        rrep1(j,i+1,n) {
            int a = 0;
            rep1(k,d) {
                int b =x[i][k]-x[j][k];
                a = b*b+a;
            }
            int c = sqrt(a);
            if (c*c==a)
            {
                count++;
            }
        }
    }
    cout << count;
    return 0;
}


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb(a) push_back(a)
#define debug(x) cerr << #x << ": " << x << '\n'
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;

int main() {
    int n;
    cin >> n;
    vint v(30, -1);
    REP(i, n) {
        string s;
        cin >> s;
        vint tv(30);
        for (auto &c : s) {
            tv[c - 'a']++;
        }
        REP(j, 30) {
            if (v[j] < 0)
                v[j] = tv[j];
            else
                v[j] = min(v[j], tv[j]);
        }
    }
    REP(i, v.size()) {
        REP(j, v[i]) {
            cout << (char)(i + 'a');
        }
    }
    cout << endl;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fbo find_by_order
#define ook order_of_key
#define INF (ll)1e18
#define PI (ld)3.14159265358979323846
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    string s;cin>>s;
    ll cnt=0;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-1-i])cnt++;
    }
    cout<<cnt<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_a
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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

const int N = int(1e5)+10;
const int MOD = int(1e9)+7;
const int INF = int(2e9)+5;
const ll INF64 = 1e18;

ll a[N],dp[N];

int main () {
    FastIO
    int n;cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>a[i];
    }
    dp[0] = dp[1] = 0;
    a[0] = a[1];
    for (int i=2;i<=n;i++) {
        dp[i] = min(dp[i-1] +  abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#define MOD (ll)(1e9+7)
using namespace std;
int main(){
    int n;
    cin>>n;
    map<int,int> mp,tmp;
    rep(i,n){
        mp[abs((n-1-i)-i)]++;
    }
    tmp=mp;
    int a[n];
    rep(i,n){
        cin>>a[i];
        if (tmp[a[i]]==0){
            cout<<0<<endl;
            return 0;
        }
        tmp[a[i]]--;
    }
    ll ans=1;
    rep(i,n/2){
        ans*=2;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int ans=1;
    string s;
    cin>>s;
    string t="AKIHABARA";
    for(i=0;i<t.length();i++){
        if(s[i]!=t[i]){
            s.insert(s.begin()+i,'A');
        }
    }
    if(s.length()!=t.length())ans=0;
    for(i=0;i<t.length();i++){
        if(s[i]!=t[i])ans=0;
    }
    cout<<(ans?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream fin("input.txt")
//#define of1 ofstream fout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

map< pair<string,ll>,ll>mm1;
vector<pair<string,ll> >data;

bool cmp(pair<string,ll>&a,pair<string,ll>&b)
{
	if(a.fi==b.fi)
		return a.se>b.se;
	return a.fi<b.fi;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	
	for(int u=0;u<n;u++)
	{
		string tmp;
		ll tmp1;
		cin>>tmp>>tmp1;
		mm1[mp(tmp,tmp1)]=u+1;
		data.eb(tmp,tmp1);
	}
	sort(data.begin(),data.end(),cmp);
	for(auto &x:data)
	{
		cout<<mm1[x]<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static long pow(long a,long b,long m){
        if(a==0 || a==1) return a;
        if(b==1) return a%m;
        long c=pow(a,b/2,m);
        if(b%2==0) return (c*c)%m;
        else return (((c*c)%m*(a%m))%m);
    }
    public static long sumGCD(long[] arr ,long n,long m){
        long max=0;
        for(int i=0;i<arr.length;i++)
            if(arr[i]>max) max=arr[i];
        long[] c=new long[(int)max+1];
        long[] d=new long[(int)max+1];
        long[] e=new long[(int)max+1];
        for(int i=0;i<arr.length;i++) c[(int)arr[i]]++;
        for(int i=1;i<=max;i++){
            for(int j=i;j<=max;j+=i) d[i]+=c[j];
        }
        for(int i=(int)max;i>=1;i--){
            e[i] = pow(d[i],n,m);
            for(int j=2*i;j<=max;j+=i){
                e[i] -= e[j];
                if(e[i]<=0) e[i]+=m;
            }
        }
        long sum=0;
        for(int i=1;i<=max;i++) sum=(sum+i*e[i])%m;
        return sum;
    }
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] str=br.readLine().split(" ");
        long n=Long.parseLong(str[0]);
        long k=Long.parseLong(str[1]);
        long[] arr=new long[(int)k];
        for(int i=1;i<=k;i++) arr[i-1]=i;
        long ans=sumGCD(arr,n,1000000007);
        System.out.println(ans);
    }
}

Measured memory_bytes: 37600
n = int(input())
a = list(map(int, input().split()))

ans = 0

while(1):
    f = 0
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] /= 2
            ans += 1
        elif a[i] % 2 != 0:
            f += 1
    if f == n:
        print(ans)
        exit()

Measured memory_bytes: 4148
from itertools import permutations
N = int(input())
n = list(range(1, N+1))
a_tuple = tuple(map(int, input().split()))
b_tuple = tuple(map(int, input().split()))
a = 0
b = 0
for i, tup in enumerate(sorted(list(permutations(n))), 1):
    if tup == a_tuple:
        a = i
    if tup == b_tuple:
        b = i
print(abs(a - b))
    

    


Measured memory_bytes: 8308
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N;
vector<pair<int, int>> V;
int black[2020][2020], white[2020][2020];
int dp[2020][2020];

void solve() {
    int bnum[2020] = {}, wnum[2020] = {};

    FOR(k, 0, N * 2) {
        itn c = V[k].first;
        int num = V[k].second;
        int wsum[2020] = {}, bsum[2020] = {};
        for (int l = N; l > 0; l--) {
            bsum[l - 1] = bsum[l] + bnum[l - 1];
            wsum[l - 1] = wsum[l] + wnum[l - 1];
        }
        for (int l = N; l >= 0; l--) {
            if (c)
                black[num][l] = bsum[num] + wsum[l];
            else
                white[num][l] = wsum[num] + bsum[l];
        }
        if (c)
            bnum[num]++;
        else
            wnum[num]++;
    }
    Fill(dp, INF);
    dp[0][0] = 0;
    FOR(i, N + 1)
    FOR(j, N + 1) {
        if (i < N)
            chmin(dp[i + 1][j], dp[i][j] + black[i][j]);
        if (j < N)
            chmin(dp[i][j + 1], dp[i][j] + white[j][i]);
    }
    cout << dp[N][N] << endl;
}

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

    cin >> N;
    FOR(N * 2) {
        int b;
        char a;
        cin >> a >> b;
        b--;
        if (a == 'B')
            a = 1;
        else
            a = 0;
        V.pb({a, b});
    }


    solve();
    return 0;
}


Measured memory_bytes: 95744
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

int main() {
  int N, K; cin >> N >> K;
  vector<int> V(N); cin >> V;

  int C = min(N, K);
  int vmax = 0;
  for (int A = 0; A <= C; ++A) {
    for (int B = 0; A + B <= C; ++B) {
      int k = K - (A + B);
      priority_queue<int> que;

      int sum = 0;
      for (int i = 0; i < A; ++i) {
        sum += V[i];
        que.push(-V[i]);
      }
      for (int i = 0; i < B; ++i) {
        int r = N-i-1;
        sum += V[r];
        que.push(-V[r]);
      }

      for (int i = 0; i < k && !que.empty(); ++i) {
        if (que.top() <= 0) break;
        sum += que.top(); que.pop();
      }

      vmax = max(vmax, sum);
    }
  }
  cout << vmax << endl;
}


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

 using namespace std;

 #define mp make_pair
 #define fi first
 #define se second
 #define all(v) v.begin(),v.end()
 #define allarr(a) a , a + n
 #define ll long long
 #define pb push_back
 #define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
 typedef pair<int, int> pi;
 typedef pair<ll,ll> pll; 
 typedef pair<int,pi> trp ;
 typedef vector<pi> vpi;
 typedef vector<pll> vpll ; 
 int _abs (int x ) { return (x>0?x:-x); }

const int N =1e5+5  , H = 1e4 ; 
int dp[N]; 
int h[N]; 
int main(){
    int n ;
    cin>>n ; 
    for(int  i=0;i<n;i++){
        cin>>h[i]; 
        dp[i]=2e9; 
    }
    dp[0]=0 ; // base case 
    for(int i = 1 ; i < n ; i++ ){
        if( i - 1 >= 0 )dp[i] = min( dp[i] , dp[i-1] + _abs(h[i]-h[i-1])); 
        if( i - 2 >= 0 )dp[i] = min( dp[i] , dp[i-2]+ _abs(h[i]-h[i-2])); 
    }
    cout<<dp[n-1]<<endl; 
}

Measured memory_bytes: 1024
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
vector<int> v[N];
LL A(LL n, LL m)
{
	if (n < m) return 0;
	LL ret = 1;
	while (m--)
	{
		ret = ret * n-- % INF;
	}
	return ret;
}
int n, k;
LL dfs(int x, int rest, int fa = 0)
{
	int sons = v[x].size();
	if (fa) sons--;
	LL res = A(rest, sons);
	for (auto& y : v[x])
	{
		if (y == fa) continue;
		res = dfs(y, k - 2, x) * res % INF;
	}
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n >> k;
	for (int i = 1; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	cout << k * dfs(1, k - 1) % INF << endl;
	return 0;
}

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

int main(){
    int s,w;
    cin >> s >> w;
    if(s <= w){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3588
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(1000000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(X, Y, Z):
    X, Y = Y ,X
    X, Z = Z, X
    return X, Y, Z


def main():
    X, Y, Z = read_int_n()
    print(*slv(X, Y, Z))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7740
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    pair<int, int> p[m];
    rep(i, m) {
        cin >> a[i] >> b[i];
        p[i] = make_pair(b[i], a[i]);
    }
    sort(p, p+m);

    int x = p[0].first - 1;
    int ans = 1;
    for(int i = 1; i < m; i++) {
        if(p[i].second <= x) {
            continue;
        }

        x = p[i].first - 1;
        ans++;
    }

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

Measured memory_bytes: 1792
# ABC094D - Binomial Coefficients (ARC095D)
from bisect import bisect_left as bs


def main():
    # pascal's triangle := mid area (nCn/2) is the biggest -> bisect
    N = int(input())
    A = sorted(map(int, input().split()))
    if N == 2:
        print(A[1], A[0])
        return
    n, idx = A[-1], bs(A[:-1], A[-1] // 2)
    cand = [(abs(A[i] - n / 2), A[i]) for i in (idx - 1, idx, idx + 1)]
    r = min(cand)[1]
    print(n, r)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14052
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
	long a=s.nextLong();
	long b=s.nextLong();
	long k=s.nextLong();
	
	if(a>0&&k>0){
	    
	if(a>=k){
	a-=k;
	k=0;}
	else{
	k-=a;
	a=0;
	}
	}
	 if(b>0&&k>0){
	if(b>=k){
	b-=k;
	k=0;}
	else{
	
	k-=b;
	b=0;
	}
	 }
	
	System.out.println(a+" "+ b);
	}
}
	

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int D = sc.nextInt();
		int x = sc.nextInt();

		for(int i=2001;i<=2010;i++) {
			x = (r * x) - D;
			System.out.println(x);
		}
	}

}


Measured memory_bytes: 21844
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

dp = [[[0]*(N+2) for _ in range(N+2)] for _ in range(N+2)]
CA = Counter(A)
SA = CA[1]
SB = CA[2]
SC = CA[3]
for c in range(SC+1):
    for b in range(SB+SC+1):
        if b + c > N:
            break
        for a in range(N+1):
            if a + b + c > N:
                break
            S = a + b + c
            if S == 0:
                continue
            dp[a][b][c] = N/S + a/S*dp[a-1][b][c]\
            +b/S*dp[a+1][b-1][c]\
            +c/S*dp[a][b+1][c - 1]

print(dp[SA][SB][SC])


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

#define int long long


signed main() {
    
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for(int i=0; i<N; i++) cin >> L[i];
    
    int c = 0;
    int ans = 1;
    for(int i=0; i<N; i++){
        c += L[i];
        if(c<=X) ans++;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define T 1
#define S 2
#define E 3
#define W 4
#define N 5
#define B 6
 
int main(void){
    int dice[7],buf[7];
    char hoko[101]={NULL};
    int i,j;
    for(i=1;i<=6;i++){
        scanf("%d",&dice[i]);
    }
    scanf("%s",hoko);
    for(i=0;(int)hoko[i];i++){
        for(j=1;j<=6;j++) buf[j]=dice[j];
        if (hoko[i]=='S'){
            dice[T]=buf[N];
            dice[S]=buf[T];
            dice[E]=buf[E];
            dice[W]=buf[W];
            dice[N]=buf[B];
            dice[B]=buf[S];
        }
        else if (hoko[i]=='E'){
            dice[T]=buf[W];
            dice[S]=buf[S];
            dice[E]=buf[T];
            dice[W]=buf[B];
            dice[N]=buf[N];
            dice[B]=buf[E];
        }
        else if (hoko[i]=='W'){
            dice[T]=buf[E];
            dice[S]=buf[S];
            dice[E]=buf[B];
            dice[W]=buf[T];
            dice[N]=buf[N];
            dice[B]=buf[W];
        }
        else if (hoko[i]=='N'){
            dice[T]=buf[S];
            dice[S]=buf[B];
            dice[E]=buf[E];
            dice[W]=buf[W];
            dice[N]=buf[T];
            dice[B]=buf[N];
        }
    }
    printf("%d\n",dice[T]);
    return 0;
}

Measured memory_bytes: 596
menu = [int(input()) for _ in range(5)]

wait = []
for i in menu:
    w = i
    n = max(len(str(i)),2)
    while w % 10 != 0:
        w += 1
    wait.append([i,(w-i)%(10**(n-1))])
wait.sort(key=lambda x: x[1])
time = 0
for i in range(len(wait)):
    time += wait[i][0]
    if time % 10 != 0 and i != len(wait)-1:
        time += wait[i][1]
print(time)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		if(N==M)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
int tbl[10][10];
string to_s(int n) {
  char number[6];
  sprintf(number, "%05lld", n);
  return string(number);
}
int check(const string &s) {
  int d = tbl[0][s[0] - '0'];
  d = tbl[d][s[1] - '0'];
  d = tbl[d][s[2] - '0'];
  d = tbl[d][s[3] - '0'];
  d = tbl[d][s[4] - '0'];
  return d == 0;
}
string make(int n) {
  char number[5];
  sprintf(number, "%04lld", n);
  string s = string(number);
  int d = tbl[0][s[0] - '0'];
  d = tbl[d][s[1] - '0'];
  d = tbl[d][s[2] - '0'];
  d = tbl[d][s[3] - '0'];
  s.push_back(d + '0');
  return s;
}
signed main() {
  ios::sync_with_stdio(false);
  REP(i,10) REP(j,10) cin >> tbl[i][j];
  int error = 0;
  REP(n,10000) {
    string s = make(n);
    if(!check(s)) continue;
    bool e = false;
    REP(i,5) REP(j,10) {
      string t = s;
      t[i] = '0' + j;
      if(t != s) {
        if(check(t)) {
          e = true;
          // DEBUG(s);
          // DEBUG(t);
        }
      }
    }
    REP(i,4) {
      string t = s;
      swap(t[i], t[i + 1]);
      if(t != s) {
        if(check(t)) {
          e = true;
          // DEBUG(s);
          // DEBUG(t);
        }
      }
    }
    if(e) {
      error++;
    }
  }
  cout << error << endl;
}

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

main () {
    int n;
    cin >>n;
    int a;
    map<int,int> num;

    priority_queue<int, vector<int>, greater<int>> pq;


    for (int i=0; i<n; i++) {
        cin >> a;
        num[a]=i+1;

        pq.push(a);
    }

    for (int i=0; i<n; i++) {
        cout << num[pq.top()] << " " <<flush;
        pq.pop();
    }

}

Measured memory_bytes: 5880
processQueueList = []
completeList = []
time = 0
amount , quantum=map(int,input().split())
for process in range(amount):
    name ,needtime = input().split()
    processQueueList.append([name,needtime])
while len(processQueueList)!=0:
    process = processQueueList.pop(0)
    process[1] = int(process[1]) - quantum
    if process[1] <= 0:
        time = time + process[1] + quantum
        completeList.append([process[0],time])
    else:
        time = time + quantum
        processQueueList.append(process)
for process in completeList:
    print(*process)


Measured memory_bytes: 14668
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	while (a > 0 and c > 0) {
		c -= b;
		if (c <= 0) {
			printyn(true);
			break;
		}
		a -= d;
		if (a <= 0)printyn(false);
		//cerr << a << ' ' << c << '\n';
	}

	Please AC;
}


Measured memory_bytes: 3744
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define fr first
#define sc second
using namespace std;
#define INF 10000000
typedef pair<int,int> iiP;
typedef pair<double,int> diP;
typedef pair<diP,iiP> PP;
struct edge{
  int to,limit;
  double dist;
  edge(){}
  edge(int to,double dist,int limit):to(to),dist(dist),limit(limit){};
};
int n,m;
int S,G;
double t[31][31][31];
bool used[31][31][31];
int main(){

  while(cin >> n >> m && (n||m)){
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
        for(int k=0;k<31;k++){
          used[i][j][k] = false;
          t[i][j][k] = INF;
        }
      }
    }
    cin >> S >> G;
    vector< vector<edge> > info(n + 1);
    for(int i=0,x,y,d,c;i<m;i++){
      cin >> x >> y >> d >> c;
      info[x].push_back(edge(y,d,c));
      info[y].push_back(edge(x,d,c));
    }

    t[S][0][0] = 0.0;
    priority_queue< PP,vector<PP>,greater<PP> > que;
    que.push(PP(diP(0.0,S),iiP(0,0)));
    while(!que.empty()){
      PP p = que.top();
      int now = p.fr.sc,prev = p.sc.fr,speed = p.sc.sc;
      double time = p.fr.fr;

      que.pop();
      if( used[now][prev][speed] ) continue;
      used[now][prev][speed] = true;

      for(int i = 0,l = info[now].size();i < l;i++){
        edge e = info[now][i];
        if(e.to != prev){
          for(int j = -1;j < 2;j++){
            if(speed + j > 0 && speed + j <= e.limit && !used[e.to][now][speed + j]){
              if(t[e.to][now][speed + j] > time + e.dist / (speed + j)){
                t[e.to][now][speed + j] = time + e.dist / (speed + j);
                que.push(PP(diP(t[e.to][now][speed + j],e.to),iiP(now,speed + j)));
              }
            }
          }
        }
      }
    }
    double ans = INF;
    for(int i=0;i<=n;i++) ans = min(ans,t[G][i][1]);
    if(ans == INF) cout << "unreachable" << endl;
    else{
      cout << fixed << setprecision(7) << ans << endl;
    }
  }
}

Measured memory_bytes: 2036
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<cmath>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;

int main() {
	string s;
	ll n;

	cin >> n >> s;
	if (n == 1) {
		cout << "No" << endl;
		exit(0);
	}
	if (n % 2 != 0) {
		cout << "No" << endl;
		exit(0);
	}
	for (ll i = 0; i <= (s.size() - 1) / 2; i++) {
		if (s[i] != s[s.size() / 2 + i]) {
			cout << "No" << endl;
			exit(0);
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let mut vec: Vec<u16> = line.unwrap()
                    .split_whitespace()
                    .map(|s| s.parse().unwrap())
                    .collect();
        if (vec[0]+vec[1]) == 0 {break;}
        vec.sort();
        println!("{} {}", vec[0], vec[1]);

    }
}


Measured memory_bytes: 5036
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double v[] = new double[n];
		for(int i = 0;i < n;i ++) {
			v[i] = sc.nextDouble();
		}
		//if(n % 2 == 1)n++;
		for(int i = 0; i < n-1; i++) {
			Arrays.sort(v);
			v[i+1] =( v[i] + v[i + 1] )/ 2;
		}
		System.out.println(v[n-1]);
		
		
		

	}

}

Measured memory_bytes: 23380
#include <iostream>

int main() {
  int32_t a, b;
  std::cin >> a >> b;

  int32_t r;
  if (a - b >= 2) {
    r = a + (a -1);
  } else if (b - a >= 2) {
    r = b + (b - 1);
  } else {
    r = a + b;
  }

  std::cout << r << std::endl;
  return 0;
}

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

typedef unsigned long long ll;
vector<vector<int> >G;
vector<int>visited;

int equ,unk;

void dfs(int now){
    equ++;
    visited[now]=1;
    for(int i=0;i<G[now].size();i++){
        unk++;
        if(!visited[G[now][i]])
            dfs(G[now][i]);
    }
}

int main(){
    int n,m,ans=0;
    cin>>n>>m;
    G.resize(n);
    visited.resize(n,0);
    for(int i=0;i<m;i++){
        int s,t;
        cin>>s>>t;
        G[s-1].push_back(t-1);
    }
    for(int i=0;i<n;i++){
        if(!visited[i]){
            unk=0;
            equ=0;
            dfs(i);
            ans+=unk-equ+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1268
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

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

using namespace std;

int main() {
    int A[5];
    rep(i, 5) cin >> A[i];
    int min1 = 1LL<<29;
    rep(i, 5) {
        if(A[i] % 10 > 0) min1 = min(min1, A[i]%10);
    }
    int sum = 0;
    rep(i, 5) {
        sum += A[i] - A[i]%10;
        if (A[i]%10>0) sum += 10;
    }
    if (min1 != 1LL<<29) sum += min1 - 10;
    cout << sum << endl;
}


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

int main() {
  ll X,N;
  cin >> X >> N;
  
  if(N==0){
    cout << X << endl;
    return 0;
  }
  
  vector<ll> P(N);
  for(ll i=0;i<N;i++){
    cin >> P.at(i);
  }
  
  int t=0;
  for(ll i=0;i<3*N;i++){
    if(i%2==0){
      t=(i+1)/2;
    }
    else if(i%2==1){
      t=-(i+1)/2;
    }
    bool f=true;
    for(ll j=0;j<N;j++){
      if(P.at(j)-X==t){
        f=false;
      }
    }
    if(f){
      cout << X+t <<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3624
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var a = NextLong;
        var b = NextLong;
        var gcd = GCD(a, b);
        long i = 2;
        int res = 1;
        var sqrt = (int)Ceiling(Sqrt(gcd));
        while (i <= sqrt)
        {
            if (gcd % i == 0)
            {
                res++;
                while (gcd % i == 0) gcd /= i;
            }
            i++;
        }
        if (gcd != 1) res++;
        Console.WriteLine(res);
    }

    static long GCD(long a, long b)
    {
        while (true)
        {
            if (b == 0) return a;
            a %= b;
            if (a == 0) return b;
            b %= a;
        }
    }

    static long NextLong
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            long res = 0;
            int next = Console.In.Read();
            int sign = 1;
            while (45 > next || next > 57) next = Console.In.Read();
            if (next == 45) { next = Console.In.Read(); sign = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = Console.In.Read();
            }
            return res * sign;
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll inf  = 1e7+5;
typedef pair<int, bool> pib;
bool visited [inf];
int dist[inf];
int main() {
  int r; cin >> r;
  cout << r * r * 3;
}



Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut ans = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            for k in (j + 1)..n {
                if a[i] == a[j] {
                    continue;
                }
                if a[j] == a[k] {
                    continue;
                }
                if a[i] == a[k] {
                    continue;
                }

                if a[i] + a[j] > a[k] && a[j] + a[k] > a[i] && a[k] + a[i] > a[j] {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 2136
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String str[]=br.readLine().split(" ");
        int n=Integer.parseInt(str[0]);
        int k=Integer.parseInt(str[1]);
        str=br.readLine().split(" ");
        int arr[]=new int[n];
        for(int i=0;i<n;i++)
        arr[i]=Integer.parseInt(str[i]);
        int l=1,r=(int)1e9;
        while(l<=r)
        {
            int mid=(l+r)/2;
            int req=0;
            for(int i=0;i<n;i++)
            req+=(arr[i]-1)/mid;
            if(req<=k)
            r=mid-1;
            else
            l=mid+1;
        }
        pw.println(r+1);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 62104
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  int N; cin >> N;
  vector <int> Correct(3);
  for (int i = 0; i < 3; i++) cin >> Correct[i];
  sort(Correct.begin(), Correct.end());

  vector <int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];

  int all = pow(4, N) - 1;
  int ans = 1e9;
  for (int i = 0; i < all; i++){
    vector <int> now(N), cnt(4);
    int num = i;
    for (int j = 0; j < N; j++){
      now[j] = num % 4;
      cnt[num % 4]++;
      num /= 4;
    }

    bool flag = true;
    for (int j = 0; j < 3; j++){
      if (cnt[j] == 0) flag = false;
    }
    if (cnt[3] > N - 3) flag = false;

    if (flag == false) continue;

    vector <int> Length(3);
    int sum = 0;
    for (int j = 0; j < N; j++){
      if (now[j] == 3) continue;

      if (Length[now[j]] > 0) sum += 10;
      Length[now[j]] += L[j];
    }
    sort(Length.begin(), Length.end());
    
    for (int j = 0; j < 3; j++){
      sum += abs(Length[j] - Correct[j]);
    }
    
    ans = min(sum, ans);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  ll t = 0;
  rep(i,n) t += a[i];
  int j = n;
  int ans = 0;
  rep(i,m+1) {
    while (j > 0 && t > k) {
      --j;
      t -= a[j];
    }
    if (t > k) break;
    ans = max(ans, i+j);
    if (i == m) break;
    t += b[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4860
io = STDIN
n,a,b=io.gets.split.map(&:to_i)
MOD = 1_000_000_007
def pawmod(b, i)  #b**i
  return 1 if i==0
  i.odd? ?
  pawmod(b, i-1)*b % MOD :
  pawmod(b, i/2)**2 % MOD
end
def inv(a)
  pawmod(a, MOD-2)
end
def nCk(n,k)
  f1,f2=1,1 # n*n-1*..*n-k-1 / 1*2*..*k
  k.times do|i|
    f1 *= n-i
    f2 *= i+1
    f1 %= MOD
    f2 %= MOD
  end
  f1 * inv(f2) % MOD
end

puts (pawmod(2,n)-1-nCk(n,a)-nCk(n,b)) % MOD


Measured memory_bytes: 1916
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma once
#include<bits/stdc++.h>
#define q register
typedef long long ll;
using namespace std;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	for(q ll i=0;i<s.length();i+=2)   cout<<s[i];
	return 0;
}

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

using namespace std;

int main()
{
    long long int a, b;
    char ch;

    scanf("%lld %c %lld", &a, &ch, &b);

    if(ch=='+') printf("%lld\n", a+b);
    else printf("%lld\n", a-b);
    return 0;
}


Measured memory_bytes: 256