akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <bitset>

using ll = long long;

using namespace std;

using B = bitset<4000001>;

int main() {
    int n;
    cin >> n;
    B b;
    b.set(0);
    int sum = 0;
    for (int i=0, ai; i<n; i++) {
        cin >> ai;
        sum += ai;
        b |= (b << ai);
    }
    for (int i=(sum+1)/2; i<=sum; i++) {
        if (b[i]) {
            cout << i << '\n';
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,ba,p[10];
	char a[101];
	int i,j;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++) p[i]=0;
		scanf("%s",a);
		
		j=0;ba=0;
		for(i=0;i<100;i++){
			if(j>=n) j=0;
			p[j]++;
			if(a[i]=='S'){
				ba+=p[j]; p[j]=0;
			}
			if(a[i]=='L'){
				p[j]+=ba; ba=0;
			}
			j++;
		}
		
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(p[i]>p[j]) swap(p[i],p[j]);
			}
		}
		
		for(i=0;i<n;i++) printf("%d ",p[i]);
		printf("%d\n",ba);
	}
	return 0;
}


Measured memory_bytes: 2768
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s,t=input().split()
a,b=map(int,input().split())
u=input()
if u==s:
    a-=1
else:
    b-=1
print(a,b)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  queue<int> q;
  q.push(1);
  int ans = 0;
  vector<bool> seen(n,0);
  while(!q.empty()){
    int now = q.front();
    q.pop();
    if(seen[now-1]){
      cout << -1 << endl;
      return 0;
    }
    seen[now-1] = 1;
    if(now == 2){
      cout << ans << endl;
      return 0;
    }
    ans ++;
    q.push(a[now-1]);
  }
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		boolean AC[]=new boolean[N];
		int WA[]=new int[N];
		int ac=0,wa=0;
		for(int i=0;i<M;i++){
			int p=stdIn.nextInt()-1;
			String S=stdIn.next();
			if(S.equals("AC"))
				AC[p]=true;
			if(AC[p]==false&&S.equals("WA"))
				WA[p]++;
		}
		for(int i=0;i<N;i++){
			if(AC[i]){
				ac++;
				wa+=WA[i];
			}
		}
		System.out.println(ac);
		System.out.println(wa);
	}
}


Measured memory_bytes: 63760
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  cout << fixed << setprecision(10);
  ll n;
  cin>>n;
  vector<double> p(n);
  rep(i,n)cin>>p[i];
  vector<vector<double>> dp(n+1,vector<double>(n+1));
  dp[0][0]=1;
  rep(i,n){
    rep(j,n){
      dp[i+1][j]+=dp[i][j]*(1.0-p[i]);
      dp[i+1][j+1]+=dp[i][j]*p[i];
    }
  }
  ll k=(n+1)/2;
  double ans=0;
  for(int i=k;i<=n;i++){
   ans+=dp[n][i];
  }
  COUT(ans);
}

Measured memory_bytes: 70784
import sys
'import math'
while(1):
    n,m=input().split()
    if n=='0' and m=='0':
        sys.exit()
    n=int(n)+1
    m=int(m)
    cnt=0
    for a in range(1,n):
        for b in range(a+1,n):
            for c in range (b+1,n):
                if a+b+c==m:
                    cnt+=1
    print(cnt)


Measured memory_bytes: 5596
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

N = int(input())
A = list(map(int, input().split()))
gcd_left = [A[0]]
gcd_right = [A[-1]]
for i in range(1, N):
    gcd_left.append(gcd(gcd_left[-1], A[i]))
    gcd_right.append(gcd(gcd_right[-1], A[N-i-1]))
gcd_right = list(reversed(gcd_right))

ans = 0
for i in range(N):
    if 0 < i < N-1:
        ans = max(ans, gcd(gcd_left[i-1], gcd_right[i+1]))
    elif i == 0:
        ans = max(ans, gcd_right[i+1])
    else:
        ans = max(ans, gcd_left[i-1])
print(ans)

Measured memory_bytes: 14400
import java.util.Scanner;

public class Main {

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

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

		Student[] students = new Student[N];
		CheckPoint[] check_points = new CheckPoint[M];

