akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int cnt = 0; string S, T; cin >> S >> T;
    for (int i = 0; i < 3; ++i) if (S[i] == T[i]) cnt++;
    printf("%d\n", cnt);
}


Measured memory_bytes: 256
def check(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    d = 3
    while d * d <= n:
        if n % d == 0:
            return False
        d += 2
    return True


x = int(input())
while True:
    if check(x):
        print(x)
        break
    x += 1


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <string>
#include <math.h>
#include <stdint.h>
#include <bitset>
#include <iomanip>

using namespace std;

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

  double result = pow((L/3.0), 3.0);

  cout << std::setprecision(15) << result << endl; 
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;
int n;
int d[100];
int main() {
	cin >> n;
	int t=0;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (n == i * j) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
class Unionfind
  attr_accessor(:par, :size)

  def initialize(n)
    @par = Array.new(n+1)
    (n+1).times do |i|
      @par[i] = i
    end
    @size = Array.new(n+1,1)
  end

  def root(x)
    while @par[x] != x
      x = @par[@par[x]]
      @par[x] = @par[@par[x]]
    end
    x
  end

  def unite(x,y)
    rx = root(x)
    ry = root(y)
    if rx != ry
      @size[ry] += size(rx)
      @par[rx] = ry
    end
  end

  def same(x,y)
    return root(x)==root(y)
  end

  def size(x)
    if @par[x] == x
      @size[x]
    else
      size(root(par[x]))
    end
  end

end

N,M = gets.chomp.split(" ").map(&:to_i)
x,y,z = M.times.map{gets.split.map(&:to_i)}.transpose
tree = Unionfind.new(N)
cnt = N
M.times do |i|
  if !tree.same(x[i],y[i])
    tree.unite(x[i],y[i])
    cnt -= 1
  end
end
puts cnt

Measured memory_bytes: 24924
//============================================================================
// Name        : timecard.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int h1,m1,s1; //Aさんの出社時刻
	int h2,m2,s2; //Bさんの退社時刻

	for(int i=0; i<3;i+=1){


		cin >>h1>> m1 >> s1;
		cin >>h2>> m2 >> s2;

		int h=h2-h1;
		int m=m2-m1;
		int s=s2-s1;


		int k =0;
		if(s<0){
			k=1;
			s= s+ 60;
		}
		m =m2-m1-k;
		k=0;
		if(m<0){
			k=1;
			m= m+ 60;
		}
		h =h2-h1-k;
		k=0;


		cout <<h<<" "<<m<<" " <<s<<endl;

	}



	return 0;
}

Measured memory_bytes: 1160
// need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
//#include <chrono>
#include <random>
#include <numeric>
#define INF 1000000005

using namespace std;
long a[100005];

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a+n);
  while(a[0] != a[n-1]){
	for(int i = 1; i < n; i++){
      if(a[i] % a[0] == 0)
        a[i] = a[0];
      if(a[0] < a[i])
        a[i] = a[i] % a[0];
    }
    sort(a,a+n);
  }
  cout << a[0] << endl;
  return 0;
}


Measured memory_bytes: 1024
//#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 2e5 + 55, mod = 1e9 + 7 , i2 = (mod+1)/2;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;cin >> n;cout <<(n+1)/2;
}



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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<pair<ll, ll>> vec;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		vec.push_back(make_pair(a, b));
	}
	sort(vec.begin(), vec.end());

	ll res = vec[n-1].first + vec[n-1].second;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
template<typename T>
void print_to(std::ostream &os,const char *,const char *tail,const T &fst){
  os<<fst<<tail;
}
template<typename Fst,typename... Rst>
void print_to(std::ostream &os,const char *del,const char *tail,const Fst &fst,const Rst &... rst){
  os<<fst<<del;
  print_to(os,del,tail,rst...);
}
template<typename Iter>
void print_to_(std::ostream &os,const char *del,const char *tail,Iter bgn,Iter end){
  for(Iter it=bgn;it!=end;){
    os<<*it;
    if(++it!=end)os<<del;
    else os<<tail;
  }
}
template<typename Fst,typename... Rst>
void println(const Fst &fst,const Rst &... rst){
  print_to(std::cout,"\n","\n",fst,rst...);
}
template<typename Fst,typename... Rst>
void print(const Fst &fst,const Rst &... rst){
  print_to(std::cout," ","\n",fst,rst...);
}
template<typename Iter>
void println_(Iter bgn,Iter end){
  print_to_(std::cout," ","\n",bgn,end);
}
using namespace std;
//const ll MOD=(ll)1e9+7;
const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
int ma,mb;
int a[41],b[41],c[41];
ll dp[41][401][401];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>n>>ma>>mb;
  int suma=0,sumb=0;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
    suma+=a[i];
    sumb+=b[i];
  }
  ll ans=inf;
  int nowma=0,nowmb=0;
  while(nowma+ma<=suma && nowmb+mb<=sumb){
    nowma+=ma;nowmb+=mb;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=nowma;j++){
        for(int k=0;k<=nowmb;k++){
          dp[i][j][k]=inf;
        }
      }
    }
    dp[0][0][0]=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<=nowma;j++){
        for(int k=0;k<=nowmb;k++){
          if(j+a[i]<=nowma && k+b[i]<=nowmb){
            dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
          }
          dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
        }
      }
    }
    ans=min(ans,dp[n][nowma][nowmb]);
  }
  if(ans==inf)print(-1);
  else print(ans);
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}






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

