akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		int num = r * 100 + g * 10 + b;
		if (num % 4 == 0){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23764
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    n = int(input())

    ans = 0
    root = int(n**0.5)

    for i in range(1,root+1):
        if n%i == 0:
            ans += (n/i-1)

    if root*(root+1) == n:
        ans -= root
    if root**2 == n:
        ans -= (root-1)
    print(int(ans))


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

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

    if(x < 600){
        cout << "8" << endl;
    }else if(x < 800){
        cout << "7" << endl;

    }else if(x < 1000){
        cout << "6" << endl;
    }else if(x < 1200){
        cout << "5" << endl;
    }else if(x < 1400){
        cout << 4 << endl;
    }else if(x < 1600){
        cout << 3 << endl;
    }else if(x < 1800){
        cout << 2 << endl;
    }else if(x < 2000){
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
int n,a[1010111],sum,ans,r=1;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int l=1;l<=n;)
	{
		while(r<=n&&((sum^a[r])==(sum+a[r])))
			sum^=a[r++];
		ans+=r-l;
		sum^=a[l++];
	}
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

int numbers[200001];

int main(int argc, char *argv[]) {
	int N, K;
	cin >> N >> K;

	int k = 0;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		if (numbers[n] == 0) k++;
		numbers[n]++;
	}

	sort(begin(numbers), end(numbers));

	int ans = 0;
	for (int i = 0; i < 200001 && K < k; i++) {
		if (numbers[i] > 0) {
			ans += numbers[i];
			k--;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>



int main(){

  int m[101][101],i,j,u,k,n,x;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      m[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&x);
      m[i][x]=1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j!=1){
	printf(" ");
      }
      printf("%d",m[i][j]);
    }
    printf("\n");
  }
  return 0;
}
    
    



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 30005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll fl[N];
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
		fl[ar[i]]++;
	}

	ll ans=0;
	for(i=1;i<=n;i++){
		fl[ar[i]]--;
		for(j=i+1;j<=n;j++){
			fl[ar[j]]--;
			ll a,b;
			a=max(ar[i]-ar[j],ar[j]-ar[i])+1;
			b=ar[i]+ar[j]-1;
			if(a>=0&b>=a){
			//	cout<<a<<" "<<b<<" "<<i<<" "<<j<<endl;
				for(k=a;k<=b;k++){
					ans+=fl[k];
				}
			}
			fl[ar[j]]++;
		}
		fl[ar[i]]++;
	}
	cout<<ans/3<<endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        m: usize,
    }

    if n % 2 == 1 {
        for i in 0..m {
            println!("{} {}", i + 1, n - i);
        }
    } else {
        for i in 0..m {
            if i < n / 4 {
                println!("{} {}", i + 1, n - i);
            } else {
                println!("{} {}", i + 1, n - i - 1);
            }
        }
    }
}


Measured memory_bytes: 2152
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}


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

  vector<char> pw;
  FORN(i, A.size()) {
    pw.PB(A[i]);
    if (B.size() > i) pw.PB(B[i]);
  }

  string pass(pw.begin(),pw.end());
  cout << pass << "\n";
    
  return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
rN = math.ceil(math.sqrt(N))
ans = 10
def max_digit(A, B):
    d = max(A, B)
    cnt = 0
    while d > 0:
        d = d // 10
        cnt += 1
    return cnt