		for(int i = 0; i < students.length; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			students[i] = new Student(a, b);
		}
		for(int i = 0; i < check_points.length; i++){
			int c = sc.nextInt();
			int d = sc.nextInt();
			check_points[i] = new CheckPoint(c, d);
		}

		for(Student st: students){
			st.SetDestination(check_points);
		}
		for(Student st: students){
			System.out.println(st.Destination);
		}

		sc.close();
	}

}

class Student {
	Point Position;
	int Destination;

	Student(int a, int b){
		Position = new Point(a, b);
	}

	void SetDestination(CheckPoint[] cpts){
		int mindist = Integer.MAX_VALUE;
		for(CheckPoint c: cpts){
			int dist = Distance.Manhattan(this.Position, c.Position);
			if(dist < mindist){
				Destination = c.Id;
				mindist = dist;
			}
		}
	}
}

class CheckPoint {
	static int InitId = 1;

	int Id;
	Point Position;

	CheckPoint(int c, int d){
		Id = InitId;
		InitId++;
		Position = new Point(c, d);
	}
}

class Distance {
	static int Manhattan(Point a, Point b){
		return Math.abs(a.X - b.X) + Math.abs(a.Y - b.Y);
	}
}

class Point {
	int X;
	int Y;

	Point(int x, int y){
		X = x;
		Y = y;
	}
}

Measured memory_bytes: 21844
from collections import Counter

n = int(input())
d = list( map(int, input().split()))
c=Counter(d)
dmax = max(d)
MOD = 998244353

if d[0] != 0:
    print(0)
    exit()

if len(c)-1 != dmax:
    print(0)
    exit()

if c[0] != 1:
    print(0)
    exit()

ans = 1

for i in range(1,dmax):
    ans *= c[i]**c[i+1]
    ans %= MOD

print(ans)

Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n,K;
  cin >> n >> K;
  vector<ll> A(n);
  for (auto& _a : A) {
    cin >> _a;
    --_a;
  }
  ll idx = 0;
  unordered_map<ll,ll> m;
  ll i = 0;
  while (i < K) {
    if (m.count(idx)) {
      ll cycle_len = i - m[idx];
      ll steps_remain = K - i;
      i += (steps_remain/cycle_len)*cycle_len;
      if (i==K) break;
    } else {
      m[idx] = i;
    }
    idx = A[idx];
    ++i;
  }
  cout << idx+1 << endl;
  

}


Measured memory_bytes: 11876
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    int N, f, cnt = 0;
    string S;
    cin >> N >> S;
    REP(i, 1000){
        int p[3] = {i/100, (i%100)/10, i%10};
        f = 0;
        REP(j, N){
            if (S[j] == ('0' + p[f])){
                f++;
            }
            if (f == 3){
                break;
            }
        }
        if (f == 3) cnt++;
    }
    cout << cnt << endl;
}

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

using namespace std;
static const int MAX=200000;

int main(){
	int R[MAX],n;
	cin >> n;
	for(int i=0;i<n;i++) cin >> R[i];
	
	int maxv=-2000000000;
	int minv=R[0];

	for(int i=1;i<n;i++){
		maxv=max(maxv,R[i] - minv);
		minv=min(minv,R[i]);
	}

	cout << maxv <<endl;
	return 0;
	
}




Measured memory_bytes: 3876
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

int n, m;
int POW[16];

int calc(int A, int B, int C) {
	int res = 0;
	for_(i,0,n) {
		int k = n - i - 1;
		if (A >> i & 1) res += 2 * POW[k];
		if (B >> i & 1) res += POW[k], swap(A, C);
	}
	return res;
}

void solve() {
	int cup[3] = { 0 };
	
	for_(i,0,3) {
		int d; cin >> d;
		for_(j,0,d) {
			int p; cin >> p; --p;
			cup[i] |= 1 << p;
		}
	}
	
	int ans = min(calc(cup[0], cup[1], cup[2]), calc(cup[2], cup[1], cup[0]));
	cout << ( (ans > m) ? -1 : ans) << endl;
}

