akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc136/tasks/abc136_d
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        s: chars
    };
    let n = s.len();

    let mut v = vec![0; n];
    let mut fr = 0;
    let mut to = 0;
    while fr < n {
        let mut to = fr;
        while to < n && s[to] == 'R' {
            to += 1;
        }
        let r = to-fr;
        while to < n && s[to] == 'L' {
            to += 1;
        }
        let l = to-fr-r;
        let lidx = fr+r-1;
        let ridx = fr+r;

        v[lidx] += (r+1)/2+l/2;
        v[ridx] += r/2+(l+1)/2;
        fr = to;
    }

    let line = v.into_iter().map(|num| num.to_string()).collect::<Vec<_>>().join(" ");
    println!("{}", line);
}


Measured memory_bytes: 10492
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		for(int i=0;i<n;i++){
			String str = new String();
			str = scan.next();
			char[] num = str.toCharArray();
			char[] max = new char[str.length()];
			char[] min = new char[str.length()];
			int index = 0;
			
			
			for(int j=57;j>=48;j--){
				for(int k=0;k<str.length();k++){
					if(num[k] == j){
						max[index] = num[k];
						index++;
					}
				}
			}
			
			index = 0;
			for(int j=48;j<=57;j++){
				for(int k=0;k<str.length();k++){
					if(num[k] == (char)j){
						min[index] = num[k];
						index++;
					}
				}
			}
			
			String maxStr = String.valueOf(max);
			String minStr = String.valueOf(min);
			int maxNum = Integer.parseInt(maxStr);
			int minNum = Integer.parseInt(minStr);
			
			System.out.println((maxNum-minNum));
		}
	}
}

Measured memory_bytes: 17176
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String A=gs();
	    String B=gs();
	    String C=gs();

	    int a=0;
	    int b=1;
	    int c=2;
	    int t=a;
	    int ai=0;
	    int bi=0;
	    int ci=0;
	    while(true) {
	        if (t==a) {
	        	t=A.charAt(ai) - 97;
	        	ai++;
	        }else if (t==b) {
	        	t=B.charAt(bi) - 97;
	        	bi++;
	        } else if (t==c) {
	        	t=C.charAt(ci)-97;
	        	ci++;
	        }
	        
	        if (t==a && ai==A.length()) {
	        	System.out.print("A");
	        	return;
	        }else if (t==b && bi==B.length()) {
	        	System.out.print("B");
	        	return;
	        }else if (t==c && ci==C.length()) {
	        	System.out.print("C");
	        	return;
	        }
	    }
//        if (a<=c&&c<=b) {
//        	System.out.print("Yes");
//        }else{
//        	System.out.print("No");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35412
n,m=map(int,input().split())
x=list(map(int,input().split()))
num=[]
if n>=m:
    ans=0
else:
    x.sort()
    for i in range(m-1):
        num.append(x[i+1]-x[i])
    num.sort()
    ans=sum(num[:m-n])
print(ans)


Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int ans;
  if (d.at(N/2-1) == d.at(N/2)){
    ans = 0;
  } else {
    ans = d.at(N/2) - d.at(N/2-1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }


int main(){
    ll a=ii(),b=ii(),c=ii(),k=ii();
    ll ret=0;
    oie(min(a,k)-max(0LL,min(c,k-a-b)));

    return 0;
}


Measured memory_bytes: 3632
if __name__ == "__main__":
  n = int(input())
  h = [int(x) for x in input().split()]

  dp = [10**10]*3
  dp[0] = 0
  for  i in range(1,n):
    dp[i%3] = 10**10
    for j in range(3):
      ind = (i-j+3)%3
      dp[i%3] = min(dp[i%3], dp[ind] + abs(h[i]-h[i-j]))
    #print(i, dp[i%3])

  print(dp[(n-1)%3])


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

int findSumOfDigits(int n) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int total = 0, digits_sum;
	for (int i = 1; i <= N; i++) {
		digits_sum = findSumOfDigits(i);
		if (A <= digits_sum && digits_sum <= B)
			total += i;
	}
	cout << total << endl;
}

Measured memory_bytes: 256
from itertools import product
n=int(input())
ans=[]
for i in range(3,10):
    l=list(product(["3","5","7"],repeat=i))
    for j in l:
        if len(set(j))==3:
            ans.append(int("".join(list(j))))

ans.sort()
m=len(ans)
l,r=0,m-1
while l+1<r:
    k=(l+r)//2
    if ans[k]<n:
        l=k
    elif ans[k]>n:
        r=k
    else:
        l,r=k,k
        break