int main(){
 string s,t;
  cin >> s >> t;
  int cnt = 0;
  int n = s.size();
  for(int i = 0; i < n; i++){
  	if(s[i] != t[i])
      cnt++;
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int e=a+b,f=c+d;
	if(e>f)cout<<"Left";
	else if(e==f)cout<<"Balanced";
	else if(e<f)cout<<"Right";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N, D;
    scanf("%d %d", &N, &D);
    int ans = N / (2 * D + 1) + (N % (2 * D + 1) != 0 ? 1 : 0);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n) , b(n) , c(n);
  
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
  
	int dp[n + 100][3];
	for(int i = 0; i < n + 100; i++){
		for(int j = 0; j < 3; j++){
			dp[i][j] = 0;
		}
	}
  
	for(int i = 1; i <= n; i++){
		dp[i][0] += max((dp[i - 1][1] + a[i - 1]) , (dp[i - 1][2] + a[i - 1])); 
		dp[i][1] += max((dp[i - 1][0] + b[i - 1]) , (dp[i - 1][2] + b[i - 1])); 
		dp[i][2] += max((dp[i - 1][0] + c[i - 1]) , (dp[i - 1][1] + c[i - 1])); 
	}
  
	long long ans = max({dp[n][0] , dp[n][1] , dp[n][2]});
  
	cout << ans << endl;
  
	return 0;
}
 


Measured memory_bytes: 5552
using System;
using System.Linq;
using System.Collections.Generic;

public class Prime{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
         
        var primeFactors = PrimeFactors(n);
         
        string output = primeFactors.Count() == 0 
                        ? n.ToString() 
                        : string.Join(" ", primeFactors.Select (f => f.ToString()).ToArray()); //AOJ??¨
                        //:string.Join(" ", primeFactors);
        Console.WriteLine("{0}: {1}", n, output);
    }
     
    public static IEnumerable<int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
         
        while (i * i <= n)
        {
            if(tmp % i == 0){
                tmp /= i;
                yield return i;
            }else{
                i++;
            }
        }
		if(tmp != 1) yield return tmp;
    }
}

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	string w;
	cin >> w;
	map<char, int> mp;
	rep(i, w.size()) {
		mp[w[i]]++;
	}
	bool ok = true;
	for (char c = 'a'; c <= 'z'; ++c) {
		if (mp[c] % 2 == 1) ok = false;
	}
	if (ok) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}



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

