akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		out.println(a>b?a-1:a);
	}
}


Measured memory_bytes: 23380
#include <stdio.h>
#include <string.h>
int main(){
	
	char namaA[15];
	char namaB[15];
	char namaC[15];
	
	scanf("%s %s %s", &namaA,&namaB,&namaC);

	int panjangA = strlen(namaA) - 1;
	int panjangB = strlen(namaB) - 1;
	int panjangC = strlen(namaC) - 1;
	
	if(namaA[panjangA] == namaB[0] && namaB[panjangB] == namaC[0]){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1600
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

const N = int(1e6)

var primes = make([]int, N+1)

func findPrimes() {
	for i := range primes {
		primes[i] = 1
	}

	for i := N; i > 1; i-- {
		for j := i; j <= N; j += i {
			primes[j] = i
		}
	}
}

func main() {
	findPrimes()

	n := readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}

	cnt := make([]int, N+1)
	for i := range a {
		ps := map[int]bool{}
		cur := a[i]
		p := primes[cur]
		for p != 1 {
			if _, ok := ps[p]; !ok {
				cnt[p]++
				ps[p] = true
			}
			cur /= p
			p = primes[cur]
		}
	}

	pairwise, setwise := true, true
	for i := range cnt {
		if cnt[i] > 1 {
			pairwise = false
		}
		if cnt[i] == n {
			setwise = false
		}
	}

	if pairwise {
		fmt.Println("pairwise coprime")
	} else if setwise {
		fmt.Println("setwise coprime")
	} else {
		fmt.Println("not coprime")
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(i = 0; i < n; i++)
    cin >> a[i];
  
  ll result = 0;
  for(i = 0; i < n; i++){
    for(j = 0; a[i] % 2 == 0; j++)
      a[i] /= 2;
    result += j;
      
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

S = 0
O = []
c = 0
for i in range(N):
    if A[i] < B[i]:
        S += B[i] - A[i]
        c += 1
    else:
        O.append(A[i]-B[i])
if c == 0:
    ok = True
if c != 0:
    O.sort(reverse=True)
    a = 0
    ok = False
    for o in O:
        a += o
        c += 1
        if a >= S:
            ok = True
            break

if ok:
    print(c)
else:
    print(-1)

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

using namespace std;
map <int, int> op;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        op[x]++;
    }

    int ans = 0;
    for (auto it = op.begin(); it != op.end(); it++)
    {
        if (it->second >= it->first) ans += it->second - it->first;
        else
            ans += it->second;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h,w;
  cin>>h>>w;
  vector<vector<int>> hw(h+2,vector<int>(w+2,0));
  rep(i,h)rep(j,w)
  {
    char c;cin>>c;
    hw[i+1][j+1]=c=='#';
  }
  rep(i,h)rep(j,w)
  {
    if(hw[i][j])
    {
      if(hw[i-1][j]|hw[i+1][j]|hw[i][j-1]|hw[i][j+1])continue;
      else {cout<<"No"<<endl;return 0;}
    }
  }
  cout<<"Yes"<<endl;
  



  return 0;

}


Measured memory_bytes: 256
n = int(input())
num_list = list()
string = input().split()
for i in range(n):
	num_list.append(int(string[i]))
del n
del string
num_list = sorted(num_list)
pro = 1
for number in num_list:
	pro *= number
	if pro > 10**18:
		pro = -1
		break
print(pro)

Measured memory_bytes: 21492
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    while(k--) {
        if(a >= b) b *= 2;
        else if(b >= c) c *= 2;
    }
    Yes(a < b and b < c);
}

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

using namespace std;

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

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> kids(N);
    rep(i, N){
        cin >> kids.at(i);
    }
    sort(kids.begin(), kids.end());
    int ans = 0;
    bool complete = true;
    for(int kid : kids){
        if(x >= kid){
            x -= kid;
            ans++;
        } else {
            complete = false;
            break;
        }
    }
    if(x > 0 && ans > 0 && complete) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
l = len(s)
#後ろから見たら一意
"""
tryブロックでsys.exit()を呼ぶと強制終了しない。
"""
import sys
i = l-1
try:
    while i>-1:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dreamer":
                i-=7
            else:
                print("NO")###
                sys.exit()
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
            else:
                print("NO")###
                sys.exit()
    print("YES")
except:
    pass

Measured memory_bytes: 40432
use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeMap;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let xn: Vec<i64> = (0..n).into_iter().map(|_| read()).collect();
    let mut ret = std::i64::MAX;
    for p in 1..101 {
        let mut s = 0;
        for &x in &xn {
            s += (p - x) * (p - x);
        }
        ret = std::cmp::min(ret, s);
    }
    println!("{}", ret);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h));
    int l = 0, r = 1e9;
    while((l + 1) < r) {
        ll m = (l + r) / 2;
        ll cnt = 0;
        ll mb = m * b;
        auto it = upper_bound(all(h), mb);
        reps(i, it - h.begin(), n) {
            cnt += ((h[i] - mb) + (a - b - 1)) / (a - b);
        }
        if (cnt <= m) r = m;
        else l = m;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#define MAX_N 20000
#define MAX_M 20000
using namespace std;

bool infected[MAX_N + 1];
int t[MAX_M], s[MAX_M], d[MAX_M];

int identify(int n, int m) {
  for (int i = 0; i < m; i++) {
    if (infected[s[i]] == true) infected[d[i]] = true;
  }

  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (infected[i] == true) count++;
  }
  return count;
}

