akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    using P = pair<double, pair<int, int>>;
    vector<P> a;
    a.reserve(100);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        a.emplace_back(atan2(y, x), make_pair(x, y));
    }
    sort(a.begin(), a.end());
    double xs = 0, ys = 0;
    for (auto &e: a) {
        xs += e.second.first;
        ys += e.second.second;
    }

    double ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j <= n; ++j) {
            double xt = 0, yt = 0;
            for (int k = i; k < j; ++k) {
                xt += a[k].second.first;
                yt += a[k].second.second;
            }
            ans = max(sqrt(xt * xt + yt * yt), ans);

            xt = xs - xt;
            yt = ys - yt;
            ans = max(sqrt(xt * xt + yt * yt), ans);
        }
    }

    cout << fixed << setprecision(20) << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int main() {
    ll x;cin >> x;
    ll k = 11*(x/11);
    if(k==x)cout << 2*(x/11) << endl;
    else if(k+6>=x) cout << 2*(x/11)+1 << endl;
    else cout << 2*(x/11+1) << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))
 

int main(){ 
	ll k,x;
	cin >> k >> x;
	cout << (x-k+1);
	FOR(i,x-k+2,x+k){
		cout << " " << i;
	}
	cout << endl;
}


Measured memory_bytes: 256
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @aa = map { $_ - 0 } split(/\s+/,<STDIN>);


my $t_xor = 0;
for(my $i=0;$i<$n;$i++){
  $t_xor = ( $t_xor ^ $aa[$i] );
}

my @out = ();
$#out = ($n-1);
for(my $i=0;$i<$n;$i++){
  $out[$i] = ( $t_xor ^ $aa[$i] );
}

print join(' ',@out);
print "\n";



Measured memory_bytes: 41988
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;



public class Main{


	public static void main(String[] args){

		Scanner scan=new Scanner(System.in);

		//SHDC?????????????????????????????????
		int[][] Bld1=new int[3][10];
		int[][] Bld2=new int[3][10];
		int[][] Bld3=new int[3][10];
		int[][] Bld4=new int[3][10];

		for(int i=0;i<3;i++){
			Arrays.fill(Bld1[i], 0);}
		for(int i=0;i<3;i++){
			Arrays.fill(Bld2[i], 0);}
		for(int i=0;i<3;i++){
			Arrays.fill(Bld3[i], 0);}
		for(int i=0;i<3;i++){
			Arrays.fill(Bld4[i], 0);}

		int Bld_num, floor,room,volume;

		try{
		int n=scan.nextInt();//n?????????

		for(int i=0;i<n;i++){
			Bld_num=scan.nextInt();
			floor=scan.nextInt();
			room=scan.nextInt();
			volume=scan.nextInt();



			switch(Bld_num){//???????????????????????????????????¨????????????1?????£??\???

			case 1:
				Bld1[floor-1][room-1]+=volume;
				break;
			case 2:
				Bld2[floor-1][room-1]+=volume;
				break;
			case 3:
				Bld3[floor-1][room-1]+=volume;
				break;
			case 4:
				Bld4[floor-1][room-1]+=volume;
				break;
			}
		}



		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				System.out.print(" "+Bld1[i][j]);
			}System.out.println();
		}

		System.out.println("####################");

		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				System.out.print(" "+Bld2[i][j]);
			}System.out.println();
		}

		System.out.println("####################");

		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				System.out.print(" "+Bld3[i][j]);
			}System.out.println();
		}

		System.out.println("####################");

		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				System.out.print(" "+Bld4[i][j]);
			}System.out.println();
		}


		scan.close();

		}catch(InputMismatchException e){
			System.out.println("??¨??????"+e);
		}


	}

}

Measured memory_bytes: 29396
#B = list(map(int,input().split()))
A=[]
for i in range(3):
    a=list(map(int,input().split()))
    A.append(a)
N = int(input())
b=[]
for i in range(N):
    B=int(input())
    b.append(B)

Sheet=[[0,0,0],[0,0,0],[0,0,0]]

for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            Sheet[i][j]+=1

if Sheet[0][0]==Sheet[1][0]==Sheet[2][0]==1 or Sheet[0][1]==Sheet[1][1]==Sheet[2][1]==1 or Sheet[0][2]==Sheet[1][2]==Sheet[2][2]==1 or Sheet[0][0]==Sheet[0][1]==Sheet[0][2]==1 or  Sheet[1][0]==Sheet[1][1]==Sheet[1][2]==1 or  Sheet[2][0]==Sheet[2][1]==Sheet[2][2]==1 or  Sheet[0][0]==Sheet[1][1]==Sheet[2][2]==1 or  Sheet[0][2]==Sheet[1][1]==Sheet[2][0]==1:
    print('Yes')