if ans[l]==n:
    print(l+1)
elif ans[r]==n:
    print(r+1)
elif ans[l]>n:
    print(l)
elif ans[r]<n:
    print(r+1)
elif ans[l]<n:
    print(l+1)
#print(l,r)
#print(ans)


Measured memory_bytes: 7284
#include<iostream>
int main(){
  long long int X;
  std::cin>>X;
  for(long long int i=-200;i<200;i++){
    for(long long int j=-200;j<200;j++){
      if(i*i*i*i*i-j*j*j*j*j==X){
        std::cout<<i<<" "<<j<<std::endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include <cmath>

using namespace std;

void Circle()
{
    double x1, y1;
    double x2, y2;
    double x3, y3;
    double px, py, r;
    int n;
    
    cin>>n;
    
    while(n--)
    {
        cin>>x1>>y1>>x2>>y2>>x3>>y3;
        
        //AB: (y - y1) / (y2 - y1) = (x - x1) / (x2 - x1);
        //BC:  (y - y2) / (y3 - y2) = (x - x2) / (x3 - x2);
        px = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) - (y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) / (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
        
        py = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) - (x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) / (2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3));
        
        r = sqrt((x1 - px) * (x1 - px) + (y1 - py) * (y1 - py));
        
        cout.setf(ios::fixed);
        cout.precision(3);
        
        cout<<px<<" "<<py<<" "<<r<<endl;
    }
    
    return;
}

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

Measured memory_bytes: 1296
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		char c[] = s.toCharArray();
		for (int i = 0; i < 19; i++) {
			if (i != 5 && i != 13) {
				System.out.print(c[i]);
			} else {
				System.out.print(" ");
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



int main(){
    ll n,m,a[101010],sum=0;
    string s;
   cin>>n>>m;
   rep(i,m){cin>>a[i];sum+=a[i];}
   if(n>=sum)cout<<n-sum;
   else cout<<-1;
   cout<<endl;
}


Measured memory_bytes: 3704
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

int solve() {
	ll n, m, k;
	cin >> n >> m >> k;

	vector<ll> as(n);
	for (ll i = 0; i < n; ++i) {
		cin >> as[i];
	}
	vector<ll> bs(m);
	for (ll i = 0; i < m; ++i) {
		cin >> bs[i];
	}
	vector<ll> accum_as(n + 1);
	for (ll i = 0; i < n; ++i) {
		accum_as[i + 1] = accum_as[i] + as[i];
	}
	vector<ll> accum_bs(m + 1);
	for (ll i = 0; i < m; ++i) {
		accum_bs[i + 1] = accum_bs[i] + bs[i];
	}

	ll res = 0;
	ll j = m;
	for (ll i = 0; i <= n; ++i) {
		while (j > 0 && accum_as[i] + accum_bs[j] > k) {
			--j;
		}
		if (accum_as[i] + accum_bs[j] <= k) {
			res = max(res, i + j);
		}
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


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

int main(void){
    int n,k;
    cin >> n >> k;
    vector<int> vec(n);
    rep(i,n) cin >> vec.at(i);
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    int max=0;
    for(int i=0;i<k;i++){
        max += vec.at(i);
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<limits.h>
#include<queue>
#include<string>
using namespace std;

int pop_and_print(priority_queue<int>& qu)
{
	cout << qu.top() << endl;  
	qu.pop();
	return 0;
}

int main(){
	string s;
	int inp;
	priority_queue<int> qu;
	while(1){
		cin >> s;
		if (s=="end"){
			break;
		}else if(s=="insert"){
			cin >> inp;
			qu.push(inp);
		}else{
			pop_and_print(qu);
		}
	}
	
	return 0;
}

Measured memory_bytes: 7036
_ = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

counter = 0
for i in range(len(b)):
    counter += min(a[i],b[i])
    if b[i] - a[i] >= 0:
        c = b[i]-a[i]
        if a[i + 1] - c >= 0:
            a[i + 1] -= c
            counter += c
        else:
            counter += a[i + 1]
            a[i + 1] = 0

print(counter)


Measured memory_bytes: 18476
#include <iostream>

int main() {
  int r;
  std::cin >> r;
  if (r < 1200) {
    std::cout << "ABC";
  } else if (r < 2800) {
    std::cout << "ARC";
  } else {
    std::cout << "AGC";
  }
  std::cout << std::endl;
}

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

int main() {
    string s;
    int q;
    cin >> s >> q;
    int rev = 0;
    string front = "", back = "";
    for (int i=0; i<q; i++) {
        int query;
        cin >> query;
        if (query == 1) rev = 1 - rev;
        else {
            int f;
            string c;
            cin >> f >> c;
            f--;
            if (rev == f) {
                front = c + front;
            } else {
                back = back + c;
            }
        }
    }
    if (rev) {
        if (s.size() >= 2) {
            reverse(s.begin(), s.end());
        }
        if (front.size() >= 2) {
            reverse(front.begin(), front.end());
        }
        if (back.size() >= 2) {
            reverse(back.begin(), back.end());
        }
        cout << back << s << front << endl;
    }
    else cout << front << s << back << endl;
}

Measured memory_bytes: 1160
import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.System.*;
public class Main
{
public static void main (String args[]) throws Exception
{
	Scanner sc=new Scanner(in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
	arr[i]=sc.nextInt();
	}
	Arrays.sort(arr);
	long sum=0;
	int count=0;
	for(int i=n-1;i>=0;i--)
	{
		if(count==k) break;
		sum=sum+arr[i];
		count++;
	}
	out.println(sum);
}
}


class Berland
{
char ch;
int pos;
public Berland(int a,char b)
{
ch=b;
pos=a;
}
}
class ChComparator implements Comparator<Berland>
{
public int compare(Berland f1,Berland f2)
{
if(f1.ch==f2.ch)
return 0;
if(f1.ch<f2.ch)
return -1;
return 1;
}
}


Measured memory_bytes: 21844
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>

namespace AtCoder {
	using Input = std::vector<std::string>;
	using Num = std::vector<int>;

	Input input(void) {
		Input result;
		{
			std::string buf = "", row = "";
			std::getline(std::cin, buf);
			for (unsigned int i = 0; i < buf.size(); i++) {
				if (' ' == buf[i]) {
					result.push_back(row);
					row = "";
				} else {
					row += buf[i];
				}
			}
			result.push_back(row);
		}
		return result;
	}

	Num replaceToInteger(Input original = { "" }) {
		Num result;
		for (unsigned int i = 0; i < original.size(); i++) {
			result.push_back(atoi(original[i].c_str()));
		}
		return result;
	}
}

int main(void) {

	AtCoder::Num s = AtCoder::replaceToInteger(AtCoder::input());

	int a = 0, b = 0;

	a = s[0];
	b = s[1];

	if (a >= 13) {
		printf("%d\n", b);
	} else if (a >= 6) {
		printf("%d\n", (b / 2));
	}else{
    	printf("0\n");
    }

	return 0;
}

Measured memory_bytes: 888
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, H = LI()
    a = []
    b = []
    for _ in range(N):
        ab = LI()
        a.append(ab[0])
        b.append(ab[1])
    b.sort(reverse=True)
    a_max = max(a)

    # amax以上のbを強い順に投げていく
    # その後amaxを連打 amaxを持つ刀を先に投げていても、後に投げたことにすればよい
    ans = 0
    i = 0
    while i < N and H > 0 and b[i] > a_max:
        H -= b[i]
        i += 1
        ans += 1

    if 0 < H:
        ans += (H - 1) // a_max + 1

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 18120
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int N, M;
vector<vector<int>> T;
int cnt = 0;
vector<bool> visited;

void dfs(int s){
    visited[s] = true;
    for(int i=0; i<(int)T[s].size(); i++){
        if(!visited[T[s][i]]) dfs(T[s][i]);
    }
    
    bool ok = true;
    for(int i=0; i<N; i++){
        if(!visited[i]) ok = false;
    }
    if(ok) cnt++;
    visited[s] = false;
    return;
}




int main() {
    cin >> N >> M;
    visited.resize(N);
    T.resize(N);
    for(int i=0; i<M; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    
    dfs(0);
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a,b, c;
    cin >> a>>b>>c;

    int ans = c-(a-b);

    if (ans<0) ans=0;

    cout << ans << endl;

   return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<string> s(N);
    vector<int> a(3, 0);
    for(int i = 0;i < N;i++)    cin >> s[i];
    int ans = 0;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < s[i].size()-1;j++){
            if(s[i][j] == 'A' && s[i][j+1] == 'B')  ans++;
        }
        if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A')    a[0]++;
        else if(s[i][0] == 'B') a[1]++;
        else if(s[i][s[i].size()-1] == 'A') a[2]++;
    }
    ans += max(a[0]-1, 0);
    if(a[1] > 0 && a[0] > 0){
        ans++;
        a[1]--;
    }
    if(a[2] > 0 && a[0] > 0){
        ans++;
        a[2]--;
    }
    ans += min(a[1], a[2]);
    cout << ans << endl;
    // cout << a[0] << a[1] << a[2] << endl;
}

Measured memory_bytes: 768
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <stdio.h>
int main()
{   int a[101],sum=0,n,k,m,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    double avg=((double)sum/(double)n);
    double min=1000;
    for(i=0;i<n;i++){
        if(fabs(avg-a[i])<min){
            min=fabs(avg-a[i]);
            k=i;
        }
    }
    printf("%d",k);

    return 0;
}


Measured memory_bytes: 128
import itertools

n=int(input())

lis=[]
for i in range(n):
    ai=int(input())
    lisi=[]
    for _ in range(ai):
        xi,yi=map(int,input().split())
        lisi.append([xi-1,yi])
    lis.append(lisi)


ans=-1
for binary in itertools.product([1,0],repeat=n):
    check=0
    for i in range(n):
        if binary[i]==1:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]!=lis[i][j][1]:
                    check+=1
    if check==0:
        ans=max(ans,sum(binary))

print(ans)
    

Measured memory_bytes: 9200
n, m = [int(i) for i in input().split(" ")]
k = [[int(i) for i in input().split(" ")] for j in range(n)]

for i in range(n):
  k[i] = k[i][1:]

ary = [1] * m
for i in range(n):
  for j in range(m):
    if(not j+1 in k[i]):
      ary[j] = 0
print(sum(ary))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;cin>>s;
	string ans = "";
	for(int i = 0; i < s.size(); i++) {
		if (s[i] == '0'){
			ans.pb('0');
		}
		else if(s[i] == '1'){
			ans.pb('1');
		}
		else if(ans != ""){
			ans.erase(ans.end() - 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;
    if(((A==1)&&(B==2))||((A==2)&&(B==1)))
    cout<<"3";
    else if(((A==1)&&(B==3))||((A==3)&&(B==1)))
        cout<<"2";
    else if(((A==2)&&(B==3))||((A==3)&&(B==2)))
        cout<<"1";
    return 0;
}

Measured memory_bytes: 256
//aoj http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_A
// 全て正の数列　a1,..,an が与えられるので、この数列からいくつかとって総和がAにできるかどうかを判定せよ。

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int a[50];

int main()
{
    int n, q;
    cin >> n;
    rep(i, n) cin >> a[i];

    cin >> q;

    rep(i, q)
    {
        int A;
        cin >> A;
        bool dp[n + 1][A + 1]; //dp[i+1][j] i番目まで使ってjをつくれるかどうか

        rep(j, A + 1) dp[0][j] = 0;
        dp[0][0] = 1;
        rep(i, n)
        {
            rep(j, A + 1)
            {
                if (j - a[i] >= 0)
                    dp[i + 1][j] = (dp[i][j - a[i]] || dp[i][j]);
                else
                    dp[i + 1][j] = dp[i][j];
            }
        }

        dp[n][A] == 1 ? OP("yes") : OP("no");
    }
    return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>
int n, x;
char s[100];
int main() {
	scanf("%d", &n);
	scanf(" %s", s);
	for (int i = 0; i < n - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')x++;
	}
	printf("%d\n", x);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL k;
    cin >> k;
    LL res=0;
    LL ans=0;
    LL idx=1;
    vector<LL> num_list(k,0);
    while(true){
        ans++;
        res=res*10;
        res=res%k;
        num_list[res]++;
        if(num_list[res]>=2){
            ans=-1;
            break;
        }
        res=(res+7)%k;
        if(res==0){
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11152
n,k = map(int, input().split())

snacks = []
for i in range(k):
    d = int(input())
    snack = list(map(int, input().split()))
    ssnack = []
    for j in range(d):
        ssnack.append(snack[j]-1)
    snacks.append(ssnack)

marks = [1 for i in range(n)] # お菓子を持っていなければ1
for i in snacks:
    for j in i:
        marks[j] = 0


print(str(sum(marks)))

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

struct Node{
    int key;
    Node *prev, *next;
};

Node *nil;

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    //番兵の直後に要素を追加
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    //検索したノードを削除
    deleteNode(listSearch(key));
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(true){
        if (cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main(){
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();

    for (i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i'){insert(key); np++; size++; }
        else if (com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            }
            else{
                deleteKey(key); nd++;
            }
            size--;
        }
    }

    printList();

    return 0;
}


Measured memory_bytes: 34340
/*
AOJ 2322
title;Chinese Classics
@kankichi573
*/
#include <stdio.h>
#include <string.h>

int N;
char kanbun[10000][21];
char already[10000];
int  jump_to[10000];
int  jump_from[10000];

void read_all()
{
  int lp,jp,jf;

  lp=0;jf=0;
  while(lp<N)
    {
      //printf("%d [%d ][ %d]\n",lp,jump_from[lp],jump_to[lp]);
      if(already[lp]==0)
	{
	  if(jump_from[lp]==-1 || jf==1)
	    {
	      printf("%d\n",lp+1);
	      already[lp]=1;
	      //printf("lp =%d => 1\n",lp);
	      jf=0;
	      if(-1 != jump_to[lp])
		{
		  lp = jump_to[lp];
		  jf=1;
		  //printf("jmp to %d:",lp+1);
		  //printf("al %d\n",already[jp]);
		  continue;
		}
	    }
	}
      lp++;
    }
}

int is_reten(int lno)
{
  char d1[20],d2[20];
  int n1;

  if((0==strcmp(&kanbun[lno][0],"v")) || 
     (3==sscanf(&kanbun[lno][0],"%[a-z]%d%[v]",d1,&n1,d2)))
    return(1);
  else
    return(0);
}

int jump_no(int lno)
{
  char d1[20];
  int n1;

  if(2==sscanf(&kanbun[lno][0],"%[a-z]%d",d1,&n1))
    return(n1);
  else
    return(0);
}


int jump_next(int lno)
{
  char d1[21],buf[21],buf1[21],buf2[21];
  int i,n1,ret,buflen;


  sscanf(&kanbun[lno][0],"%[a-z]%d",d1,&n1);
  sprintf(buf,"%s%d",d1,n1+1);
  sprintf(buf1,"%s%d",d1,1);

  for(i=lno-1;i>=0;i--)
    if(0==strcmp(buf,&kanbun[i][0]))
      return(i);
    

  return(-1);
}


solve_address()
{
  int i,next;

  for(i=0;i<N;i++)
    {
      if(is_reten(i))
	{
	  jump_from[i]=i+1;
	  jump_to[i+1]=i;
	}
      if(jump_no(i)>0)
	if((next=jump_next(i)) > -1 && jump_to[i]== -1)
	  {
	    jump_to[i]=next;
	    jump_from[next]=i;
	  }
    }
}

dump()
{
  int i;
  for(i=0;i<N;i++)
    printf("%d [%d->] [->%d]\n",i,jump_from[i],jump_to[i]);

}



int main()
{

  int i;
  

  while(scanf("%d",&N) && N)
    {
      memset(kanbun,0,sizeof(kanbun));
      memset(already,0,sizeof(already));
      memset(jump_from,-1,sizeof(jump_from));
      memset(jump_to,-1,sizeof(jump_to  ));

      for(i=0;i<N;i++)
	scanf("%s",&kanbun[i][0]);

      solve_address();
      
      //dump();
      read_all();
    }
  return 0;
}

Measured memory_bytes: 932
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 16
#define PAT_MAX (1<<16)

struct affinity{
    int pat;
    int64_t point;
};

int desc_by_point(const void *a1, const void *a2) {
    struct affinity *af1 = (struct affinity*)a1;
    struct affinity *af2 = (struct affinity*)a2;
    if(af1->point < af2->point) {
        return 1;
    } else if (af1->point == af2->point) return 0;
    return -1;
}

int main(void) {
    int num = get_int();
    static int rels[NUM_MAX][NUM_MAX];
    int i, j;
    for(i = 0; i < num; i++) {
        fget_array(rels[i], num);
    }
    static int64_t points[PAT_MAX];
    int pat, bit;
    for(pat = 1; pat < (1<<num); pat++) {
        int labels[NUM_MAX] = {0};
        int idx = 0;
        for(bit = 0; bit < num; bit++) {
            if(!(pat & (1<<bit))) continue;
            labels[idx++] = bit;
        }
        int64_t res = 0;
        for(i = 0; i < idx; i++) {
            for(j = i+1; j < idx; j++) {
                res += rels[labels[i]][labels[j]];
            }
        }
        points[pat] = res;
    }

    static int64_t ans[PAT_MAX];
    for(pat = 1; pat < (1<<num); pat++) {
        int pat2;
        for(pat2 = pat; pat2 > 0; pat2 = (pat2-1)&pat) {
            ans[pat] = max(ans[pat-pat2] + points[pat2], ans[pat]);
        }
    }
    printf("%lld\n", ans[(1<<num)-1]);
    return 0;
}

Measured memory_bytes: 1152
def f(A, B):
    if B % 2 == 1:
        B_kisuu = B
    else:
        B_kisuu = B - 1

    if A % 2 == 0:
        if (B_kisuu - A - 1) % 4 == 0:
            ans = 1
        else:
            ans = 0
    else:
        if (B_kisuu - A) % 4 == 0:
            ans = A
        else:
            ans = A - 1

    if B % 2 == 0:
        ans = ans ^ B

    return ans


A, B = map(int, input().split())
print(f(A, B))


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

int main()
{
  set<string> s;
  string last,curr;
  bool valid = true;
  int n;
  cin>>n;
  cin>>last;
  s.insert(last);
  n--;
  while(n--)
  {
    cin>>curr;
    if(s.find(curr) != s.end())
      valid=false;
    int len = last.length();
    if(curr[0] != last[len-1])
      valid = false;
    s.insert(curr);
    last = curr;
  }
  if(valid)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        boolean res = true;
        int indexC = 0;

        if (s.charAt(0) != 'A') {
            res = false;
            System.out.println("WA");
            return;
        }

        boolean hasC = false;
        for (int i = 2; i <= s.length() - 2; i++) {
            if (s.charAt(i) == 'C') {
                hasC = true;
                indexC = i;
                break;
            }
        }

        res = hasC ? true : false;
        if (!res) {
            System.out.println("WA");
            return;
        }

        for (int i = 0; i < s.length(); i++) {
            if (i == 0 || i == indexC) continue;

            if (!Character.isLowerCase(s.charAt(i))) {
                res = false;
                break;
            }
        }

        System.out.println(res ? "AC" : "WA");
    }
}


Measured memory_bytes: 21716
// 2016-12-04
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int n;
	int a[1000];
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		int m = 1000000;
		for (int i = 1; i < n; i++) {
			m = min(m, a[i] - a[i - 1]);
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;

mint dp[101][5000];
//mx = 3281
int main(){
	// int can = 0;
	// int N = 100;
	// int a[100];
	// for(int i=N;i>=1;i--){
	// 	a[i] = i;
	// 	if(a[i]>i) continue;
	// 	a[i] += can;
	// 	can += a[i]/i;
	// }
	// show(can);

	int N,K;
	cin>>N>>K;

	dp[N][0] = 1;
	for(int i=N;i>=1;i--){
		rep(can,5000) if(dp[i][can]){
			rep(v,K+1){
				int ni = i-1;
				int ncan = can;
				if(v<=i){
					ncan += (v+can)/i;
				}
				dp[ni][ncan] += dp[i][can];
			}
		}
	}
	mint al = 1;
	rep(i,N) al *= K+1;
	al *= N;
	al *= K;
	al /= 2;

	mint ans = al;
	rep(can,5000) ans -= dp[0][can]*can;
	cout<<ans<<endl;
}


Measured memory_bytes: 2176
using System;
 
namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            //a = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            a = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            b = int.Parse(str[1]);
            c = int.Parse(str[2]); 
            
            int buf = c;
            for(int i = 0; i< 10; i++)
            {
                Console.WriteLine((buf * a) - b);
                buf = (buf * a) - b;
            }
        }
    }
}

Measured memory_bytes: 11092
use std::str::FromStr;
use std::io::stdin;

fn main() {
    let n: usize = read();
    let vec: Vec<i64> = read_vec();
    let mut min: i64 = std::i64::MAX;
    for i in 0..101 {
        let mut sum = 0;
        for j in 0..n {
            sum += (i - vec[j]).pow(2);
        }
        min = std::cmp::min(min, sum);
    }
    println!("{}", min);
}

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

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

Measured memory_bytes: 4352
//
// Created by 加藤英祐 on 2020/04/14.
//
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    vector<int>a(M);

    int homeworkDays = 0;
    for (int i = 0; i < M; ++i) {
        cin >> a.at(i);
        homeworkDays += a.at(i);
    }
    if(homeworkDays <= N){
        cout << N-homeworkDays;
    } else{
        cout << -1;
    }

    return 0;
}

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

ans = [0]*n
for i in range(n):
    if i%2 == 0:
        ans[i//2] = str(a[-i-1])
    else:
        ans[n-1-i//2] = str(a[-i-1])
print(' '.join(ans))


Measured memory_bytes: 31940
while True :
    d1 = input()
    
    if d1 == "0" :
        break
    else :
        d2 = input()
        d3 = input()
        
        d1A = d1[1 : len(d1)].count("A")
        d1B = len(d1) - d1A - 1
        if d2[0] == "A" :
            d1A += 1
        else :
            d1B += 1
            
        d2A = d2[1 : len(d2)].count("A")
        d2B = len(d2) - d2A - 1
        if d3[0] == "A" :
            d2A += 1
        else :
            d2B += 1
            
        d3A = d3[1 : len(d3)].count("A")
        d3B = len(d3) - d3A - 1
        if d3A >= 10 and d3B >= 10 :
            if d3A > d3B :
                d3A += 1
            else :
                d3B += 1
        else :
            if d3A > d3B :
                d3A += 1
            else :
                d3B += 1
        
        print(d1A, d1B)
        print(d2A, d2B)
        print(d3A, d3B)
        
        


Measured memory_bytes: 5560
N, M = map(int, input().split())
A = []
for i in range(M):
  a, b = map(int, input().split())
  A.append([a - 1, b - 1])
A = sorted(A, key=lambda a: a[0])
cut = 1
b_min = N
for a in A:
  if a[0] >= b_min:
    cut += 1
    b_min = N
  b_min = min(b_min, a[1])
print(cut)

Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sim template < class c
#define ris return *this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", ", d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; it++)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	vector<bool> dp(K + 1, false);
	for (int i = 1; i <= K; i++) {
		for (int j = 0; j < N; j++) {
			int val = i - a[j];
			if (val < 0) {
				break;
			}
			if (!dp[val]) {
				dp[i] = true;
			}
		}
	}
	if (dp[K]) {
		cout << "First";
	} else {
		cout << "Second";
	}
	
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[100050];
int a[150][2];
int main(){
    int n,w;
    cin>>n>>w;
    for(int i=0;i<n;i++)cin>>a[i][0]>>a[i][1];
    for(int i=0;i<n;i++){
        for(int j=w-a[i][0];j>=0;j--){
            int k=j+a[i][0];
            dp[k]=max(dp[k],dp[j]+1LL*a[i][1]);
        }
    }

    
    cout<<dp[w];
    
    return 0;
}

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

using namespace std;

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

int main() {
    int N;
    cin >> N;
    vector<string> ss(N);
    rep(i, N){
        cin >> ss.at(i);
    }
    int M;
    cin >> M;
    vector<string> ts(M);
    rep(i, M){
        cin >> ts.at(i);
    }
    map<string, int> values;
    for(string s : ss){
        values[s]++;
    }
    for(string t : ts){
        values[t]--;
    }
    int ans = 0;
    for(auto value : values){
        ans = max(ans, value.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

struct union_find{
	vector<int> par;
	union_find(int _n) : par(_n + 1, -1) {}
	bool same_set(int a, int b){ return find(a) == find(b); }
	int size(int x) { return -par[find(x)]; }
	int find(int x){
		return par[x] < 0 ? x : par[x] = find(par[x]);
	}
	void unite(int a, int b){
		a = find(a), b = find(b);
		if(a == b) return;
		if(par[a] > par[b]) swap(a, b);
		par[a] += par[b], par[b] = a;
	}
};

int n, k, l;
vector<pair<int, int>> edg;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k >> l;
	union_find roads(n), rails(n);
	for(int i = 0; i < k; i++){
		int a, b;
		cin >> a >> b;
		roads.unite(a, b);
		if(a > b) swap(a, b);
		edg.push_back({a, b});
	}
	for(int i = 0; i < l; i++){
		int a, b;
		cin >> a >> b;
		rails.unite(a, b);
		if(a > b) swap(a, b);
		edg.push_back({a, b});
	}
	map<pair<int, int>, int> mp;
	for(int i = 1; i <= n; i++) mp[{roads.find(i), rails.find(i)}]++;
	for(int i = 1; i <= n; i++) cout << mp[{roads.find(i), rails.find(i)}] << ((i == n) ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 15088
import math

D,G = map(int,input().split())
P = []
C = []
for _ in range(D):
    p,c = map(int,input().split())
    P.append(p)
    C.append(c)

ans = sum(P)
for i in range(2**D - 1):
    inSolve = -1
    score_tmp = 0
    solved = 0
    for j in range(D):
        if (i>>j)%2 == 1:
            score_tmp += (j+1)*100*P[j]+C[j]
            solved += P[j]
        else:
            inSolve = max(j,inSolve)
    if score_tmp < G and inSolve != -1:
        if math.ceil((G-score_tmp)/((inSolve+1)*100)) <= P[inSolve]:
            ans = min(ans,solved + math.ceil((G-score_tmp)/((inSolve+1)*100)))
    elif score_tmp >= G:
        ans = min(ans,solved)
print(ans)

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; 

int main()
{
	int a,b,c,k;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	int t=max(a,max(b,c));
	for(int i=1;i<=k;i++)
	t=t*2;
	if(a>=c&&a>=b) printf("%d",t+b+c);
	else if(b>=c&&b>=a) printf("%d",a+t+c);
	else if(c>=a&&c>=b) printf("%d",a+b+t);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int X=sc.nextInt();
		int Y=sc.nextInt();
		int Z=sc.nextInt();
		int K=sc.nextInt();

		ArrayList<Long> A = new ArrayList<>();
		ArrayList<Long> B = new ArrayList<>();
		ArrayList<Long> C = new ArrayList<>();

		for(int i=0; i<X; i++) A.add(sc.nextLong());
		for(int i=0; i<Y; i++) B.add(sc.nextLong());
		for(int i=0; i<Z; i++) C.add(sc.nextLong());

		Collections.sort(A, Collections.reverseOrder());
		Collections.sort(B, Collections.reverseOrder());
		Collections.sort(C, Collections.reverseOrder());

		ArrayList<Long> ABC = new ArrayList<>();
		for(int i=0; i<X; i++) {
			for(int j=0; j<Y; j++) {
				if((i+1)*(j+1)>K) break;
				for(int k=0; k<Z; k++) {
					if((i+1) * (j+1) * (k+1) > K) break;
					ABC.add(A.get(i)+B.get(j)+C.get(k));
				}
			}
		}
		Collections.sort(ABC, Collections.reverseOrder());

		for(int i=0; i<K; i++) {
			System.out.println(ABC.get(i));
		}

		sc.close();
	}

}


Measured memory_bytes: 35232
import java.util.*;

public class Main {

    static long[] bit;
    static int n;
    static void add(int x, int y) {
        for (int i=x;i<=n;i+=i&(-i)) {
            bit[i]+=y;
        }
    }

    static long sum(int x) {
        long tmp = 0L;
        for (int i=x;i>0;i-=i&(-i)) {
            tmp+=bit[i];
        }
        return tmp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        bit = new long[n+1];
        int[] a = new int[n];
        TreeSet<Integer> set = new TreeSet<Integer>();
        for (int i=0;i<n;i++) {
            a[i] = sc.nextInt();
            set.add(a[i]);
        }
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        for (int i=0;i<n;i++) {
            a[i] = Collections.binarySearch(list, a[i])+1;
        }
        long ans = 0L;
        for (int i=0;i<n;i++) {
            add(a[i], 1);
            ans+=sum(n)-sum(a[i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 117944
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

string s;



int main(){
	cin>>s;
	char t=s[0];
	int k=0;
	int cnt=-1;
	Rep(i,100000){
		if(k>=s.size()) break;
		t=s[k];
	while(t==s[k]){
		k++;
	}
	cnt++;
	}
	cout<<cnt<<endl;
	

	return 0;
}

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

#define MAX (2000000)
#define INFTY (1<<30)

int H;
int A[MAX + 1];

int parent(int i) { return i / 2; }
int left(int i) { return i * 2; }
int right(int i) { return i * 2 + 1; }

void maxHeapify(int A[], int i)
{
	int l = left(i);
	int r = right(i);
	int largest;
	// 左の子、自分、右の子で最大を選ぶ
	if (l <= H && A[l] > A[i])
		largest = l;
	else
		largest = i;
	if (r <= H && A[r] > A[largest])
		largest = r;

	if (largest != i)
	{
		swap(A[i], A[largest]);
		maxHeapify(A, largest);
	}
}

void buildMaxHeap(int A[])
{
	for (int i = H / 2; i > 0; i--)
		maxHeapify(A, i);
}

int heapExtractMax(int A[])
{
	if (H < 1)
		return -INFTY;
	int max = A[1];
	A[1] = A[H];
	H--;
	maxHeapify(A, 1);

	return max;
}

void heapIncreaseKey(int A[], int i, int key)
{
	if (key < A[i])
		return;
	A[i] = key;
	while (i > 1 && A[parent(i)] < A[i])
	{
		swap(A[i], A[parent(i)]);
		i = parent(i);
	}
}

void insert(int key)
{
	H++;
	A[H] = -INFTY;
	heapIncreaseKey(A, H, key);
}



int main()
{
	int key;
	string com;

	while (1)
	{
		cin >> com;
		if (com == "end") break;
		if (com == "insert")
		{
			cin >> key;
			insert(key);
		}
		else
			cout << heapExtractMax(A) << endl;
	}

	return 0;
}


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

int main()
{
    int n;
    cin>>n;
    ll a;
    cin>>a;
    ll res = 0, h = a;
    for (int i=1; i<n; i++) {
        cin>>a;
        if (a > h) h = a;
        else res += (h - a);
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 3588