void sort(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = i; j > 0; j--) {
      if (t[j - 1] > t[j]) {
	swap(t[j - 1], t[j]);
	swap(s[j - 1], s[j]);
	swap(d[j - 1], d[j]);
      }
    }
  }
}

void init() {
  for (int i = 0; i < MAX_N + 1; i++)
    infected[i] = false;
  for (int i = 0; i < MAX_M; i++) {
    t[i] = s[i] = d[i] = 0;
  } 
}

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return 0;

    init();
    for (int i = 0; i < m; i++)
      cin >> t[i] >> s[i] >> d[i];
    
    sort(m);
    infected[1] = true;
    int number = identify(n, m);
    cout << number << endl;
  }
}

Measured memory_bytes: 3304
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.server.UnicastRemoteObject;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        
        int r=sc.nextInt()-sc.nextInt();
        int c=sc.nextInt();

        
      
        out.println(max(0,c-r));
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x, y;
	P(int  x, int y) {
	  this.x=x;
	  this.y=y;
	}
}


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return b-p.b;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21332
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main()
{
    cin >> N;
    Pa prev = Pa(0, 0);
    int prev_t = 0;
    bool flag = true;
    rep(i, N){
        cin >> A >> B >> C;
        if(abs(prev.first - B) + abs(prev.second - C) > A - prev_t 
        || (abs(prev.first - B) + abs(prev.second - C)) % 2 != (A - prev_t)%2) flag = false;
        prev = Pa(B, C);
        prev_t = A;
    }
    cout << (flag ? "Yes" : "No");
}


Measured memory_bytes: 256
import math

N = int(input())

X = [0 for i in range(N)]
Y = [0 for i in range(N)]
for i in range(N):
    x,y = map(int, input().split())
    X[i] = x
    Y[i] = y

D = 0
for i in range(N):
    for j in range(N):
        if i < j:
            a = (X[i]-X[j])**2
            b = (Y[i]-Y[j])**2
            c = math.sqrt(a+b)
            D += c
print((2*D)/N)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		Arrays.sort(A);
		int count = 1;
		for(int i = 0; i < N - 1; i++) {
			if(A[i] != A[i + 1]) {
				count++;
			}
		}
		if(count % 2 == 0) {
			count--;
		}
		
		System.out.println(count);
		scan.close();

	}

}


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