int f(int x){
  if(x == 0 || x == 1) return 0;
  
  return x * (x - 1)/2;
}

  
int main(){
  int n, m;
  cin >> n >> m;
  
  cout << f(n) + f(m) << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;
ll dp[100005][13];
static const ll MOD =1000000007;

int main(){
    string S;
    int n;
    ll ans = 0;

    cin >> S;
    n = S.size();

    dp[0][0] = 1;
    for(int i=0; i<n; i++){
        int c;
        if(S[i]=='?') c=-1;
        else c=S[i] - '0';

        for(int j=0; j<10; j++){
            if(c != -1 && c != j) continue;
            for(int k=0; k<13; k++){
                dp[i+1][(k*10+j)%13] += dp[i][k];
            }
        }
        for(int j=0; j<13; j++){
            dp[i+1][j] %= MOD;
        }
    }
    ans = dp[n][5];

    cout << ans << endl;
    return 0;
}

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

template <int char_size, int margin>
struct Trie{
    struct TrieNode{
        int nxt[char_size];
        vector<int> idx;
        TrieNode(){
            fill(nxt, nxt+char_size, -1);
        }
    };

    vector<TrieNode> nodes;
    Trie(){
        nodes.push_back(TrieNode());
    };
    void add(const string &str, int id){
        int node_index = 0;
        nodes[0].idx.push_back(id);
        for(int i=0;i<int(str.size());i++){
            int c = str[i] - margin;
            if(nodes[node_index].nxt[c] == -1){
                nodes[node_index].nxt[c] = int(nodes.size());
                nodes.push_back(TrieNode());
            }
            node_index = nodes[node_index].nxt[c];
            nodes[node_index].idx.push_back(id);
        }
    }
    void add(const string &str){
        add(str, int(nodes[0].idx.size()));
    }
    int find(const string &str){
        int node_index = 0;
        for(int i=0;i<int(str.size());i++){
            int c = str[i] - margin;
            if(nodes[node_index].nxt[c] == -1){
                return -1;
            }
            node_index = nodes[node_index].nxt[c];
        }
        return node_index;
    }
};

int N, Q;
vector<string> words;
Trie<26, 'a'> trie;
vector<int> ls;

int main() {
    cin >> N >> Q;
    words.resize(N);
    for(int i=0;i<N;i++) cin >> words[i];
    sort(words.begin(), words.end());
    // suffix trie木の構築
    for(int i=0;i<N;i++){
        reverse(words[i].begin(), words[i].end());
        trie.add(words[i]);
        reverse(words[i].begin(), words[i].end());
    }
    string pre, suf;
    for(int i=0;i<Q;i++){
        cin >> pre >> suf;
        // suffixの一致するnodeを探索
        reverse(suf.begin(),suf.end());
        int id = -1;
        if((id = trie.find(suf)) < 0 || id >= trie.nodes.size()){
            cout << 0 << endl;
            continue;
        }
        ls = trie.nodes[id].idx;  // suffixの一致する文字列の番号集合
        // prefixを二分探索
        int lo, hi;
        lo = lower_bound(words.begin(), words.end(), pre) - words.begin();
        lo = lower_bound(ls.begin(), ls.end(), lo) - ls.begin();
        pre += '~';
        hi = lower_bound(words.begin(), words.end(), pre) - words.begin();
        hi = lower_bound(ls.begin(), ls.end(), hi) - ls.begin();
        cout << hi - lo << endl;
    }
    return 0;
}



Measured memory_bytes: 307784
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int X;
  cin>>X;
  if(X==3 || X==5 || X==7){
    cout<< "YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  
}


Measured memory_bytes: 256
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 1000000007
	limit = 10**18
	ans = 0
	start = {}
	def pre(arr):
		ans = [arr[0]]
		for i in range(1,len(arr)):
			ans.append((ans[-1] + arr[i])%mod)
		return ans
	for test in range(tests):
		[n,k] = inlt()
		a = inlt()
		dp = [[0 for j in range(k+1)] for i in range(n)]
		for i in range(0,a[0]+1):
			dp[0][i] = 1
		pre_sum = pre(dp[0])
		for i in range(1,n):
			for j in range(0,k+1):
				lower = max(j - a[i],0)
				dp[i][j] = (pre_sum[j] - pre_sum[lower] + dp[i-1][lower])%mod
			pre_sum = pre(dp[i])
		# print(dp)
		print(dp[-1][-1]) 

				





		
		


if __name__== "__main__":
	main()

Measured memory_bytes: 223696
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 area = a * b;
        int length = (a + b)*2;
        System.out.println(area + " " + length);
    }
}


Measured memory_bytes: 26212
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MOD 1000000007

ll mypow(ll n, ll k) {
	ll cur = n;
	ll ret = 1;
	while (k) {
		if (k & 1) {
			ret *= cur;
			ret %= MOD;
		}
		k >>= 1;
		cur *= cur;
		cur %= MOD;
	}
	return ret;
}

ll divide(ll a, ll b) {
	ll invb = mypow(b, MOD - 2);
	return (a * invb) % MOD;
}

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

ll lcm(ll a, ll b) {
	return (divide(a * b, lcd(a, b))) % MOD;
}

#define MAXN (1 << 20)

ll a[MAXN];
ll f[MAXN];

void up(ll val, int pos) {
	f[pos] = max(f[pos], val);
}

ll cnt(ll & x, int t) {
	int ret = 0;
	while (x % t == 0) {
		x /= t;
		ret++;
	}
	return ret;

}

void factor(ll x) {
	ll y = x;
	for (int i = 2; i * i <= x; i++) {
		up(cnt(y, i), i);
	}
	if (y > 1) {
		up(1, y);
	}
}

