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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vector<int>> mi;
typedef vector<vector<pair<int, int>>> w_graph;
typedef vector<vector<int>> uw_graph;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	#ifdef DEBUG
		freopen("out.txt", "w", stdout);
	#endif

	int n; cin >> n;
	int dp[2][3];
	for (int i = 0; i < 2; i++) dp[i][0] = dp[i][1] = dp[i][2] = 0;
	
	for (int i = 1; i <= n; i++){
		int a, b, c;
		cin >> a >> b >> c;
		dp[1][0] = max(dp[0][1], dp[0][2]) + a;
		dp[1][1] = max(dp[0][0], dp[0][2]) + b;
		dp[1][2] = max(dp[0][0], dp[0][1]) + c;
		
		dp[0][0] = dp[1][0];
		dp[0][1] = dp[1][1];
		dp[0][2] = dp[1][2];
	}
	
	cout << max(dp[1][0], max(dp[1][1], dp[1][2])) << endl;

	return 0;
}


Measured memory_bytes: 256
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [a,b] <- map (read::String->Int) . words <$> getLine
  s<-getLine
  let left = take a s; hyphen = s!!a; right = (take b .reverse) s
  putStrLn $ if checkZIP left hyphen right then "Yes" else "No"

checkZIP x y z = and [checknum x, checkhyphen y, checknum z]
checknum x = and $ elemList x ['0'..'9']
checkhyphen x = x=='-'
elemList [] _ = []
elemList (x:xs) list  = elem x list : elemList xs list

Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define emb emplace_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define N  999999
#define f first 
#define em emplace
#define s second
#define lint long long int 
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<lint> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

 
#define fori(n) for(int i=0; i<int(n); i++)
 
#define cins(s) string s; cin>>s;
#define cini(i) lint i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }
#define z 1000000007 
   
void solve(){
 cini(n);
 cinai(b,n);
 int arr[N]; 
 memset(arr,-1,sizeof(arr));
 
 arr[n-1]=0; arr[n-2]=abs(b[n-1]-b[n-2]);

 for(int i=n-3;i>=0;i--){
    arr[i]=min(abs(b[i]-b[i+1])+arr[i+1],abs(b[i]-
        b[i+2])+arr[i+2]);
 }
 cout<<arr[0]<<endl;

 




}
 
 
int main()
{ 
  fast;
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("hex.txt","w",stdout);
  #endif*/

  solve();
 }

Measured memory_bytes: 4992
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

int main(){
	int n;
	cin >> n;
	int x[n],y[n];
	REP(i,n){
		cin >> x[i];
		y[i] = x[i];
	}
	sort(y, y + n);
	REP(i,n){
		if(x[i] < y[n / 2]) cout << y[n / 2] << endl;
		else cout << y[n / 2 - 1] << endl;
	}
}