int main() {
	POW[0] = 1;
	for_(i,1,16) POW[i] = POW[i - 1] * 3;
	while (cin >> n >> m, n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;
#include <climits>
#include <cmath>

typedef long long ll;

int main() {
    ll n;   cin >> n;
    ll *a = new ll[n];
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    ll ans = LLONG_MAX, x = 0;

    for (int i = 0; i < n-1; i++) {
        x += a[i];
        sum -= a[i];
        ans = min(ans, abs(x - sum));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

int main() {
	int n;
	
	while (std::cin >> n, n) {
		int ans = 0;

		for (int i = 0; i < n / 4; ++i) {
			int x;
			std::cin >> x;

			ans += x;
		}

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

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

using namespace std;

int main() {
	int a;
	int b;
	scanf("%d%d", &a, &b);
	int c = 1;
	for (int i = 1; i <= a; i++) c = min(c * 2, c + b);
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
a = []
b = []

for i in range(n):
    a.append(int(input()))
for i in range(m):
    b.append(int(input()))

rank = [0]*n

for i in b:
    for j in range(n):
        if i >= a[j]:
            rank[j] += 1
            break

print(rank.index(max(rank))+1)


Measured memory_bytes: 5624
r,w,c,rr=map(int,input().split())
lsr=[]
lsw=[]
lsc=[]
lsrr=[]
n=0
m=0
while True:
    R,W,C,RR=map(int,input().split())
    lsr.append(R)
    lsw.append(W)
    lsc.append(C)
    lsrr.append(RR)
    if R==0:
        break
    n+=1

if lsr[0]/lsw[0]>=lsc[0]:
        print(0)
else:
    while lsr[0]+lsrr[0]*m<lsw[0]*lsc[0]:
        m+=1
    print(m-1)
for i in range(n):
    m=0
    
    if lsr[i]/lsw[i]>=lsc[i]:
        print(0)
    else:
        while lsr[i]+lsrr[i]*m<lsw[i]*lsc[i]:
            m+=1
        print(m)



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

using namespace std;

#define MAXN 100010
#define PI acos(-1.0)
#define mo 1000000007
#define INF 0x3f3f3f3f
#define eps 1e-8
typedef long long LL;

int n, cnt[MAXN];

int main()
{
    int i, a;
    scanf("%d", &n);
    for(i = 1; i <= n; ++i){
        scanf("%d", &a);
        ++cnt[a % 4];
    }

    if(cnt[1] + cnt[3] > cnt[0] + 1) printf("No\n");
    else if(cnt[1] + cnt[3] == cnt[0] + 1){
        if(cnt[2]) printf("No\n");
        else printf("Yes\n");
    }
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    int k, x;
    cin >> k >> x;
    if (500 * k >= x)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  char s;
  cin >> s;
  if(s>=65 && s<=90)cout << 'A' << endl;
  else cout << 'a' << endl;

}

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

int main(){
    long long int n=0;
    long long int ans=0;
    cin>>n;
    for(long long int i=0;i<=n;i++){
        if(i%3!=0&&i%5!=0){
            ans=ans+i;
        }
        else{}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
N=gets.to_i
b=gets.split.map &:to_i
r=""
while !b.empty? do
    f=0
    (b.size-1).downto(0){|j|
        if b[j]==j+1 then
            r=(j+1).to_s+"\n"+r
            b.delete_at(j)
            f=1
            break
        end
    }
    if f==0 then 
        p -1
        exit
    end
end
puts r

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define MOD 1000000007 
using namespace std;
typedef long long LL;

int main(){
  int K, Q, D[5000];
  cin >> K >> Q;
  REP(i, K) {
    cin >> D[i];
  }
  REP(_, Q) {
    LL N, X, M, E[5000];
    cin >> N >> X >> M;
    X %= M;
    LL ret = N - 1;
    LL a_last = X;
    REP(i, K) {
      LL count = (N-1) / K + ((N-1) % K > i ? 1 : 0);
      a_last += count * (D[i] % M);
      if(D[i] % M == 0) {
        ret -= count;
      }
    }
    ret -= a_last / M;
    cout << ret << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
int x;
string u, v;
void solve(){
        if(u=="A") v="T";
        if(u=="G") v="C";
        if(u=="C") v="G";
        if(u=="T") v="A";
    cout<<v<<"\n";
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> u;
    solve();
}

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

using namespace std;

const int MAXN = 17;

int N;

long long dp[1 << MAXN];
long long points[1 << MAXN];

long long ar[MAXN][MAXN];

int main() {

	scanf("%d", &N);

	for( int i=0 ; i < N ; i++ ) {

		for( int j=0 ; j < N ; j++ ) {
		
			scanf("%lld", &ar[i][j]);
		}
	}

	for( int mask=1 ; mask < (1 << N) ; mask++ ) {

		for( int i=0 ; i < N ; i++ ) {

			if ((1 << i) & mask) {

				for( int j = i + 1 ; j < N ; j++ ) {

					if ((1 << j) & mask) {

						points[mask] += ar[i][j];
					}
				}
			}
		}
	}

	for( int mask = 1 ; mask < (1 << N) ; mask++ ) {

		dp[mask] = points[mask];

		for ( int submask = mask ; submask ; submask = (submask - 1) & mask ) {

			int group = mask ^ submask;

			dp[mask] = max(dp[mask], dp[submask] + points[group]);
		}
	}

	printf("%lld\n", dp[(1 << N) - 1]);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main(){
	int k;
	cin >> k;
	vector<long long> a;
	for(int i=1;i<=9;i++) a.push_back(i);
	while(1){
		if( k <= a.size() ){
			cout << a[k-1] << endl;
			return 0;
		}
		k -= a.size();
		vector<long long> old;
		swap(old,a);
		//cout << "a.size():" << a.size() << endl;
		//cout << "old.size():" << old.size() << endl;
		for(int i=0; i<old.size();i++){
			for(int j=-1;j<=1;j++){
				long long d=fmod(old[i],10)+j;
				if(d<0 || d>9 ) continue;
				long long nx = old[i]*10+d;
				a.push_back(nx);
			}
		}
	}
	return 0;	
}

Measured memory_bytes: 1716
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,t = li()
print(b * (t//a))

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

int main(){
  int t,n,d;
  cin>>t;
  while(t--){
    cin>>n>>d;
    if(n%2)cout<<127*(n-1)+d<<endl;
    else cout<<127*(n-1)+(d^127)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}

template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	ll n, m, d;
	cin >> n >> m >> d;
	int cnt = 0;
	FOR(i, 1, n + 1)
	{
		if (i + d <= n)
		{
			cnt++;
		}
	}
	//cout << cnt << endl;
	long double pr;
	if (cnt == n)
	{
		pr = (ll)cnt / (long double)(n * n);
	}
	else
	{
		pr = (ll)cnt*2 / (long double)(n*n);
	}
	//cout<<pr<<endl;
	cout << setprecision(9) << pr * (m - 1) << endl;
}


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

int main() {
	int n;
	cin >> n;
	vector<vector<int>>nini(9, vector<int>(9,0));
	for (int i = 1; i <= n; i++) {
		string x = to_string(i);
		int a = x.at(0) - '0';
		int b = x.at(x.length() - 1) - '0';
		if (a == 0 || b == 0)continue;
		a--, b--;
		nini.at(a).at(b)++;
	}
	ll ans = 0;
	for (int i = 0; i < 9; i++) {
		for (int j = 0; j < 9; j++)ans += nini.at(i).at(j) * nini.at(j).at(i);
	}
	cout << ans << endl;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n;
  while(cin >> n, n) {
    int cou1 = 0, cou2 = 0;
    rep(i, 0, n) {
      int k;
      cin >> k;
      if(k < 2) cou1++;
      if(k) cou2++;
    }
    if(cou1 == n) cout << "NA" << endl;
    else cout << cou2 + 1 << endl;
  }
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S, ans;
  bool flag = true;
  cin >> S;
  if(S.at(2) != S.at(3)) flag = false;
  if(S.at(4) != S.at(5)) flag = false;
  if(flag) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
res = [0]*n
ans = []
for i in range(n-1, -1, -1):
    if sum(res[i::i+1])%2!=a[i]:
        res[i] = 1
        ans.append(i+1)
print(len(ans))
print(*ans)

Measured memory_bytes: 14004
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string S; cin >> S;
    string ans="NO";
    vector <int> N(3,0);
    rep(i,S.size()) N[S[i]-'a']+=1;
    
    sort(N.begin(),N.end());
    if (N[2]-N[0]<=1) ans="YES";
    cout << ans << endl;
}

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

int main(){
	int a,b,t;
	cin >> a >> b >> t;
	
	cout << t/a*b << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetStr().ToCharArray();
            var ans = YesNo((N[1] == N[2]) && (N[0] == N[1] || N[2] == N[3]));


            Console.WriteLine(ans);
        }


        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

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

int main() {
  string s;
  cin >> s;
  int a_pos = s.size();
  int z_pos = 0;
  
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 'A' && a_pos > i) a_pos = i;
    if(s.at(i) == 'Z') z_pos = i;
  }
  
  int ans = z_pos - a_pos + 1;
  cout << ans << endl;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
A.sort()
lis = [False]*10**6
ans = 0
for i in range(N):
    if lis[A[i]-1]==False:
        if (i<N-1 and A[i]!=A[i+1]) or i==N-1:
            ans += 1
        a = A[i]
        while a<=10**6:
            lis[a-1] = True
            a += A[i]
print(ans)



Measured memory_bytes: 97008
#include<bits/stdc++.h>
using namespace std;
 
int h, w, a1[400][400], a2[400][400], dp[400][400][400];
 
signed main()
{
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a1[i][j];
    }
  }
 
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      a2[i + j][i - j + w] = a1[i][j];
    }
  }
 
  dp[0][w][w] = a1[0][0];
 
  for(int i = 1; i <= h + w - 2; i++){
    for(int j = 1; j <= h + w - 1; j++){
      for(int k = 1; k <= h + w - 1; k++){
	dp[i][j][k] = max({dp[i - 1][j - 1][k - 1], dp[i - 1][j - 1][k + 1], dp[i - 1][j + 1][k - 1], dp[i - 1][j + 1][k + 1]});
	if(j == k){
	  dp[i][j][k] += a2[i][j];
	}
	else{
	  dp[i][j][k] += a2[i][j] + a2[i][k];
	}
      }
    }
  }
  
  cout << dp[h + w - 2][h][h] << endl;
  return 0;
}

Measured memory_bytes: 249984
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N; ll C; cin >> N >> C;

  vector <ll> X(N + 2), V(N + 2);

  for (int i = 1; i <= N; i++){
    cin >> X[i] >> V[i];
  }
  X[N + 1] = C;

  vector <ll> sumV(N + 2), RsumV(N + 2);
  for (int i = 1; i < N + 2; i++){
    sumV[i] = sumV[i - 1] + V[i];
  }

  for (int i = N; i >= 0; i--){
    RsumV[i] = RsumV[i + 1] + V[i];
  }
  
  ll ans = 0;

  for (int i = 0; i < N + 2; i++){
    ans = max(ans, sumV[i] - X[i]);
  }
  for (int i = N + 1; i >= 0; i--){
    ans = max(ans, RsumV[i] - (C - X[i]));
  }
  

  // 時計回り -> 反時計回り
  vector <ll> L1(N + 2), R1(N + 2);
  for (int i = 0; i < N + 2; i++){
    L1[i] = sumV[i] - 2 * X[i];
  }
  
  for (int i = N + 1; i >= 0; i--){
    R1[i] = RsumV[i] - (C- X[i]);
    if (i < N + 1){
      R1[i] = max(R1[i], R1[i + 1]);
    }
  }

  for (int i = 0; i < N + 1; i++){
    ans = max(ans, L1[i] + R1[i + 1]);
  }

  // 反時計周り -> 時計回り

  vector <ll> L2(N + 2), R2(N + 2);
  for (int i = N + 1; i >= 0; i--){
    R2[i] = RsumV[i] - 2 * (C - X[i]);
  }

  for (int i = 0; i < N + 2; i++){
    L2[i] = sumV[i] - X[i];
    if (i > 0){
      L2[i] = max(L2[i - 1], L2[i]);
    }
  }
  
  for (int i = N + 1; i >= 1; i--){
    ans = max(ans, R2[i] + L2[i - 1]);
  }
  
  cout << ans << endl;
  

  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

struct Combination {
    vector<lint> fac, finv, inv;
    Combination(lint maxN) : fac(maxN + 100), finv(maxN + 100), inv(maxN + 100) {
        maxN += 100; // for safety
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1]            = 1;
        for (lint i = 2; i <= maxN; ++i) {
            fac[i]  = fac[i - 1] * i % mod;
            inv[i]  = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    lint operator()(lint n, lint k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint h, w, a, b;
    cin >> h >> w >> a >> b;
    Combination nCk(200000);
    mint ret = 0;
    for (int i = b; i < w; ++i) {
        ret += nCk(i + h - 1 - a, i) * nCk(a - 1 + w - 1 - i, a - 1);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <bitset>
#include <cmath>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    ll n;
    cin >> n;


    vector<  bitset< 60 > > v(n);
    for(int i = 0; i < n; i++){
        ll p;
        cin >> p;
        v[i] = bitset<60>(p);
    }

    vector<ll> cnt(60); 
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 60; j++){
            if(v[i][j] == 1) cnt[j] ++;
            
        }
    }

    ll pow2 = 1;
    ll ans = 0;
    for(ll i = 0; i < 60; i++){
        ll num1 = cnt[i];
        ll num0 = n - cnt[i];
        ll num = (num0 * num1);
        num %=  1000000007; 
        ll tmp = num * pow2;
        tmp %=  1000000007;
        ans += tmp;
        ans %=  1000000007;
        pow2 *= 2;
        pow2 %= 1000000007;
    }

    cout << ans << endl;
    //sort(all(v));

}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
    int Hit,bro;
    string r,n;
    while(1){
        Hit=0;bro=0;
        cin>>r>>n;
        if(r[0]=='0'&&n[0]=='0')break;
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(r[i]==n[i]){
                Hit++;
                break;
            }else if(r[i]==n[j]){
                bro++;
                break;
            }
        }
    }
        cout<<Hit<<" "<<bro<<"\n";
}
}

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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;
}

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int A, B;

void solve() {
    cin >> A >> B;
    cout << max(0, A - 2 * B);
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll testCases = 1; // cin >> testCases;
    while (testCases--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

int C;
std::vector<int> D;

int getD(int from, int to)
{
    return D[(from - 1) * C + to - 1];
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int N;
    std::cin >> N >> C;
    D.reserve(C * C);
    for (int i = 0; i < C * C; ++i) {
        int n;
        std::cin >> n;
        D.push_back(n);
    }

    using Cells = std::map<int, int>; // key = color index, value = number of cells
    std::vector<Cells> colors { Cells(), Cells(), Cells() }; // mod 3 = 0, 1, 2
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            int c;
            std::cin >> c;
            ++colors[(i + j) % 3][c];
        }
    }

    using Dist = std::pair<int, int>; // pair = color index, total dists
    using Dists = std::vector<Dist>;
    std::vector<Dists> dists { Dists(), Dists(), Dists() }; // mod 3 = 0, 1, 2
    for (int i = 0; i < 3; ++i) {
        const Cells& colorMap = colors[i];
        Dists& distVec = dists[i];
        for (int c = 1; c <= C; ++c) {
            int dist = 0;
            for (auto p : colorMap) {
                dist += getD(p.first, c) * p.second;
            }
            distVec.emplace_back(std::make_pair(c, dist));
        }
        std::partial_sort(distVec.begin(), distVec.begin() + 3, distVec.end(),
                          [](const Dist& lhs, const Dist& rhs){ return lhs.second < rhs.second; });
        distVec.resize(3);
    }
    int minDist = -1;
    for (const Dist& p0 : dists[0]) {
        for (const Dist& p1 : dists[1]) {
            if (p1.first == p0.first) continue;
            for (const Dist& p2 : dists[2]) {
                if (p2.first == p0.first || p2.first == p1.first) continue;
                int total = p0.second + p1.second + p2.second;
                if (minDist == -1 || total < minDist)
                    minDist = total;
            }
        }
    }
    std::cout << minDist << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
 
using namespace std;
 
int main(){
    int n;
    cin>>n;
    vector<int> hoge(n);
    for(int i=0;i<n;i++){
        cin>>hoge.at(i);
    }
    vector<int> fuga=hoge;
    sort(hoge.begin(),hoge.end());
    int left=hoge.at(n/2-1);
    int right=hoge.at(n/2);
    
    for(int i=0;i<n;i++){
        if(fuga.at(i)<=left) cout<<right<<endl;
        else cout<<left<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <stdio.h>
#include <unordered_set>

#define MAX_N 200'001

using namespace std;

bool B[MAX_N];

int main() {
  int N, M;
  cin >> N >> M;
  unordered_set<int> S;
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      S.insert(b);
    } else if (b == N) {
      B[a] = true;
    }
  }
  for (auto &s : S) {
    if (B[s]) {
      printf("POSSIBLE\n");
      return 0;
    }
  }
  printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 6856
// nyaa

# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define y0 asjdlksajldjals
#define y1 ajsldjalksdkjlk

#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = (int)1e9 + 7;
const int maxn = (int)6e5 + 7;
const int lmaxn = (int)4e6 + 7;
const ll linf = (ll)1e18 + 7;

const ld eps = ld(1e-11);

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

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return (a * b / gcd(a, b));
}

ll n;
ll a[maxn];
ll cnt[maxn];

int main(){
    scanf("%lld", &n);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        if(a[i] % 2 == 1){
            if(cnt[1]){
                ++cnt[0];
                cnt[1] = 0;
            } else{
                ++cnt[1];
            }
        } else{
            ++cnt[0];
        }
    }
    if(!cnt[1]){
        printf("YES");
    } else{
        printf("NO");
    }
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
//define
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define str string
//vectordefine
#define vint vector<int>
#define vvint vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vool vector<bool>
#define vtr vector<str>
#define vvtr vector<vector<str>>
//queuedefine
#define qint queue<int>
#define qtr queue<string>
#define qc queue<char>
//pairdefine
#define pint pair<int,int>
#define pic pair<int,char>
#define pci pair<char,int>
#define pis pair<int,str>
#define psi pair<str,int>
#define pcc pair<char,char>
#define pss pair<str,str>
#define mp make_pair
//mapdefine
#define mint map<int,int>
#define mic map<int,char>
#define mci map<char,int>
#define mis map<int,str>
#define msi map<str,int>
#define pb() push_back()
#define all(x) x.begin(),x.end()
#define elif else if
//function
str shizuku(char,char);
//UnionFind
struct UnionFind{
  vint par;
  UnionFind(int N):par(N){
    rep(0,N)par[i]=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry)return;
    par[rx]=ry;
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
};
//binary_search

//main
signed main(){
    int N=0,M,X,count=0,count2=0;
    double d,D;
    int alph='A'-'a';
    char op,Ch;
    str S,T;
    cin>>N;
    int a[N]={};
    rep(0,N)cin>>a[i];
    if(N%2==0){
      for(int i=N;i>0;i-=2)cout<<a[i-1]<<" ";
      for(int i=0;i<N;i+=2)cout<<a[i]<<" ";
    }
    elif(N%2==1){
      for(int i=N;i>0;i-=2)cout<<a[i-1]<<" ";
      for(int i=1;i<N;i+=2)cout<<a[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 3712
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int x, y, one, two, thr;
	cin >> x >> y >> one >> two >> thr;
	vector<ll> a(one), b(two), c(thr);
	for(auto& el: a) cin >> el;
	for(auto& el: b) cin >> el;
	for(auto& el: c) cin >> el;
	sort(a.begin(), a.end(), greater<ll>());
	sort(b.begin(), b.end(), greater<ll>());
	sort(c.begin(), c.end());
	while(a.size() > x) a.pop_back();
	while(b.size() > y) b.pop_back();

	ll ans = accumulate(a.begin(), a.end(), 0LL) + accumulate(b.begin(), b.end(), 0LL);
	while(c.size() && (a.size() || b.size())) {
		ll mnr;
		if(b.empty() || (a.size() && a.back() < b.back())) {
			mnr = a.back(); a.pop_back();
		} else {
			mnr = b.back(); b.pop_back();
		}
		if(mnr >= c.back()) break;
		ans += c.back() - mnr;
		c.pop_back();
	}
	cout << ans << '\n';
}


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

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n%2==0)
        {
            printf("%d\n",n);
        }
        else
        {
            printf("%d\n",n*2);
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
bool isPrime(ll x){
    if(x < 2)return false;
    else if(x == 2) return true;
    if(x%2 == 0) return false;
    for(ll i = 3; i*i <= x; i += 2) if(x%i == 0) return false;
    return true;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long X;
    cin >> X;
    while(!isPrime(X)) X++;
    cout << X << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    if(n == m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

public class Main{
  public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] s = br.readLine().split(" ");
    int h1 = Integer.parseInt(s[0]);
    int w1 = Integer.parseInt(s[1]);
    s = br.readLine().split(" ");
    int h2 = Integer.parseInt(s[0]);
    int w2 = Integer.parseInt(s[1]);
    
    System.out.println((h1 - h2) * (w1 - w2));
  }
}

Measured memory_bytes: 22996
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>
//#include <ctime>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 500100, MAXK = 20;
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

int n;
int pref[MAXN], suf[MAXN];

int main() {
    setIO();
	//setIO("lmio_1991_3e1_seka_01");

    cin >> n;
    FOR(i, 1, n) {
        char c; cin >> c;
        if (c == 'W') pref[i]++;
        else suf[i]++;
    }

    FOR(i, 1, n) pref[i] += pref[i-1];
    for (int i = n; i > 0; i--) suf[i] += suf[i+1];

    int ans = min(pref[n], suf[1]);
    FOR(i,1 , n-1) {
        ans = min(ans, max(pref[i],suf[i+1]));
    }

    cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 5204
//おまじないc++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
 
int main() {
long int a,b,k;
  cin>>a>>b>>k;
  if(a-k>=0){
    cout<<a-k<<' '<<b;
  }
  else if(a+b-k>=0){
    cout<<0<<' '<<b-(k-a);
  }
  else{
    cout<<0<<' '<<0;
  }
}

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

int n;
int main()
{
	int i, j;
	cin >> n;
	for (i = 11; n; i += 10) {
		for (j = 2; j * j <= i; j++) if (i % j == 0) break;
		if (j * j > i) n--, printf("%d ", i);
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cfloat>
#include <iomanip>

using namespace std;

struct edge {
    int from;
    int to;

    edge (int from , int to) : from(from), to(to) {}
    edge () {
        edge(-1, -1);
    }

    bool operator ==(const edge& other) {
        return from == other.from && to == other.to;
    }
};

vector<int> table[605];
double dp[605];
double dp2[605];

signed main() {
    int N, M;
    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        table[s].push_back(t);
    }

    // dp[i] = sum(dp[next] + 1) / n
    //       = sum(dp[next]) / n + 1
    for (int i = N-2; i >= 0; i--) {
        double sum = 0;
        for (int next : table[i]) {
            sum += dp[next];
        }
        sum /= table[i].size();
        dp[i] = sum + 1;
    }

    double ret = DBL_MAX;
    for (int i = 0; i < N; i++) {
        int mx_next = -1;
        double mx = -1;
        for (int next : table[i]) {
            if (dp[next] > mx) {
                mx_next = next;
                mx = dp[next];
            }
        }

        edge delete_edge = edge(i, mx_next);
        bool ok = true;
        fill(dp2, dp2 + N, 0);
        for (int j = N-2; j >= 0; j--) {
            double sum = 0;
            int cnt = 0;
            for (int next : table[j]) {
                if (edge(j, next) == delete_edge) continue;
                cnt++;
                sum += dp2[next];
            }
            if (cnt == 0) {
                ok = false;
                break;
            }

            sum /= cnt;
            dp2[j] = sum + 1;
        }

        if (!ok) continue;
        ret = min(ret, dp2[0]);
    }

    cout << setprecision(10) << fixed << ret << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
//cin.ignore();	// better to use 2 times getline(cin,s);
// g++ iterator.cpp -std=c++17
//cout << (A + B == C ? "YES" : "NO") << endl;
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);}


int main(void)
{
	fast();
	string s;
	cin>>s;
	string hi="";
	for(int i=1;i<=5;i++)
	{
		hi=hi+"hi";
		if(hi==s)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;

	// if(s.size%2!=0)
	// {
	// 	cout<<"No"<<endl;
	// }
	// else
	// {
	// 	if(s.size==2)
	// 	{
	// 		if(s=="hi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;			// too many lines of code(think...)
	// 		}
	// 	}
	// 	else if(s.size==4)
	// 	{
	// 		if(s=="hihi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;
	// 		}
	// 	}
	// 	else if(s.size==6)
	// 	{
	// 		if(s=="hihihi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;
	// 		}
	// 	}
	// 	else if(s.size==8)
	// 	{
	// 		if(s=="hihihihi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;
	// 		}
	// 	}
	// 	else if(s.size==10)
	// 	{
	// 		if(s=="hihihihihi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;
	// 		}
	// 	}
	// }
}

Measured memory_bytes: 256