int main() {
	int n;
	ll x = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		factor(a[i]);
	}
	for (int i = 2; i < MAXN; i++) {
		for (int j = 0; j < f[i]; j++) {
			x *= i;
			x %= MOD;
		}
	}
	ll ret = 0;
	for (int i = 0; i < n; i++) {
		ret += divide(x, a[i]);
		ret %= MOD;
	}
	cout << ret << endl;

	return 0;
}


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

int main(){
 int a, b, c, k, ans = 0;
 cin >> a >> b >> c >> k;
 
  if( a <= k ){
    ans += a;
    if( k - a < b ){
      ans = ans; 
    }
    else{
      ans -= k - a - b;
    }
  }
  else{
    ans += k;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;

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

        int n = sc.nextInt();
        long[] v = new long[n];
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
        }

        HashMap<Long, Long> evenMap = new HashMap<>();
        HashMap<Long, Long> oddMap = new HashMap<>();

        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                if (!evenMap.containsKey(v[i])) {
                    evenMap.put(v[i], 1L);
                } else {
                    evenMap.put(v[i], evenMap.get(v[i]) + 1L);
                }
            } else {
                if (!oddMap.containsKey(v[i])) {
                    oddMap.put(v[i], 1L);
                } else {
                    oddMap.put(v[i], oddMap.get(v[i]) + 1);
                }
            }
        }

        List<Map.Entry<Long, Long>> evenEntries = new ArrayList<Map.Entry<Long, Long>>(evenMap.entrySet());
        List<Map.Entry<Long, Long>> oddEntries = new ArrayList<Map.Entry<Long, Long>>(oddMap.entrySet());

        Collections.sort(evenEntries, new Comparator<Map.Entry<Long, Long>>() {
            @Override
            public int compare(Map.Entry<Long, Long> o1, Map.Entry<Long, Long> o2) {
                return o2.getValue().compareTo(o1.getValue());
            }
        });

        Collections.sort(oddEntries, new Comparator<Map.Entry<Long, Long>>() {
            @Override
            public int compare(Map.Entry<Long, Long> o1, Map.Entry<Long, Long> o2) {
                return o2.getValue().compareTo(o1.getValue());
            }
        });

        long ret = 0;

        if (!evenEntries.get(0).getKey().equals(oddEntries.get(0).getKey())) {
            ret = evenEntries.get(0).getValue() + oddEntries.get(0).getValue();
            // ここから下は, 最上位のkeyが同じ
        } else if (evenEntries.get(0).getValue() == n/2 && oddEntries.get(0).getValue() == n/2) { // 偶奇ともに1種類しかない
            ret = n/2;
        } else if (evenEntries.get(0).getValue() == n/2) { // 偶数が1種類しかない, 奇数は2種類以上
            ret = oddEntries.get(1).getValue();
        } else if (oddEntries.get(0).getValue() == n/2) { // 奇数が1種類しかない, 偶数は2種類以上
            ret = evenEntries.get(1).getValue();
        } else {
            ret = Math.max(oddEntries.get(0).getValue() + evenEntries.get(1).getValue(), evenEntries.get(0).getValue() + oddEntries.get(1).getValue());
        }

        System.out.println(n - ret);
    }
}

Measured memory_bytes: 62268
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[100010], B[100010];A[0] = 0;B[0] = 0;
    for(int i = 1;i <= N + 1;i++){
        cin >> A[i];
    }
    for(int i = 1;i <= N;i++){
        cin >> B[i];
    }
    
    long long ans = 0;
    for(int i = 1;i <= N + 1;i++){
        if(A[i] <= B[i - 1]){ans += A[i];B[i - 1] -= A[i];}
        else if(B[i - 1] + B[i] >= A[i]){B[i] -= A[i] - B[i - 1];ans += A[i];}
        else{ans += B[i - 1] + B[i];B[i] = 0;}
    }
    cout << ans;
}



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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)

typedef pair<int, int> P;
struct Order {
    bool operator()(P const& a, P const& b) const {
        return a.second < b.second || a.second == b.second && a.first < b.first;
    }
};

vector<long long int> v[110000];