Measured memory_bytes: 3712
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int ans = (h2 - h1) * 60 + (m2 - m1) - k;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    bool judge = true;
    int a,b;
    string s;
    cin >> a >> b >> s;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == '-')
        {
            if(i != a){judge = false; break;}
        }
        else
        {
            if(i == a){judge = false; break;}
        }
    }
    if(judge){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

string s;

void input() {
  cin >> s;
}

void solve() {
  cout << string(s.size(), 'x');
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    ll mod = 998244353;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    if(v[0]!=0) {
        cout << 0 << endl;
        return 0;
    }
    sort(ALL(v));
    ll ans = 1;
    if(v[0]!=0 || v[1]==0) {
        cout << 0 << endl;
        return 0;
    }

    ll pre = 1;
    ll cnt = 0;
    ll now = 1;
    v.push_back(0);
    REP(i,1,n) {
        ans *= pre;
        ans %= mod;
        cnt++;
        if(v[i+1]!=v[i]) {
            if(v[i+1]!=0 && v[i+1]!=(v[i]+1)) {
                cout << 0 << endl;
                return 0;
            }
            pre = cnt;
            cnt = 0;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010;
int n;
int a[N],v[N],g[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=='-'?o=-1:0,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return o*x;
}
inline bool check(int k) {
    int tp=0;
    for(int i=2;i<=n;i++) {
	if(a[i]<=a[i-1]) {
	    while(tp&&v[tp]>a[i]) --tp;
	    int t=a[i];
	    while(t) {
		if(v[tp]<t) {
		    if(k==1) return 0;
		    v[++tp]=t,g[tp]=2;
		    break;
		}
		if(g[tp]<k) {++g[tp];break;}
		--tp,--t;
	    }
	    if(!t) return 0;
	}
    }
    return 1;
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi();
    int l=1,r=n;
    while(l<=r) {
	int mid=(l+r)>>1;
	if(check(mid)) r=mid-1;
	else l=mid+1;
    }
    cout<<l;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]){
        cout << "No" << endl;
    }else{
        cout <<"Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from pprint import pprint as pp
from functools import lru_cache
import math
"""
問題文
「N も (N+1)÷2 も素数」を満たす奇数 N を 2017に似た数 とします。
Q 個のクエリが与えられます。
クエリ i(1≦i≦Q) では奇数 li,ri が与えられるので、li≦x≦ri かつ 2017に似た数 となる奇数 x の個数を求めてください。
制約
    1≦Q≦105
    1≦li≦ri≦105
    li,ri は奇数
    入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
Q
l1 r1
:
lQ rQ
出力
i 行目 (1≦i≦Q) に、クエリ i の答えが x 個のとき、x を出力せよ。
"""

prime = [True] * 100000
prime[0] = False
prime[1] = False
for i in range(2,len(prime)):
    if prime[i]:
        for j in range(i*2, len(prime), i):
            prime[j] = False
prime2017 = [0] * 100000
prime2017[0] = 0
prime2017[1] = 0
prime2017[2] = 0
ruiseki=0
for x in range(3,len(prime)):
    if prime[x] and prime[int((x+1)/2)]:
        ruiseki+=1
    prime2017[x] = ruiseki
q=int(input())
lr_ary = []
for _ in range(q):
    l,r=list(map(int, input().split()))
    print(prime2017[r]-prime2017[l-1])

Measured memory_bytes: 5876
#include  <bits/stdc++.h>
#define ll long long
using namespace std;
 
int  main(){
    //freopen("inp.txt","r",stdin);
    ll n,h,w,res=0;
    cin>>n>>h>>w;
    for (int i=0;i<n;i++){
        ll hh,ww;
        cin>>hh>>ww;
        if (hh>=h && ww>=w) res++;
    }
    cout<<res;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int r = sc.nextInt();
		int s = sc.nextInt();
		int p = sc.nextInt();
		String t = sc.next();
		boolean[] win = new boolean[n];
		int ans = 0;
		for(int i = 0; i < n; i++) {
			//System.out.println(t.charAt(i));
			if(i<k) {
				if(t.charAt(i) == 'r') {
					win[i] = true;
					ans+=p;
				}
				else if(t.charAt(i) == 's') {
					win[i] = true;
					ans+=r;
				}
				else if(t.charAt(i) == 'p') {
					win[i] = true;
					ans+=s;
				}
			}
			else {
				if((t.charAt(i)=='r'&&t.charAt(i-k)!='r')||(t.charAt(i)=='r'&&t.charAt(i-k)=='r'&&win[i-k]!=true)) {
					win[i] = true;
					ans+=p;
				}
				else if((t.charAt(i)=='s'&&t.charAt(i-k)!='s')||(t.charAt(i)=='s'&&t.charAt(i-k)=='s'&&win[i-k]!=true)) {
					win[i] = true;
					ans+=r;
				}
				else if((t.charAt(i)=='p'&&t.charAt(i-k)!='p')||(t.charAt(i)=='p'&&t.charAt(i-k)=='p'&&win[i-k]!=true)) {
					win[i] = true;
					ans+=s;
				}
			}
		}
		System.out.println(ans);
	 }
}

Measured memory_bytes: 26364
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#define N 100002
#define D 12
using namespace std;
struct edge 
{
	int nxt,point,v;
};

struct node 
{
	int v,c,d;	
};

edge e[N << 1];

node a[N];
int n,m,Q,f[N][D],cnt;

	void add(int u1,int v1)
	{
		e[++cnt].nxt = e[u1].point; e[u1].point = cnt; e[cnt].v = v1;
	}
	
	void insert(int u1,int v1)
	{
		add(u1,v1); add(v1,u1);
	}
void init()
{
	scanf("%d %d",&n,&m);
	cnt = 0;
	for (int i = 1;i <= m; ++i)
	{
		int u1,v1;
		scanf("%d %d",&u1,&v1);
		insert(u1,v1);	
	}
	memset(a,0,sizeof(a));
	scanf("%d",&Q);
	for (int i = 1;i <= Q; ++i)
	{
		scanf("%d %d %d",&a[i].v,&a[i].d,&a[i].c);
		f[a[i].v][a[i].d] = max(f[a[i].v][a[i].d],i);
	}
	//cout<<"ha"<<f[6][1]<<endl;
}

void DO_IT()
{
	for (int i = 9;i >= 0; --i)
		for (int j = 1;j <= n; ++j)
			for (int p = e[j].point;p;p = e[p].nxt)
				f[j][i] = max(f[j][i],f[e[p].v][i + 1]);		
	//for (int i = 1;i <= 9; ++i)
}

void print()
{
	for (int i = 1;i <= n; ++i)
	{
		int M = 0;
		for (int j = 0;j <= 10; ++j)
			M = max(M,f[i][j]);
		printf("%d\n",a[M].c); 
	}
}

int main()
{
	init();
	DO_IT();
	print();
	return 0;
}

Measured memory_bytes: 8960
li=list(input())
odd_0 = li[0::2].count("0")
even_0 = li[1::2].count("0")
odd_1 = li[0::2].count("1")
even_1 = li[1::2].count("1")

#
# if odd_0 >= even_0:
#     print(odd_1+even_0)
# else:
#     print(odd_0+even_1)


if odd_0 > even_0:
    print(odd_1+even_0)
elif odd_0 < even_0:
    print(odd_0+even_1)
else:
    print(min(odd_1+even_0,odd_0+even_1))

Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b;
  a = b = 0;
  string s;
  in(s);
  rep(i, s.size()){
    if(s[i] == '0')
      a++;
    else
      b++;
  }
  out(2 * min(a, b));
  memi;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

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

    ans = n * (n - 1) / 2;

    put(ans);
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{

	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next(){
			try{
				while(st==null||!st.hasMoreElements()){
					st = new StringTokenizer(br.readLine());
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			return st.nextToken();
	
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
		public double nextDouble(){
			return Double.parseDouble(next());
		}
		public String nextLine(){
			String s = "";
			try{
				s = br.readLine();
			}catch(Exception e){
				e.printStackTrace();
			}	
			return s;		
		}
	} 
	public static void seive(boolean[] dp,int n){
		for(int i = 1; i <= n; i++){
			dp[i] = true;
		}
		dp[1] = false;
		for(int i = 2; i*i <= n; i++){
			for(int j = i*i; j <=n ; j+=i){
				dp[j] = false;
			}
		}
	}
	public static int exp(int x,int n){
		int exp = 0;
		int p = x;
		while(n/p>0){
			exp+= n/p;
			p = p*x;
		}
		return exp;
	}
	public static void main(String[] args){
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		boolean div[] = new boolean[n+1];
		int sum = 0;
		int mod=(int)(1e9)+7;
		boolean dp[] = new boolean[n+1];
		seive(dp,n);
		int tmp = 0;
		long ans = 1;
		for(int i = 1; i <= n ; i++){
			if(dp[i])
			{	
				tmp = exp(i,n);
				ans = (ans*(tmp+1)%mod);
			}
		}
		out.println(ans);
		out.flush();
		out.close();  
	}

}





Measured memory_bytes: 20944
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;

ll p10[19];
map<ll,ll> ma[19][19];

ll solve(ll sum, int l, int r)
{
	if(ma[l][r].count(sum)>0) return ma[l][r][sum];
	ll ans=0;
	if(l==r)
	{
		if(sum==0)
		{
			if(l==0)
			{
				ans+=9;
			}
			else
			{
				ans+=10;
			}
		}
	}
	else if(r==l+1)
	{		
		for(int i = 0; i <= 9; i++)
		{
			for(int j = 0; j <= 9; j++)
			{
				if(l==0&&i==0) continue;
				ll coeff = p10[r] - p10[l];
				if(coeff*ll(j-i)==sum)
				{
					//cerr<<i<<' '<<j<<'\n';
					ans++;
				}
			}
		}
	}
	else
	{
		ll L = 0;
		ll R = 0;
		int i2=l+1; int j2=r-1;
		for(;i2<=j2;i2++,j2--)
		{
			L-=9LL*(p10[j2]-p10[i2]);
			R+=9LL*(p10[j2]-p10[i2]);
		}
		for(int i = 0; i <= 9; i++)
		{
			for(int j = 0; j <= 9; j++)
			{
				if(l==0&&i==0) continue;
				ll coeff = p10[r] - p10[l];
				ll res = sum-coeff*ll(j-i);
				if(res>=L&&res<=R)
				{
					ans+=solve(res,l+1,r-1);
				}
			}
		}
	}
	//if(ans>0) cerr<<l<<' '<<r<<' '<<sum<<' '<<ans<<'\n';
	return (ma[l][r][sum]=ans);
}
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	//freopen("mirrored.in","r",stdin);
	//freopen("mirrored.out","w",stdout);
	int c;
	//for(int i=0;i<100000;i++)
	//{
		cin>>c;
		string s;
		while(c)
		{
			s+=char('0'+c%10);
			c/=10;
		}
		reverse(s.begin(),s.end());
		assert(s[0]!='0');
		ll d=0;
		for(int i=0;i<s.length();i++)
		{
			d*=10LL;
			d+=s[i]-'0';
		}
		p10[0]=1;
		for(int i=1;i<=18;i++)
		{
			p10[i]=p10[i-1]*10LL;
		}
		ll ans=0;
		for(int i = 1; i <= 18; i++)
		{
			/*
			int l = i - 1; int r = 0;
			ll cnt = 1;
			ll sum = d;
			for(;r<=l;r++,l--)
			{
				ll coeff = p10[l] - p10[r];
				
			}
			if(sum==0) ans+=cnt;
			*/
			ans+=solve(d,0,i-1);
			//cerr<<solve(d,0,i-1)<<'\n';
			for(int i=0;i<19;i++)
			{
				for(int j=0;j<19;j++)
				{
					ma[i][j].clear();
				}
			}
		}
	//	cout<<"Case #"<<d<<" ";
		cout<<ans<<'\n';
	//}
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto& e : a) {
		cin >> e;
	}
	sort(rbegin(a), rend(a));
	vector<int> s(2);
	for (int i = 0; i < n; i++) {
		s[i % 2] += a[i];
	}
	cout << s[0] - s[1] << endl;
	return 0;
}


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

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef long long ll;

int main(void){
	string s;
	getline(cin, s);
	ll k;
	cin >> k;

	int flg = 1;
	REP(i, s.length()){
		if(!i) continue;
		if(s[i] != s[i-1]){
			flg = 0;
			break;
		}
	}
	if(flg){
		cout << s.length()*k/2 << endl;;
		return 0;
	}

	ll same = 1, same1 = 1;
	ll ans = 0;
	if(s[0] != s[s.length()-1]){
		REP(i, s.length()){
			if(!i) continue;
			if(s[i] == s[i-1]){
				same++;
			}else{
				ans += same/2;
				same = 1;
			}
		}
		ans += same/2;

		cout << ans*k << endl;
	}else{
		REP(i, s.length()){
			if(!i) continue;
			if(s[i] == s[i-1]){
				same++;
			}else{
				if(i != same){
					ans += same/2*k;
				}
				same = 1;
			}
		}
		ans += same/2;
		same++;
		REP(i, s.length()){
			if(!i) continue;
			if(s[i] == s[i-1]){
				same1++;
				same++;
			}else{
				ans += same/2*(k-1);
				ans += same1/2;
				break;
			}
		}

		cout << ans << endl;
	}

	return 0;
}


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

using namespace std;


int main(void) {
    while(1) {
        int n,w;
        cin >> n >> w;
        if(!n) break;

        int histo[1000]={};

        for(int i=0; i<n; i++) {
            int v;
            cin >> v;
            histo[v/w]++;
        }

        int mini=0,maxi=0,maxh=0;
        for(int i=0; i<1000; i++) {
            if(histo[i]) maxi = i;
            maxh = max(maxh, histo[i]);
        }

        int cnt=maxi-mini;
        double ink=0.;

        ink += 0.01; // various purposes
        for(int i=mini; i<=maxi; i++)
            ink += (1.-(0.+i-mini)/cnt) * (1.*histo[i]/maxh);
        printf("%.16f\n",ink);
    }
    return 0;
}

Measured memory_bytes: 1192
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.parseLong;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int m = parseInt(sc.next());
		int x = parseInt(sc.next());
		int[] a = new int[n+1];
		for (i = 0; i < m; i++) {
			a[parseInt(sc.next())] = 1;
		}
		sc.close();
		int cst0 = 0;
		for (i = x-1; i > 0; i--) {
			cst0 += a[i];
		}
		int cstn = 0;
		for (i = x+1; i < n; i++) {
			cstn += a[i];
		}
		out.println(Math.min(cst0, cstn));
	}
}


Measured memory_bytes: 21844
#include <stdio.h>

int main() {
    int i, j, tmp, N1, N2, N3, N4;
    int array[4];
    
    scanf("%d", &N1);
    scanf("%d", &N2);
    scanf("%d", &N3);
    scanf("%d", &N4);
    
    array[0] = N1, array[1] = N2, array[2] = N3, array[3] = N4;
    
    /* 数値を降順にソート */
    for (i = 0; i < 4; ++i) {
        for (j = i + 1; j < 4; ++j) {
            if (array[i] < array[j]) {
                tmp =  array[i];
                array[i] = array[j];
                array[j] = tmp;
            }
        }
    }
    
    /* 降順にソートして，9741であるか確認 */
    if (array[0] == 9 && array[1] == 7 && array[2] == 4 && array[3] == 1) {
        printf("YES");
    }else{
        printf("NO");
    }

    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cctype>

const int NUMBER_OF_OPERANDS = 100;
const int STACK_SIZE = NUMBER_OF_OPERANDS;

const char PLUS = '+';
const char MINUS = '-';
const char MULTIPLY = '*';

int main() {
  int pointer = 0;
  int stack[STACK_SIZE] = {0};

  std::string a;
  std::string b;

  while (std::cin >> a) {
    if ((a[0] == PLUS) || (a[0] == MINUS) || (a[0] == MULTIPLY)) {
      
      char op = a[0];
      
      pointer--;
      int y = stack[pointer];

      pointer--;    
      int x = stack[pointer];

      int z = 0;
    
      if (op == PLUS) {
	z = x + y;
      } else if (op == MINUS) {
	z = x - y;      
      } else if (op == MULTIPLY) {
	z = x * y;
      }
      
      stack[pointer] = z;
      pointer++;
    } else {
      int x = 0;

      std::stringstream ss;
      
      ss << a;
      ss >> x;
      
      stack[pointer] = x;
      pointer++;
    }
  }

  std::cout << stack[0] << std::endl;
  
  return 0;
}

Measured memory_bytes: 1224
N, Q = map(int, input().split())
S = list(input())
lr = list(list(map(int, input().split())) for _ in range(Q))

lst = [0] * N
'''
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        lst[i] += 1

for i in range(Q):
    print( sum( lst[ lr[i][0] - 1 : lr[i][1] - 1 ] ) )
'''
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C' and i == 0:
        lst[i] += 1
    elif S[i] == 'A' and S[i+1] == 'C':
        lst[i] += 1 + lst[i-1]
    else:
        lst[i] += lst[i-1]

for i in range(Q):
    print(lst[ lr[i][1] - 2 ] - lst[ lr[i][0] - 2 ] )


Measured memory_bytes: 34736
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
typedef long long ll;
using namespace std;

vector<vector<int>> G;
int L[200010], R[200010];
ll C[200010], dijk[100010];
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;

int main(void){
    int N, M;
    cin >> N >> M;
    G.resize(N+1);
    for(int i=0; i<M; ++i){
        cin >> L[i] >> R[i] >> C[i];
        G[L[i]].emplace_back(i);
    }
    for(int i=1; i+1<N; ++i){
        L[M+i-1]=i+1;
        R[M+i-1]=i;
        C[M+i-1]=0;
        G[i+1].emplace_back(M+i-1);
    }
    dijk[1]=0;
    for(int i=2; i<=N; ++i) dijk[i]=1e18;
    pq.push(make_pair(dijk[1], 1));
    while(!pq.empty()){
        int s=pq.top().second;
        if(s==N){
            cout << dijk[N] << endl;
            return 0;
        }
        if(dijk[s]==pq.top().first){
            pq.pop();
            for(int i=0; i<G[s].size(); ++i){
                if(dijk[s]+C[G[s][i]]<dijk[R[G[s][i]]]){
                    dijk[R[G[s][i]]]=dijk[s]+C[G[s][i]];
                    pq.push(make_pair(dijk[R[G[s][i]]], R[G[s][i]]));
                }
            }
        }
        else{
            pq.pop();
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 10492
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;
const int C = 2500;


int n, m;
int a[55];
int x;
long long dp[55][5005];

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] -= m;
    }
    dp[0][C] = 1;
    for (int i = 0; i < n; ++i) {
        x = a[i + 1];
        for (int j = 0; j <= C + C; ++j) if (dp[i][j]) {
            dp[i + 1][j + x] += dp[i][j];
            dp[i + 1][j] += dp[i][j];
        }
    }
    cout << dp[n][C] - 1<< '\n';
    return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
  int N;
  cin >> N;
  static bool drawable[4][4][4][4];
  for (int i = 0; i < N; i++) {
    int H, W;
    cin >> H >> W;
    for (int k = -H+1; k < 4; k++) {
      for (int l = -W+1; l < 4; l++) {
        drawable[max(0, k)][max(0, l)][min(3, k+H-1)][min(3, l+W-1)] = true;
      }
    }
  }
  vector<string> goal(4);
  for (int i = 0; i < 4; i++) {
    cin >> goal[i];
  }

  queue<int> q;
  q.push(0);
  static const int INF = 1000000;
  vector<int> dist(1<<16, INF);
  dist[0] = 0;
  while (!q.empty()) {
    const int n = q.front();
    q.pop();
    if (n == (1<<16)-1) {
      break;
    }
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = i; k < 4; k++) {
          for (int l = j; l < 4; l++) {
            if (drawable[i][j][k][l]) {
              for (int c = 0; c < 3; c++) {
                static const char rgb[] = "RGB";
                const char cc = rgb[c];
                int next = n;
                for (int x = i; x <= k; x++) {
                  for (int y = j; y <= l; y++) {
                    if (goal[x][y] == cc) {
                      next |= 1 << (4*x+y);
                    } else {
                      next &= ~(1 << (4*x+y));
                    }
                  }
                }
                if (dist[n]+1 < dist[next]) {
                  dist[next] = dist[n]+1;
                  q.push(next);
                }
              }
            }
          }
        }
      }
    }
  }
  cout << dist[(1<<16)-1] << endl;
  return 0;
}

