akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  string S;
  cin >> S;

  reverse(all(S));
  vector<string> sub = {"dream", "dreamer", "erase", "eraser"};
  rep(i, 4) {
    reverse(all(sub[i]));
  }

  int i = 0;
  while (i < S.size()) {
    int match = false;
    rep(s, 4) {
      int len = sub[s].size();
      if (S.substr(i, len) == sub[s]) {
        i += len;
        match = true;
      }
    }
    if (!match) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
#include<iostream>
using namespace std;

int A[1000000],N;

int binarySaerch(int key ){
  int left =0;
  int right =N;
  int mid;
  while(left < right){
    mid = (left + right )/2;
    if(key ==A[mid])return 1;
    if(key > A[mid])left = mid +1;
    else if(key < A[mid])right =mid;
  }
  return 0;
}

int main(){
  int i,q,k,sum=0;
  cin >> N;
  REP(i,N)cin >> A[i];
  cin >> q;
  REP(i,q){
    cin >>k;
    if(binarySaerch(k))sum ++;
  }
  cout << sum << endl;

  return 0;

}



Measured memory_bytes: 3472
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
using namespace std;

int main() {
 
  int n,b;
  cin >>n;
  string s,c;
  cin >>s;
  b = 0;
  for (int i=0;i<n;++i){
    if(i==n-1){
      break;
    }
    if(s.at(i)!=s.at(i+1)){
     b++;
    }
  }
  cout << b+1<< endl;
  return 0;
}

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

int n, m, vis[100009], dis[100009];
vector<int> adj[100009];

int dfs(int s)
{
    if(vis[s])
        return dis[s];
    vis[s] = 1;
    int ret = 0;
    for(auto u : adj[s])
        ret = max(ret, dfs(u) + 1);

    return dis[s] = ret;
}

int main()
{
    int i;
    cin >> n >> m;

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

    int ans = 0;
    for(i = 1; i <= n; i++)
    {
        if(!vis[i])
            ans = max(ans, dfs(i));
    }

    cout << ans;
}


Measured memory_bytes: 8576
/* DSL2_C: Range Search (kD Tree) */

#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

class Node {
    public:
        int location;
        int p, l, r;
        Node() {}
};

class Point {
    public:
        int id, x, y;
        Point() {}
        Point(int id, int x, int y):
            id(id), x(x), y(y) {}

        bool operator < (const Point &p) const {
            return id < p.id;
        }
};

static const int MAX = 1000000;
static const int NIL = -1;

Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

int makeKDTree(int l, int r, int depth) {
    if (r <= l) return NIL;

    if (depth % 2 == 0) {
        sort(P + l, P + r, lessX);
    } else {
        sort(P + l, P + r, lessY);
    }

    int mid = (l + r) / 2;
    int t = np++;
    T[t].location = mid;
    T[t].l = makeKDTree(l, mid, depth + 1);
    T[t].r = makeKDTree(mid + 1, r, depth + 1);

    return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {
    Node node = T[v];
    int x = P[node.location].x;
    int y = P[node.location].y;

    if (sx <= x && x <= tx && sy <= y && y <= ty) {
        ans.push_back(P[node.location]);
    }

    if (depth % 2 == 0) {
        if (node.l != NIL && sx <= x) {
            find(node.l, sx, tx, sy, ty, depth + 1, ans);
        }
        if (node.r != NIL && x <= tx) {
            find(node.r, sx, tx, sy, ty, depth + 1, ans);
        }
    } else {
        if (node.l != NIL && sy <= y) {
            find(node.l, sx, tx, sy, ty, depth + 1, ans);
        }
        if (node.r != NIL && y <= ty) {
            find(node.r, sx, tx, sy, ty, depth + 1, ans);
        }
    }
}

int main() {
    int x, y, n_points;
    scanf("%d", &n_points);
    for (int i = 0; i < n_points; i++) {
        scanf("%d %d", &x, &y);
        P[i] = Point(i, x, y);
        T[i].l = T[i].r = T[i].p = NIL;
    }

    np = 0;
    int root = makeKDTree(0, n_points, 0);

    int n_queries;
    scanf("%d", &n_queries);

    int sx, tx, sy, ty;
    vector<Point> ans;
    for (int i = 0; i < n_queries; i++) {
        scanf("%d %d %d %d ", &sx, &tx, &sy, &ty);
        ans.clear();
        find(root, sx, tx, sy, ty, 0, ans);
        sort(ans.begin(), ans.end());
        for (int i_a = 0; i_a < ans.size(); i_a++) {
            printf("%d\n", ans[i_a].id);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 17416
import java.util.Scanner;

public class Main{
	private static Scanner scan;

	public static void main(String[] args) {
		scan = new Scanner(System.in);
		while(scan.hasNext()){
			String s1 = scan.next();
			String s2 = scan.next();
			int i =  Integer.parseInt(s1) + Integer.parseInt(s2);
			String s = String.valueOf(i);
			System.out.println(s.length());
		}
		System.exit(0);
	}
}

Measured memory_bytes: 12000
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

struct node{
	int parent;
	int *nect;
};

int main(){

        ios::sync_with_stdio(false);
        cin.tie(0);

	
	int n;
	cin >> n;
	
	vector<int> par(n+1);
	vector<int> num(n+1);
	par[0]=0;
	par[1]=1;
	for(int i=2;i<n+1;i++){	
		int tmp;
		cin >> tmp;
		par[i]=tmp;
		num[par[i]]++;
		
	}
	/*
	for(int i=1;i<n+1;i++){
		for(int j=i+1;j<n+1;j++){
			if(par[j]==i)
				num[par[j]]++;
		}
		cout<<num[i];
		if(i!=n) cout<<"\n";
	}
	*/
	for(int i=1;i<n+1;i++){
		cout<<num[i];
		if(i!=n) cout<<"\n";
	}
	return 0;	
}



Measured memory_bytes: 4784
fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut order: Vec<usize> = vec![0; n];
    for i in 0..n {
        let a = v[i] - 1;
        order[a] = i;
    }

    let ret = order.into_iter().map(|e| (e+1).to_string() ).collect::<Vec<_>>().join(" ");
    println!("{}", ret);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.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()
}


Measured memory_bytes: 10492
# coding: utf-8


def solve(*args: str) -> str:
    x = int(args[0])
    if 400 <= x <= 599:
        return '8'
    elif 600 <= x <= 799:
        return '7'
    elif 800 <= x <= 999:
        return '6'
    elif 1000 <= x <= 1199:
        return '5'
    elif 1200 <= x <= 1399:
        return '4'
    elif 1400 <= x <= 1599:
        return '3'
    elif 1600 <= x <= 1799:
        return '2'
    elif 1800 <= x <= 1999:
        return '1'
    return ''


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 9180
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <cctype>
#include <algorithm>
using namespace std;
int main(void){
    int a[3] ;
    for(int i = 0; i < 3 ; i++){
        cin >> a[i] ;
    }    

    sort(a,a+3);

    if(a[0] + a[1] == a[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define Ans(s) cout << s << endl

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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; }

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

typedef long long ll;
typedef vector<int> inv;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main()
{
	int x, a;
	cin >> x >> a;
	if (x < a) cout << 0 << endl;
	else cout << 10 << endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn = 1e5+5;
int a[maxn][3],dp[maxn][3];
int n;
int main()
{
	scanf("%d",&n);
	for( int i = 1 ; i <= n ; i++)
	{
		for(int j = 0 ;  j < 3 ; j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	dp[1][0]=a[1][0];
    dp[1][1]=a[1][1];
    dp[1][2]=a[1][2];
    for(int i = 2 ; i <= n ;i++)
    {
        dp[i][0]+=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]+=max(dp[i-1][2],dp[i-1][0])+a[i][1];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][0])+a[i][2];
        
    }
    int ans =max(dp[n][0],max(dp[n][1],dp[n][2])) ;
	printf("%d\n",ans);
    
	return 0;
}



Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0; i < S.length() - 1; i++) {
		if (S[i] == S[i + 1]) {
			ans++;
		}
	}
	if (ans == 0) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}
	return 0;
}

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

#define INF (100 * 100 * 100 * 100)

int n, m[110][110];

void matrixChainOrder(int *p){
  for(int i = 1;i <= n;i++) m[i][i] = 0;
  
  for(int l = 2;l <= n;l++){
    for(int i = 1;i <= n - l + 1;i++){
      int j = i + l - 1;
      m[i][j] = INF;
      for(int k = i;k <= j - 1;k++){
        int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
        m[i][j] = min(m[i][j], q);
      }
    }
  }
}

int main(){
  
  int p[110];
  
  cin >> n;
  
  for(int i = 0;i < n;i++){
    int r, c;
    
    cin >> r >> c;
    if(i) p[i + 1] = c;
    else{
      p[0] = r;
      p[1] = c;
    }
  }
  
  matrixChainOrder(p);
  
  cout << m[1][n] << endl;
  
  return 0;
}



Measured memory_bytes: 3112
use std::io;

fn choose_digit(available_digits: &Vec<bool>, lower_digits: &mut Vec<usize>, d: usize) -> usize {
    if available_digits[d] {
        // println!("available: {}", d);
        lower_digits.push(d);
        return 0;
    }
    clear_lower_digits(&available_digits, lower_digits);
    // println!("cleared");
    for i in d+1..10 {
        if available_digits[i] {
            // println!("chosen: {}", i);
            lower_digits.push(i);
            return 0;
        }
    }
    lower_digits.push(0);
    return 1;
}

fn clear_lower_digits(available_digits: &Vec<bool>, ds: &mut Vec<usize>) {
    let mut d = 0;
    for i in 0..10 {
        // println!("i: {}", i);
        if available_digits[i] {
            d = i;
            break
        }
    }
    // println!("lowest digit: {}", d);
    let len = ds.len();
    for i in 0..len {
        ds[i] = d;
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut iter = input.split_whitespace();
    let mut n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let mut available_digits = vec![true; 10];
    let mut line = String::with_capacity(2 * k);
    io::stdin().read_line(&mut line).unwrap();
    for token in line.split_whitespace() {
        let d: usize = token.parse().unwrap();
        available_digits[d] = false;
    }
    let mut digits = Vec::with_capacity(5);
    let mut carry = 0;
    while n > 0 {
        let d = n % 10 + carry;
        if d <= 9 {
            carry = choose_digit(&available_digits, &mut digits, d);
        } else {
            choose_digit(&available_digits, &mut digits, 0);
            carry = 1;
        }
        n = n / 10;
    }
    if carry > 0 {
        choose_digit(&available_digits, &mut digits, carry);
    }
    if digits.len() == 0 {
        println!("0");
        return
    }
    for d in digits.iter().rev() {
        print!("{}", d);
    }
    println!("");
}


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

int N, A[20], x[20][20], y[20][20];

int counter(int x) {
	if (x == 0) return 0;
	return counter(x >> 1) + (x & 1);
}


int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		for (int j = 1; j <= A[i]; j++) {
			cin >> x[i][j] >> y[i][j];
		}
	}
	int ans = 0;
	for (int bits = 1; bits < (1 << N); bits++) {
		bool ok = true;
		for (int i = 1; i <= N; i++) {
			if (!(bits & (1 << (i - 1)))) continue;
			for (int j = 1; j <= A[i]; j++) {
				if (((bits >> (x[i][j] - 1)) & 1) ^ y[i][j]) ok = false;
			}
		}
		if (ok) ans = max(ans, counter(bits));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
 #include <queue>
 #include <algorithm>
 #include <numeric>
 using namespace std;
 const long long INF = 1LL << 40 ;

 int main () {
     long long N, K; cin >> N >> K;
     vector <vector < long long >> s (N); // s [i]: = set of delicious flavors of type i
     for ( int i = 0 ; i <N; ++ i) {
         long long t, d; cin >> t >> d; --t;
         s [t] .push_back (d);
     }

     // For each type, arrange in order of taste
     for ( auto & v: s) {
         sort (v.begin (), v.end (), greater < long long > ());
         if (v.empty ()) v.push_back (-INF); // sentinel
     }

     // The order of the news item with the largest value of “deliciousness”
     sort (s.begin (), s.end (), [&] (vector < long long > a, vector < long long > b) {
             return a [ 0 ]> b [ 0 ];});
 
     // First select K types
     long long cur = 0 ;
     priority_queue < long long > que;
     for ( int i = 0 ; i <K; ++ i) {
         cur += s [i] [ 0 ];
         for ( int j = 1 ; j <s [i] .size (); ++ j) que.push (s [i] [j]);
     }
     for ( int i = K; i <N; ++ i) for ( int j = 0 ; j <s [i] .size (); ++ j) que.push (s [i] [j]);

     // scan
     long long res = cur + K * K;
     for ( long long x = K- 1 ; x>= 1 ; --x) {
         long long v = s [x] [ 0 ];
         long long w = que.top ();
         if (v <w) {
             que.pop (); cur += w;
             que.push (v); cur-= v;
         }
         res = max (res, cur + x * x);
     }
     cout << res << endl;
 }

Measured memory_bytes: 8696
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a,b;cin>>a>>b;
if(a+b>=a-b&&a+b>=a*b){
cout<<a+b;
}
else if(a-b>=a+b&&a-b>=a*b){

cout<<a-b;
}
else
cout<<a*b;
 return 0;
}

Measured memory_bytes: 256
//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int32_t main()
{
    speed
    int x,y;
    cin>>x>>y;
    if(2*x<=y&&4*x>=y&&y%2==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        double a = scn.nextInt();
        double b = scn.nextInt();
        double h = scn.nextInt();
        double m = scn.nextInt();

        double ans = 0;
        double r = Math.abs(((((h * 60) + m) / 2) - (m * 6)));

        if ( r == 0) {
            System.out.println(Math.abs(a - b));
        } else if (r == 180) {
            System.out.println(a + b);
        } else {
            ans = Math.sqrt((a * a) + (b * b) - (2 * a * b * Math.cos(Math.toRadians(r))));
            System.out.println(ans);
        }

        scn.close();
    }
}

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

#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9
#define         lli         long long int

using namespace std;

///ISNNJB

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main() {
    /***freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    lli t,a,b,m,n,x,total;
    cin>>a>>b;

    if(b%2!=0)
        cout<<"No"<<endl;
    else {
        m=2*a;
        n=4*a;
        if(b>=m&&b<=n)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3648
/*
[jsc2019-qual] E - Card Collector
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;
const int MAX_H = 1e5;
const int MAX_W = 1e5;

const int MAX_V = MAX_H + MAX_W;

class UnionFind {
public:
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false;
        }
        if (data[y] < data[x]) {
            swap(x, y);
        }
        data[x] += data[y];
        data[y] = x;

        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : (data[x] = root(data[x])); }
    int size(int x) { return -data[root(x)]; }
};

int N, H, W;
pair<int, pii> ARC[MAX_N];
int ce[MAX_V];

ll solve() {
    UnionFind uf(H + W);

    sort(ARC, ARC + N);

    ll ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        int u = ARC[i].second.first, v = H + ARC[i].second.second;
        int ne = uf.same(u, v) ? ce[uf.root(u)] + 1
                               : ce[uf.root(u)] + ce[uf.root(v)] + 1;
        int nv = uf.same(u, v) ? uf.size(u) : uf.size(u) + uf.size(v);
        if (ne <= nv) {
            uf.unite(u, v);
            ce[uf.root(u)] = ne;
            ans += ARC[i].first;
        }
    }

    return ans;
}

int main() {
    cin >> N >> H >> W;
    for (int i = 0; i < N; i++) {
        int r, c, a;
        cin >> r >> c >> a;
        r--, c--;
        ARC[i] = {a, {r, c}};
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<queue>
#include<functional>
#include<climits>
#include<map>
#include<set>
#include<cmath>
#include<cstdlib>
#include<cassert>

#define M 51
#define H 11
#define W 11

using namespace std;

const int infty = INT_MAX;
const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};

struct state{
  int o,i,j,cost;
  int l,r;
  state():o(0),i(-1),j(-1),cost(infty),l(-1),r(-1){}
  state(int o,int i,int j,int l, int r,int cost):o(o),i(i),j(j),cost(cost),l(l),r(r){}
  bool operator>(const state &t)const{return cost>t.cost;}
};

bool isinside(int i, int j, int h, int w){ return 0<=i&&i<h&&0<=j&&j<w; }

int dijkstra(int o, int maxO, int maxC, int h, int w, int g[H][W])
{
  int ret = infty;
  priority_queue<state,vector<state>,greater<state> > pq;
  static int A[M][H][W][W][W];
  static bool vis[M][H][W][W][W];

  o=min(maxO,o);

  fill(&A[0][0][0][0][0],&A[M-1][H-1][W-1][W-1][W],infty);
  fill(&vis[0][0][0][0][0],&vis[M-1][H-1][W-1][W-1][W],false);

  for(int stj = 0; stj < w; ++stj){
    int ic;
    int io;
    if(o<=1) return infty;
    if(g[0][stj]>0){ic=0;io=min(maxO,o+g[0][stj]-1);}
    else{ic=-g[0][stj];io=o-1;}
    state init(io,0,stj,stj,stj,ic);
    A[io][0][stj][stj][stj] = ic;
    pq.push( init );
  }
  
  while(!pq.empty()){
    state nst = pq.top(); pq.pop();

    if( vis[nst.o][nst.i][nst.j][nst.l][nst.r] ) continue;
    else vis[nst.o][nst.i][nst.j][nst.l][nst.r] = true;

    if(nst.i == h-1 && nst.o >= 1 )
      ret = min(ret, nst.cost);
    
    // printf("(%d,%d) with oxygen %d cost = %d\n", nst.i, nst.j, nst.o, nst.cost);
    
    for(int k=1;k<4;++k){
      state next = nst;
      next.i += di[k];
      next.j += dj[k];
      if( isinside( next.i, next.j, h, w ) ){
	if( next.o - 1 <= 0 ) continue;
	if( k == 2 ){
	  next.l = W+1;
	  next.r = -1;
	}
	if( g[next.i][next.j] > 0 ){
	  int d_o = g[next.i][next.j];
	  if( next.l <= next.j && next.j <= next.r )
	    d_o = 0;
	  next.o += d_o;
	}else{
	  int d_c = -g[next.i][next.j];
	  if( next.l <= next.j && next.j <= next.r )
	    d_c = 0;
	  next.cost += d_c;
	}
	next.o = min( maxO, next.o-1 );
	next.l = min( next.l, next.j);
	next.r = max( next.r, next.j);
	if( next.cost > maxC ) continue;
	
	if( next.o > 0 ){
	  if( next.cost < A[next.o][next.i][next.j][next.l][next.r] ){
	    A[next.o][next.i][next.j][next.l][next.r] = next.cost;
	    if( !vis[next.o][next.i][next.j][next.l][next.r] )
	      pq.push(next);
	  }
	}
      }
    }
  }
  return ret;
}

int main()
{
  while(true){
    int w,h;
    int g[H][W];
    int f,m,o;
    int res=infty;
    scanf("%d%d", &w, &h);
    if( w==0 && h==0 ) break;
    scanf("%d%d%d", &f, &m, &o);

    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
	scanf("%d", &g[i][j]);
      }
    }

    res=dijkstra(o,m,f,h,w,g);
    if(res>f){
      puts("NA");
    }else{
      printf("%d\n",res);
    }
  }
  return 0;
}

Measured memory_bytes: 4744
# ABC143E - Travel by Car
def floyd_warshall(dist):
    """
    Compute the shortest paths of all pairs and modify dist.
    """
    V = len(dist)
    for i in range(V):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(V)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3


def main():
    # FW -> once more FW to edges <= L
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    INF = 1 << 60
    dist = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        dist[i][i] = 0
    for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
    floyd_warshall(dist)

    # assume distance within L as 1 and compute the number of fueling
    modified_dist = [[1 if x <= L else INF for x in d] for d in dist]
    floyd_warshall(modified_dist)
    ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] < INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 97984
S = input()
A, B, C, D = [int(s) for s in S]
op_l = ["+", "-"]

ex = ""
for op_1 in op_l:
    for op_2 in op_l:
        for op_3 in op_l:
            ans = A + B if op_1 == "+" else A - B
            ans = ans + C if op_2 == "+" else ans - C
            ans = ans + D if op_3 == "+" else ans - D
            if ans == 7:
                ex = str(A) + op_1 + str(B) + op_2 + str(C) + op_3 \
                     + str(D) + "=7"

print(ex)

Measured memory_bytes: 62004
import os
import sys
import math
if os.environ.get("DEBUG") is not None:
    sys.stdin = open("in.txt", "r")
rl = sys.stdin.readline

n, s = [rl().rstrip("\n") for _ in range(2)]
x = 0
ans = 0
for it in s:
    if it == "I":
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)

Measured memory_bytes: 9060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
    //cout << fixed << setprecision(8);

    string s; cin >> s;
    int K; cin >> K;

    int n = s.size();
    set<string> se;
    for(int i=0; i<26; ++i){

        for(int j=n-1; j>=0; --j){
            if(s[j]==(char)('a'+i)){
                for(int k=0; k<K; ++k){
                    if(j+k>=n) break;
                    se.insert(s.substr(j, k+1));
                }
            }

        }
        if(se.size()>=K) break;
    }

    int cnt=1;
    for(auto e: se){
        if(cnt==K){
            cout << e << endl;
            break;
        }
        cnt++;
    }
    return 0;
}

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

using namespace std;

int main()
{
    string S;
    cin >> S;

    char tmp = S[0];
    bool flag = false;
    for(int i = 1; i < (int)S.size(); ++i)
    {
        if(tmp == S[i])
        {
            flag = true;
        }
        tmp = S[i];
    }
    if(flag)
    {
        cout << "Bad" << endl;
    }
    else
    {
        cout << "Good" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	long long m;
	cin >> n >> m;
	vector<int> a;
	a.resize(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int> ());
	int l = 0, r = 200005, lim = 0;
	while(r - l > 1) {
		int mid = l + r >> 1;
		long long cnt = 0;
		for(int i = 0; i < n; ++i) {
			int L = -1, R = n, p = -1;
			while(R - L > 1) {
				int Mid = L + R >> 1;
				if(a[Mid] + a[i] >= mid) {
					L = p = Mid;
				} else {
					R = Mid;
				}
			}
			cnt += p + 1;
		}
		if(cnt >= m) {
			l = lim = mid;
		} else {
			r = mid;
		}
	}
	vector<long long> pre;
	pre.resize(n);
	pre[0] = a[0];
	for(int i = 0; i < n - 1; ++i) {
		pre[i + 1] = pre[i] + a[i + 1];
	}
	long long ans = 0;
	long long sum = 0;
	for(int i = 0; i < n; ++i) {
		int l = -1, r = n, p = -1;
		while(r - l > 1) {
			int mid = l + r >> 1;
			if(a[mid] + a[i] >= lim) {
				l = p = mid;
			} else {
				r = mid;
			}
		}
		if(p != -1) {
			ans += 1LL * a[i] * (p + 1) + pre[p];
			sum += p + 1;
		}
	}
	cout << ans - 1LL * (sum - m) * lim << '\n';
	return 0;
}

Measured memory_bytes: 1408
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	m <- readInt
	[ ds, cs ] <- transpose <$> replicateM m readIntegers
	let
		digit_num = sum cs
		digit_sum = sum $ zipWith (*) ds cs
		end_dsum = let m = digit_sum `mod` 9 in if m == 0 then 9 else m
        print $ ( digit_num - 1 ) + ( ( digit_sum - end_dsum ) `div` 9 )	

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

int main(){
    int n;
    cin >> n;
    long long z,w,a[n];
    cin >> z >> w;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    if(n > 2){
        cout << max(abs(a[n-2]-a[n-1]),abs(a[n-1]-w)) << endl;
    }
    else{
        cout << abs(a[n-1]-w) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll x;
  cin >> x;

  int a = x/500 * 1000;
  int mod = x % 500;
  int b = mod/5 * 5;

  cout << a+ b << endl;
}

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

using namespace std;

#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

typedef long long ll;

const int N = 505000;
const int mod = 1e9 + 7;
const ll inf = 1e18;

int n, a[N];

ll ans = 0;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    cin >> n;
    fo(i, n) cin >> a[i], a[i] -= i;
    sort(a + 1,a + n + 1);
    int x = a[(n + 1) / 2];
    fo(i, n) ans += abs(a[i] - x);
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
h = list(map(int, input().split()))
dp = [int(10000000000)]*100000
dp[0] = 0
cost = 0
for i in range(1, n):
  if dp[i] > dp[i-1]+abs(h[i]-h[i-1]):
    dp[i]=dp[i-1]+abs(h[i]-h[i-1])
  if i > 1:
    if dp[i] > dp[i-2]+abs(h[i]-h[i-2]):
      dp[i]=dp[i-2]+abs(h[i]-h[i-2])
print(dp[n-1])

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

//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second

//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << p.first << " " << p.second;return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if (it != v.begin())os << " ";os << *it;
  }return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}

//typedef
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;


signed main(){
	int a, b;
	scanf("%lld%lld", &a, &b);
	printf("%lld\n", (a+b)/2);
	return 0;
}







Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;

const int LIMIT = 45000;

int main() {
	int n;
	cin >> n;
	int count[26][n];
	
	for(int i = 0; i < 26; i++){
		for(int j = 0; j < n; j++){
			count[i][j] = 0;
		}
	}

	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		for(int j = 0; j < s.length(); j++){
			char ch = s[j];
			count[ch -'a'][i]++;
			//cout << ch -'a' << "," << i << endl;
		}
	}




	for(int i = 0; i < 26; i++){
		int cnt = 2501;
		for(int j = 0; j < n; j++){
			cnt = min(cnt,count[i][j]);
		}
		for(int k = 0; k < cnt; k++){
			cout << (char)('a'+i);
		}
	}




	cout << endl;

	return 0;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

X, Y = map(int, input().split())

max_diff = min(X,Y)
if (X+Y) % 3 == 0:
  n = (X + Y) // 3
  k = max_diff - n
  mod = 10**9+7
  N = 10**6
  g1 = [1, 1]
  g2 = [1, 1]
  inverse = [0, 1]
  for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
  ans = cmb(n,k,mod)
else:
  ans = 0

print(ans)

Measured memory_bytes: 122016
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

//on outside it's 0-indexed
template<typename T>
class BIT {
    // Consider this on a 1-index vector
    vector<T> table;
    int size;
    T zero;
public:
    BIT(int size): table(size+1, 0) {
        this->size = size;
    }
    // Consider this on a 1-indexed vector
    BIT(vector<T> &arr, T zero): zero(zero), table(arr.size()+1, zero) {
        this->size = arr.size();
    }
    
    //sum from [0,i]
    T sum(int i) {
        i++;
        T sum = zero;
        while(i>0) {
            sum+=table[i];
            i-=(i&(-i));
        }
        return sum;
    }
    
    //0-indexed
    T rangeSum(int l, int r) {
        T ans = sum(r)-sum(l-1);
        return ans;
    }
    
    //point update
    void pointUpdate(int i, T delta) {
        i++;
        while(i<=size) {
            table[i]+=delta;
            i+=(i&(-i));
        }
    }
};

struct Query {
    int l, r, i;
};

bool QueryCmp(const Query &a, const Query &b) {
    return a.r < b.r;
}

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<int> v(N);
    for(int i=0; i<N; i++) {
        cin >> v[i];
    }
    //queries sort by right endpoint
    vector<Query> queries(Q);
    vector<int> queryAns(Q, 0);
    for(int q=0; q<Q; q++) {
        cin >> queries[q].l >> queries[q].r;
        queries[q].l--;
        queries[q].r--;
        queries[q].i = q;
    }
    sort(queries.begin(), queries.end(), QueryCmp);
    vector<int> lastVisit(5e5+1, -1);
    //USE BIT
    BIT<int> bit(N);//0-indexed
    int q = 0;
    for(int i=0; i<N; i++) {
        if(lastVisit[v[i]]!=-1) {
            bit.pointUpdate(lastVisit[v[i]], -1);
        }
        //update lastVisit
        lastVisit[v[i]] = i;
        bit.pointUpdate(i, 1);
        //solve all queries with right ending at this index
        while(q<Q && queries[q].r==i) {
            queryAns[queries[q].i] = bit.rangeSum(queries[q].l, queries[q].r);
            q++;
        }
    }
    //print out query answers
    for(int ans : queryAns) {
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 17400
#include<bits/stdc++.h>
using namespace std;
int A,B;
main(){
  cin>>A>>B;
  int a_road=rand()%A;
  int b_road=rand()%B;
  string s;
  for(int a=0;a<A;++a){
    for(int b=0;b<B;++b){
      if(a==a_road||b==b_road)
        s+=" ";
      else
        s+="w";
    }
    s+="\n";
  }
  //cout<<s;
  cout<<count(s.begin(),s.end(),'w')<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);


int main(){
    IOS;
    string s;cin>>s;
    f(i,0,3)cout<<s[i];
    return 0;  
} 





Measured memory_bytes: 3636
n = int(input())
a_list = list(map(int, input().split()))

money = 1000
kabu = 0

for i in range(n):

    if i < n - 1 : 

        if a_list[i] < a_list[i + 1] :

            if money >= a_list[i] :
                kabu = money // a_list[i]
                money = money % a_list[i]
        else :
            if kabu != 0 :
                money = money + kabu * a_list[i]
                kabu = 0
    else :
        if kabu != 0 :
            money = money + kabu * a_list[i]
            kabu = 0

print(money)

Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define prt_cs                  printf("Case %lld: ",cs)
#define sqr(x)                  (x)*(x)
#define ms(a,b)                 memset(a, b, sizeof(a))
#define db                      double
#define ll                      long long int
#define MOD                     100000007
#define PI                      acos(-1.0)
#define pii                     pair< int, int >
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
#define gcd(a, b)               __gcd(a, b)
#define lcm(a, b)               (((a)*(b))/gcd(a,b))
#define MAX                     100005

using namespace std;

int main()
{
//    READ;
//    WRITE;
    int n,x,t;
    scanf("%d %d %d",&n,&x,&t);
    int cnt = n/x;
    if(n%x!=0)cnt++;
    printf("%d\n",cnt*t);
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

struct UnionFind {
    vector<int> data;
    UnionFind(int N) : data(N, -1){}
    void init(int N) { data.assign(N, -1);}
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(x != y){
            data[x] += data[y];
            data[y] = x;
        }
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]);}
    bool same(int a, int b) { return root(a) == root(b);}
};

struct Edge {
    int from, to, num;
    Edge(int f, int t, int n)
         : from(f), to(t), num(n) {}
};
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    int s_, t_, c_;
    map<int, vector<Edge>> edges;
    rep(i, M) {
        cin >> s_ >> t_ >> c_;
        --s_; --t_;
        edges[c_].push_back(Edge(s_, t_, i));
    }
    UnionFind uf(N);
    vector<pint> memo;
    for(const auto& pev: edges) { 
        rep(i, pev.second.size()) {
            Edge e = pev.second[i];
            if(uf.same(e.from, e.to)) continue;
            uf.unite(e.from, e.to);
            memo.push_back(pint(pev.first, i));
        }
    }
    int ans_num = 0, ans_cos = 0;
    UnionFind temp(N);
    for(const pint& p : memo) {
        Edge aim = edges[p.first][p.second];
        temp.init(N);
        for(const pint& e : memo)
          if(p != e) temp.unite(edges[e.first][e.second].from, edges[e.first][e.second].to);
        int ra = temp.root(aim.from), rb = temp.root(aim.to);
        bool ok = true;
        REP(i, p.second + 1, edges[p.first].size()) {
            Edge e = edges[p.first][i];
            int rf = temp.root(e.from), rt = temp.root(e.to);
            if((ra == rf && rb == rt) || (ra == rt && rb == rf)) {
                ok = false;
                continue;
            }
        }
        if(ok) { ans_num++; ans_cos += p.first;}
    }
    cout << ans_num << ' ' << ans_cos << endl;
    return 0;
}

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

#define int long long int
const int mxN = 3005;
int dp[mxN][mxN];

void print_LCS(string s, string t, int n, int m) {
    int i=n, j=m;
    string lcs = "";
    
    while((i>0) && (j>0)) {
        if(s[i-1] == t[j-1]) {
            lcs = s[i-1] + lcs;
            --i;
            --j;

        } else if(dp[i-1][j] > dp[i][j-1]) {
            --i;
        } else {
            --j;
        }
    }
    cout << lcs << endl;
}

void LCS(string s, string t) {
    // lcs
    int n = s.length();
    int m = t.length();

    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            if(s[i-1] == t[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else 
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    // print lcs
    print_LCS(s, t, n, m);
}

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

    LCS(s, t);
}

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

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sec second
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define MOD (1000000007ll)
using namespace std;

int main()
{
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    ll ans = 0;
    rep(i, n)
    {
        if (a[i] == b[i] && b[i] == c[i])
            ans += 0;
        else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i])
            ans += 1;
        else
            ans += 2;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n;
	cin >> n;
	ll arr[n+1];
	for(ll i=1;i<=n;i++)
		cin >> arr[i];
	ll pre[n+1];
	ll suf[n+1];
	pre[1] = arr[1];
	for(ll i=2;i<=n;i++)
	{
		pre[i] = pre[i-1]^arr[i];
	}
	suf[n] = arr[n];
	for(ll i=n-1;i>=1;i--)
	{
		suf[i] = suf[i+1]^arr[i];
	}
	ll ans [n+1];
	ans[1] = suf[2];
	ans[n] = pre[n-1];

	for(ll i=2;i<=n-1;i++)
	{
		ans[i] = pre[i-1]^suf[i+1];
	}

	lp(1,n)
	{
		cout << ans[i] << " ";
	}
	cout << endl;

	return 0;	
}


Measured memory_bytes: 9772
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define maxn 1000010
#define mod 2147483647
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	repeat(i,1,10)
	repeat(j,1,10)
	if(i*j==n){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

const int MN = 1010;
const int MW = 10010;
const int MD = 1e9+114514;
int n;
int W;
int c[MN], t[MN], w[MN]; // cute, type, weight

int dp[2][MW];
int sm[MW+1];
bool solve(int md) {
//    printf("solve %d %d\n", n, md);

    memset(dp, 0, sizeof(dp));
    dp[0][0] = dp[1][0] = 1;

    int r = 0;
    for (int l = 0; l < n; l++) {
        while (r < n && c[r] - c[l] <= md) {
            // insert r
            for (int i = W; i >= w[r]; i--) {
                dp[t[r]][i] += dp[t[r]][i - w[r]];
            }
            r++;
        }
//        printf("%d %d\n", l, r);
        // check

        // for (int i = 0; i < 2; i++) {
        //     printf("dp table %d\n", i);
        //     for (int j = 0; j <= W; j++) {
        //         printf("%d ", dp[i][j]);
        //     }
        //     printf("\n");
        // }
        sm[0] = 0;
        for (int i = 1; i <= MW; i++) {
            sm[i] = sm[i-1];
            if (dp[1][i-1]) sm[i]++;
        }

        for (int i = 1; i < MW; i++) {
            if (!dp[0][i]) continue;
            if (sm[min(W+1, i+md+1)] != sm[max(1, i-md)]) return true;
        }
        // erase l
        for (int i = w[l]; i <= W; i++) {
            dp[t[l]][i] -= dp[t[l]][i - w[l]];
        }
    }
    return false;
}

int main() {
    int na, nb;
    cin >> na >> nb >> W;
    n = na + nb;
    static T tt[MN];
    for (int i = 0; i < na; i++) {
        int m, c;
        cin >> m >> c;
        tt[i] = T(c, 0, m);
    }
    for (int i = 0; i < nb; i++) {
        int m, c;
        cin >> m >> c;
        tt[na+i] = T(c, 1, m);
    }

    sort(tt, tt+n);

    for (int i = 0; i < n; i++) {
        tie(c[i], t[i], w[i]) = tt[i];
    }
    int l = -1, r = 1e9+10;
    while (r - l > 1) {
        int md = (l+r)/2;
        if (!solve(md)) {
            l = md;
        } else {
            r = md;
        }
    }
    cout << r << endl;
    return 0;
}

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

string s;

int check(int index){
	if(index >= s.length() - 2 || s[index] != 'm') return -1;
	if(s[index + 1] == 'e') index++;
	else index = check(index + 1);
	if(index == -1 || index >= s.length() - 1 || s[index] != 'e') return -1;
	if(s[index + 1] == 'w') index++;
	else index = check(index + 1);
	if(index == -1 || index >= s.length() || s[index] != 'w') return -1;
	return index + 1;
}

int main(){
	cin >> s;
	int pos = check(0);
	if(pos == -1 || pos != s.length()) cout << "Rabbit" << endl;
	else cout << "Cat" << endl;
	return 0;
}

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

using namespace std;

int main() {
    int n,m,x,a[100];
    cin>>n>>m>>x;
    for(int i=0;i<m;i++)cin>>a[i];
    int l=0,r=0;
    for(int i=0;i<m;i++){
        if(a[i]<x)l++;
        else r++;
    }
    cout<<min(l,r)<<endl;
    return 0;
}

Measured memory_bytes: 256