akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    Graph G(N);
    map<pair<int, int>, int> dic;
    rep(i,N-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        dic.emplace(make_pair(a,b), i);
    }

    vector<int> color(N-1);
    queue<pair<int, int>> que;
    que.emplace(0,-1);
    int K = 0;
    while (!que.empty()) {
        int v,pv;
        tie(v,pv) = que.front(); que.pop();
        int col = -1;
        if (pv != -1) col = color[dic[minmax(v,pv)]];
        int c = 1;
        for (auto nv : G[v]) {
            if (c == col) c++;
            if (nv == pv) continue;
            color[dic[minmax(v,nv)]] = c;
            chmax(K,c);
            c++;
            que.emplace(nv,v);
        }
    }
    cout << K << endl;
    rep(i,N-1) cout << color[i] << endl;
}


Measured memory_bytes: 12800
/*
 * Bad Move
 * Code be weshen zyk :'(
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define S second
#define F first
#define pb push_back

using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 1e5 + 5, K = 205, MOD = 998244353;
const ll MX = 1e15;
const int blkSz = 320;
int n;
vector<ll> L, R;
int main() {
//#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//#endif
	int n;
	cin >> n;
	vector<int> a(n);

	for (auto & x : a)
		cin >> x;

	if (a[0]) {
		cout << -1 << '\n';
		return 0;
	}

	for (int i = 0; i + 1 < n; i++) {
		if (a[i + 1] - a[i] > 1) {
			cout << -1 << '\n';
			return 0;
		}
	}
	ll ans = 0;
	for(int i = 1; i < n; i++){
		if(a[i]){
			ans++;
			if(a[i] != a[i-1] + 1){
				ans += (a[i] - 1);
			}
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define int long long int
#define modulo 1000000007
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      vector<int> A(n),B(n),a,b;
      for(int i=0;i<n;i++)cin>>A[i];
      for(int i=0;i<n;i++)cin>>B[i];
      a=A,b=B;
      sort(all(a),greater<int>()),sort(all(b),greater<int>());
      for(int i=0;i<n;i++){
            if(a[i]>b[i]){
                  cout<<"No";
                  return 0;
            }
      }
      int cnt=0;
      vector<ii> arr;
      for(int i=0;i<n;i++){
            arr.pb({B[i],A[i]});
      }
      sort(all(arr),greater<ii>());
      for(int i=0;i<n;i++){
            if(a[i]==arr[i].second)cnt++;
      }
      for(int i=1;i<n;i++){
            if(a[i-1]<=b[i]){
                  cnt++;
            }
      }
      if(cnt>0){
            cout<<"Yes";
            return 0;
      }
      cnt=0;
      map<int,int>data;
      for(int i=0;i<n;i++){
            data[arr[i].second]=i;
      }
      for(int i=0;i<n;i++){
            if(arr[i].second!=a[i]){
                  int x=arr[i].second,y=a[i];
                  swap(arr[i].second,arr[data[y]].second);
                  swap(data[y],data[x]);
                  cnt++;
            }
      }
      if(cnt<=n-2){
            cout<<"Yes";
      }
      else cout<<"No";
}



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

sum = (1+n)*n/2
sum3 =(3+ 3*(n//3))*(n//3)/2
sum5 =(5+ 5*(n//5))*(n//5)/2
sum15 =(15+ 15*(n//15))*(n//15)/2

print(int(sum-sum3-sum5+sum15))

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

int n;
char s[10005];

int main() {

    scanf("%d\n", &n);
    scanf("%s", s);

    for (int i = 0; i < strlen(s); i++)
    {
        printf("%c", ((s[i] - 'A') + n) % 26 + 'A');
    }

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    int n; cin>>n;
    n = n%100;
    n = n%10;
    if(n==3) cout << "bon"<<endl;
    else if(n==0||n==1||n==6||n==8) cout << "pon"<<endl;
    else cout<< "hon" << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
#include<array>
#include<cstring>
#include<numeric>
#include<string>
#include<set>
#include<cstdio>
#include<cmath>
#include<unordered_map>
#include<bitset>
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<string> x;
    map<string, int> y;
    while(n--){
        string tmp;
        cin>>tmp;
        y[tmp]++;
    }
    int vote = 1;
    map<string, int>::iterator it = y.begin();
    for(auto i = y.begin(); i != y.end(); i++){
        if(i->second > vote){
             vote = i->second;
             it = i;
        }
    }
    vector<int> indAll;
    for(auto i = y.begin(); i != y.end(); i++){
        if(i->second == it->second) x.push_back(i->first);
    }
    sort(x.begin(), x.end());
    for(int i=0; i<x.size(); i++){
        cout<<x[i]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 27212
#include <iostream>
#include <algorithm>

using namespace std;

int const NMAX = 1000;
int v[1 + NMAX];

int main() {

  int n, m, ans = 0;
  cin >> n >> m;
  for(int i = 1;i <= n;i++){
    cin >> v[i];
  }
  sort(v+1, v+n+1);
  for(int i = 1;i <= m;i++){
    ans += v[i];
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
typedef long long ll;
ll a, b;
int main(void){
    // Your code here!
    cin >> a >> b;
    if (b < 0) {
        if ((b - a) % 2) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    } else if (a > 0) {
        cout << "Positive" << endl;
    } else {
        cout << "Zero" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
const int maxn = 2e5+5;
int col[maxn],sub[maxn],sz[maxn];
ll cnt[maxn];
vector<int> g[maxn];
int n,dfn;

void dfs(int u,int f)
{
    sz[u] = 1;
    int pre = sub[col[u]];
    for(int v:g[u])if(v!=f){
        int t = sub[col[u]];
        dfs(v,u);
        int dt = sub[col[u]] - t;
        int tmp = sz[v] - dt;
        cnt[col[u]] -= (ll)tmp*(tmp+1)/2;
        sz[u] += sz[v];
    }
    sub[col[u]] = pre+sz[u];
}

int main()
{
    fastio();
    cin>>n;
    for(int i=1;i<=n;i++) cnt[i] = (ll)n*(n+1)/2;
    for(int i=1;i<=n;i++) {cin>>col[i];}
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v);g[v].pb(u);
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++)
    {
        int t = n-sub[i];
        cnt[i] -= (ll) t*(t+1)/2;
        cout<<cnt[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 37184
def solve(m,ans):
    global L,S
    if m == len(L):
        S.add(ans)
    else:
        solve(m+1,ans+L[m])
        solve(m+1,ans)

n = int(input())
S = set([])
L = list(map(int,input().split()))
q = int(input())
solve(0,0)
for i in map(int,input().split()):
    if i in S:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5656
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int p[10];
    for(int i=0;i<n;i++) cin>>p[i];
    sort(p,p+n);
    int ans=0;
    for(int i=0;i<n;i++) ans+=p[i];
    cout<<ans-p[n-1]/2;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    string str;
    cin >> str;

    string tmp;
    REP(i, str.size()) {
        if (i % 2 == 0)
            tmp += str[i];
    }

    cout << tmp << '\n';
    return 0;
}

Measured memory_bytes: 592
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int main(void){

    string S,T; cin>>S>>T;

    if(S.length()+1!=T.length()){
        cout<<"No"<<endl;
        return 0;
    }

    for (int i = 0; i < S.length(); ++i) {
        if(S[i]!=T[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;

}


Measured memory_bytes: 3632
<?php
while ($line = fgets(STDIN)) {
    $inputs[] = trim($line);
};
list($takaha_hp, $takaha_atk, $aoki_hp, $aoki_atk) = explode(" ", $inputs[0]);
$takaha_hp = (int) $takaha_hp;
$takaha_atk = (int) $takaha_atk;
$aoki_hp = (int) $aoki_hp;
$aoki_atk = (int) $aoki_atk;

while(true) {
    $aoki_hp = $aoki_hp - $takaha_atk;
    if ($aoki_hp <= 0) {
        echo "Yes\n";
        exit;
    }
    $takaha_hp = $takaha_hp - $aoki_atk;
    if ($takaha_hp <= 0) {
        echo "No\n";
        exit;
    }
}


Measured memory_bytes: 16104
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[3000000];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0;
  string s,w;
  cin >>s>>w;
  sort(s.begin(),s.end());
  sort(w.begin(),w.end(),greater<char>());
  if(s<w) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX_N 100000

int n;
struct edge { int to; ll cost; };
vector<edge> G[MAX_N];
int ans[MAX_N];
bool seen[MAX_N] = {};

void DFS(int v, ll dist){
    ans[v] = dist % 2;
    seen[v] = true;
    REP(i,G[v].size()){
        if(seen[G[v][i].to] == true) continue;
        DFS(G[v][i].to , dist + G[v][i].cost);
    }
}

signed main(){
    cin >> n;
    int u,v;
    ll w;
    REP(i,n - 1){
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back((edge){v, w});
        G[v].push_back((edge){u, w});
    }
    DFS(0, 0);
    REP(i,n){
        cout << ans[i] << endl;
    }
}

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

#define ll long long

int n,d;
map <int, bool> mm;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>d;
		mm[d]=1;
	}
	cout<<mm.size()<<endl;
	return 0;	
}

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

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}

fn read_mat<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_mat_char(n: usize) -> Vec<Vec<char>> {
    (0..n).map(|_| read_vec_char()).collect()
}

fn main() {
    let mut v = read_vec::<usize>();
    v.sort();
    println!("{}",v[2] - v[0]);
}


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

#define loop(i, n) for (int i = 0; i < n; i++) 
#define INF 1010001000

typedef pair<int, int> i_i;
typedef struct Edge{ int fr, to, co; } Edge;

int n, m;
int par[101], rank[101];

void init(int n);
int find(int x);
void unite(int x, int y);
bool same(int x, int y);
int kruskal(Edge e[]);
bool cmp(const Edge &e1, const Edge &e2);

int main()
{
    while (cin >> n >> m, (n|m)) {
        Edge e[m];
        loop(i, m) {
            cin >> e[i].fr >> e[i].to >> e[i].co;
        }
        cout << kruskal(e) << endl;
    }
    return 0;
}

int kruskal(Edge e[])
{
    sort(e, &e[m], cmp);
    int ans = 0;
    init(n);
    loop(i, m) {
        if (!same(e[i].fr, e[i].to)) {
            ans += e[i].co;
            unite(e[i].fr, e[i].to);
        }
    }
    return ans;
}

void init(int n)
{
    loop(i, n) {
        par[i] = i;
        rank[i] = 0;
    }
}

int find(int x)
{
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y) {
        return ;
    }
    if (rank[x] < rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rank[x] == rank[y]) {
            rank[x]++;
        }
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}
                
bool cmp(const Edge &e1, const Edge &e2)
{
    return e1.co < e2.co;
}

Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc=new Scanner(System.in)){
			int w=sc.nextInt();
			int n=sc.nextInt();
			int value[]=new int[w];
			for(int i=0;i<value.length;i++) {
				value[i]=i+1;
			}
			for(int i=0;i<n;i++) {
				String str=sc.next();
				String[] ab=str.split(",");
				int a=Integer.parseInt(ab[0])-1;
				int b=Integer.parseInt(ab[1])-1;
				int m=value[a];
				value[a]=value[b];
				value[b]=m;
			}
			for(int i=0;i<w;i++) {
				System.out.println(value[i]);
			}
			
		}
	}

}



Measured memory_bytes: 26152
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class DChatInACircle {
public:
  static void solve(istream &cin, ostream &cout) {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(ALL(A));
    multiset<int> temp;
    temp.insert(A[N - 1]);
    int ans = 0;
    rep(i, N - 1) {
      ans += temp.rbegin().operator*();
      temp.erase(temp.find(temp.rbegin().operator*()));
      temp.insert(A[N - (i + 2)]);
      temp.insert(A[N - (i + 2)]);
    }
    cout << ans << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  DChatInACircle solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int h, w, K;
    cin >> h >> w >> K;
    vector<string> s(h);
    for (Int i = 0; i < h; i++) {
        cin >> s[i];
    }
    Int d[11][1001] = {};
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            d[i + 1][j + 1] = s[i][j] == '1';
        }
    }
    for (Int i = 0; i <= h; i++) {
        for (Int j = 0; j < w; j++) {
            d[i][j + 1] += d[i][j];
        }
    }
    for (Int j = 0; j <= w; j++) {
        for (Int i = 0; i < h; i++) {
            d[i + 1][j] += d[i][j];
        }
    }
    Int res = h - 1 + w - 1;
    for (Int bit = 0; bit < (1<<(h - 1)); bit++) {
        Int cnt = 0;
        vector<Int> a;
        a.push_back(0);
        for (Int j = 0; j < h - 1; j++) {
            if (bit & (1<<j)) {
                a.push_back(j + 1);
                cnt++;
            }
        }
       a.push_back(h);
       bool aaa = true;
       Int l = 0;
       for (Int j = 1; j <= w; j++) {
           bool check = true;
           for (Int i = 0; i < (Int)a.size() - 1; i++) {
               Int x = d[a[i + 1]][j] + d[a[i]][l] - d[a[i + 1]][l] - d[a[i]][j];
               if (x > K) {
                   check = false;
               }
           }
           if (not check) {
               if (j - l == 1) {
                   aaa = false;
                   break;
               } else {
                   cnt++;
                   l = j - 1;
                   j--;
               }
           }
       }
       if (aaa) {
           res = min(res, cnt);
       }
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 384
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): any => {
  const A = +lines[0]
  const B = +lines[1]
  const C = +lines[2]
  const X = +lines[3]
  const obj = { A, B, C, X }
  debug(obj)
  return obj
}

// solver
export const solve = (lines: string[]): string => {
  const { A, B, C, X } = parseLines(lines)
  let count = 0
  for(let i = 0; i <= A; i++) {
    for (let j = 0; j <= B; j++) {
      for (let k = 0; k <= C; k++) {
        const sum = i * 500 + j * 100 + k * 50
        if (sum === X) {
          count++
        }
      }
    }
  }
  return `${count}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 11596
#include<iostream>
using namespace std;
int main(){
	int h,w;
	cin>>h>>w;
	char s[h+2][w+2]={};
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>s[i][j];
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(s[i][j]=='#')
				cout<<'#';
			else{
				int cnt=0;
				for(int ni=i-1;ni<=i+1;ni++)
					for(int nj=j-1;nj<=j+1;nj++)
						if(s[ni][nj]=='#')
							cnt++;
				cout<<cnt;
			}
		}
		cout<<endl;
	}
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while (n != 0) {
			String str = sc.next();
			Set<String> set = new HashSet<String>();
			set.add(str);
			for (int i = 1; i < str.length(); i++) {
				String a = str.substring(0, i);
				String b = str.substring(i, str.length());
				String ra = new StringBuilder().append(a).reverse().toString();
				String rb = new StringBuilder().append(b).reverse().toString();
				set.add(a + rb);
				set.add(b + a);
				set.add(ra + b);
				set.add(rb + a);
				set.add(b + ra);
				set.add(ra + rb);
				set.add(rb + ra);
			}
			System.out.println(set.size());
			n--;
		}
	}

}

Measured memory_bytes: 13000
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
ll a,b,sum;
int main()
{
    int n,k;
    cin>>n>>k;
    for(ll i=k+1;i<=n;i++)
    {
        sum+=n/i*(i-k);
        sum+=max(0ll,n%i-k+1);
        if(k==0)
        {
            sum--;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
// input vector
template<typename T>
void invec(vector<T> &A){for(T& a : A) cin >> a;}


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

int H, W; cin >> H >> W;
VS a(H); invec(a);
VI cnt(26, 0);
for(string s: a) for(char c: s) ++cnt[c - 'a'];
//4つ組の数
int c4 = W/2 * (H/2);
//2つ組の数
int c2 = W%2 * (H/2) + H%2 * (W/2);
// 中心1つ
int c1 = W%2 * H%2;

rep(i, 0, 26){
    if (c4){
        c4 -= cnt[i] / 4;
        cnt[i] %= 4;
    }
    if (c2){
        c2 -= cnt[i] / 2;
        cnt[i] %= 2;
    }
    if (c1) {
        c1 -= cnt[i];
        cnt[i]= 0;
    }
}
if (all_of(ALL(cnt), [](int i){return i == 0;}))
    cout << "Yes\n";
else 
    cout << "No\n";


}
// 書いて考える．場合分け
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

int calc(int x){
    int ret = 0;
    while(x % 100 == 0){
        x = x/100;
        ++ret;
    }
    return ret;
}

int main(){
    int D, N;
    cin >> D >> N;
    int cnt=0, val = 0;
    while (cnt<N){
        ++val;
        if(calc(val) == D){
            ++cnt;
        }
    }
    cout << val << endl;
}

Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define lli long long int
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define ve vector<lli>
#define vep vector<pair<lli,lli> >
#define fr(i,n) for(lli i=0;i<(n);i++)
#define F first
#define S second
long long int gcd(long long int a,long long int b)
{
	if(a==0)return b;
	return gcd(b%a,a);
}
int bin(long int a[],long int low,long int high,long d,long day[])
{
	//cout<<low<<" "<<high<<" "<<d<<"\n";
	if(low>high)return -1;
	long mid=(low+high)/2;
	if(a[mid]>(a[low]+d)&&(a[mid-1]<=(a[low]+d)||day[mid-1])&&day[mid]==0)
		return mid;
	else if(a[mid]>(a[low]+d)&&day[mid]==0)
		return bin(a,low,mid-1,d,day);
	else
		return bin(a,mid+1,high,d-a[mid+1]+a[low],day);
}
long long power(long long a,long long b)
{
	//cout<<a<<" "<<b<<"\n";
	if(b==0)return 1;
	if(b%2==0)return (power((a*a),b/2));
	return ((a)*(power((a*a),b/2)));
}
/*int subtree(vector<int>v,int sub[],i,j)
{
	if(sub[i]>0)return sub[i];
	for(auto x:v[i])
	{
		if(x!=j)sub[i]+=subtree(v,sub,x,i);
	}
	return sub[i];
}*/
int edge[100010]={0};
bool cmp(int a,int b)
{
	return edge[a]>edge[b];
}	
bool sortbysecdesc(const pair<int,int> &a, 
                   const pair<int,int> &b) 
{ 
       return a.first>b.first; 
} 
lli re(vector<vector<lli> >v,lli i,lli j,lli n,lli a[])
{
	if(i+j==n)return 0;
	lli b,c;
	//cout<<i<<" "<<j<<"\n";
	if(v[i][n-j-1]>-1)return v[i][n-j-1];
	if(i+1<n)b=v[i+1][n-j-1];
	else b=0;
	if(n-j-2>=0)c=v[i][n-j-2];
	else c=0;
	if(b==-1)b=re(v,i+1,j,n,a);
	if(c==-1)c=re(v,i,j+1,n,a);
	v[i][n-1-j]=max(a[i]-b,a[n-j-1]-c);
	return v[i][n-1-j];
}
int main()
{	
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	int t=1;
	//cin>>t;
	for(int X=1;X<=t;X++)
	{
		//cout<<"Case #"<<X<<": ";
		lli n;
		cin>>n;
		lli a[n],i,j,dp[n][n],k;
		vector<vector<lli> >v(n,vector<lli>(n,-1));
		fr(i,n)cin>>a[i];
		//cout<<re(v,0,0,n,a)<<"\n";
		//cout<<v[n-1][n-1]<<"\n";
		fr(i,n)dp[i][i]=a[i];
		for(k=1;k<n;k++)
		{
			for(i=0;i<n-k;i++)
			{
				j=k+i;
				dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
			}
		}
		cout<<dp[0][n-1]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++)
    cin>>a[i];
    int sum=0;
    for(int i=0;i<m;i++)
    {
        sum=sum+a[i];
    }
    if(sum>n)
    cout<<"-1";
    else
    cout<<n-sum;
}

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


