akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b;

  scanf("%d %d", &a, &b);

  int cnt = 0;

  FOR(i, a, b + 1) {
    if (i / 10000 == i % 10 && (i / 1000) % 10 == (i % 100) / 10) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
     
    using namespace std;
    int num[30];
    int main()
    {
        int n,m;
        int a,b;
        cin>>n>>m;
        while(m--)
        {
            cin>>a>>b;
            num[a]++;
            num[b]++;
        }
        for(int i=1;i<=n;i++)
            cout<<num[i]<<endl;
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <time.h>
#define int long long
#define ll long long
#define us unsigned
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define nin(ary, n) for (int i = 0; i < (n); i++) cin >> ary[i]
#define nnin(ary, h, w) for (int i = 0; i < (h); ++i) for (int j = 0; j < (w); ++j) cin >> ary[i][j]
#define opt(conditions, a, b) cout << ((conditions) ? #a : #b) << endl
using namespace std;
const double PI = acos(-1.0);
const int MOD = 1e9 + 9;

int max_n(int ary[], int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_o(int ary[], int length) {
	int max;
	max = max_n(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_n(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_o(int ary[], int length) {
	int min;
	min = min_n(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

int gcm(int a, int b) {
	int result = a;
	int k = 0;
	int n = b;
	do {
		k = result % n;
		result = n;
		n = k;
	} while (k != 0);
	return result;
}

int gcm_n(int ary[], int length) {
	int g = ary[0];
	for (int i = 0; i < length; i++)
		g = gcm(g, ary[i]);
	return g;
}

int lcm(int a, int b) {
	int g, n;
	g = gcm(a, b);
	n = gcm(a, g);
	a = a / n;
	b = b / (g / n);
	return a*b;
}

int lcm_n(int ary[], int length) {
	int l = ary[0];
	for (int i = 0; i < length; i++)
		l = lcm(l, ary[i]);
	return l;
}

signed main() {
	int n, cnt = 0;
	bool bef;
	string a, b;
	cin >> n >> a >> b;

	int i = 0;
	if (a[i] == b[i]) {
		cnt += 3;
		i++;
		bef = true;
	}
	else {
		cnt += 6;
		i += 2;
		bef = false;
	}

	while (i < n) {
		if (a[i] == b[i]) {
			if (bef)
				cnt *= 2;
			i++;
			bef = true;
		}
		else {
			if (!bef)
				cnt *= 3;
			else cnt *= 2;
			i += 2;
			bef = false;
		}
		cnt %= 1000000007;
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int a[N],b[N],n,m,k,ans;
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]+=a[i-1];
	}
	for(int i=1;i<=m;i++)
	{
		cin>>b[i];
		b[i]+=b[i-1];
	}
	for(int l=0,r=m;l<=n;l++)
	{
		if(a[l]>k)
			break;
		while(a[l]+b[r]>k)
			r--;
		ans=max(ans,l+r);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6760
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")
    };
}

fn main() {
    input! {
        a: [i32;5],
        k: i32
    }
    let res = a.iter().max().unwrap() - a.iter().min().unwrap() <= k;
    println!("{}", if res {"Yay!"} else {":("});
}


Measured memory_bytes: 4352
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

bool palindrome(int n)
{
    string S = to_string(n);
    
    string T = S; reverse(T.begin(), T.end());
    
    return S == T;
}

int main()
{
    int n, ret = 999999999;
    
    scanf("%d", &n);
    
    for(int i = 1; i <= 100001; i++)
    {
        if(palindrome(i) && abs(i - n) < abs(ret - n))
        {
            ret = i;
        }
    }
    
    printf("%d\n", ret);
    
    return 0;
}

Measured memory_bytes: 3352
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,0,sizeof(p));
#define mp make_pair;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);}

int main() {
	fast();
	string s;
	cin>>s;
	int mon=0,yr=0;
	if (stoi(s.substr(0,2))<13 && stoi(s.substr(0,2))>0) mon=1;
	if (stoi(s.substr(2,2))<13 && stoi(s.substr(2,2))>0) yr=1;
	if (mon && yr) cout<<"AMBIGUOUS"<<endl;
	else if (mon) cout<<"MMYY"<<endl;
	else if (yr) cout<<"YYMM"<<endl;
	else cout<<"NA"<<endl;
}

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

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

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

const long long int MOD = 998244353;
int cnt[100000];
long long int mypow(long long int x,long long int n)
{
	if(x==0)
	{
		return 0;
	}
	long long int res = 1;
	while(n>0)
	{
		if(n%2==1)
		{
			res = ((res%MOD)*(x%MOD)%MOD);
			res%=MOD;
		}
		x = ((x%MOD)*(x%MOD)%MOD);
		x%=MOD;
		n/=2;
	}
	return res;
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,t;

	memset(cnt,0,sizeof(cnt));
	cin >> n;
	int Max = 0;
	for(int i=0;i<n;i++)
	{
		cin >> t;
		if(i==0 && t!=0)
		{
			cout << 0 << '\n';
			return 0;
		}
		cnt[t]++;
		Max = max(Max,t);
	}

	if(cnt[0]!=1)
	{
		cout << 0 << '\n';
		return 0;
	}

	long long int res = 1;

	for(int i=1;i<=Max;i++)
	{
		res = ((res%MOD)*(mypow(cnt[i-1],cnt[i])%MOD)%MOD);
		res%=MOD;
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 640
building = [[[0 for k in range(10)] for j in range(3)] for i in range(4)]
n = int(input())
for _ in range(n):
    b,f,r,v = [int(i) for i in input().split()]
    building[b-1][f-1][r-1] += v
building = [[[" "+str(k) for k in j] for j in i] for i in building]
print("\n####################\n".join(["\n".join(["".join(j) for j in i]) for i in building]))


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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"

ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n,k,i,num;
	cin>>n>>k;
	ll a[n];
	ll sum=0;
	for(i=0;i<n;++i)cin>>a[i];
	for(i=0;i<k;++i)sum+=a[i];
	ll ans=sum;
	for(i=1;i<=n-k;++i)
	{
		sum-=a[i-1];sum+=a[i-1+k];
		ans=max(ans,sum);
	}
	cout<<fixed<<setprecision(10)<<(ans+k)/2.0;
	return 0;
}


Measured memory_bytes: 1792
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
A_dic = Counter(A)

set_A = sorted((set(A)), reverse=True)
tmp = 0
for a in set_A:
    if A_dic[a] >= 4:
        print(max(tmp*a, a*a))
        exit()
    if A_dic[a] >= 2:
        ans = tmp * a
        if ans != 0:
            print(ans)
            exit()
        tmp = a
print(0)


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

int n,m,q;
int a[55],b[55],c[55],d[55];
int A[13], ans;

void fun(int i){
    if(i>n){
        int sum = 0;
        for(int j=1;j<=q;++j)
            if(A[b[j]]-A[a[j]]==c[j]) sum += d[j];
        if(sum > ans) ans = sum;
        return;
    }
    for(int j=A[i-1];j<=m;++j){
        A[i] = j;
        fun(i+1);
    }
}

int main(void)
{
    cin>>n>>m>>q;
    for(int i=1;i<=q;++i) cin>>a[i]>>b[i]>>c[i]>>d[i];
    A[0] = 1;
    fun(1);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = unsigned long long;
using pii = pair<int, int>;

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7,maxn = 100000000;
const double PI = acos(-1);


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;

    cout << (a + b) %24 << endl;
    return 0;
}

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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

const int dx[]={1,-1,0,0},
		  dy[]={0,0,1,-1};

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int main(){
	//IO();
	scanf("%d%d",&n,&k);
	if (n<10)
		k+=(100 * (10-n));
	printf("%d\n",k);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
using namespace std;
typedef long long ll;
const double PI = acos( -1.0 );

int main( void ) {
    double a, b, c;
    cin >> a >> b >> c;
    double x = sqrt( a * a + b * b - 2 * a * b * cos( c * PI / 180.0 ) );
    double h = b * sin(c * PI / 180.0);
    printf( "%.8lf\n", h * a / 2.0 );
    printf( "%.8lf\n", a + b + x );
    printf( "%.8lf\n", h );

    return 0;
}



Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
bool cmp(int x,int y){
	return x>y;
}
int main(){
	int n,k,i,a[1001],s=0;
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=k;i++) s+=a[i];
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, key, l, largest, tmp;
  char com[20];
  while (1) {
    scanf("%s", com);
    if (com[0] == 'i') {
      scanf("%d", &key);
      A[++H] = key;
      for (i=H; i>1 && A[i/2]<A[i];i/=2) {
        tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
      }
      continue;
    } else if (com[1]=='x') { // extract
      printf("%d\n", A[1]);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i*2;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
      continue;
    }
    break;
  }
  return 0;
}


Measured memory_bytes: 5652
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::{input, marker::{Isize1, Usize1, Bytes, Chars}};

//#[proconio::fastout]
fn main() {
    input!(
        a: i64,
        b: i64,
        c: i64,
    );
    if c - a - b > 0 && 4*a*b < (c - a - b).pow(2) { println!("Yes"); }
    else { println!("No"); }
}


Measured memory_bytes: 2148
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    var K = sc.nextInt
    val x = Array.fill(N)(sc.nextInt)

    if (x.contains(0)) K -= 1
    val xr = 0 +: x.filter(_ < 0).map(-_).sorted.take(K)
    val xf = 0 +: x.filter(_ > 0).sorted.take(K)

    val a =
      (for (i <- xr.indices if K - i < xf.length) yield xr(i) * 2 + xf(K - i)) ++:
      (for (i <- xf.indices if K - i < xr.length) yield xf(i) * 2 + xr(K - i))

    a.min.toString
  }
}


Measured memory_bytes: 66788
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int q;
	scanf("%d", &q);
	ll par = 0;
	while (q--)
	{
		int p, n;
		char c;
		scanf("%d %c %d", &p, &c, &n);
		if (c == '(')
			par += n;
		else
			par -= n;

		if (par == 0)
			puts("Yes");
		else
			puts("No");
	}
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  long long r = 0;
  int h = 0;
  for(int x : a){
    if(x < h){
      r += h - x;
    } else {
      h = x;
    }
    //cout << "h: " << h << " r: " << r << endl;
  }
  cout << r;
  return 0;
}

Measured memory_bytes: 4032
import sys
import math


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


n = int(input())

prims = prime_factorize(n)

prim_set = set(prims)

deleted_prims = {}

ans = 0
for prim in prim_set:
    while True:
        if prim not in deleted_prims:
            deleted_prims[prim] = 1
        times = deleted_prims[prim]
        # print(times)
        if times == 0:
            break
        if times <= prims.count(prim):
            # 操作できる
            ans += 1
            for i in range(times):
                prims.remove(prim)
            deleted_prims[prim] += 1
            # print("OK", prims)

        else:
            break

print(ans)


Measured memory_bytes: 9224
#include <stdio.h>
int main(void) {
  int A,B;
  scanf("%d",&A);
  scanf("%d",&B);
  if (A!=1 && B!=1) printf("1\n");
  else if (A!=2 && B!=2) printf("2\n");
  else if (A!=3 && B!=3) printf("3\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MAXN = 500005;
using namespace std;
int arr[MAXN],dp[MAXN];
int main() {
  /* ifstream cin("input.txt");
   ofstream cout("output.txt");*/
   ll l,r,d,count=0;
   cin>>l>>r>>d;
   for(int i=d;i<=r;i=i+d){
   	if(i>=l){
   		count++;
   	  }
   }
   cout<<count<<endl;
   return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <limits.h>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main() {
    int wa;
    char s[4];
    cin >> s;
    for (int i = 0; i < 4; i++) {
        if (s[i] == '+') wa++;
        else wa--;
    }
    cout << wa;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long H,W;
	scanf("%ld%ld", &H,&W);
	long height = 0;
	long width = 0;
	long sum = 0;

	if (H == 1 || W == 1)
	{
		printf("%d", 1);
		return 0;
	}
	// if (H % 2 == 0 && W % 2 == 0)
	// {
	// 	height = (H / 2);
	// 	width = (W / 2);
	// 	sum = (height * width) * 2;
	// }
	if (H % 2 && W % 2)
	{
		sum = (H / 2) * W;
		sum += (W / 2 + 1);
	}
	else if (H % 2 == 0 || W % 2 == 0)
		sum = (H * W) / 2;
	// if (H % 2 == 0 && W % 2)
	// 	sum = (H / 2) * W;
	// if (H % 2 && W % 2 == 0)
	// 	sum = (W / 2) * H;
	printf("%ld", sum);
	return (0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() 
{
   long int t,count[4]={0};
   cin>>t;
   while(t--)
   {
     string s;
     cin>>s;
     if(s=="AC")
     count[0]++;
     else if(s=="WA")
     count[1]++;
     else if(s=="TLE")
     count[2]++;
     else
     count[3]++;
   }
   cout<<"AC"<<" "<<"x"<<" "<<count[0]<<endl;
   cout<<"WA"<<" "<<"x"<<" "<<count[1]<<endl;
   cout<<"TLE"<<" "<<"x"<<" "<<count[2]<<endl;
   cout<<"RE"<<" "<<"x"<<" "<<count[3]<<endl;
   
}

Measured memory_bytes: 3620
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        sum +=s_dict[s[i]]
        s_dict[s[i]] += 1
    else:
        s_dict[s[i]] = 1
print(sum)

Measured memory_bytes: 19404
from heapq import *
n, m = map(int, input().split())

j = []
for _ in range(n):
    a,b = map(int, input().split())
    if a <= m :
        j.append((a,b))
j.sort(reverse=True)

ans = 0
q = []
for i in range(1, m+1):
    while j and j[-1][0] <= i:
        a,b = j.pop()
        heappush(q, -b)
    if q:
        ans -= heappop(q)
print(ans)


Measured memory_bytes: 17252
#include<bits/stdc++.h>
using namespace std;
int dp(int i,int sum,int cnt);
int n,p,t;
int w[109],v[109];
int memo[109][1009][109];

int main(){
  memset(memo,-1,sizeof(memo));
  cin>>n>>p;
  for(int i=0;i<n;i++){
    cin>>w[i]>>v[i];
    if(i==0){
      t=w[i];
      w[i]=0;
    }
    else w[i]-=t;
  }
  cout<<dp(0,0,0)<<endl;
  return(0);
}

int dp(int i,int sum,int cnt){
  if(memo[i][sum][cnt]!=-1)return memo[i][sum][cnt];
  if(i==n)return 0;
  int rec=dp(i+1,sum,cnt);
  if(sum+w[i]+t*(cnt+1)<=p){
    rec=max(rec,dp(i+1,sum+w[i],cnt+1)+v[i]);
  }
  return memo[i][sum][cnt]=rec;
}


Measured memory_bytes: 47104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;



public class Main {
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] parts = br.readLine().split(" ");
		
		long N = Integer.parseInt(parts[0]);
		long  K = Integer.parseInt(parts[1]);
		
		parts = br.readLine().split(" ");
		
		long[] H = new long[parts.length];
		
		for (int i = 0; i < H.length; i++) {
			H[i] = Integer.parseInt(parts[i]);
		}
		
		Arrays.sort(H);

		
		long sum = 0;
		for (int i = 0; i < H.length-K; i++) {
			sum += H[i];
	
		}
		
		System.out.println(sum);
		
		
		
	}
}


Measured memory_bytes: 66316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,z;
  cin >> x >> y >> z;
  int sum=z;
  int i,count=0;
  for(i=0;i<x;i++){
      sum+=z+y;
    if(x>=sum){
      count++;
    }else{
      break;
    }
  }
  cout << count;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n[4];
    bool a[4] = {false,false,false,false};
    cin >> n[0] >> n[1] >> n[2] >> n[3];
    REP(i,4){
        if(n[i]==1){
            a[0]=true;
        }else if(n[i]==9){
            a[1]=true;
        }else if(n[i]==7){
            a[2]=true;
        }else if(n[i]==4){
            a[3]=true;
        }
    }
    if(a[0]&&a[1]&&a[2]&&a[3]){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }


    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;
using ll=long long;
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}

int main() {
ll N;
ll ans=0;
cin >> N;

ll A[N];

FOR(i,0,N-1){
cin >> A[i];
}

FOR(i,0,N-1){
  if(A[i]%2!=0){
    ans++;
  }
}

if(ans%2==0){cout <<"YES" << endl;}
else{cout <<"NO" << endl;}



  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#define MOD 1000000007
using Int = long long;

int main() {

	Int n;
	std::cin >> n;

	Int ans = 1;

	for (Int i = 1; i <= n; i++) {
		ans *= i;
		ans %= MOD;
	}

	std::cout << ans << std::endl;

}

Measured memory_bytes: 256
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest095-B
#  https://beta.atcoder.jp/contests/abc095/tasks/abc095_B

def  makeDonutCounter(x,donutGram):
		allCount = 0
		firstLotFract = x-sum(donutGram)
		allCount = len(donutGram)
		forminCount = firstLotFract // min(donutGram)
		allCount = allCount + forminCount
		answer = allCount
		return answer


if __name__ == '__main__':
	n,x=map(int,input().split(" "))
	gramRange=range(0,n)
	donutGram=[]
	for _  in gramRange:
		donutGram.append(int(input()))
	ans=makeDonutCounter(x,donutGram)
	print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int i,j,k,n,x,y,z,a[100],b[100],s,sum;
	sum=0;
	scanf("%d %d",&n,&x);
	for(i=0;i<x;i++){
		scanf("%d",&a[i]);
	}
	scanf("%d",&y);
	for(i=0;i<y;i++){
		scanf("%d",&b[i]);
	}
	scanf("%d",&z);
	for(i=0;i<z;i++){
		scanf("%d",&s);
		sum++;
		for(j=0;j<x;j++){
			if(s==a[j]){
				sum--;
				for(k=0;k<y;k++){
					if(s==b[k]){
					sum++;
					}
				}
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll W,N,dp[2][100001],w[100002],v[100001];
  cin >> N >> W;
  REP(i,N)cin >> w[i+1] >> v[i+1];
  REP(i,2)REP(j,100001)dp[i][j] = 0;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
      if(j-w[i] >=0)
        dp[i%2][j] = max(dp[(i-1)%2][j],dp[(i-1)%2][j-w[i]]+v[i]);
      else
        dp[i%2][j] = dp[(i-1)%2][j];
    }
  }
  cout << (dp[N%2][W]) << endl;
  return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <climits>
#include <map>
using namespace std;

static const long long INFTY = (1LL<<32);


int main() {
    int n;
    cin >> n;
    
    int ans = 1;
    int value = 0;
    
    while ( n > 0 ) {
        value++;
        n /= 2;
    }
    
    while ( --value > 0 ) {
        ans *= 2;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << n - k + 1 - 1 << endl;
}

Measured memory_bytes: 384
import sys
input=sys.stdin.readline
n,k=[int(j) for j in input().split()]
a=[int(j) for j in input().split()]
mod=10**9+7
import numpy as np
dp=np.zeros((n+1,k+1),dtype=np.int64)
dp[0][0]=1
for i in range(n):
    dp[i+1]=dp[i]
    dp[i+1,a[i]+1:]-=dp[i,:-(a[i]+1)]
    np.cumsum(dp[i+1],out=dp[i+1])
    dp[i+1]%=mod
print(dp[n][k])

Measured memory_bytes: 90844
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long l,r;
  cin >> l >> r;
  long long m=2020;
  for(long long i=l;i<r;i++){
    for(long long j=i+1;j<=r;j++){
      if(m>(i*j)%2019)m=(i*j)%2019;
      if((i*j)%2019==0){
        cout << 0;
        return 0;
      }
    }
  }
  cout << m;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int money = scanner.nextInt();
        int value = (money / 500) * 1000;
        value += ((money % 500) / 5) * 5;
        System.out.println(value);
    }
}


Measured memory_bytes: 23252
N,M = map(int,input().split())
list = []
for i in range(N):
    A,B = map(int,input().split())
    list.append([A,B])
list = sorted(list)
cost = 0
while True:
    M -= list[0][1]
    if M <= 0:
        cost += list[0][0] * (list[0][1]+M)
        break
    else:
        cost += list[0][0] * list[0][1]
        list.remove(list[0])
print(cost)


Measured memory_bytes: 20816
#include <bits/stdc++.h>
using namespace std;
int n,a[3],dp[3];

int main(){
	cin >> n >> a[0] >> a[1] >> a[2];
	dp[0] = a[0] , dp[1] = a[1] , dp[2] = a[2];
	for(int i = 1 ; i < n ; i += 1){
		int newdp[3] = {0};
		cin >> a[0] >> a[1] >> a[2];
		for(int j = 0 ; j < 3 ; j += 1){
			for(int k = 0 ; k < 3 ; k += 1){
				if(j == k){
					continue;
				}
				newdp[k] = max(newdp[k],a[k]+dp[j]);
			}
		}
		for(int j = 0 ; j < 3 ; j += 1){
			dp[j] = newdp[j];
		}
	}
	cout << max({dp[0],dp[1],dp[2]}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(ALL(x));
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,e=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    cin >> a >> b >> k;
 if(k <= a)cout << a - k << ' ' << b <<endl;
 else if(k <= a+b)cout << 0 << ' ' << b - (k-a) <<endl;
 else cout << 0 << ' ' << 0 <<endl;
}

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

const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x=0):x( (x%mod + mod) % mod ) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ( (x += a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ( ( x += mod - a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        ( x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

vector<int> to[2000005];
mint ans = 0;
int n;

int dfs(int v, int p=-1) {
  int res =  1;
  vector<int> ts;
  for (int u : to[v]) {
    if (u == p) continue;
    int t = dfs(u,v);
    res += t;
    ts.push_back(t);
  }
  if(p != -1)
    ts.push_back(n-res);
  mint now = mint(2).pow(n-1) - 1;
  for (int t : ts) {
    now -= mint(2).pow(t) - 1;
  }
  ans += now;
  return res;
}
 
int main() {
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  ans /= mint(2).pow(n);
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n][2] = {};
    int c[m][2] = {};
    for(int i=0; i<n; i++){
        cin >> a[i][0] >> a[i][1];
    }
    for(int i=0; i<m; i++){
        cin >> c[i][0] >> c[i][1];
    }
    for(int i=0; i<n; i++){
        unsigned int min = 4e9;
        int ind = 0;
        for(int j=0; j<m; j++){
            int dis = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]);
            if(dis < min){
                min = dis;
                ind = j;
            }
        }
        cout << ++ind << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
def gcd(m,n):
    if n==0:
        return m
    return gcd(n,m%n)

k=int(input())
t=0
for i in range(1,k+1):
    for j in range(1,k+1):
        g=gcd(i,j)
        for k in range(1,k+1):
            if k%g==0:
                t+=g
            elif g%k==0:
                t+=k
            else:
                t+=gcd(g,k)
print(t)

            
    


Measured memory_bytes: 9472
import sys

A = [0] * 3

for i in range(3):
    A[i] = list(map(int, input().split()))

N = int(input())
for i in range(N):
    b = int(input())
    if b in A[0]:
        A[0][A[0].index(b)] = 0
    elif b in A[1]: 
        A[1][A[1].index(b)] = 0
    elif b in A[2]:
        A[2][A[2].index(b)] = 0

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2]:
        print("Yes")
        sys.exit()
    elif A[0][i] == A[1][i] == A[2][i]:
        print("Yes")
        sys.exit()

if A[0][0] == A[1][1] == A[2][2]:
    print("Yes")
    sys.exit()
elif A[0][2] == A[1][1] == A[2][0]:
    print("Yes")
    sys.exit()
else:
    print("No")

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int main(){
  int N;
  cin >> N;
  string c;
  cin >> c;

  int r_count = 0;
  int w_count = 0;

  for(int i = 0; i < N; i++){
    if(c[i] == 'R'){
      r_count ++;
    } else {
      w_count ++;
    }
  }

  int left_r_count = 0;
  int left_w_count = 0;
  int ans = min(r_count, w_count);

  for(int i = 0; i < N; i++){
    if(c[i] == 'R'){
      left_r_count ++;
    } else {
      left_w_count ++;
    }

    int right_r_count = r_count - left_r_count;
    int right_w_count = w_count - left_w_count;
    int exchange = min((i + 1) - left_r_count, (N - i - 1) - right_w_count);
    ans = min(ans, (i + 1) - left_r_count + (N - i - 1) - right_w_count - exchange);
    //ans = min(ans, (i + 1) - cur_r_count + (N - i - 1) - (w_count - cur_))
  }
  cout << ans << endl;
  return 0;
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

template<class Abel>
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

struct Point {
    int l, r;
    ll d;
};

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

    vector<Point> points(m);
    rep(i, m) cin >> points[i].l >> points[i].r >> points[i].d;
    rep(i, m) points[i].l--;
    rep(i, m) points[i].r--;
    UnionFind<ll> uf(n);
    for (Point p : points) {
        uf.merge(p.l, p.r, p.d);
    }

    for (Point p : points) {
        if (uf.diff(p.l, p.r) != p.d) {
            cout << "No" << endl;
            ret();
        }
    }
    cout << "Yes" << endl;

}




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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
  int n;
  cin >> n;
  int a[n];
  inputArray(a,n);
  int b[n];
  inputArray(b,n);
  int c[n - 1];
  inputArray(c,n - 1);
  int ans = 0;
  rep(i,n)
  {
    ans += b[a[i] - 1];
    if(i > 0 && a[i] - a[i - 1] == 1)
    {
      ans += c[a[i - 1] - 1];
    }
  }
  cout << ans << endl;
}



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

int main() {
	int n;
	string s,t;
	cin >> n >> s >> t;
	rep(i,n) {
		cout << s[i] << t[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

count = 0

while True:
    try:
        D = list(map(int, input().split()))
        if D[0] == D[1]:
            count += 1
        else:
            count = 0

        if count == 3:
            print('Yes')
            break

    except:
        print('No')
        break


Measured memory_bytes: 62292
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int open = Math.max(a - b * 2, 0);
		System.out.println(open);
		sc.close();
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define ll uint64_t
#define vi vector <int>
#define vl vector <ll>
#define dl pair <ll, ll>
#define ii pair <double, double>
#define vii vector <ii>
#define graph vector <set <int> >
#define eps 0.000000001
 
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
    int n;
    cin >> n;
    ll in;
    ll suma = 0;
    ll mayor = 0;
    for (int i = 0; i < n; i++) {
    	cin >> in;
    	mayor = max(mayor, in);
    	suma += mayor - in;
    }
    cout << suma << "\n";
    return 0;
}

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

#define pb push_back

#define ll long long

#define ft first

#define sd second

using namespace std;

const int N = 5050 ;

bool used[N];

ll z , r , w ;

ll p = -1 ;

int main(){

    string s ;
    cin >> s ;
    int n = s.size( ) ;
            int k = 0 ;
            for(int i = 0 ; i < n / 2; i ++ , k ++ ){
                if(s[i]!=s[ n - k - 1 ]){
                    z++;
                }
            }

    cout<<z;
}


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

using namespace std;

int main() {

  int n, w, d, p, s;

  while(1){
    cin>>n>>w>>d;
    if(n==0 && w==0 && d==0) break;

    vector< vector<int> > v;

    vector<int> a(3);
    a[0] = w*d;
    a[1] = w;
    a[2] = d;
    v.push_back(a);

    for(int i=0; i<n; i++){
      cin>>p>>s;
      int sd = s % (2*v[p-1][1] + 2*v[p-1][2]);
      vector<int> b1(3), b2(3);

      if(sd < v[p-1][1]){
        //cout<<"case1"<<endl;
        b1[0] = v[p-1][0] * sd / v[p-1][1];
        b2[0] =  v[p-1][0] - b1[0];
        b1[1] = sd; b2[1] = v[p-1][1] - b1[1];
        b1[2] = b2[2] = v[p-1][2];
      }else if(v[p-1][1] < sd && sd < v[p-1][1] + v[p-1][2]){
        //cout<<"case2"<<endl;
        b1[0] = v[p-1][0] * (sd - v[p-1][1]) / v[p-1][2];
        b2[0] =  v[p-1][0] - b1[0];
        b1[1] = b2[1] = v[p-1][1];
        b1[2] = sd - v[p-1][1]; b2[2] = v[p-1][2] - b1[2];
      }else if(v[p-1][1] + v[p-1][2] < sd && sd < 2*v[p-1][1] + v[p-1][2]){
        //cout<<"case3"<<endl;
        b1[0] = v[p-1][0] * (sd - (v[p-1][1] + v[p-1][2])) / v[p-1][1];
        b2[0] =  v[p-1][0] - b1[0];
        b1[1] = sd - (v[p-1][1] + v[p-1][2]); b2[1] = v[p-1][1] - b1[1];
        b1[2] = b2[2] = v[p-1][2];
      }else{
        //cout<<"case4"<<endl;
        b1[0] = v[p-1][0] * (sd - (2*v[p-1][1] + v[p-1][2])) / v[p-1][2];
        b2[0] =  v[p-1][0] - b1[0];
        b1[1] = b2[1] = v[p-1][1];
        b1[2] = sd - (2*v[p-1][1] + v[p-1][2]); b2[2] = v[p-1][2] - b1[2];
      }

      if(b1[0] < b2[0]){
        v.push_back(b1);
        v.push_back(b2);
      }else{
        v.push_back(b2);
        v.push_back(b1);
      }
      v.erase(v.begin() + (p - 1) );

    }

    sort(v.begin(), v.end());
    for(int i=0; i<(int)v.size(); i++){
      cout<<v[i][0];
      if(i != (int)v.size() - 1) cout<<" ";
    }
    cout<<endl;

  }

  return 0;
}

Measured memory_bytes: 3112
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_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;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}


#define VERTEX_MAX 100000
// undirected
#define EDGE_MAX (100000*2)
struct list {
    struct list *next;
    int dst;
};

struct list *create_graph(int vs) {
    static struct list graph[VERTEX_MAX];
    int i;
    for(i = 0; i < vs; i++) {
        graph[i].next = &graph[i];
    }
    return graph;
}

struct list lpool[EDGE_MAX];
int lidx = 0;

void add_list(struct list *head, int v) {
    struct list *elem = &lpool[lidx++];
    elem->dst = v;
    elem->next = head->next;
    head->next = elem;
}

void get_dist(struct list *graph, int node, int parent, int *out) {
    if(parent == -1) {
        out[node] = 0;
    } else {
        out[node] = out[parent]+1;
    }
    struct list *elem;
    struct list *head = &graph[node];
    for(elem = head->next; elem != head; elem = elem->next) {
        if(elem->dst == parent) continue;
        get_dist(graph, elem->dst, node, out);
    }
    return;
}


int main(void) {
    int num = get_int();
    struct list *graph = create_graph(num);
    int i;
    for(i = 0; i < num-1; i++) {
        int v1, v2;
        get_int2(&v1, &v2);
        v1--; v2--;
        add_list(&graph[v1], v2);
        add_list(&graph[v2], v1);
    }

    static int aout[VERTEX_MAX];
    static int bout[VERTEX_MAX];
    get_dist(graph, 0, -1, aout);
    get_dist(graph, num-1, -1, bout);

    int blacks = 0;
    int whites = 0;
    for(i = 0; i < num; i++) {
        if(aout[i] <= bout[i]) {
            blacks++;
        } else {
            whites++;
        }
    }
#ifdef DEBUG
    printf("%d vs %d\n", blacks, whites);
#endif
    printf("%s\n", blacks > whites ? "Fennec" : "Snuke");
    return 0;
}

Measured memory_bytes: 11904
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
# ... 最小側の制約も確認した？
# ... オーバーフローしない？
n = int(input())
blue = [input() for i in range(n)]
k = int(input())
red = [input() for i in range(k)]
T={}
for x in blue:
    if x not in T: T[x] = 1
    else: T[x]+=1
for x in red:
    if x not in T: T[x] = -1
    else: T[x]-=1
print(max(max(T.values()), 0))

Measured memory_bytes: 9336
#include<stdio.h>

int gcd(int a,int b,int c)
{
    int min = a;
    if(a<b&&a<c)
    {
        min = a;
    }
    if(b<a&&b<c)
    {
        min = b;
    }
    if(c<a&&c<b)
    {
        min = c;
    }
    for(int i=min;0<i;i--)
    {
        if(a%i==0&&b%i==0&&c%i==0)
        {
            return i;
        }
    }
}

int main(void)
{
    int k,sum=0;
    scanf("%d",&k);
    for(int i=1;i<=k;i++)
        for(int j=1;j<=k;j++)
            for(int l=1;l<=k;l++)
            {
                sum = sum + gcd(i,j,l);
            }
    printf("%d",sum);

}

Measured memory_bytes: 1732
//arc060_c.cpp
//Sat Jun 23 13:19:44 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

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

	int x[50];
	for (int i=0;i<n;i++){
		cin >> x[i+1];
	}

	ll dptable[51][51][2501];

	for (int j=0;j<=n;j++){
		for (int k=0;k<=n;k++){
			for (int s=0;s<=2500;s++){
				if (j==0 && k==0 && s==0){
					dptable[j][k][s] = 1;
				}else if (j>=1 && s<x[j]){
					dptable[j][k][s] = dptable[j-1][k][s];
				}else if (j>=1 && k>=1 && s>=x[j]){
					dptable[j][k][s] = dptable[j-1][k][s] + dptable[j-1][k-1][s-x[j]];
				}else {
					dptable[j][k][s] = 0;
				}
			}
		}
	}

	ll ans = 0;

	for (int k=1;k<=n;k++){
		ans += dptable[n][k][k*a];
	}

	cout << ans << endl;
}

Measured memory_bytes: 51072
# include <bits/stdc++.h>
using namespace std;
int s[3];
int main ()
{
    int n;
	int a,b;
	cin>>n>>a>>b;   
	for (int i=1;i<=n;++i)
	   {
	   	int p; 
	   	cin>>p;
	   	if (p<=a)
	   	   s[0]++;
	   	if (a<p&&p<=b)
	   	  s[1]++;
	   	if (p>b)
	   	  s[2]++;
	   }
	sort (s,s+3);
	printf ("%d\n",s[0]);
	return 0;
}

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

int main() {
    string S;
    cin >> S;
    int p = 700;
    for(int i = 0; i < 3; ++i) {
        if(S[i] == 'o') {
            p += 100;
        }
    }
    cout << p << endl;
}


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

int main() {
    int n;
    cin >> n;
    int k = 1, sum = 0;
    while (sum + k < n) {
        sum += k;
        k += 1;
    }
    cout << k << "\n";
    return 0;
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int n;
string s, t;
string ans;

int main()
{
    cin >> n;
    cin >> s >> t;

    rep(i, n)
    {
        ans += s[i];
        ans += t[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstring>
#include<algorithm>
#include<cstdio>

using namespace std;

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

int H, A[MAX+1];

void maxHeapify(int i){
    int l, r, largest;
    l=2*i;
    r=2*i+1;

    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(largest);
  }
}

int extract(){
  int maxv;
  if(H < 1)
     return -INF;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}

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

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

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s", com);
    if(com[0] == 'e' && com[1] == 'n') 
          break;
    if(com[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n", extract());
    }
  }

  return 0;
}





Measured memory_bytes: 6628
import java.util.Scanner;

public class Main {

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

        String s = sc.next();

        sc.close();

        int max = 0;
        int cnt = 0;

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'A' || s.charAt(i) == 'G' || s.charAt(i) == 'C' || s.charAt(i) == 'T') {
                cnt++;
                max = Math.max(max, cnt);
            } else {
                cnt = 0;
            }
        }

        System.out.println(max);

    }
}

Measured memory_bytes: 23124