else:
    print('No')


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

using namespace std;

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

	vector<pair<int,int> > in(n); 

	for(int i=0;i<n;i++)
		cin >> in[i].first >> in[i].second;

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

	int count=0;
	long long ans=0;
	bool flag=false;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<in[i].second;j++)
		{
			ans+=in[i].first;
			count++;
			if(count>=m)
			{
				flag=true;
				break;
			}
		}
		if(flag)break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int main() {
    ios;
   ll n;cin>>n;
   ll ans=1000*(n/500);
   n=n-500*(n/500);
   if(n>0)ans+=5*(n/5);
   cout<<ans;
 
    
}

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

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define int long long
#define DBG 1
using VI=vector<int>;
using VVI = vector<VI>;
const int INF = 0x3f3f3f3f3f3f3f3fLL;

signed main(void) {
	for (int n, k, s; cin >> n >> k >> s && n;) {
		int ans = INF;
		vector<int> x(n), y(n), z(n);
		rep(i, 0, n)cin >> x[i] >> y[i] >> z[i];

		auto S = [&](int i, int j) {
			int ans = -1LL;
			int dx = s - abs(x[i] - x[j]);
			int dy = s - abs(y[i] - y[j]);
			int dz = s - abs(z[i] - z[j]);
			if (dx >= 0 && dy >= 0 && dz >= 0)
				ans = 2 * ((dx * dy) + (dy * dz) + (dz * dx));
			//cerr << i << " " << j << " " << ans << endl;
			return ans;
		};

		vector<vector<int>> G(n);
		rep(i, 0, n)rep(j, i + 1, n) {
			if (S(i, j) > 0) {
				G[i].push_back(j);
				G[j].push_back(i);
				////cerr << i << " " << j << endl;
			}
		}

		vector<bool> vis(n);

		function<bool(int, vector<int>&)> dfs = [&](int u, vector<int>& list) {
			vis[u] = true;
			int p = list.size() ? list.back() : -1;
			list.push_back(u);
			for (auto v : G[u]) {
				if (p == v)continue;
				if (vis[v])return true;
				return dfs(v, list);
			}
			return false;
		};
		//cerr << " " << endl;
		rep(i, 0, n) {
			if (vis[i])continue;
			vector<int> list;
			bool loop = dfs(i, list);
			if (!loop) {
				for (auto u : list)vis[u] = false;
				int u = list.back();
				list.clear();
				dfs(u, list);
			}
			int m = list.size();

			if (m < k)continue;
			int cs = 2 * s * s * 3 * k;
			rep(j, 0, k - 1)
				cs -= S(list[j], list[(j + 1) % m]);
			ans = min(ans, cs);
			if (loop && m == k && m >= 2) {
				cs -= S(list[k - 1], list[0]);
				ans = min(ans, cs);
				//cerr << " " << endl;
			}
			else {
				rep(j, 0, m) {
					int a = S(list[j], list[(j + 1) % m]);
					int b = S(list[(j + k - 1) % m], list[(j + k) % m]);
					if (b < 0)break;
					cs += a;
					cs -= b;
					ans = min(ans, cs);
				}
			}
		}

		cout << (ans == INF ? -1 : ans) << endl;

	}
}


Measured memory_bytes: 3152
import math

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

A1 = A * 12.5
A2 = (A + 0.9) * 12.5
B1 = B * 10
B2 = (B + 0.9) * 10

if B1 <= A1 and A1 < (B + 1) * 10:
    print(math.ceil(A1))
elif A1 <= B1 and B1 < (A + 1) *12.5 :
    print(B1)
else:
    print(-1)

Measured memory_bytes: 3064
using System;

namespace AOJ.Volume1
{
    public class SpeedSkatingBadgeTest
    {
        public static int Main()
        {
            var time_500 = new double[7] { 35.5, 37.5, 40, 43, 50, 55, 70 };
            var time_1000 = new double[7] { 71, 77, 83, 89, 105, 116, 148 };
            var rank = new string[7] { "AAA", "AA", "A", "B", "C", "D", "E" };

            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                var time_array = input.Split(' ');
                var t1 = double.Parse(time_array[0]);
                var t2 = double.Parse(time_array[1]);

                string rank_str = "NA";
                for (int i = 0; i < 7; i++)
                {
                    if (t1 < time_500[i] && t2 < time_1000[i])
                    {
                        rank_str = rank[i];
                        break;
                    }
                }
                Console.WriteLine(rank_str);
            }

            return 0;
        }
    }
}