int main() {
  int N, A;
  cin >> N >> A ;
  if (N <= A){
    cout << "Yes" << endl;
  }
  else if (N > A){
    if (N % 500 <= A){
      cout << "Yes"<< endl;
    }
    else if (N % 500 > A){
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const int MM = 2e5+2, MN = 40;

int n, m, ans;
ll dp[MN];

struct st{
    ll x, y;
} a[MM];

vector<ll> no;

int main(){
    for(int i = 1; i < MN; i++)
        dp[i] = 1e9+1;
    scan(n, m);
    for(int i = 1; i <= n; i++){
        scan(a[i].x, a[i].y);
        if(!a[i].x)
            no.push_back(a[i].y);
    }
    sort(no.begin(), no.end());
    sort(a+1, a+1+n, [](st a, st b){
        return b.x*(a.y+1) < a.x*(b.y+1);
    });
    
    for(int i = 1; i <= n; i++){
        if(!a[i].x) continue;
        for(int j = MN-1; j; j--){
            dp[j] = min(dp[j], (dp[j-1]+1)*(a[i].x+1)
            + a[i].y);
        }
    }
    for(int i = 0; i < MN; i++){
        ll rem = m-dp[i];
        int cnt = i;
        for(int j: no){
            j++;
            if(j <= rem){
                rem -= j;
                cnt++;
            }
        }
        if(rem >= 0){
            ans = max(ans, cnt);
        }
    }
    
    print(ans);
    
    return 0;
}
/*
[  first time      ] [second time                      ]
1 + a.x(t+1) + a.y + 1 + b.x(t+1 + a.x(t+1) + a.y+1) + b.y
a.x(t+1) + a.y + b.x(t+1) + b.x(a.x)(t+1) + b.x*a.y + b.x + b.y
b.x*a.y + b.x
b.x*a.y + b.x < a.x*b.y + a.x
b.x*(a.y+1) < a.x*(b.y+1)
 
 */

Measured memory_bytes: 5104
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define ld long double
#define F first
#define S second
int const M=2e5+10,mod=1e9+7,inf=1e9+10;
// chan satr ya stoon 
char aa[100][100];
bool bad[100][100];
int cnt1[M],cnt2[M];
int match[M];
int a[M],b[M],n,m;
bool check(int x,int y)
{
	for(int i=1;i<=n;i++)
	{
		if(aa[i][x]!=aa[match[i]][y])return 0;
	}
	return 1;
}
void bt(int ty,bool ro,int len)
{
	if(ty==1){
		for(int i=len;i>=1;i--)
		{
			if(bad[a[len]][a[i]])continue;
			if(i==len && ro==0 && n%2==1)
			{
				match[a[i]]=a[i];
				if(len==1)
				{
					bt(0,0,m);
				}
				else bt(1,1,len-1);
			}
			else if(i!=len)
			{
				match[a[i]]=a[len];
				match[a[len]]=a[i];
				swap(a[len-1],a[i]);
				if(len==2)bt(0,0,m);
				else bt(1,ro,len-2);
				swap(a[i],a[len-1]);
			}
		}	
	}
	else
	{
		for(int i=len;i>=1;i--)
		{
			if(!check(b[len],b[i]))continue;
			if(i==len && ro==0 && m%2==1)
			{
				if(len==1)
				{
					cout<<"YES";
					exit(0);
				}
				else
				{
					bt(0,1,len-1);
				}
			}
			else if(i!=len)
			{	
				swap(b[i],b[len-1]);
				if(len==2)
				{
				//	cout<<b[i]<<" "<<b[len]<<endl;
				//	cout<<match[1]<<endl;
					cout<<"YES";
					exit(0);
				}
				bt(0,ro,len-2);
				swap(b[i],b[len-1]);
			}
		}
	}
}
main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{	
		for(int j=1;j<=m;j++)
		{
			cin>>aa[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			for(int k=0;k<26;k++)cnt1[k]=0,cnt2[k]=0;
			for(int k=1;k<=m;k++)
			{
				cnt1[aa[i][k]-'a']++,cnt2[aa[j][k]-'a']++;
			}
			for(int k=0;k<26;k++)
			{
				if(cnt1[k]!=cnt2[k])bad[i][j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++)a[i]=i;
	for(int j=1;j<=m;j++)b[j]=j;
	bt(1,0,n);
	cout<<"NO";
}

Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10**7)
n=int(input())
if n==1:
    print(2)
    exit()
edge=[[] for _ in range(n)]
for _ in range(n-1):
    x,y=map(int,input().split())
    x-=1
    y-=1
    edge[x].append(y)
    edge[y].append(x)
dp=[[0]*2 for _ in range(n)]
mod=10**9+7
def dfs(s,prev):
    if edge[s]==[prev]:
        dp[s][0]=1
        dp[s][1]=1
        return
    w=1
    b=1
    for c in edge[s]:
        if c==prev:
            continue
        dfs(c,s)
        w=w*(dp[c][0]+dp[c][1])%mod
        b=b*dp[c][0]%mod
    dp[s][0]=w
    dp[s][1]=b
    return
dfs(0,-1)
print(sum(dp[0])%mod)

Measured memory_bytes: 113756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin >> n ;
	vector<ll>dp(3,0);// 3 activities
	for(int i=0;i<n;i++)
	{
	ll a[3];
			vector<ll>dpx(3,-1);
		cin >> a[0] >> a[1] >> a[2];
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				if(i!=j)
				{
					dpx[j] = max(dp[i] + a[j],dpx[j]);
				}
			}
		}
		dp = dpx;
//		cout << dpx[2] << endl;
	}
	sort(dp.begin(),dp.end());
	cout << dp[2] << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    string S;
    cin >> S;
    if(S[S.size()-1] == 's') cout << S << "es" << endl;
    else cout << S << "s" << endl;
}

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

using namespace std;
int main(){
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    long long ans=0;
    int last=0;
    for(auto i:a){
        if(i<last){
            ans+=last-i;
        }else last=i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3980
#include <stdio.h>
#include <algorithm>
int main(void){
    long long n,m;
    scanf("%lld%lld",&n,&m);
    long long p[m],y[m],x[m];
    for(int i=0;i<m;i++){
        scanf("%lld%lld",&p[i],&y[i]);
        x[i]=y[i]*100000+i;
    }
    std::sort(x,x+m);
    for(int i=0;i<m;i++){
        y[x[i]%100000]=i;
    }
    for(int i=0;i<m;i++){
        x[i]=p[i]*10000000000+y[i]*100000+i;
    }
    std::sort(x,x+m);
    int c=1;
    y[x[0]%100000]=((x[0]/10000000000)*1000000+c);
    for(int i=1;i<m;i++){
        if(x[i]/10000000000==x[i-1]/10000000000)c++;
        else c=1;
        y[x[i]%100000]=(x[i]/10000000000*1000000+c);
    }
    for(int i=0;i<m;i++){
        printf("%012lld\n",y[i]);
    }
}

Measured memory_bytes: 3712
#include<iostream>
#include<cmath>
using namespace std;
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    long long int N,X,M;
    cin>>N>>X>>M;
    long long int len=min(N,M+1);
    long long  int arr[len];
    long long int rem=X;
    for(long long int i=0;i<len;i++){
        arr[i]=rem;
        long int temp=rem;
        temp=temp*temp;
        rem=temp%M;
    }
    
    long long int total=0;
    if(len==N){
        for(long long int i=0;i<len;i++){
            total=total+arr[i];
        }
        cout<<total<<endl;
        return 0;
    }
    
    long long int index=-1;
    for(long long int i=0;i<len-1;i++){
        if(arr[i]==arr[len-1]){
            index=i;
            break;
        }
    }
    
    long long int prev=0;
    for(long long int i=0;i<index;i++){
        prev+=arr[i];
    }
    
    long long int interval=0;
    for(long long int i=index;i<len-1;i++){
        interval+=arr[i];
    }
    
    
    long long int ilen=(len-2)-index+1;
    N=N-index;
    total=total+prev;
    long long int cnt=N/ilen;
    total=total+interval*cnt;
    long long int rest=N%ilen;
    for(long long int i=index;i<index+rest;i++){
        total+=arr[i];
    }
    
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 4364
#include <bits/stdc++.h>
//#define rep(i,n) for (int i  = 0 ; i < n ; i++)
using namespace std ;
using ll = long long;
using p = pair <int , int >;
using V = vector <int> ;
using S = vector <string>;


int main (){
	string s ;
	cin >> s;
	if (s == "ABC"){
		cout << "ARC" << endl;

	}
	else if (s == "ARC"){
		cout << "ABC" << endl;
	}
	else{return 0;}
	return 0 ;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int A[100];
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A,A+N);
  cout<<A[N-1]-A[0]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ll ans=0;
    rep (i,1,n+1)
    {
        if (i%3!=0&&i%5!=0)
        {
            ans+=i;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3652
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut i: usize = 0;
    let mut v: Vec<usize> = Vec::new();

    while i < n {
        let a: usize = parse_line().unwrap();
        v.push(a);
        i = i + 1;
    }

    v.sort();
    i = 0;
    let mut res: usize = 0;

    while i < n {
        let cc: usize = v[i];
        let mut f: usize = 0;
        while i < n && v[i] == cc {
            f = f + 1;
            i = i + 1;
        }
        res = res + f % 2;
    }

    println!("{}", res);
}


Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var N int
	var x, sum float64
	var y string
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		fmt.Scan(&x, &y)
		if y == "JPY" {
			sum += x
		} else {
			sum += 380000.0 * x
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <cstdio>
using namespace std;

int main() {
	int H,W;
	while(1) {
		scanf("%d%d",&H,&W);
		if (H==0 && W==0) break;
		for(int j=0;j<H;++j) {
			for(int i=0;i<W;++i) {
				if(j==0 || i==0 || j==H-1 || i==W-1) {
					printf("#");
				} else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

const int mod = 1e9 + 7;

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

    int n;
    cin>>n;
    vector<ll> input(n);
    vector<ll> pref(n);

    for(int i = 0; i<n; i++){
        cin>>input[i];
        pref[i] = input[i];

        if(i != 0){
            pref[i] += pref[i-1];
            pref[i] %= mod;
        }
    }

    ll ans = 0;

    for(int i = 1; i<n; i++){
        ans += pref[i-1]*input[i];
        ans %= mod;
    }

    cout<<ans<<"\n";

    return 0;
}
///

Measured memory_bytes: 6352
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

ll c, d, e;

ll calc(ll a) {
    return (c == d ? a - a/c : a - a/c - a/d + a/e);
}

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

int main() {
    ll a = gli();
    ll b = gli();
    c = gli();
    d = gli();
    e = c*d/gcd(c, d);

    cout << calc(b) - calc(a-1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<(n);++i)
 
 
using namespace std;
 
int main(){
string S;
cin >>S;
rep(i,S.size()){
    if(i%2){
        if(S[i]!='L'&&S[i]!='U'&&S[i]!='D'){
            cout <<"No"<<endl;
            break;
        }
    }
    else{
	    if(S[i]!='R'&&S[i]!='U'&&S[i]!='D')
        {
		    cout <<"No"<<endl;
            break;
	    }
    }
    if(i==S.size()-1)cout <<"Yes"<<endl;
}
return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextIntArray(N);

        System.out.println( solve() );
    }

    static int solve() {
        // xor=0で順番が回ってくると負ける
        // 相手が先手なのでxor=0の状態を作れるかどうかになる
        int xor = 0;
        int eatableBits = 0;
        for (int a : A) {
            xor ^= a;
            eatableBits |= Integer.lowestOneBit(a);
        }
        
        int answer = 0;
        while(xor != 0) {
            int high = Integer.highestOneBit(xor);
            if( (high & eatableBits) != 0 ) {
                xor ^= high;
                xor ^= high-1;
                answer++;

            } else {
                return -1;
            }

        }
        return answer;
    }

    @SuppressWarnings("unused")
    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



Measured memory_bytes: 36384
#include<stdio.h>
#include<string.h>
int main(void){
    while(1){
		char record[200];
		int a=0;
		int b=0;
		int i=1;
		scanf("%s",record);
		if(strcmp(record,"0") == 0){
		    break;
		}
		while(record[i]!='\0'){
			if(record[i]=='A'){
			    a++;
			}else if(record[i]=='B'){
			    b++;
			}
			i++;
		}
		if(a<b){
		    b++;
		}else{
		    a++;
		}
		printf("%d %d\n",a,b);
    }
	return 0;
}


Measured memory_bytes: 2088
#include<stdio.h>

int main()
{
	char c;
	int sum1 = 0, sum2 =0;

	while(1) {
		c = getchar();
		if (c == '0') {
			sum1++;
		}
		else if (c == '1') {
			sum2++;
		}
		else {
			break;
		}

		c = getchar();
		if (c == '0') {
			sum2++;
		}
		else if (c == '1') {
			sum1++;
		}
		else {
			break;
		}
	}

	printf("%d", sum1 < sum2 ? sum1 : sum2);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();

		String num = br.readLine();

		for (int i = 0; i < Integer.parseInt(num); i++) {

			String[] oders = br.readLine().split(" ");

			switch (oders[0]) {
			case "replace":
				/* System.out.println(oders[0]); */
				str = replace(oders[1], oders[2], str, oders[3]);
				break;
			case "reverse":
				/* System.out.println(oders[0]); */
				str =reverse(oders[1], oders[2], str);
				break;

			case "print":
				/* System.out.println(oders[0]); */
				print(oders[1], oders[2], str);
				break;

			default:
				break;
			}
		}

	}

	public static String replace(String num1, String num2, String word, String replacestr) {
		StringBuilder builer = new StringBuilder();

		builer.append(word.substring(0, Integer.parseInt(num1)));
		builer.append(replacestr);
		builer.append(word.substring(Integer.parseInt(num2) + 1, word.length()));

		/* System.out.println(builer.toString());*/

		return builer.toString();
	}

	public static String reverse(String num1, String num2, String word) {
		StringBuilder builer = new StringBuilder();

		builer.append(word.substring(0, Integer.parseInt(num1)));
		for (int i = Integer.parseInt(num2); i >= Integer.parseInt(num1); i--) {
			builer.append(word.charAt(i));
		}
		builer.append(word.substring(Integer.parseInt(num2) + 1, word.length()));

	/*	 System.out.println(builer.toString());*/

		return builer.toString();
	}
	public static void print(String num1, String num2, String word) {
		StringBuilder builer = new StringBuilder();

		for (int i = Integer.parseInt(num1); i <= Integer.parseInt(num2); i++) {
			builer.append(word.charAt(i));
		}

		 System.out.println(builer.toString());


	}

}

Measured memory_bytes: 27476
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int a,b;

vi city[5];
vector<bool> already(5,false);
int res;

void dfs(int a){
    res++;
    for(auto e:city[a]){
        if(already[e]) continue;
        else{
            already[e]=true;
            dfs(e);
            break;
        }
    }
}

signed main(){

    rep(i,3){
        in(a,b);
        city[a].pb(b);
        city[b].pb(a);
    }
    already[1]=true;
    dfs(1);
    YN(res==4);

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<climits>
#include<algorithm>
#include<functional>
#include<iomanip>
#define LL long long
using namespace std;

int a,b;

int gcd(int x,int y){
    if(y==0) return x;
    return gcd(y,x%y);
}

int main(void){
    while(scanf("%d %d",&a,&b)!=EOF){
        int g=gcd(a,b);
        LL l=(LL)a*b/g;
        printf("%d %lld\n",g,l);
    }
    return 0;
}









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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// #define ll long long
// bool isEven(ll n) {return (n%2!=0)?false:true;}

using namespace std;

//atcoder - dp
//b

int a[100005], memo[100005];
int n, k;

int dp(int i);
int minK(int i, int k);

int main()
{
	std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

	cin>>n>>k;

	FOR0(i, n)
	{
    	cin>>a[i];
    	memo[i] = -1;
	}

	cout<<dp(0)<<endl;
}


int minK(int i, int k)
{
	int minimum = INT_MAX;

	for (int j = 1; j <= k; ++j)
	{
		minimum = min(minimum, abs(a[i]-a[i+j]) + dp(i+j));
	}

	return minimum;
}

int dp(int i)
{
	if(i==n-1)
		return 0;

	if(i>n-1)
		return INT_MAX;

	if(memo[i]!=-1)
		return memo[i];


	if(i<n-k)
	{
		memo[i] = minK(i, k);
	}
	else
	{
		memo[i] = minK(i, n-1-i);
	}	

	return memo[i];
}


Measured memory_bytes: 8832
#include <cstdio>
#include <algorithm>
int main() {
	static int N, T, t[200005];
	long long ans = 0;
	scanf("%d%d", &N, &T);
	for(int i = 1; i <= N; ++i) scanf("%d", t + i);
	ans = T;
	for(int i = N - 1; i; --i) ans += std::min(T, t[i + 1] - t[i]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<17;

vector <int> V[MAX];
int nim[MAX];
int ima[MAX];

int dfs(int node, int pr) {
  int ret = 0;
  for (auto it : V[node])
    if (it != pr) ret ^= 1 + dfs(it, node);
  return ret;
}

int main()
{
  int n;
  scanf("%d", &n);
  REP(i, n-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    V[a].push_back(b);
    V[b].push_back(a);
  }

  printf("%s\n", dfs(1, -1) ? "Alice" : "Bob");
  

  return 0;
}


Measured memory_bytes: 11136
//include<bits/stdc++.h>
#include<iostream>
#include<vector>

using namespace std; 

using ll = long long;

const int N = 1005, INF = 1000000005;

bool vis[N];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int x, n;   cin  >> x >> n;
    for(int i = 0; i < n; i++){
        int v;  cin >> v;
        vis[v] = 1;
    }
    int mini = INF, ans = 0;
    for(int i = 0; i <= N; i++){
        if(vis[i] == 0){
            int r = abs(i - x);
            if(r < mini){
                mini = r;
                ans = i;
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3192
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;
template <class T>
inline void read(T &x)
{
   x=0; char c=getchar(); int f=1;
   while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
   while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
map<int,int> mp;
int find(int x)
{
	for(int i=31;i>=0;i--)
	if((x>>i)&1) return (1ll<<i+1)-x;
	return 1;
}
int main()
{
	int x,n,ans=0; read(n);
	for(int i=1;i<=n;i++) read(x),mp[x]++;
	while(n)
	{
		int x=(--mp.end())->first;
		n--,mp[x]--; if(!mp[x]) mp.erase(mp.find(x));
		int y=find(x);
		if(mp.count(y))
		{
			ans++,n--,mp[y]--;
			if(!mp[y]) mp.erase(mp.find(y));
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 9600
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))

    val Array(n, m) = in.readLine().split("\\s+").map(_.toInt)
    val bulbsSwitchesWithCriteria = Array.fill(m) {
      in.readLine().split("\\s+").map(_.toInt - 1).tail
    }.zip {
      in.readLine().split("\\s+").map(_.toInt)
    }

    out.println(
      (0 until Math.pow(2, n).toInt).count { switchStatus =>
        bulbsSwitchesWithCriteria forall {
          case (bulbSwitches, criterion) =>
            bulbSwitches.count { bulbSwitch =>
              (switchStatus >> bulbSwitch & 1) == 1
            } % 2 == criterion
        }
      }
    )
    out.flush()
  }
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int A[200100], B[200100];

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

  std::cin >> N;

  for(int i=0;i<N;++i){
      std::cin >> A[i] >> B[i];
  }

  std::sort(A, A + N);
  std::sort(B, B + N);

  int l, r;
  
  if(N % 2 == 1){
      l = A[N/2];
      r = B[N/2];
  }else{
      l = A[N/2] + A[N/2-1];
      r = B[N/2] + B[N/2-1];
  }

  int res = r + 1 - l;
  std::cout << res << std::endl;
}


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

int main() {
	string s; cin >> s;
	int n = s.size();
	int a, z;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'A') {
			a = i;
			break;
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			z = i;
			break;
		}
	}
	cout << z - a + 1<< endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
 
using namespace std;
 
int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int i = 0; i <= 3000; i++)
    for (int j = 0; j <= 3000; j++) {
      int v = i * R + j * G;
      if (N >= v && (N - v) % B == 0) ans++;
    }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    ll N, C;
    cin >> N >> C;
    vector<ll> x(N + 2, 0), v(N + 1, 0);
    REP(i, N) cin >> x.at(i + 1) >> v.at(i + 1);
    x[N + 1] = C;

    vector<ll> clk(N + 1), cclk(N + 1);
    ll now = 0;
    FOR(i, 1, N + 1) {
        now += v[i] - (x[i] - x[i - 1]);
        clk[i] = max(now, clk[i - 1]);
    }
    now = 0;
    for (int i = N; i >= 1; i--) {
        now += v[i] - (x[i + 1] - x[i]);
        cclk[i - 1] = max(now, cclk[i]);
    }

    ll ans = 0;
    chmax(ans, cclk[0]);
    now = 0;
    for (int i = 1; i < N + 1; i++) {
        now += v[i] - (x[i] - x[i - 1]) * 2;
        chmax(ans, now + cclk[i]);
    }

    chmax(ans, clk[N]);
    now = 0;
    for (int i = N; i >= 1; i--) {
        now += v[i] - (x[i + 1] - x[i]) * 2;
        chmax(ans, now + clk[i - 1]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

main = do
  [m, d] <- getIntList
  print $ sum [1| i <- [1..m], j <- [1..d], check i j]

check m d
  | (i < 2) || (j < 2) = False
  | otherwise = i*j == m
  where
    (i, j) = divMod d 10

-- IO
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getIntVec :: Int -> IO (VU.Vector Int)
getIntVec n = VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine


Measured memory_bytes: 380
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    string S;
    cin >> S;

    ll entry = 0;
    ll overseas = 0;

    for (ll i = 0; i < N; i++)
    {
        bool ok = false;
        if (S[i] == 'a')
        {
            if (entry < A + B) {
                ok = true;
                entry += 1;
            }
        }
        else if (S[i] == 'b')
        {
            if (overseas < B && entry < A + B) {
                ok = true;
                entry += 1;
                overseas += 1;
            }
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
}

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

using namespace std;

int main() 
{ 
    int A,B;

  cin>>A;
   cin>>B;
  
   switch(A)
   {
     case 1:
            if(B==2)
             cout<<3;
            else
             cout<<2;
    break;

     case 2:
             if(B==3)
             cout<<1;
            else
             cout<<3;
    break;

     case 3:
             if(B==2)
             cout<<1;
            else
             cout<<2;
    break;
   }
return 0;
}

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

int main(){
	string n;
	cin >> n;
	if((n[0] == n[1] && n[1] == n[2])|| (n[1] == n[2] && n[2] == n[3])) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256