int main()
{
  int h, w; cin >> h >> w;
  vector<string> s(h);
  rep(i, h)
    cin >> s[i];
  vector<vector<int>> ans(h, vector<int>(w, 100000));
  if (s[0][0] == '.')
    ans[0][0] = 0;
  else
    ans[0][0] = 1;
  rep(i, h)
    rep(j, w)
    {
      if (i == 0)
      {
        if (j == 0)
          continue;
        if (s[i][j] == '#' && s[i][j-1] == '.')
          ans[i][j] = ans[i][j-1] + 1;
        else
          ans[i][j] = ans[i][j-1];
      }
      else if (j == 0)
        if (s[i][j] == '#' && s[i-1][j] == '.')
          ans[i][j] = ans[i-1][j] + 1;
        else
          ans[i][j] = ans[i-1][j];
      else
      {
        int u, l;
        if (s[i][j] == '#' && s[i-1][j] == '.')
          u = ans[i-1][j] + 1;
        else
          u = ans[i-1][j];
        if (s[i][j] == '#' && s[i][j-1] == '.')
          l = ans[i][j-1] + 1;
        else
          l = ans[i][j-1];
        ans[i][j] = min(u, l);
      }
    }
  cout << ans[h-1][w-1] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int N,M;
  int a,b;
  int c[100010]={0};

  scanf("%d %d",&N,&M);
  int i;
  int flag = 1;
  for(i=0;i<M;i++){
    scanf("%d %d",&a,&b);
    c[a]++;
    c[b]++;
  }
  for(i=0;i<100010;i++){
    if(c[i]%2==1){
      flag = 0;
      break;
    }
  }

  if(flag){
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl

const long long MOD = 1000000007;


int main(){
    ll n;
    cin >> n;
    string ss[n];
    rep(i, n){
        cin >> ss[i];
        sort(all(ss[i]));
    }

    ll count = 0;
    sort(ss, ss+n);
    ll a = 0;
    string s = ss[0];
//    rep(i, n){
//        debug(ss[i]);
//    }
    for(int i = 1; i <= n; i++){
        if(i != n) {
            if(s == ss[i]) {
                a++;
            } else {
                s = ss[i];
//                debug(a);
                count += (a * (a + 1) / 2);
                a = 0;
            }
        }else{
//            debug(a);
            count += a*(a+1)/2;
        }
    }

    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();
 
		if(u.equals(s)) {
			a -= 1;
		}else if(u.equals(t)) {
			b -= 1;
		}

		System.out.println(a + " " + b);
		sc.close();
	}

}

Measured memory_bytes: 38640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
	int N; cin >> N;
	vector<ll> a(N+1);
	a[0] = 2;
	a[1] = 1;
	if(N == 1){
		cout << 1 << endl;
		return 0;
	}
	repr(i,2,N+1){
		a[i] = a[i-1]+a[i-2];
	}
	cout << a[N] << endl;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v: Vec<usize> = read();
    let n = v[0];
    let d: Vec<String> = read();
    let ans = (n..)
        .find(|i| d.iter().all(|x| !i.to_string().contains(x)))
        .unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <unordered_map>

int main()
{
   int length;
   std::cin >> length;
   int idxMax = 0;
   int idxNext = 0;
   int valueMax = 0;
   int valueNext = 0;
   int value;
   for (int i = 0; i < length; i++) {
      std::cin >> value;
      if (value > valueMax) {
         valueNext = valueMax;
         idxNext = idxMax;
         valueMax = value;
         idxMax = i;
      } else if (value > valueNext) {
         valueNext = value;
         idxNext = i;
      }
   }

   for (int i = 0; i < length; i++) {
      if (i == idxMax) {
         std::cout << valueNext << std::endl;
      } else {
         std::cout << valueMax << std::endl;
      }
   }
   return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, K;
  cin >> N >> K;
  vi A(N);
  cin >> A;

  v(bool) dp(K+1,false);
  rep(i,K+1){
    for(auto &a : A){
      if(i-a>=0 and dp[i-a]==false) {
        dp[i] = true;
        break;
      }
    }
  }
  if(dp[K]) cout << "First\n";
  else cout << "Second\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<vector<int> > matr(n,vector<int> (3));
for(int i=0;i<n;i++){
	cin>>matr[i][0]>>matr[i][1]>>matr[i][2];
}
vector<vector<int> > ans(n,vector<int> (3,INT_MIN));
for(int i=0;i<3;i++){
	ans[0][i]=matr[0][i];
}
int res=0;
for(int i=1;i<n;i++){
	ans[i][0]=max(matr[i][0]+ans[i-1][1],matr[i][0]+ans[i-1][2]);
	ans[i][1]=max(matr[i][1]+ans[i-1][0],matr[i][1]+ans[i-1][2]);
	ans[i][2]=max(matr[i][2]+ans[i-1][0],matr[i][2]+ans[i-1][1]);
}
res=max(ans[n-1][0],max(ans[n-1][1],ans[n-1][2]));
cout<<res<<" ";
}


Measured memory_bytes: 11136
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, k = map(int, input().split())
radius = k // 2
edge = [[] for _ in range(n)]
uv = []
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)
    uv.append((a, b))