Measured memory_bytes: 9360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	vector<ll> dp(n+1,0);
	ll now=1;
	dp[n-1]=s[n-1]-'0';
	for(int i=n-2;i>=0;i--){
		now*=10;
		now%=2019;
		dp[i]=(now*int(s[i]-'0')+dp[i+1])%2019;
	}
	map<ll,ll> mp;
	ll ans=0;
	for(int i=n;i>=0;i--){
		ans+=mp[dp[i]];
		mp[dp[i]]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = a * c;
	chmax(ans, a * d);
	chmax(ans, b * c);
	chmax(ans, b * d);
	if (a <= 0 && b >= 0) chmax(ans, 0);
	if (c <= 0 && d >= 0) chmax(ans, 0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int>v1(n), v2(n);
	for (int i = 0; i < n; i++) {
		cin >> v1[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> v2[i];
	}
	vector<int>v(n);
	for (int i = 0; i < n; i++) {
		v[i] = i + 1;
	}
	vector<vector<int>>have;
	do {
		have.pb(v);
	} while (next_permutation(v.begin(), v.end()));
	sort(have.begin(), have.end());
	int nax1 = 0, nax2 = 0;
	for (int i = 0; i < int(have.size()); i++) {
		vector<int>got = have[i];
		if (got == v1)nax1 = i;
		if (got == v2)nax2 = i;
	}
	cout << abs(nax1 - nax2) << endl;
}

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

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

int main()
{
    int H, W;
    cin >> H >> W;
    char grid[H][W];
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> grid[i][j];
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (grid[i][j] == '#')
            {
                cout << grid[i][j];
                continue;
            }
            else if (grid[i][j] == '.')
            {
                int countMine = 0;
                for (int k = 0; k < 8; k++)
                {
                    int new_x = i + dx[k];
                    int new_y = j + dy[k];

                    //マスの外に出てしまうなら考えない
                    if (new_x < 0 || new_x >= H || new_y < 0 || new_y >= W)
                    {
                        continue;
                    }
                    if (grid[new_x][new_y] == '#')
                    {
                        countMine++;
                    }
                }
                grid[i][j] = '0' + countMine;
            }
            cout << grid[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            String op = sc.next();
            String operand = sc.next();
            if (op.equals("insert")) {
                set.add(operand);
            } else { // find
                if (set.contains(operand)) {
                    System.out.println("yes");
                } else {
                    System.out.println("no");
                }
            }
        }
    }
}

Measured memory_bytes: 252364
def fun(i,j):
	# print(i,j)
	if i>j or i>=n or j<0:
		return 0
	elif i==j:
		dp[i][j]=arr[i]
		return dp[i][j]
	else:
		if dp[i][j]==0:
			dp[i][j]=max(arr[i]+min(fun(i+1,j-1),fun(i+2,j)),arr[j]+min(fun(i+1,j-1),fun(i,j-2)))
		return dp[i][j]
n=int(input())
dp=[0]*n
for i in range(n):
	dp[i]=[0]*n
arr=list(map(int,input().split()))
print(2*fun(0,n-1)-sum(arr))

Measured memory_bytes: 164488
#include "bits/stdc++.h"
using namespace std;

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

const int INF = 1000000007;

int main(){
	ll n,k; cin>>n>>k;
	int a[110000]={0}, b[110000]={0};
	P p[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		p[i].first = a[i];
		p[i].second = b[i];
	}
	sort(p, p + n);
	ll cnt=0;
	for(int i=0;i<n;i++){
		cnt += p[i].second;
		if(cnt >= k){
			cout<< p[i].first <<endl;
			break;
		}
	}



	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
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; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

long double dp[330][330][330];//3,2,1枚
int a;
int cnt[5];

int main(){cout<<fixed<<setprecision(20);
		   int n;
           cin>>n;
           rep(i,0,n){
            cin>>a;
             cnt[a]++;
           }
           rep(i,0,n+1)rep(j,0,n+1)rep(k,0,n+1){
             long double non=i+j+k;
             if(non==0)continue;
             dp[i][j][k]+=n/non;//0以外引くまで
             if(i-1>=0)dp[i][j][k]+=dp[i-1][j+1][k]*i/non;
             if(j-1>=0)dp[i][j][k]+=dp[i][j-1][k+1]*j/non;
             if(k-1>=0)dp[i][j][k]+=dp[i][j][k-1]*k/non;
           }
           cout<<dp[cnt[3]][cnt[2]][cnt[1]]<<endl;
}

Measured memory_bytes: 472020
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	Long a = sc.nextLong();
    Long b = sc.nextLong();
    Long n = sc.nextLong();
    Long max;
    if(n < b) max = a*n/b;
    else max = a*(b-1)/b;
    System.out.println(max);
  }
}