for i in range(1, rN + 1):
    if N % i == 0:
        ans = min(ans, max_digit(i, N / i))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;

    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    
    ll S = 0;
    rep(i, n) {
        S += v[i] * t[i];
    }

    // 0.5sec単位での速度を求めていく

    ll total = accumulate(all(t), 0LL);

    ld INF = 1e18;
    vector<ld> V(total * 2 + 1, INF);

    ll now = 0;
    rep(i, n) {
        rep(dt, t[i]) {
            ll t1 = now + 2 * dt; 
            ll t2 = now + 2 * dt + 1; 
            V[t1] = min(V[t1], (ld)v[i]);
            V[t2] = min(V[t2], (ld)v[i]);
        }
        now += t[i] * 2;
        V[now] = min(V[now], (ld)v[i]);
    }

    // 両端は0
    V[0] = 0;
    V[2 * total] = 0;

    // 前から速度をあげれるだけ上げたときの制約
    for (ll i = 1; i < V.size(); i++) {
        V[i] = min(V[i], V[i-1] + 0.5);
    }

    // 後ろから速度をあげれるだけ上げたときの制約
    for (ll i = V.size() - 2; i >= 0; i--) {
        V[i] = min(V[i], V[i+1] + 0.5);
    }

    ld res = 0;
    rep(i, V.size()-1) {
        res += (V[i] + V[i+1]) * 0.5 / 2;
    }
    printf("%.12Lf\n", res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3772
#include<stdio.h>

int main(void)
{
	int n;
	int k;
	int x;
	int y;
	int sum;
	sum=0;

	scanf("%d%d%d%d",&n,&k,&x,&y);
	sum+=n*x;
	if(n>k){
		sum-=(n-k)*(x-y);
	}
	printf("%d\n",sum);
	return 0;
}

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

typedef long long ll;

main()
{
    int a, b;
    cin >> a >> b;
    if(a <= 9 && b <= 9){
        cout << a * b;
    }
    else{
        cout << -1;
    }


}





///promy_pompom
//hello world


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>
#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

using namespace std;

struct Item{
  int value, weight;
};

int N,W;
Item items[NMAX+1];
int C[NMAX+1][WMAX+1],G[NMAX+1][WMAX+1];

void compute(int &maxValue, vector<int> &selection){
  for(int w=0;w<=W;w++){
    C[0][w]=0;
    G[0][w]=DIAGONAL;
  }


  for(int i=1;i<=N;i++){
    C[i][0]=0;
  }

  for(int i=1;i<=N;i++){
    for(int w=1;w<=W;w++){
      C[i][w]=C[i-1][w];
      G[i][w]=TOP;
      if(items[i].weight>w)continue;
      if(items[i].value+C[i-1][w-items[i].weight]>C[i-1][w]){
        C[i][w]=items[i].value+C[i-1][w-items[i].weight];
        G[i][w]=DIAGONAL;
      }
    }
  }

  maxValue=C[N][W];
  selection.clear();
  for(int i=N,w=W;i>=1;i--){
    if(G[i][w]==DIAGONAL){
      selection.push_back(i);
      w-=items[i].weight;
    }
  }

  reverse(selection.begin(),selection.end());
}

void input(){
  cin >> N >> W;
  for(int i=1;i<=N;i++){
    cin >> items[i].value >> items[i].weight;
  }
}

int main(){
  int maxValue;
  vector<int> selection;
  input();
  compute(maxValue,selection);

  cout << maxValue << endl;

  return 0;
}

Measured memory_bytes: 11000
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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

        String find = inp.next();

        String s = "";

        ArrayList<String> stringArray = new ArrayList<>();

        while (!s.equals("END_OF_TEXT")) {
            s = inp.next();

            String[] sWords = s.trim().split(" ");

            stringArray.addAll(Arrays.asList(sWords));
        }

        System.out.println(findWord(stringArray, find)+ "");
    }

    private static int findWord(ArrayList<String> s, String find) {
        int counter = 0;
        
        String findLower = find.toLowerCase();

        for (String word : s) {
            String wordLower = word.toLowerCase();
            if (wordLower.equals(findLower)) {
                counter++;
            }
        }

        return counter;
    }
}