def dfs(p, v, d):
    ret = 0
    st = []
    st.append((p, v, d))
    while st:
        p, v, d = st.pop()
        if d > radius:
            ret += 1
        for nv in edge[v]:
            if nv == p:
                continue
            st.append((v, nv, d+1))
    return ret

ans = n 
if k % 2 == 0:
    for i in range(n):
        ret = dfs(-1, i, 0)
        ans = min(ans, ret)
else:
    for u, v in uv:
        ret = dfs(u, v, 0) + dfs(v, u, 0)
        ans = min(ans, ret)

print(ans)

Measured memory_bytes: 53340
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let a = it.next().unwrap();
    let b = it.next().unwrap();
    let c = it.next().unwrap();
    let d = it.next().unwrap();
    if a * b >= c * d {
        println!("{}", a * b);
    } else {
        println!("{}", c * d);
    }
}


Measured memory_bytes: 4352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Security;
using System.Text;
using static System.Console;
using static System.Math;
using  static Ex;
class Simple {
    void Solve() {
        //input
        var N = io.Int;
        var a = new int[N];
        N.REP(i=>a[i]=io.Int);
        
        //cal
        var dict = new Dictionary<int,int>();
        foreach(var n in a) {
            if(!dict.ContainsKey(n)) dict[n] = 0;
            dict[n]++;
        }
        var ans = dict.Aggregate(0, (acc, x) => {
            if      (x.Value <  x.Key) return acc + x.Value;
            else if (x.Value == x.Key) return acc;
            else                       return acc + (x.Value - x.Key); 
        });
        
        //ret
        WriteLine(ans);

    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO {
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] {' ', '"', ','};
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if(_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while(st == "")
            st = ReadLine();
        _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}
static class Ex {
    public static void REP(this int n, Action <int> act) {
        for(var i = 0; i < n; ++i)
            act(i);
    }
    public static void FOR(int a, int b, Action <int> act) {
        for(var i = a; i < b; ++i)
            act(i);
    }
}


Measured memory_bytes: 26720
length = gets.to_i
array = gets.split(' ').map(&:to_i)

puts 'err!' if array.length != length

sum = 0

array.each do |d_1|
  array.each do |d_2|
    sum += d_1 * d_2
  end
end


cross_sum = array.map { |d| d ** 2 }.inject(:+)


puts ((sum - cross_sum) / 2)


Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
const int N = 5005;
const int K=31;  
const int M=10921000; 
const LL INF = (1LL<<40); 
const LL MOD = 998244353;
int n,m;
int main ()
{
    while (~scanf("%d",&n))
    {
        multiset <int> st;
        for (int i=0;i<n;i++)
        {
            int a;
            scanf("%d",&a);
            st.insert(a);
        }
        scanf("%d",&m);
        int f=0;
        for (int i=0;i<m;i++)
        {
            int a;
            scanf("%d",&a);
            if (f==1)
                continue;
            if (st.find(a)==st.end())
                f=1;
            else
                st.erase(st.find(a));
        }
        if (f)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}

/*

5
3 1 4 1 5
3
5 4 3

*/

Measured memory_bytes: 9600
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll D,G;
ll p[11];
ll c[11];


int main() {
    scanf("%lld%lld",&D,&G);
    rep(i,D) {
        scanf("%lld%lld",&p[i+1],&c[i+1]);
    }
    ll ans = inf;
    for(ll i=0; i< 1<<D; i++){
        ll temp = 0;
        ll n = 0;
        ll re = -1;
        rep(j,D){
            if (i & 1<<j){
                temp += 100*(j+1)*p[j+1]+c[j+1];
                n += p[j+1];
            }
            else re = j+1;
        }
        if (temp < G){
            if (temp + 100*re*(p[re]-1) < G){
                n = inf;
            }
            rep(k,p[re]-1){
                if (temp + 100*re*(k+1) >= G){
                    n += k+1;
                    break;
                }
            }
        }
        ans = min(ans,n);
    }
    cout << ans << endl;
  
    return 0;
}


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

using namespace std;

typedef long long ll;

unsigned long long factorial(ll n) {
  if (n == 0) return 1;

  return n * factorial(n - 1);
}

int main() {
  int N, P, i;
  cin >> N >> P;
  vector<int> A(N);
  for (auto &x : A) cin >> x;

  vector<int> even, odd;
  for (auto &x : A) (x % 2 == 0) ? even.push_back(x) : odd.push_back(x);

  ll ans;
  int n1 = even.size(), n2 = odd.size();
  if (n1 == N) {
    if (P == 0) {
      ans = pow(2, N);
    } else {
      ans = 0;
    }
  } else {
    ans = pow(2, N - 1);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#define ll long long

using namespace std;
int main(void){
  ll n, m;
  ll ret = 0;
  cin >> n >> m;

  if(2*n >= m){
    ret += m/2;
  }else{
    ret += n;
    m -= 2*n;
    ret += m/4;
  }

  cout << ret << "\r\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main() {
  int N,K,temp=0,count=0;
  scanf("%d",&N);scanf("%d",&K);
  for (int i = 0; i < N; i++) {
    scanf("%d",&temp);
    if (temp>=K) {
      count++;
    }
  }
  printf("%d\n",count );
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
ll a[maxn] , b[maxn];
ll suma[maxn] , sumb[maxn];
int main()
{
    ios::sync_with_stdio(false);
    ll n , m , k; cin >> n >> m >> k;
    for (int i = 1 ; i <= n ; i++) cin >>a[i] , suma[i] = suma[i - 1] + a[i];
    for (int i = 1 ; i <= m ; i++) cin >>b[i] , sumb[i] = sumb[i - 1] + b[i];
    if (suma[n] + sumb[m] <= k){
        cout << n + m << endl;
        return 0;
    }
    int ans = 0;
    for (int i = 0 ; i <= n ; i++){
        if (suma[i] > k) break;
        //cout << sumb + 1 + m << endl;
        int down = lower_bound(sumb + 1 , sumb + 1 + m , k - suma[i]) - sumb;
        if (sumb[down] != k - suma[i]) down--;
        ans = max(ans , down + i);
      //  cout << i << " " << down << endl;
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
    int y,m,d;
    char c1,c2;



    cin>>y>>c1>>m>>c2>>d;
    if(m<=4){
        cout<<"Heisei"<<endl;
    }else {
        cout<<"TBD"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
require "prime"

def _divisors(primes, k)
  Enumerator.new do |y|
    if primes.size == k
      y << 1
    else
      p, e = primes[k]
      _divisors(primes, k + 1).each {|d|
        (e + 1).times {|e1|
          y << p ** e1 * d
        }
      }
    end
  end
end

def divisors(n)
  _divisors(Prime.prime_division(n), 0).to_a.sort
end

n = gets.to_i
ary = divisors(n)
ary.size % 2 == 0 ? a = ary[(ary.size / 2 ) - 1] : a = ary[ary.size / 2]
b = n / a
puts a + b - 2




Measured memory_bytes: 2428
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
int main(int argc, char *argv[]) {
	size_t n;
	std::cin >> n;
	typedef struct {
		int x, y, h;
	} xyh_t;
	std::vector<xyh_t> v(n);
	xyh_t v_ref;
	for (size_t i = 0; i < n; i++) {
		std::cin >> v[i].x >> v[i].y >> v[i].h;
		if (v[i].h >= 1) { v_ref = v[i]; }
	}
	for (int cx = 0; cx <= 100; cx++) {
		for (int cy = 0; cy <= 100; cy++) {
			const int ch = std::max(v_ref.h + std::abs(v_ref.x - cx) + std::abs(v_ref.y - cy), 0);
			const bool found = std::accumulate(
				v.begin(), v.end(), true,
				[&cx, &cy, &ch] (const auto &acc, const auto &arg) {
					const int h = std::max(ch - std::abs(arg.x - cx) - std::abs(arg.y - cy), 0);
					const bool exact = (arg.h == h);
					return (acc && exact);
				}
			);
			if (found) {
				std::cout << cx << " " << cy << " " << ch << std::endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
s  = [int(N) for N in input().split()]
sum_list = []
for i in range(N):
    if i >= 1:

        num = s[i-1] - s[i]
        if num > 0:
            sum_list.append(num)
            s[i] += num
print(sum(sum_list))

Measured memory_bytes: 32184
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC103.A
{
    class Program
    {
        static void Main()
        {
            var sc = new Scanner();
            var tasks = sc.Arrayint(3);
            Array.Sort(tasks);
            Console.WriteLine(tasks[2] - tasks[0]);
        }
    }
    class Scanner
    {
        string[] s;
        long i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public int Nextint()
        {
            return int.Parse(Next());
        }
        public int[] Arrayint(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }

        public double[] ArrayDouble(long N, double add = 0)
        {
            double[] Array = new double[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }

        public decimal NextDecimal()
        {
            return decimal.Parse(Next());
        }

        public decimal[] ArrayDecimal(long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal();
            }
            return Array;
        }
    }
}

Measured memory_bytes: 11220
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long k = sc.nextLong();
    long x = 0;
    int result = -1;
    for (int i = 1; i <= k; i++) {
      x = x * 10 + 7;
      if (x % k == 0) {
        result = i;
        break;
      }
      x %= k;
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 35712
class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = float('inf')
        self.p = -1
        self.state = -1
        # -1 -> undiscovered
        #  1 -> finished
        #  0 -> found(not finished)


M = [float('inf')] * 100
for i in range(100):
    M[i] = [float('inf')] * 100

n = int(input())
nodes = [0] * 100
for i in range(n):
    V = [int(x) for x in input().split()] 
    for (j,m) in enumerate(V):
        M[i][j] = m if not m == -1 else float('inf') 
    nodes[i] = Node([])

nodes[0].d = 0
while True:
    mincost = float('inf')
    u = -1
    for i in range(n):
        node = nodes[i]
        if (mincost > node.d) and (node.state != 1):
            u = i
            mincost = node.d

    if u == -1:
        break

    nodes[u].state = 1
    for v in range(n):
        node = nodes[v]
        if (node.state != 1) and (M[u][v] != float('inf')):
            if node.d > M[u][v]:
                node.d = M[u][v]
                node.p = u
                node.state = 0

sum = 0
for i in range(n):
    if nodes[i].p != -1:
        sum += M[i][nodes[i].p]

print(sum)

Measured memory_bytes: 7968
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int g[51];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    while (m--)
    {
        int a, b;
        cin >> a >> b;
        g[a]++;
        g[b]++;
    }
    for (int i = 1; i <= n; ++i)
        cout << g[i] << '\n';
}


Measured memory_bytes: 256
s = list(input())
box = []
for i in range(len(s)):
  if s[i] == "0":
    box.append("0")
  elif s[i] == "1":
    box.append("1")
  else:
    if box == []:
      pass
    else:
      box.pop(-1)
print("".join(box))

Measured memory_bytes: 9044