Measured memory_bytes: 35744
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
typedef long long LL;
namespace solveIt
{
char buf[1<<21],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
LL read()
{
	LL x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')	f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')	x=(x<<3)+(x<<1)+(c^'0'),c=getchar();
	return x*f;
}
template<class Type>
void write(Type x)
{
	if(x<0)	putchar('-'),x=-x;
	if(x>9)	write(x/10);
	putchar(x%10+'0');
}
char str[1005]; 
void MAIN()
{
	scanf("%s",str+1);
	int n=strlen(str+1);
	if(str[n]=='s')	printf("%ses",str+1);
	else	printf("%ss",str+1);
}
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	solveIt::MAIN();
	return 0;
}

Measured memory_bytes: 3236
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int N;
        cin >> N;
        vector<int> vec(N);
        for (int i = 0; i < N; i++)
        {
                cin >> vec[i];
        }

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

        cout << abs(vec[0] - vec.back()) << endl;

        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int num = 0;
    char c;
    bool flag = false;
    while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
        if (c == '-') flag = true;
    else
        num = c - '0';
    while (isdigit(c = getchar()))
    num = num * 10 + c - '0';
    return (flag ? -1 : 1) * num;
}
int main()
{
    long long a[3];
	a[0]=read();
	a[1]=read();
	a[2]=read();
	if(a[0]%2==0||a[1]%2==0||a[2]%2==0)
	{
		cout<<0<<endl;
		return 0;
	}
	else sort(a,a+3);
	cout<<a[0]*a[1]<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
int main()
{
    string s;
    cin >> s;
    int ans = 0, v = 0;
    for (int i = 0; i < SZ(s); ++i) {
        int k = s[i] - '0';
        v += k;
        if (k > 0)
            ans = max(ans, v - 1 + (SZ(s) - i - 1) * 9);
    }
    cout << max(ans,v) << endl;
}


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

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<pair<pii, int>> XY,YX;
priority_queue<pair<int, pii>> pque;
//UnionFind
class UnionFind {
public:
  UnionFind(int size_) : parent(size_, -1), __size(size_) {}
  void unite(int x, int y) {
    if ((x = find(x)) != (y = find(y))) {
      if (parent[y] < parent[x])
        std::swap(x, y);
      parent[x] += parent[y];
      parent[y] = x;
      __size--;
    }
  }
  bool is_parent(int x) { return find(x) == x; }
  bool is_same(int x, int y) { return find(x) == find(y); }
  int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
  int size(int x) { return -parent[find(x)]; }
  int size() const { return __size; }

private:
  std::vector<int> parent;
  int __size;
};
//UnionFind

int main() {

    cin >> N;
    UnionFind ut(N);
    for (int i = 0; i < N; i++){
        int x,y;
        cin >> x >> y;
        XY.emplace_back(mp(mp(x, y), i));
        YX.emplace_back(mp(mp(y, x), i));
    }
    sort(XY.begin(), XY.end());
    sort(YX.begin(), YX.end());
    for (int i = 0; i < N-1; i++){

        int px,py,pi;
        int qx,qy,qi;
        //XY
        px = XY[i].first.first;
        py = XY[i].first.second;
        pi = XY[i].second;

        qx = XY[i + 1].first.first;
        qy = XY[i + 1].first.second;
        qi = XY[i + 1].second;
        int cost = abs(px - qx);
        pque.emplace(mp(-cost, mp(pi, qi)));
    }
    for (int i = 0; i < N-1; i++){

        int px,py,pi;
        int qx,qy,qi;
        //XY
        px = YX[i].first.second;
        py = YX[i].first.first;
        pi = YX[i].second;

        qx = YX[i + 1].first.second;
        qy = YX[i + 1].first.first;
        qi = YX[i + 1].second;
        int cost = abs(py - qy);
        pque.emplace(mp(-cost, mp(pi, qi)));
    }
    ll res = 0;
    while (ut.size(0) != N){
        auto p = pque.top();
        pque.pop();
        int cost = p.first;
        cost *= -1;
        int pi,qi;
        pi = p.second.first;
        qi = p.second.second;
        if (not ut.is_same(pi, qi)){
            ut.unite(pi, qi);
            res += cost;
        }
    }
    cout << res << endl;
   return 0;
 }


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

int main(){
    int n,m;
    cin >> n >> m;
    int a[n][m] = {};
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            //cout << a[i][j] << " ";
        }
        //cout << endl;
    }
    int b[m] = {};
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        int x = 0;
        for(int j = 0; j < m; j++){
            x += a[i][j] * b[j];
        }
        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