int main() {

    int n, m; cin >> n >> m;

    rep(i, n) {
        int a,b; cin >> a >> b;
        // お金をもらえるまでの日数ごとにまとめておく
        v[a].push_back(b);
    }


    ll ans = 0;
    // 優先度付きキューのソート順でsecond(金額)の大きい順にする
    priority_queue< P, vector<P>, Order> Q;

    // m-1日後から逆に計算していく
    // m-1日時点でお金がもらえるのはa=1の仕事のみ、それらをPriorityQueueにpushする
    // そのまま、優先度付きキューから先頭要素を取り出す。
    // 次にm-2日語時点では、a=1 or a=2の仕事のみ取り出せる。 a=1の仕事はすでに1つ前のループ内でいれられているので, a=2を入れる
    // PriorityQueueの仕様でa=1, a=2の中で最大の金額がもらえるものが得られる.
    for(int i=1; i <= m; i++) {

        // 1日ごとにPriorityQueueに利用可能な仕事をいれていくのが肝
        rep(j, v[i].size()) {
            P tmp = make_pair(i, v[i][j]);
            Q.push(tmp);
        }

        if(!Q.empty()) {
            ans += Q.top().second;
            Q.pop();
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e9;
ll mod=998244353 ;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
//#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define SIZE 5000 + 1

long long expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M)%M;
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}
bool is_pali(string s)
{
    int n=s.length();
    for(int i=0;i<(s.length()/2);i++)
    {
        if(s[i]!=s[n-1-i])return false;
    }
    return true;
}

void solve()
{
 double L;cin>>L;
 double ans=(L/3)*(L/3)*(L/3);
 cout<<fixed<<setprecision(6)<<ans;

}

int main(){
    boost;
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
  COMinit();
  int n,k;
  cin>>n>>k;
  
  
  
  for(int i=1;i<=k;i++){
    int q=i;
    if(q-1>n-k){
      cout<<0<<endl;
    continue;}
      ll val=1;
    

  val*=COM(k-1, q-1);
    val*=COM(n-k+1, q);
    val%=MOD;
    cout<<val<<endl;
  }
    
    
  
  
  
  
 
 
}

Measured memory_bytes: 12160
//C:\Program Files(x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\x86_64-w64-mingw32\bits\stdc++.h
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

const int INF=1e9+7;

int n;
int a[4005],b[4005];
int dp[4005][4005];

struct Binary_Indexed_Tree{
	int sum[4005];
	void init(){
		memset(sum,0,sizeof(sum));
	}
	void add(int x){
		while(x<=2*n){
//			printf("%d\n",x);
			sum[x]+=1;
			x+=x&(-x);
		}
		return;
	}
	int query(int x){
		int res=0;
		while(x){
//			printf("%d\n",x);
			res+=sum[x];
			x-=x&(-x);
		}
		return res;
	}
	void out(){
		for(int i=1;i<=2*n;i++) printf("%d ",sum[i]);
		puts("");
		return;
	}
}BIT;

int main(){
	cin>>n;
	for(int i=1;i<=n*2;i++){
		char c;
		int d;
		cin>>c>>d;
		if(c=='W') a[d]=i;
		else b[d]=i;
	}
//	for(int i=1;i<=n;i++){
//		printf("%d ",a[i]);
//	}
//	puts("");
//	for(int i=1;i<=n;i++){
//		printf("%d ",b[i]);
//	}
//	puts("");
	for(int i=0;i<=n*2;i++){
		for(int j=0;j<=n*2;j++) dp[i][j]=INF;
	}
	dp[0][0]=0;
	for(int i=0;i<=n;i++){
		BIT.init();
		for(int j=1;j<=i;j++) BIT.add(a[j]);
		for(int j=0;j<=n;j++){
			if(j) BIT.add(b[j]);
//			printf("i=%d j=%d\n",i,j);
//			BIT.out();
			if(i<n){
//				printf("i=%d j=%d dp[i][j]=%d res=%d dp[i+1][j]=%d\n",i,j,dp[i][j],(a[i+1]-1-BIT.query(a[i+1]-1)),dp[i+1][j]);
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(a[i+1]-1-BIT.query(a[i+1]-1)));
			}
			if(j<n){
//				printf("i=%d j=%d dp[i][j]=%d res=%d dp[i][j+1]=%d\n",i,j,dp[i][j],(b[j+1]-1-BIT.query(b[j+1]-1)),dp[i][j+1]);
				dp[i][j+1]=min(dp[i][j+1],dp[i][j]+(b[j+1]-1-BIT.query(b[j+1]-1)));
			}
		}
	}
/*	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++) printf("%d ",dp[i][j]);
		puts("");
	}
*/	printf("%d\n",dp[n][n]);
	return 0;
}