Measured memory_bytes: 1276
import sys

#A.sort() #これを実装するぞ
def qsort(seq, left, right):
    #[再帰の終了条件は？]
    if left == right: return seq
    elif left+1 == right:
        if seq[left]>seq[right]:
            seq[left],seq[right] = seq[right], seq[left]
        return seq
    med = (left+right)//2
    pivot = seq[med] #[与えられた範囲の真ん中に位置する要素]
    #カーソルを⽤意
    cur_l = left
    cur_r = right
    #このwhile文で並べ替え終わらせる
    while True:
        #[左カーソル（cur_l）をpivotより⼤きい要素まで進める]
        while seq[cur_l] < pivot:
            if cur_l >= cur_r: break
            cur_l += 1
        #[右カーソル（cur_r）をpivotより⼩さい要素まで進める]
        while seq[cur_r] > pivot:
            if cur_r <= cur_l: break
            cur_r -= 1
        # カーソル交差でループ終了
        if (cur_r <= cur_l): break
        # cur_l < cur_rだが，左側にpivotより⼤きい要素，右側にpivotより⼩さい要素がそれぞれ⾒つかった．
        #[cur_rの要素とcur_lの要素を⼊れ替える]
        seq [cur_l], seq[cur_r] = seq[cur_r], seq[cur_l]
        cur_l += 1
        cur_r -= 1
    #print(seq)
    cut = -1
    if cur_l == cur_r:
        #print('pp')
        if seq[cur_l] < pivot:
            #print('qq')
            cut = cur_l
        else:
            #print('rr')
            cut = cur_l-1
    elif cur_l == cur_r+1:
        #print('ss')
        cut = cur_r
    #print(cut)
    # このwhileループを抜けるということは，左右の要素の⼊れ替えが完了したこと．
    # 分割したグループそれぞれに対して，qsortを実⾏したい！ -> 再帰
    #[左側だけでqsort]
    qsort(seq,left,cut)
    #[右側だけでqsort]
    qsort(seq,cut+1,right)
    # どんな引数を与えれば良い？