// 素因数分解 O(√n)
// たとえば 60 = 2^2 x 3 x 5 だったら {(2, 2), (3, 1), (5, 1)} を返す
// 素因数の個数はlogn
vector<pair<ll,ll>> prime_factorize(ll n){
    vector<pair<ll,ll>> res;
    for(ll p=2;p*p<=n;p++){
        if(n%p!=0) continue;
        int num=0; // 指数
        while(n%p==0){
            num++;
            n/=p;
        }
        res.push_back({p,num});
    }
    if(n!=1) res.push_back({n,1});
    return res;
}


int main(){
    ll a,b;
    cin>>a>>b;

    ll g=gcd(a,b);

    if(g==1){
        cout<<1<<endl;
        return 0;
    }

    auto pf=prime_factorize(g);
    cout<<pf.size()+1<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 4e5 + 10;
int a[maxn];
int len, tot; LL p[maxn];
int c[maxn];
int lowbit(int x) { return x & -x; }
void upt(int x) { while(x <= len) { c[x]++; x += lowbit(x); } }
int que(int x) { int ret = 0; while(x) { ret += c[x]; x -= lowbit(x); } return ret; }
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[i] -= k;
	LL sum = 0;
	LL ans = 0;
	for(int i = 0; i <= n; ++i) sum += a[i], p[++tot] = sum;//, p[++tot] = sum + 1;
	sort(p + 1, p + tot + 1);
	len = unique(p + 1, p + tot + 1) - p - 1;
	sum = 0;
	for(int i = 0; i <= n; ++i)
	{
		sum += a[i];
		int x = lower_bound(p + 1, p + len + 1, sum) - p;
		ans += que(x);
		upt(x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5632
n,k=map(int,input().split())
d=list(map(str,input().split()))
def judge(x,y):
  X=str(x)
  ret=1
  for i in X:
    if(i in y):
      ret=0
      break
  return ret
while(True):
  if(judge(n,d)==1):
    break
  else:
    n += 1
print(n)

Measured memory_bytes: 3060
# W, H, x, y = [int(i) for i in input().split()]
N, X = [int(i) for i in input().split()]
L = [int(i) for i in input().split()]
D = 0
count = 0
answer = 1

while D <= X:
  if count + 1 > len(L):
    print(N+1)
    exit()
  D += L[count]
  count += 1
  answer += 1

print(answer - 1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 1e18
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000
#define ll long long
#define P pair<int,int>
using namespace std;
const int mod = 1000000007;
//char c[MAX][MAX];
int step[MAX][MAX];
int H,W,N; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

signed main(){
    int n; cin >> n;
    int a = n%10;
    if(n%10 == 3) cout <<"bon" << endl;
    else if(a == 0 || a == 1 || a== 6 || a == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>H>>W>>N;
    vec a(N);
    rep(i,N) cin>>a[i];
    mat ans(H,vec(W,0));
    ll sum = 0;
    rep(i,N){
        rep(j,a[i]){
            ans[sum/W][sum%W] = i+1;
            ++sum;
        }
    }
    for(int i = 1; i < H; i += 2){
        reverse(ans[i].begin(), ans[i].end());
    }
    rep(i,H){
        rep(j,W) {
            cout<<ans[i][j];
            if(j != W-1) cout<<' ';
        }
        cout<<endl;
    }

}

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

M = 1000
X = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        X = int(M/A[i])
        M = int(M - X * A[i])
    
    M = M + X * A[i+1]
    X = 0

print(int(M))


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using i64 = long long;

int gcd(int a, int b) {
    if (b > a) std::swap(a, b);
    return a % b ? gcd(b, a % b) : b;
}

int main() {
    int n;
    std::cin >> n;
    int ret;
    std::cin >> ret;
    for (int i = 1; i < n; i++) {
        int a;
        std::cin >> a;
        ret = gcd(ret, a);
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i, j, k, n, m, t;
  scanf("%d%d", &n, &m);
  int c[m], dp[n + 1];
  for(i = 1; i <= n; ++i) dp[i] = 100000;
  dp[0] = 0;
  for(i = 0; i < m; ++i) scanf("%d", &c[i]);
  for(i = 0; i < m; ++i) for(j = i + 1; j < m; ++j) if(c[i] > c[j]) t = c[i], c[i] = c[j], c[j] = t;
  for(i = 0; i < m; ++i) for(j = 0; j < n; ++j) if(j + c[i] <= n && dp[j + c[i]] > dp[j] + 1) dp[j + c[i]] = dp[j] + 1;
  printf("%d\n", dp[n]);
  return 0;
}


Measured memory_bytes: 2888
#include<iostream>
#include<cstdio>
using namespace std;
const int MAX = 500000;
const int maxnum = 1000000010;

// ???????±???¨??°???
int L[MAX / 2 + 2], R[MAX / 2 + 2];
int A[MAX], n;
int cnt = 0;

// ??????????????¶
void merge(int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];

	// ???????±???¨??°?????????????????????????????§?????°
	L[n1] = R[n2] = maxnum;
	int i = 0, j = 0;
	// ?????¶
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j])
			A[k] = L[i++];
		else
			A[k] = R[j++];
	}
}
// ??????
void mergeSort(int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(left, mid);
		mergeSort(mid, right);
		merge(left, mid, right);
	}
}
int main() {

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);

	mergeSort(0, n);
	for (int i = 0; i < n; i++)
		printf("%d%c", A[i], i == n - 1 ? '\n' : ' ');
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 7020
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int sum = x * 2;
		for (int i = 0; i < x; i++) {
			if (sum < y) {
				sum += 2;
			} else {
				break;
			}
		}
		if (sum == y) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35832
from collections import defaultdict

n = int(input())
counter = defaultdict(int)
for _ in range(n):
    s = input()
    counter[s] += 1

l = [(-n, s) for s, n in counter.items()]
l.sort()
m = l[0][0]

for x, s in l:
    if x != m:
        break
    print(s)


Measured memory_bytes: 154820
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,ans=0,cnt=0; cin>>n;
    vector<string> ss(n);
    rep(i,n){
        string s="";
        vector<char> c(10);
        rep(j,10) cin>>c[j];
        sort(al(c));
        rep(j,10) s=s+c[j];
        ss[i]=s;
    }
    sort(al(ss));
    rep(i,n-1){
        if(ss[i]==ss[i+1]){
            cnt++; ans+=cnt;
        }
        else{
            cnt=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5760
def main():
    s = input()
    k = int(input())
    l = set()
    ls = len(s)
    clist = sorted(list(set(list(s))))
    ladd = l.add
    for i in clist:
        x = []
        for j in range(ls):
            if i == s[j]:
                x.append(j)
        ladd(i)
        for j in range(len(x)):
            idx = x[j]
            xxx = s[idx]
            c = 0
            for t in range(idx+1,ls):
                xxx = xxx +s[t]
                ladd(xxx)
                c += 1
                if c > k:
                    break
        if len(l) >= k:
            l = list(l)
            print(sorted(l)[k-1])
            break
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	printf("%d\n", (1 << m) * (1900 * m + (n - m) * 100));
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int H, W, C;
	static int[][][] f;
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, 1, 0, -1 };
	static int ans;

	public static void main(String[] args) {
		while (true) {
			H = sc.nextInt();
			if (H == 0) break;
			W = sc.nextInt();
			C = sc.nextInt();
			f = new int[6][H][W];
			for (int i = 0; i < H; ++i) {
				for (int j = 0; j < W; ++j) {
					f[0][i][j] = sc.nextInt();
				}
			}
			ans = 0;
			rec(0);
			System.out.println(ans);
		}
	}

	static void rec(int level) {
		if (level == 4) {
			change(C, level);
			count();
			return;
		}
		for (int i = 1; i <= 6; ++i) {
			change(i, level);
			rec(level + 1);
		}
	}

	static void change(int color, int level) {
		for (int i = 0; i < H; ++i) {
			System.arraycopy(f[level][i], 0, f[level + 1][i], 0, W);
		}
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.add(0);
		boolean[][] used = new boolean[H][W];
		used[0][0] = true;
		int sc = f[level][0][0];
		while (!q.isEmpty()) {
			int pos = q.poll();
			int cr = pos >> 8;
			int cc = pos & 0xFF;
			f[level + 1][cr][cc] = color;
			for (int i = 0; i < 4; ++i) {
				int nr = cr + DR[i];
				int nc = cc + DC[i];
				if (nr < 0 || H <= nr || nc < 0 || W <= nc || used[nr][nc]) continue;
				if (f[level + 1][nr][nc] != sc) continue;
				q.add((nr << 8) + nc);
				used[nr][nc] = true;
			}
		}
	}

	static void count() {
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.add(0);
		boolean[][] used = new boolean[H][W];
		used[0][0] = true;
		int count = 0;
		while (!q.isEmpty()) {
			int pos = q.poll();
			int cr = pos >> 8;
			int cc = pos & 0xFF;
			++count;
			for (int i = 0; i < 4; ++i) {
				int nr = cr + DR[i];
				int nc = cc + DC[i];
				if (nr < 0 || H <= nr || nc < 0 || W <= nc || used[nr][nc]) continue;
				if (f[5][nr][nc] != f[5][0][0]) continue;
				q.add((nr << 8) + nc);
				used[nr][nc] = true;
			}
		}
		ans = Math.max(ans, count);
	}

}

Measured memory_bytes: 160316
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B, C, D);