Measured memory_bytes: 62848
#include <iostream>
#include <algorithm>
using namespace std;
int A[200000] = {0};
int N;
int main(void){
    cin >> N;
    
    for (int i=0; i<N; i++)
    {
        cin >> A[i];
    }
    
    std::sort(A, A+N);
    
    for (int i=0; i<N-1; i++)
    {
        if(A[i] == A[i+1])
        {
            cout << "NO";
            return 0;
        }
    }
    
    cout << "YES";
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<complex>
#include<cmath>

#define ERROR 0x00
#define FRONT 0x01
#define RIGHT 0x02
#define BACK 0x04
#define LEFT 0x08
#define OVER 0x10

#define sc second
#define fr first

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

using namespace std;

typedef double elem;
typedef complex<elem> point,vec;
typedef pair<point,point> line,seg,pp;

const double eps = 1.0e-4;
const double pi = acos(-1.0);
const double infty = 1e10;
point base(0,0);

bool eq(elem a, elem b){ return abs(a-b) < eps; }
bool lt(elem a, elem b){ return !eq(a,b) && a < b; }
bool leq(elem a, elem b){ return eq(a,b) || a < b; }
bool gt(elem a, elem b){ return !eq(a,b) && a > b; }
bool geq(elem a, elem b){ return eq(a,b) || a > b; }
bool ltz(elem a){ return lt( a, 0 ); }
bool gtz(elem a){ return gt( a, 0 ); }
bool eqv(vec a, vec b){ return eq( abs(b-a),0); }
bool is_zv(vec v){ return eq(abs(v),0); }

bool far(point a, point b){ return gtz( abs(b-a) ); }
bool near(point a, point b){ return leq( abs(b-a), 0 ); }
elem dot(vec a, vec b){ return (a.real() * b.real() + a.imag() * b.imag() ); }
elem cross(vec a, vec b){ return ( a.real() * b.imag() - a.imag() * b.real() ); }
elem varg(vec a, vec b){
  elem ret=arg(a)-arg(b);
  if(lt(ret,0))ret+=2*pi;
  if(gt(ret,2*pi))ret-=2*pi;
  if(eq(ret,2*pi))ret=0;
  return ret;
}
int ccw(point a, point b, point x){
  b -= a;
  x -= a;
  // if( is_zv(b) || is_zv( x ) ) return ERROR;
  if( gtz( cross(b,x) ) ) return LEFT;
  if( ltz( cross(b,x) ) ) return RIGHT;
  if( ltz( dot(b,x) ) ) return BACK;
  if( abs(b) < abs(x) ) return FRONT;
  return OVER;
}

int main(){
  while(true){
    int n ;
    elem ans=0;
    vector<point> vp;
    bool vis[500]={false,};
    cin >> n;
    if( n == 0 ) break;
    vp.push_back(point(0,0));
    REP(i,n){
      elem x,y;
      cin >> x >> y;
      vp.push_back(point(x,y));
    }
    point prev=point(0,-10);
    point now=vp[0];
    vis[0]=true;
    while(true){
      int next_vis=0;
      elem min_arg=3*pi;
      elem min_dist=infty;
      point next=vp[0];
      REP(i,vp.size()){
	if(!vis[i]){
	  elem t = varg(now-prev,vp[i]-now);
	  // cout << now << " -> " << vp[i] << " = " << t << endl;
	  if( leq( t, min_arg ) ){
	    if( eq( t, min_arg ) ){
	      if( lt( abs(vp[i]-now), min_dist) ){
		min_dist = abs(vp[i]-now);
	      }else continue;
	    }
	    min_arg = t;
	    min_dist = lt(abs(vp[i]-now),min_dist)?abs(vp[i]-now):min_dist;
	    next = vp[i];
	    next_vis = i;
	  }
	}
      }
      // cout << " NEXT : " << next << endl;
      if( next_vis == 0 ) break;
      else{
	ans+=abs(next-now);
	prev=now;
	now=next;
	vis[next_vis]=true;
      }
    }
    printf("%.1lf\n",ans);
  }
}

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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    int N, T;
    cin >> N >> T;
    int cost[N];
    for(int i = 0; i < N; i++){
        cin >> cost[i];
    }
    int profits_max = 0, cost_max = 0;
    for(int i = N - 1; i >= 0; i--){
        cost_max = max(cost_max, cost[i]);
        profits_max = max(profits_max, cost_max - cost[i]);
    }
    int ans = 0;
    cost_max = 0;
    for(int i = N - 1; i >= 0; i--){
        cost_max = max(cost_max, cost[i]);
        if(cost_max == cost[i] + profits_max){
            ans++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i){ return accumulate(f, l, i); }


string S;
VI r, l;
int ans[100010];


signed main(){
    cin >> S;

    rep(i, 0, SZ(S))
        if(S[i] == 'R') r.pb(i);
        else l.pb(i);

    rep(i, 0, SZ(S)){
        int d;
        if(S[i] == 'R'){
            d = *lb(ALL(l), i);
            if((d-i)%2) ans[d-1]++;
            else ans[d]++;
        }
        else {
            d = *(lb(ALL(r), i)-1);
            if((i-d)%2) ans[d+1]++;
            else ans[d]++;
        }
    }

    rep(i, 0, SZ(S)) cout << ans[i] << ' ';
    cout << endl;

    return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>
#include<string.h>

#define  L 1000000

char dic[L][12];

int getChar(char);
long long getnum(char*);
int A(int);
int B(int);
int finditem(char*);
int insert(char*);

int getChar(char x)
{
  if(x == 'A') {
    return 1;
  }else if(x == 'C') {
    return 2;
  }else if(x == 'G') {
    return 3;
  }else if(x == 'T') {
    return 4;
  }else{
    return 0;
  }
 }
  
long long getnum(char *lan)
{
  long long sum = 0,a=1,i;

  for(i=0;i<strlen(lan);i++) {
    sum += a*(getChar(lan[i]));
    a *= 5;
  }
  return sum;
}

int A(int num)
{
  return num % L;
}

int B(int num)
{
  return 1 + (num % (L-1));
}

int finditem(char *lan)
{
  long long num,i,b;

  num = getnum(lan);

  for(i=0;;i++) {
    b = (A(num) + i * B(num)) % L;
    if(strcmp(dic[b],lan) == 0)
       return 1;
    else if(strlen(dic[b]) == 0)
       return 0;
  }
  return 0;
}
  
int insert(char *lan)
{
  long long num,i,c;

  num = getnum(lan);

  for(i=0;;i++) {
    c = (A(num) + i * B(num)) % L;
    if(strcmp(dic[c],lan) == 0)
      return 1;
    else if(strlen(dic[c]) == 0) {
      strcpy(dic[c],lan);
      return 0;
    }
  }
  return 0;
}


int main()
{
  int n,i;
  char lan[12],rei[9];

  for(i=0;i<L;i++)
    dic[i][0] = '\0';

  scanf("%d",&n);

  for(i=0;i<n;i++) {
    scanf("%s%s",rei,lan);
    if(rei[0] == 'i') {
      insert(lan);
    }else{
      if(finditem(lan)) {
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
  return 0;
}
  



Measured memory_bytes: 13452
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000;
long long tenpow(int n){
  long long ans = 1;
  for (int i = 0; i < n; i++){
    ans *= 10;
  }
  return ans;
}
long long dfs(long long D, int mul, vector<pair<long long, map<int, int>>> &add, vector<long long> &sum, int p){
  int cnt = add.size();
  if (p == cnt){
    return mul;
  } else {
    long long ans = 0;
    long long x = add[p].first;
    for (auto P : add[p].second){
      long long next = D + x * P.first;
      if (abs(next) <= sum[p]){
        ans += dfs(next, mul * P.second, add, sum, p + 1);
      }
    }
    return ans;
  }
}
int main(){
  long long D;
  cin >> D;
  long long ans = 0;
  for (int i = 1; i <= 18; i++){
    int cnt = (i + 1) / 2;
    vector<pair<long long, map<int, int>>> add(cnt);
    for (int j = 0; j < cnt; j++){
      long long x = tenpow(i - 1 - j) - tenpow(j);
      map<int, int> mp;
      for (int k = 0; k <= 9; k++){
        for (int l = 0; l <= 9; l++){
          if (j == 0 && k == 0){
            continue;
          }
          if (j == i - 1 - j && k != l){
            continue;
          }
          mp[k - l]++;
        }
      }
      add[j] = make_pair(x, mp);
    }
    vector<long long> sum(cnt, 0);
    for (int i = cnt - 2; i >= 0; i--){
      sum[i] = sum[i + 1] + add[i + 1].first * 9;
    }
    ans += dfs(D, 1, add, sum, 0);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	int n,m; cin>>n>>m;
	mti vec(n+1,vi(0));
	vi one(0);
	rep(i,0,m){
		int a,b; cin>>a>>b;
		if(a==1) one.push_back(b);
		if(b==1) one.push_back(a);
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	if(one.size()==0){
		cout<<"IMPOSSIBLE";
		return 0;
	}
	else{
		for(int c:one){
			for(int d:vec[c]){
				if(d==n){
					cout<<"POSSIBLE";
					return 0;
				}
			}
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 12392
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define st first
#define nd second

using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
#define shandom_ruffle random_shuffle
 
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

const int mod = 998244353;
const int kMaxN = 4000;

int dpv[kMaxN][kMaxN];
int dph[kMaxN][kMaxN];

inline void Add(int &a, int b) {
	a += b;
	if (a >= mod) { a -= mod; }
}

inline int Mul(int a, int b) {
	return (ll(a) * b) % mod;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	dph[A][B] = 1;

	for (int rows = A; rows <= C; ++rows) {
		for (int col = B; col <= D; ++col) {
			Add(dph[rows + 1][col], Mul(dph[rows][col], col));
			Add(dph[rows + 1][col], dpv[rows][col]);
			Add(dpv[rows][col + 1], Mul(dpv[rows][col], rows));
			Add(dpv[rows][col + 1], Mul(dph[rows][col], rows));
		}
	}

	int ans = dph[C][D];
	Add(ans, dpv[C][D]);
	cout << ans << "\n";
}


Measured memory_bytes: 97396
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
       		String inputString = scanner.nextLine();
		String[] strStdIn = inputString.split(" ", 0);

		int firstVertical = Integer.parseInt(strStdIn[0]);
		int firstHorizon = Integer.parseInt(strStdIn[1]);
		int secondVertical = Integer.parseInt(strStdIn[2]);
		int secondHorizon = Integer.parseInt(strStdIn[3]);

		if ( (firstVertical * firstHorizon) >= (secondVertical * secondHorizon) ) {
			System.out.println((firstVertical * firstHorizon));
		} else {
			System.out.println((secondVertical * secondHorizon));
		}
	}
}

Measured memory_bytes: 9044
s = input()
ans_array = [0]*(len(s) + 1)

i = 0
while i < len(s):
  char = s[i]
  
  # < or > がいくつ続くか数える
  count = 1
  for j in range(i+1, len(s)):
    if s[j] == char:
      count = count +1
    else:
      break
  if char == '<':
    tmp = 0
    for k in range(count+1):
      ans_array[i+k] = tmp
      tmp = tmp + 1
  else:
    tmp = count
    start = 0
    if ans_array[i] > count:
      tmp = tmp - 1
      start = 1
      

    for k in range(start, count+1): 
      ans_array[i+k] = tmp
      tmp = tmp - 1
      
  i = i + count

print(sum(ans_array))

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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> children(N, 0);
    int x;
    for (int i = 1; i < N; ++i) {
        cin >> x;
        ++children[x-1];
    }
    for (int i = 0; i < N; ++i) {
        cout << children[i] << endl;
    }
    return 0; 
}

Measured memory_bytes: 3956
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys


def find_square0(data):
    max_size = 0
    dp = [] # dp??¨???2?¬??????????
    # '.'????????????1??????'*'????????????0????????????
    for row in data:
        temp = []
        for c in row:
            if c == '.':
                temp.append(1)
            else:
                temp.append(0)
        dp.append(temp)

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    for y in range(1, len(dp)):
        for x in range(1, len(dp[0])):
            if dp[y][x] == 1:
                dp[y][x] = min(dp[y-1][x-1], dp[y-1][x], dp[y][x-1]) + 1
                if dp[y][x] > max_size:
                    max_size = dp[y][x]
    return max_size


def find_square2(data):
    max_size = 0
    dp = [[0]*len(data[0]) for _ in range(len(data))] # dp??¨???2?¬???????????????¨??????0??§?????????
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y][x] = 1

    # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
    prev_row = dp[0]
    for curr_row in dp[1:]:
        for x, t in enumerate(curr_row[1:], start=1):
            if t == 1:
                curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
                if curr_row[x] > max_size:
                    max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def find_square3(data):
    from array import array
    max_size = 0
    dp = [array('I', [0]*len(data[0])) for _ in range(len(data))]  # ????¬?????????????array??????????????§?¢????
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y][x] = 1

    prev_row = dp[0]
    for curr_row in dp[1:]:
        for x, t in enumerate(curr_row[1:], start=1):
            if t == 1:
                curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
                if curr_row[x] > max_size:
                    max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def find_square4(data):
    max_size = 0
    dp = [0 for _ in range(1024*1024)]
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y*1024+x] = 1

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    for y in range(1, len(data)):
        for x in range(1, len(data)):
            if dp[y*1024+x] == 1:
                dp[y*1024+x] = min(dp[(y-1)*1024+x-1], dp[(y-1)*1024+x], dp[y*1024+x-1]) + 1
                if dp[y*1024+x] > max_size:
                    max_size = dp[y*1024+x]
    return max_size



def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        data = [input() for _ in range(n)]
        result = find_square4(data)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 35460
N, Y = map(int, input().split())
ans = []
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if (x * 10000) + (y * 5000) + (z * 1000) == Y and x + y + z == N and z >= 0:
            ans.append([x, y, z])

if len(ans) == 0:
    print(-1, -1, -1)
else:
    print(ans[0][0], ans[0][1],ans[0][2])

Measured memory_bytes: 3064