N = int(input())
vec = list(map(int,input().split()))
qsort(vec,0,N-1)
ans = vec[0]
for i in range(N-1):
  ans = (ans + vec[i+1])/2
print(ans)




Measured memory_bytes: 3064
#include <iostream>
#include <cstring>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

int N;
int A[100004];

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   cin >> N;
   FOR(i, 1, N)
      cin >> A[i];

   int res = 0;
   FOR(i, 1, N) {
      int j = A[i];
      if (A[j] == i)
         ++res;
   }

   res /= 2;
   cout << res << endl;

   return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, W;
  cin >> n >> W;
  
  vector<ll> a(1, 0), b(1, 0), c(1, 0), d(1, 0);
  ll w, v, w1;
  cin >> w1 >> v;
  a.emplace_back(v);
  for(int i = 1; i < n; i++){
    cin >> w >> v;
    if(w == w1) a.emplace_back(v);
    if(w == w1 + 1) b.emplace_back(v);
    if(w == w1 + 2) c.emplace_back(v);
    if(w == w1 + 3) d.emplace_back(v);
  }
  
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());
  sort(d.rbegin(), d.rend());
  
  for(int i = 1; i < a.size() - 1; i++) a.at(i) += a.at(i - 1);
  for(int i = 1; i < b.size() - 1; i++) b.at(i) += b.at(i - 1);
  for(int i = 1; i < c.size() - 1; i++) c.at(i) += c.at(i - 1);
  for(int i = 1; i < d.size() - 1; i++) d.at(i) += d.at(i - 1);
  
  ll ans = 0;
  ll aa, bb, cc, dd;
  aa = bb = cc = dd = 1;
  for(int i = 0; i < a.size(); i++){
    if(a.size() == 1 || i == a.size() - 1) aa = 0;
    for(int j = 0; j < b.size(); j++){
      if(b.size() == 1 || j == b.size() - 1) bb = 0;
      for(int k = 0; k < c.size(); k++){
        if(c.size() == 1 || k == c.size() - 1) cc = 0;
        for(int l = 0; l < d.size(); l++){
          if(d.size() == 1 || l == d.size() - 1) dd = 0;
          if(w1 * (i + 1) * aa + (w1 + 1) * (j + 1) * bb + (w1 + 2) * (k + 1) * cc + (w1 + 3) * (l + 1) * dd <= W){
            ans = max(ans, a.at(i) + b.at(j) + c.at(k) + d.at(l));
          }
          dd = 1;
        }
        cc = 1;
      }
      bb = 1;
    }
    aa = 1;
  }
  
  cout << ans << '\n';
}

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