// ===

const MOD: i32 = 1000000007;

fn main() {
    let (n, x, y, z): (usize, usize, usize, usize) = read();

    let mut dp: Vec<Vec<i32>> = vec![vec![0; 1<<18]; 2];
    dp[0][0] = 1;

    let mask = (1<<17)-1;
    let cmask = 1<<17;
    let okmask = (1<<(x+y+z-1))|(1<<(y+z-1))|(1<<(z-1));

    for i in 0..n {
        let fr = i % 2;
        let to = 1 - fr;
        for ptn in 0..(1<<18) {
            dp[to][ptn] = 0;
        }

        for ptn in 0..(1<<18) {
            let base = dp[fr][ptn];
            if base == 0 {
                continue
            }
            for x in 1..11 {
                let tptn = (((ptn<<x)|(1<<(x-1)))&mask);
                let ok = ptn&cmask >= 1 || tptn & okmask == okmask;
                let tptn = tptn | if ok { cmask } else { 0 };

                dp[to][tptn] += base;
                dp[to][tptn] %= MOD;
            }
        }
    }

    let mut sum: i64 = 0;
    for ptn in 0..(1<<18) {
        if ptn & cmask >= 1 {
            sum += dp[n%2][ptn] as i64;
        }
    }
    println!("{}", sum % MOD as i64);
}