Measured memory_bytes: 25944
#include<stdio.h>
int main() {
  int i,n,m,h[100002],ma[100002];

  scanf("%d %d",&n,&m);

  int a[m + 1],b[m + 1];
  
  for (i = 1;i <= n;i ++) {
    int height;
    scanf("%d",&height);
    h[i] = height;
    ma[i] = 0;
  }

  for (i = 1;i <= m;i ++) {
    int scana,scanb;
    scanf("%d %d",&scana,&scanb);
    a[i] = scana;
    b[i] = scanb;
  }
  for (i = 1;i <= m;i ++) {
    if (ma[a[i]] <= h[b[i]]) {
      ma[a[i]] = h[b[i]];
    }
    if (ma[b[i]] <= h[a[i]]) {
      ma[b[i]] = h[a[i]];
    }
  }
  int x = 0;
  for (i = 1;i <= n;i ++) {
    if (h[i] > ma[i]) {
      x ++;
    }
  }
  printf("%d",x);
}


Measured memory_bytes: 3288
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scanner = new Scanner(System.in);
		
		String input = scanner.nextLine();

		scanner.close();
		
		String[] inputs = input.split(" ", 0);
		
		String inAStr = inputs[0];
		String inBStr = inputs[1];
		
		Integer inA = Integer.parseInt(inAStr);
		Integer inB = Integer.parseInt(inBStr);
		
		Integer valAA = inA + inA - 1;
		Integer valAB = inA + inB;
		Integer valBB = inB + inB - 1;
		
		Integer max = valAA < valAB ? valAB : valAA;
		Integer max2 = max < valBB ? valBB : max;
		
		System.out.println(max2);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<char> N(3);
  for (int i = 0;i < 3;i++) {
    cin >> N.at(i);
  }
  if(N.at(0)=='7'||N.at(1)=='7'||N.at(2)=='7') {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
N = int(input())
digit = []

while N > 0:
    digit.append(N % 10)
    N //= 10

ans = sum(digit)

for i in range(1, len(digit)):
    tmp = 9*i + sum(digit[i:])
    if digit[i] != 0:
        tmp -= 1
    
    if tmp > ans:
        ans = tmp

print(ans)

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

int main() {
  long long n, c, k;
  cin >> n >> c >> k;
  vector<long long> t(n);
  for(int i = 0; i < n; i++) cin >> t.at(i);
  
  sort(t.begin(), t.end());
  int ans = 1;
  long long time = t.at(0);
  int count = 1;
  
  for(int i = 1; i < n; i++){
    if(count == c){
      time = 0;
    }
    
    if(time == 0){
      time = t.at(i);
      ans++;
      count = 1;
      continue;
    }
    
    if(t.at(i) <= time + k){
      count++;
    }
    
    else{
      count = 1;
      ans++;
      time = t.at(i);
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 1024
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let b: Vec<usize> = sc.vec(n);

    if !check(50, &a, &b, &vec![]) {
        println!("-1");
        return;
    }

    let mut ans = vec![];
    for k in (1..51).rev() {
        if !check(k - 1, &a, &b, &ans) {
            ans.push(k);
        }
    }

    println!("{}", ans.into_iter().map(|i| 1 << i).sum::<usize>());
}

fn check(k: usize, a: &Vec<usize>, b: &Vec<usize>, ans: &Vec<usize>) -> bool {
    let max = cmp::max(*a.iter().max().unwrap(), *b.iter().max().unwrap());
    let mut w = vec![vec![false; max + 1]; max + 1];
    for &a in a.iter() {
        w[a][a] = true;
    }

    for &k in ans.iter() {
        for i in 0..(max + 1) {
            w[i][i % k] = true;
        }
    }
    for k in 1..(k + 1) {
        for i in 0..(max + 1) {
            w[i][i % k] = true;
        }
    }
    for k in 0..(max + 1) {
        w[k][k] = true;
    }

    for k in 0..(max + 1) {
        for i in 0..(max + 1) {
            for j in 0..(max + 1) {
                if w[i][k] && w[k][j] {
                    w[i][j] = true;
                }
            }
        }
    }

    b.iter().enumerate().all(|(i, &b)| w[a[i]][b])
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
bool visited[100005];
const int max_N = 1e5 + 10;
int N;
int d[105];
int main(void) {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	sort(d, d + N);
	int count=1;
	for (int i = 0; i < N-1; i++) {
		if (d[i] != d[i + 1]) count++;
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A,B,C;
  cin >> A >> B >> C;
  int count=0;
  for(int i=1;i<1000;i++){
  	if((i*A)%B==C){
    	count++;
      break;
    } 
  }
  if(count) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

string s;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	while (1) {
		getline(cin, s);
		if (s == ".") break;
		string ans = [&] {
			int c1 = 0, c2 = 0;
			stack<char> sta;
			sta.push('#');
			rep (i, s.size()) {
				if (c1 < 0 || c2 < 0) return "no";
				switch (s[i]) {
					case '(':
						c1++;
						sta.push('(');
						break;
					case '[':
						c2++;
						sta.push('[');
						break;
					case ')':
						c1--;
						if (sta.top() == '[') return "no";
						sta.pop();
						break;
					case ']':
						c2--;
						if (sta.top() == '(') return "no";
						sta.pop();
						break;
					default:
						break;
				}
			}
			return (c1 == 0 && c2 == 0? "yes" : "no");
		}();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean ans = true;
		for (int i = 0; i < s.length(); i=i+2) {
			char c = s.charAt(i);
			//System.out.println(c);
			if (c != 'R' && c != 'U' && c != 'D') {
				ans = false;
				break;
			}
		}
		for (int i = 1; i < s.length(); i=i+2) {
			char c = s.charAt(i);
			//System.out.println(c);
			if (c != 'L' && c != 'U' && c != 'D') {
				ans = false;
				break;
			}
		}
		if(ans) {
		System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


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

int main() {
  int x, i=0, cnt=0;
  cin >> x;
  while (cnt < x) {
    i++;
    cnt += i;
  }
  cout << i << endl;
}

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

bool px(vector<int> p, int x) {
	for (int i = 0; i < p.size(); i++) {
		if (p[i] == x)
			return true;
	}
	return false;
}

int main()
{
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	int o = x;
	if (!px(p, o)) {
		cout << o << endl;
		return 0;
	}

	int op = o;
	int om = o;
	while (true)
	{
		op++;
		om--;
		if (!px(p, om)) {
			cout << om << endl;
			return 0;
		}
		if (!px(p, op)) {
			cout << op << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3656
using System;
using System.ComponentModel;
using System.Linq;

namespace M_SOLUTIONS_プロコンオープン {
	class Program {
		static void Main(string[] args) {
			var input = Helper<int>.Read(1);

			var result = 180 * (input[0] - 2);
			Console.WriteLine(result);
		}
	}

	public static class Helper<T> {
		public static T[] Read(int count) {
			var result = new T[count];
			for (int index = 0; index < count; index++) {
				result[index] = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(Console.ReadLine());
			}
			return result;
		}

		public static T[] ReadLine() {
			var input = Console.ReadLine();
			var inputs = input.Split(' ');
			var result = new T[inputs.Count()];
			for (int index = 0; index < inputs.Count(); index++) {
				result[index] = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(inputs[index]);
			}
			return result;
		}
	}
}


Measured memory_bytes: 14304
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
ll dp[520][100001];
ll n, q, v[300001], w[300001];

ll dfs(ll x, ll y, ll vv, ll ww) {
  if (x < (1 << 8)) {
    if (ww > y) {
      return 0LL;
    }
    return dp[x][y - ww] + vv;
  }
  return max(dfs(x / 2, y, vv + v[x], ww + w[x]), dfs(x / 2, y, vv, ww));
}

int main() {
  ll vv, l;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i + 1] >> w[i + 1];
  }
  for (ll i = 1LL; i <= min(n, (1LL << 8)); i++) {
    for (ll j = 100000LL; j >= 0; j--) {
      dp[i][j] = dp[i / 2LL][j];
      if (j - w[i] >= 0) {
        dp[i][j] = max(dp[i][j], dp[i / 2][j - w[i]] + v[i]);
      }
    }
    for (ll j = 1; j <= 100000; j++) {
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
    }
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> vv >> l;
    cout << dfs(vv, l, 0, 0) << endl;
  }
}

Measured memory_bytes: 207700
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();  
        int N = r.i();
        String[] s = new String[N];
        for(int i = 0; i < N; i++){
            char[] temp = r.s().toCharArray();
            Arrays.sort(temp);
            s[i] = String.valueOf(temp);
        }
        Arrays.sort(s, (x, y) -> x.compareTo(y));
        long ans = 0;
        for(int i = 0; i < N; ){
            String temp = s[i];
            int j = i;
            while(j < N && temp.equals(s[j])){
                j++;
            }
            long n = j-i;
            ans += n*(n-1)/2;
            i = j;
        }
        println(ans);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 47024
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=1e5+5;
int n,mini,maxi;
int a[maxn];
int main(){
	read(n);
	mini=1e9;
	rep(i,1,n){
		read(a[i]);
		mini=min(mini,a[i]);
		maxi=max(maxi,a[i]);
	}
	if(maxi>mini+1)return puts("No"),0;
	if(maxi==mini){
		int flag=1;
		rep(i,1,n)if(a[i]!=n-1)flag=0;
		if(flag)return puts("Yes"),0;
	}
	int cnt=0;
	rep(i,1,n)if(a[i]==mini)cnt++;
	if(maxi==mini)cnt=0;
	int restmax=(n-cnt)/2;
	if(cnt+1<=maxi&&cnt+restmax>=maxi)return puts("Yes"),0;
	puts("No");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n;
  unsigned long long retval = 0;
  if(scanf("%d",&n)<1){
    exit(1);
  }
  int a[n];
  for(int i = 0; i < n; i++){
  	if(scanf("%d",&a[i])<1){
      exit(1);
    }
  }
  for(int i = 1; i < n; i++){
    while(a[i-1]>a[i]){
      //printf("a[%d]: %d,a[%d]: %d\n",i-1,a[i-1],i,a[i]);
      a[i]+=1;
      retval++;
    }
  }
  printf("%llu\n",retval);
  return 0; 
}

Measured memory_bytes: 2464
import re
moji = str(input())
moji = re.sub("eraser", "", moji)
moji = re.sub("erase", "", moji)
moji = re.sub("dreamer", "", moji)
moji = re.sub("dream", "", moji)
 
if len(moji) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3572
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var Ti = Sarray();
            var M = Sarray()[0];
            var sum = Ti.Sum();
            for (var i = 0; i < M; ++i)
            {
                (long p, long x) = Slice2<long>();
                WriteLine(sum - Ti[p - 1] + x);
            }
        }
    }
}

Measured memory_bytes: 28384
/*
 * SumOfNumbers.cpp
 *
 *  Created on: 2014/07/25
 *      Author: WanWan1985
 */
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

typedef unsigned int u_int;

int main() {

	vector<int> vecResult;
	while(1) {
		string strNumbers;
		cin >> strNumbers;
		if (0 == atoi(strNumbers.c_str())) {
			break;
		}

		int iResult = 0;
		for (u_int i = 0; i < strNumbers.size(); i++) {
			iResult += atoi(((strNumbers.substr(i, 1)).c_str()));
		}
		vecResult.push_back(iResult);
	}

	for (u_int i = 0; i < vecResult.size(); i++) {
		cout << vecResult.at(i) << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
f w h x y r = 
    if((r <= x && x + r <= w) && (r <= y && y + r <= h)) 
        then "Yes"
        else "No"

main = do
    line <- getLine
    let (w:h:x:y:r:_) = map read $ words line :: [Int]
    putStrLn $ f w h x y r


Measured memory_bytes: 3476
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int  main() {
	
	string s;

	cin >> s;
	s.erase(s.length() - 1, 1);

	while(1){
		bool jud = true;

		if (s.length() % 2 == 1) {
			s.erase(s.length() - 1, 1);
			continue;
		}
		else {
			for (int i = 0; i < s.length() / 2; i++) 
				if (s[i] != s[i + s.length() / 2])jud = false;
		}

		if (jud) {
			pr(s.length());
			return 0;
		}
		else s.erase(s.length() - 1, 1);
	}


	return 0;

}

Measured memory_bytes: 256
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "random"
#include        "chrono"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"
 
#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
 
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
 
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
 
int n,m,k,q;
string s, t;
vi adj[N];
int vis[N],par[N],a[N];
 
void go()
{
    cin >> s >> t;
    n = s.size();
    m = t.size();
 
    int ans = inf;
    fo(i,0,n)
    {
        int now = 0;
        if(i + m > n ) break;
        fo(j,0,m)
        {
            now += ( s[i+j] != t[j] );
        }
        ans = min( ans ,now );
    }
 
    cout << ans << endl;
}
 
int32_t main()
{
    FAST;     
    int t=1; 
    // cin>>t;
    test(t) go();
}

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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }

    sort(a.begin(),a.end());

    vector<int> b(n);
    for(int i = 0;i < n;i ++){
        b.at(a.at(i) -1) ++;
    }

    sort(b.begin(),b.end(),greater<int>());

    int ans = 0;

    for(int i = k;i < n;i ++){
        ans += b.at(i);
    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << a*2 << endl;
    } else {
        int M = max(a, b);
        cout << M*2-1 << endl;
    }
    return 0;
}




Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

A = np.array(A, dtype=int)
D = A - np.arange(N)
print(int(np.abs(D - np.median(D)).sum()))


Measured memory_bytes: 35108
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

macro_rules! tern {
    ($condition: expr, $_true: expr, $_false: expr) => {
        if $condition {
            $_true
        } else {
            $_false
        }
    };
}

fn main() {
    let (A, B, C) = get!(isize, isize, isize);
    println!("{}", ::std::cmp::max(0, (C-(A-B))));
}


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

int main(){
  int a,s;
  cin >> a;
  vector<int>b(a);
  for(int i=0;i<a;i++){
    cin >> b.at(i);
  }
  for(int i=0;i<a;i++){
    if(i==0)s=s+b.at(0);    
    else if(i>0 && b.at(i-1)<b.at(i)){
      s=s+b.at(i)-b.at(i-1);
    }
  }
  cout <<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<int>vec[1000];
  int n,tc,t;
  long long int x;
  cin>>n>>tc;
  while(tc--)
  {
    int q;
    cin>>q;
    if(q==0)
    {
      cin>>t>>x;
      vec[t].push_back(x);
    }
    else if(q==1)
    {
      cin>>t;
      if(vec[t].size()==0)
      {
        cout<<endl;
      }
      else
      {
        cout<<vec[t][0];
        for(int i=1;i<vec[t].size();i++)
        {
          cout<<" "<<vec[t][i];
        }
        cout<<endl;
      }
    }
    else
    {
      cin>>t;
      if(!vec[t].empty())
      {
        vec[t].clear();
      }
    }
  }
}



Measured memory_bytes: 5844
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    long long int h,w;
    std::cin >> h >> w;
    std::vector<std::vector<int>> s(h+2, std::vector<int>(w+2, 0));

    std::string str;
    for (int i = 0; i < h; i++) {
        std::cin >> str;
        for (int j = 0; j < w; j++) {
            if (str[j] == '.') {
                s[i+1][j+1] = 0;
            } else {
                s[i+1][j+1] = 1;
            }
        }
    }

    for (int i = 1; i < h+1; i++) {
        for (int j = 1; j < w+1; j++) {
            if (s[i][j] == 1) {
                if (s[i+1][j] == 0 && s[i-1][j] == 0 && s[i][j+1] == 0 && s[i][j-1] == 0) {
                    std::cout << "No" << std::endl;
                    return 0;
                }
            }
        }
    }
    
    std::cout << "Yes" << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main() {
    int A;
    cin >> A;
    if (A >= 1000)
        cout << "ABD" << endl;
    else
        cout << "ABC" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll tmp;
  bool you = false;
  for(int i=0;i<N;++i) {
    cin>>tmp;
    if(tmp%2==1) you = true;
  }
  if(you) cout<<"first"<<endl;
  else cout<<"second"<<endl;
}



Measured memory_bytes: 3648
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll x,k,d,z;
            cin>>x>>k>>d;
            if(x<0)
            {
                x=-1*x;
            }
                z=x/d;
                // cout<<x<<" "<<d<<" "<<z<<" "<<k<<endl;
                if(z>=k)
                {
                    cout<<x-k*d<<endl;
                    return 0;
                }
                k=k-z;
                x=x%d;
                if(k%2==0)
                {
                    cout<<x<<endl;
                }
                else
                {
                    cout<<abs(x-d)<<endl;
                }
        }
        return 0;
    }


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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    if (s.compare("ARC") == 0)
    {
        cout << "ABC\n";
        return 0;
    }
    cout << "ARC\n";
    return 0;
}

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

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

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

    int ans = 0;
    rep (i, n-1) rep (j, m-1){
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

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

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, a, b, c; cin>>n>>a>>b>>c;
	vector<string> vec(n);
	for(int i = 0; i < n; i++){
		cin>>vec[i];
	}
	bool flag = true;
	vector<int> res(n);
	for(int i = 0; i < n && flag; i++){
		if(vec[i] == "AB"){
			if(a == 0 && b == 0){
				flag = false;
				break;
			}
			if(a == b && i < n-1){
				if(vec[i+1] == "BC"){
					b++;
					a--;
					res[i] = 1;
				}else if(vec[i+1] == "AC"){
					a++;
					b--;
					res[i] = 0;
				}else if(vec[i+1] == "AB"){
					a--;
					b++;
					res[i] = 1;
				}
			}else if(a < b){
				a++;
				b--;
				res[i] = 0;
			}else{
				a--;
				b++;
				res[i] = 1;
			}
		}else if(vec[i] == "AC"){
			if(a == 0 && c == 0){
				flag = false;
				break;
			}
			if(a == c && i < n-1){
				if(vec[i+1] == "AB"){
					c--;
					a++;
					res[i] = 0;
				}else if(vec[i+1] == "BC"){
					a--;
					c++;
					res[i] = 2;
				}else if(vec[i+1] == "AC"){
					a--;
					c++;
					res[i] = 2;
				}
			}else if(a < c){
				a++;
				c--;
				res[i] = 0;
			}else{
				a--;
				c++;
				res[i] = 2;
			}
		}else if(vec[i] == "BC"){
			if(b == 0 && c == 0){
				flag = false;
				break;
			}
			if(b == c && i < n-1){
				if(vec[i+1] == "AB"){
					c--;
					b++;
					res[i] = 1;
				}else if(vec[i+1] == "AC"){
					b--;
					c++;
					res[i] = 2;
				}else if(vec[i+1] == "BC"){
					b--;
					c++;
					res[i] = 2;
				}
			}else if(b < c){
				b++;
				c--;
				res[i] = 1;
			}else{
				b--;
				c++;
				res[i] = 2;
			}
		}
	}
	if(!flag) cout<<"No\n";
	else{
		cout<<"Yes\n";
		for(auto x: res){
			cout<<(char)(x+'A')<<"\n";
		}
	}
}

Measured memory_bytes: 6632
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define sz(a)  int((a).size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define CLR(a) memset((a), 0, sizeof(a))
#define INF (1 << 31) - 1
const int dh[8] = {-1, 1, 0, 0,1,1,-1,-1};
const int dw[8] = {0, 0, 1, -1,1,-1,1,-1};
typedef long long ll;
typedef pair<double, double> p;
typedef vector <int> VI;
typedef vector <string> VS;

int main(){
  
  ll h, w;
	cin >> h;
  cin >> w;

  ll s = h * w;
  ll ans = 10000000000;
  if(h % 3 == 0 || w % 3 == 0){
    ans = 0;  
  }else{
    ll mi = min(h, w);
    ll ma = max(h, w);

    for(ll i = 1; i < ma; i++){
      ll s1 = i * mi;
      ll s2 = (ma - i) * (mi / 2);
      ll s3 = s - s1 - s2;
      ll diff = max(abs(s1 - s3),max(abs(s1 - s2), abs(s2 - s3)));
      ans = min(diff, ans);
    }
    for(ll i = 1; i < mi; i++){
      ll s1 = i * ma;
      ll s2 = (mi - i) * (ma / 2);
      ll s3 = s - s1 - s2;
      ll diff = max(abs(s1 - s3),max(abs(s1 - s2), abs(s2 - s3)));
      ans = min(diff, ans);
    }
    ans = min(ans, mi);  
  }
  
  cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
long long int n,k,x,y,ans = 0;
cin >> n >> k >> x >> y;

if(k - n >= 0 ){
ans += n * x ;
}else{
  ans += (k) * x;
  ans += (n - k) * y;
}

cout << ans << endl;

return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
long n,i,s,a[114514],b[114514],c[114514],bb[114514],cc[114514],p,q;
int main()
{
	for(cin>>n;i<n;cin>>a[i++]);for(i=0;i<n;cin>>b[i++]);for(i=0;i<n;cin>>c[i++]);
	sort(a,a+n);sort(b,b+n);sort(c,c+n);
	for(;;)
	{
		if(a[p]<b[q])
		{
			bb[q]++;
			p++;
			if(p==n){for(;q<n;q++)bb[q+1]=bb[q];break;}
		}
		else
		{
			bb[q+1]=bb[q];
			q++;
			if(q==n)break;
		}
	}
	for(i=1;i<n;i++)bb[i]+=bb[i-1];
	p=q=0;
	for(;;)
	{
		if(b[p]<c[q])
		{
			cc[q]=bb[p];
			p++;
			if(p==n){for(;q<n;q++)cc[q+1]=cc[q];break;}
		}
		else
		{
			cc[q+1]=cc[q];
			q++;
			if(q==n)break;
		}
	}
	for(i=0;i<n;i++)s+=cc[i];
	cout<<s<<endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int min(int a, int b){
  return a < b ? a : b;
}
int main(void){
  int n;
  int sum = 0;
  int mi = INT_MAX;
  cin >> n;
  for(int i = 0; i < n; i++){
    int s;
    cin >> s;
    sum += s;
    if(s%10 != 0) mi = min(mi, s);
  }
  if(sum%10 != 0) cout << sum << endl;
  else if(mi != INT_MAX) cout << sum-mi << endl;
  else cout << 0 << endl;
  return 0;
}

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

int main() {
    int A, B, N; cin >> N >> A >> B;
    string s; cin >> s;
    int n = 0;
    int b = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'a') {
            if (n < A + B) {
                cout << "Yes" << endl;
                n++;
            } else {
                cout << "No" << endl;
            }
        } else if (s[i] == 'b') {
            if (n < A + B && b < B) {
                cout << "Yes" << endl;
                n++; b++;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 896
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);

int N=sc.nextInt();
int L=sc.nextInt();

List<String> list = new ArrayList<String>();

	for(int i = 0; i < N; i++){
		list.add(sc.next());
	}
	
	Collections.sort(list);
	
	for(String i : list) {
		System.out.print(i);
	}

}
}

Measured memory_bytes: 23764
n,m = gets.chomp.split.map(&:to_i)
gs = m.times.map{gets.chomp.split.map(&:to_i)}
lmax = 0
rmin = n+1
gs.each do |l,r|
  lmax = [l,lmax].max
  rmin = [r,rmin].min
end
puts [rmin - lmax + 1,0].max

Measured memory_bytes: 11516