int main()
{
	int n,i,j,a[4][13],k;
	char c;
	
	for(j=0;j<4;j++){
		for(i=0;i<13;i++){
			a[j][i]=0;
			}
		}
			
	cin>>n;
	for(i=0;i<n;i++){
	cin>>c>>k;
	if(c=='S')
		a[0][k-1]=1;
	else if(c=='H')
		a[1][k-1]=1;
	else if(c=='C')
		a[2][k-1]=1;
	else if(c=='D')
		a[3][k-1]=1;
	}
	
	for(j=0;j<4;j++){	
		for(i=0;i<13;i++){
			if(a[j][i]==0){
				if(j==(int)'S'-83)
				cout<<'S'<<" "<<i+1<<endl;
				else if(j==(int)'H'-71)
				cout<<'H'<<" "<<i+1<<endl;
				else if(j==(int)'C'-65)
				cout<<'C'<<" "<<i+1<<endl;
				else if(j==(int)'D'-65)
				cout<<'D'<<" "<<i+1<<endl;
				}
			}
		}
	return 0;
}
			

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <functional>
#include <stack>

int main (){
	int n;

	std::cin >> n;

	std::vector<int> v(n);

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	int count = 0;
	for (size_t i = 0; i < n - 1; i++)
	{
		if (v[i] != i + 1) {
			count++;
		}
	}
	if (count > 2) {
		std::cout << "NO" << std::endl;
	}
	else {
		std::cout << "YES" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
# define mp make_pair
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}

int main() {
  int n; cin >> n;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];

  --h[0];

  rep(i, n-1){
    if(h[i]==h[i+1]) continue;
    if(h[i] + 1 <= h[i+1]) --h[i+1];
    else {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

ll gcd(ll a,ll b) {
    while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
    }
    return a;
}

int main(){
ll N;
cin >> N;
ll sum=0;
for(ll i=1;i<N+1;i++){
 for(ll j=1;j<N+1;j++){
   for(ll k=1;k<N+1;k++){
     sum+=gcd(gcd(i,j),k)
   ;}
 ;}
;}
cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<int>a(n);
    for (auto &e : a)
        cin >> e;
    
    reverse(a.begin(), a.end());
    cout << a[0];
    for (int i = 1; i < n; ++i)
        cout << ' ' << a[i];
    cout << endl;
}



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

int n;
int a[2000001], b[2000001];

void CountingSort(int k){
    int c[10001] = {};

    for(int i = 1; i <= n; i++){
        c[a[i]]++;
    }

    for(int i = 1; i <= k ; i++){
        c[i] += c[i-1];
    }

    for(int j = n; j > 0; j--){
        b[c[a[j]]] = a[j];
        c[a[j]]--;
    }
}

int main(){
    int  maxl = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        maxl = max(a[i], maxl);
    }
    CountingSort(maxl);

    for(int i = 1; i <= n; i++){
        if(i != 1) cout << " ";
        cout << b[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 18736
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-18
inline ll read()
{
    ll tmp=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0';
    return tmp*f;
}
using namespace std;
ll a[200010],b[200010];
ll tmp[200010];
int n;
ll find(ll k)
{
    int l=1,r=n+1;
    while(l<r){
        int mid=(l+r)>>1;
        if(tmp[mid]>=k)r=mid;else l=mid+1;
    }
    return l;
}
int main()
{
    int i,k;
    n=read();
    for(i=1;i<=n;i++)a[i]=read();
    for(i=1;i<=n;i++)b[i]=read();
    ll ans=0;
    for(k=1;k<=29;k++){
        ll base=(1<<k)-1;
        for(i=1;i<=n;i++)tmp[i]=b[i]&base;
        sort(tmp+1,tmp+n+1);
        ll cnt=0;
        for(i=1;i<=n;i++)
            cnt+=n-find((1<<(k-1))-(a[i]&base))+1;
        for(i=1;i<=n;i++)
            cnt-=find((1<<k)+(1<<(k-1))-(a[i]&base))-find((1<<k)-(a[i]&base));
        if(cnt&1)ans+=(1<<(k-1));
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
int main()
{
 
	int n,m,a,b[25],c,sum,ans=0;
	cin>>n>>m>>c;
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		sum=c;
		for(int j=0;j<m;j++)
		{
			cin>>a;
			sum+=a*b[j];
		}
		if(sum>0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def intread():
    return int(sysread())
def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())


def run():
    N, *A = mapread()
    run = False
    ans = 0
    count = 0
    for a in A:
        if run:
            if not a:
                ans += count // 2
                run = False
                count = 0
            else:
                count += a
        else:
            if not a:
                continue
            else:
                run = True
                count += a
    ans += count // 2
    print(ans)

if __name__ == "__main__":
    run()


Measured memory_bytes: 18296
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll f(ll b,ll n){
	if(n<b) return n;
	else return f(b,n/b)+n%b; 
}
ll n,s,sn,ans=LONG_LONG_MAX;
int main(){
	scanf("%lld%lld",&n,&s); sn=sqrt(n)+1;
	if(s>n){printf("-1"); return 0;}
	if(s==n){printf("%lld",n+1); return 0;}
	for(ll i=2;i<=sn;i++) if(f(i,n)==s){printf("%lld",i); return 0;}
	for(ll i=1;i<=sn;i++)
		if((n-s)%i==0){
			ll b=(n-s)/i+1;
			if(f(b,n)==s) ans=min(ans,b);
		}
	if(ans==LONG_LONG_MAX) printf("-1");
	else printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 384
/**
 * Boris Sokolov
 * Software Engineer at Ring Labs
 * Kiev, Ukraine | Los Angeles, CA
 */

#pragma comment(linker, "/STACK:500000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int INF = static_cast<int>(1e9);
const int MOD = static_cast<int>(1e9) + 7;

int s[109];

int main() {
    //freopen("in.txt", "rt", stdin);
    //freopen("out.txt", "wt", stdout);
    int n;
    scanf("%d", &n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &s[i]);
        sum += s[i];
    }
    int res = ((sum % 10) == 0) ? 0 : sum;
    for (int i = 0; i < n; ++i) {
        if ((sum - s[i]) % 10 != 0) {
            res = max(res, sum - s[i]);
        }
    }
    printf("%d\n", res);
    return 0;
}

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

int main()
{
	long long a,b,n,x;
	cin>>a>>b>>n;
	
	if(b-1<=n)
	{
		x=b-1;
		cout<<floor(a*x/b)-a*floor(x/b)<<endl;
	}
	else
	{
		x=n;
		cout<<floor(a*x/b)-a*floor(x/b)<<endl;
	}
	return 0;
	
}


Measured memory_bytes: 3808
n, y = map(int, input().split())

def error_out():
    print('-1 -1 -1')
    exit()

if y > n * 10000 or y < n * 1000:
    error_out()

y //= 1000

if y >= n * 5:
    a = (y - n * 5) // 5 + (y - n * 5) % 5
    c = (y - n * 5) % 5
    b = n - a - c

    if b >= 0:
        print(a, b, c)
    else:
        error_out()
else:
    a = (y - n) % 4
    b = (y - n) // 4 - a * 2
    c = n - a - b

    if b >= 0 and c >= 0:
        print(a, b, c)
    else:
        error_out()

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

int N;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++) cin >> C[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    auto itA = lower_bound(A.begin(), A.end(), B[i]);
    auto itC = upper_bound(C.begin(), C.end(), B[i]);
    long long indexA = itA - A.begin();
    long long indexC = C.end() - itC;
    ans += indexA * indexC;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4504
n=int(input())
a=list(map(int,input().split()))
q=int(input())
dict={}
for k in a:
    if k in dict:
        dict[k]+=1
    else:
        dict[k]=1

ans=0
for k,v in dict.items():
    ans+=k*v

for _ in range(q):
    b,c=map(int,input().split())
    if b not in dict:
        print(ans)
        continue
    
    ans=ans+(c-b)*dict[b]
    if c in dict:
        dict[c]+=dict[b]
    else:
        dict[c]=dict[b]
    dict[b]=0
    print(ans)

Measured memory_bytes: 83988
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
int T,t[35],N,I[105],d,m,i,j,C[105],s,D,mc;
int main()
{
	for(;scanf("%d",&T),T;)
	{
		memset(C,0,sizeof(C));
		for(i=0;i<100;i++)I[i]=24;
		for(i=0;i<T;i++)scanf("%d",&t[i]);
		for(scanf("%d",&N),i=D=0;i<N;i++)
		{
			scanf("%d%d",&d,&m);
			D=max(D,d-1);
			I[d-1]=min(I[d-1],m);
		}
		for(i=D;i>=0;i--)
			for(C[i]=1,j=i,s=0,mc=99;i<D;j++,s++)
			{
				if(i!=j)mc=min(mc,C[j]);
				if(t[s%T]>I[j])
				{
					C[i]+=mc;
					break;
				}
			}
	printf("%d\n",C[0]-1);
	}
	return 0;
}

Measured memory_bytes: 600
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Measured memory_bytes: 82392
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);
int n;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    vi a(n);
    vector<ll> cnt(n + 1);
    ll ans = 0;
    for (int &x: a){
        cin >> x;
        ans += (ll)cnt[x];
        cnt[x]++;
    }

    for (int i = 0; i < n; i++){
        cout << ans - (cnt[a[i]] - 1) << '\n';
    }

    return 0;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void){
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll num=n/i;
        ans+=(num+1)*num/2*i;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        private long c(long p) {
            return p * (p + 1) / 2L;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {

            int n = in.readInt();

            long res = c(n);

            res -= 3 * c(n / 3) + 5 * c(n / 5) - 15 * c(n / 15);

            out.println(res);
        }

    }

    static class FastScanner {
        private StringTokenizer st;
        private BufferedReader in;

        public FastScanner(final InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
        }

        public String readToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int readInt() {
            return Integer.parseInt(readToken());
        }

    }
}



Measured memory_bytes: 32772
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] A = new int[N + 1];
    int[] B = new int[N];
    for (int i = 0; i < N + 1; i++) A[i] = scanner.nextInt();
    for (int i = 0; i < N; i++) B[i] = scanner.nextInt();

    long res = 0;
    for (int i = 0; i < N; i++) {
      int c = Math.min(A[i], B[i]);
      res += c;
      B[i] -= c;
      c = Math.min(A[i + 1], B[i]);
      res += c;
      A[i + 1] -= c;
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 89608
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main()
{
	string s;
	cin >> s;
	if (s.at(0) == s.at(1)) {
		if (s.at(1) == s[2]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

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

int max(int a, int b, int c){
	if(a > b && a > c)
		return a;
	if(b > a && b > c)
		return b;
	return c;
}	

int main(){
	int a, b;
	cin >> a >> b;
	cout << max(a*b, a+b, a-b) << endl;	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[4];
        for(int i = 0; i < 4; i++){
            int b = sc.nextInt();
            if(b == 1) a[0] = 1;
            if(b == 4) a[1] = 1;
            if(b == 7) a[2] = 1;
            if(b == 9) a[3] = 1;
        }

        if(a[0] ==1 && a[1] ==1 && a[2] ==1 && a[3] ==1) System.out.println("YES");
        else System.out.println("NO");
        sc.close();
    }

}


Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<long long int> v{a * c, a * d, b * c, b * d};
    sort(v.begin(), v.end());
    cout <<  v.back() << endl;
}




Measured memory_bytes: 3632