Measured memory_bytes: 6396
s=input()
cnt=[0]*3
for i in range(len(s)):
    if s[i]=="a":
        cnt[0]+=1
    elif s[i]=="b":
        cnt[1]+=1
    else:
        cnt[2]+=1
m=min(cnt)
for i in range(3):
    cnt[i]-=m
if max(cnt)<=1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-5;
const ll MOD=1e9+7;
int a[30][30];
int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    vector<ll> dp(1<<n+1);
    dp[0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<n);j++){
            if(__builtin_popcount(j)!=i)continue;
            for(int k=0;k<n;k++){
                if(j&(1<<k))continue;
                if(a[i][k]){
                    dp[j|(1<<k)]+=dp[j];
                    dp[j|(1<<k)]%=MOD;
                }
            }
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
}   


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

int main(){
	int n;
	long long h,a;
	bool tf=true;
	cin>>n>>a;
	for(int i=1;i<n;i++){
		cin>>h;
		if(h==a){
			a=h;
		}else if(a<h){
			a=h-1;
		}else{
			tf=false;
			break;
		}
	}
	if(tf){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
s = sum(A)
B = [int(i)for i in input().split()]
for i,b in enumerate(B):
    if b > A[i]:
        b -= max(0,A[i])
        A[i] = 0
        A[i+1] -= b
    else:
        A[i] -= b
A[-1] = max(0,A[-1])
print(s-sum(A))

Measured memory_bytes: 19156
#include <bits/stdc++.h>
#include <assert.h>
#include <stdlib.h>

using namespace std;

#define MOD 1000000007

const int INF = 1e9;

typedef long long ll;
typedef pair<int, int> pii;
int n,h;
int dp[(ll)1e3+1][(ll)1e4+1];
int a[(ll)1e3+1];
int b[(ll)1e3+1];

int f(int i , int health) {
    if(health <= 0) return 0;
    if(i >= n) return INF;
    int &ret = dp[i][health];
    if(ret != -1) return ret;
    
    ret = min(b[i] + f(i+1, health - a[i]), b[i] + f(i, health - a[i]));
    ret = min(ret, f(i+1, health));

    return ret;

}
int main() {
    // oh hi mark
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin >> n >> k;
    int h[n];
    ll sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
        sum += h[i];
    }
    sort(h, h+n);
    for(int i = n - 1; i >= max(0, n-k); i--) {
        sum -= h[i];
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static Parser parser = new Parser();

    public static void main(String[] args) {
        int A = parser.parseInt();
        int B = parser.parseInt();
        int Q = parser.parseInt();

        long[] s = new long[A];
        for(int i = 0; i < A; i++){
            long v = parser.parseLong();
            s[i] = v;
        }

        long[] t = new long[B];
        for (int i = 0; i < B; i++) {
            long v = parser.parseLong();
            t[i] = v;
        }

        Arrays.sort(s);
        Arrays.sort(t);

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < Q; i++) {
            long v = parser.parseLong();
            long ans = Long.MAX_VALUE;

            int srIdx = -Arrays.binarySearch(s, v) - 1;
            int slIdx = srIdx - 1;

            int trIdx = -Arrays.binarySearch(t, v) - 1;
            int tlIdx = trIdx - 1;

            if(srIdx < A && trIdx < B){
                ans = Math.min(ans, Math.max(s[srIdx] - v, t[trIdx] - v));
            }

            if(slIdx >= 0 && tlIdx >= 0){
                ans = Math.min(ans, Math.max(v - s[slIdx], v - t[tlIdx]));
            }

            if(slIdx >= 0 && trIdx < B){
                ans = Math.min(ans, Math.min(v - s[slIdx], t[trIdx] - v) + t[trIdx] - s[slIdx]);
            }

            if(tlIdx >= 0 && srIdx < A){
                ans = Math.min(ans, Math.min(v - t[tlIdx], s[srIdx] - v) + s[srIdx] - t[tlIdx]);
            }
            stringBuilder.append(ans);
            stringBuilder.append('\n');
        }

        System.out.print(stringBuilder.toString());
    }
}


class Parser {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final Iterator<String> stringIterator = br.lines().iterator();
    private static final Deque<String> inputs = new ArrayDeque<>();

    void fill() {
        if(inputs.isEmpty()){
            if(!stringIterator.hasNext()) throw new NoSuchElementException();
            inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
        }
    }

    Integer parseInt() {
        fill();
        if(!inputs.isEmpty()) {
            return Integer.parseInt(inputs.pollFirst());
        }
        throw new NoSuchElementException();
    }

    Long parseLong() {
        fill();
        if(!inputs.isEmpty()) {
            return Long.parseLong(inputs.pollFirst());
        }
        throw new NoSuchElementException();
    }

    Double parseDouble() {
        fill();
        if(!inputs.isEmpty()) {
            return Double.parseDouble(inputs.pollFirst());
        }
        throw new NoSuchElementException();
    }

    String parseString() {
        fill();
        return inputs.removeFirst();
    }

}

Measured memory_bytes: 49000
#include <iostream>
#include <algorithm>
using namespace std;
int a[100];
int b[300];
int n;
bool solve(int i,int m){
	if(m==0){
		return true;
	}
	if(i>=n){
		return false;
	}
	bool re=(solve(i+1,m)||solve(i+1,m-a[i]));
	return re;
}

int main(){
	int m;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>b[i];
	} 
	for(int i=0;i<q;i++){
		if(solve(0,b[i])){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  
  int K = H.at(0);
  int answer = 0;
  
  for(int i=0;i<N;i++){
    if(K <= H.at(i)){
      K = H.at(i);
      answer++;
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e5+5;

ll shr[lim],tem[lim];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
		
	int a,b,q;
	cin>>a>>b>>q;
	for(int i=0;i<a;++i)
		cin>>shr[i];
	for(int i=0;i<b;++i)
		cin>>tem[i];
	sort(shr,shr+a);
	sort(tem,tem+b);
	for(int i=0;i<q;++i)
	{
		ll x;
		cin>>x;
		int s2 = upper_bound(shr,shr+a,x)-shr,t2 = upper_bound(tem,tem+b,x) - tem;
		int s1 = s2-1,t1 = t2-1;

		ll ans = 2e18;
		vector<ll> use1,use2;
		if(s1>=0)
			use1.push_back(shr[s1]);
		if(s2<a)
			use1.push_back(shr[s2]);
		if(t1>=0)
			use2.push_back(tem[t1]);
		if(t2<b)
			use2.push_back(tem[t2]);

		for(int i=0;i<use1.size();++i)
			for(int j=0;j<use2.size();++j)
				ans = min(ans,min( abs(x-use1[i])+abs(use1[i]-use2[j]),abs(x-use2[j])+abs(use1[i]-use2[j])));
		cout<<ans<<'\n';
	}

    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,A[200000],B[200000],time=0,z=1;
    cin>>n;
    rep(i,n) cin>>A[i]>>B[i];
    vector<pair<int,int>> C;
    rep(i,n) C.push_back(make_pair(B[i],A[i]));
    sort(C.begin(),C.end());
    rep(i,n){
        time+=C[i].second;
        if(time>C[i].first){
            z=0;
            break;
        }
    }
    if(z) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 4084
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		long sum = 0;
		int min = 1000000;
		int max = -1000000;
		for (int i=0; i<n; i++) {
			int a = stdIn.nextInt();
			min = Math.min(min,a);
			max = Math.max(max,a);
			sum += a;
		}
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 31812