akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func BubbleSort(a []int) ([]int, int) {
	var count int
	flag := true
	for flag {
		flag = false
		for i := len(a) - 1; i > 0; i-- {
			if a[i] < a[i-1] {
				a[i], a[i-1] = a[i-1], a[i]
				flag = true
				count++
			}
		}
	}
	return a, count
}

func printArray(b []int) {
	for i, v := range b {
		fmt.Print(v)
		if i < len(b)-1 {
			fmt.Print(" ")
		} else {
			fmt.Println()
		}
	}
}

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	b, count := BubbleSort(a)
	printArray(b)
	fmt.Println(count)
}



Measured memory_bytes: 1132
def main():
	number_of_team = int(input())
	#チーム数
	result_matrix = [list(map(int, input().split())) for l in range(int(number_of_team*(number_of_team-1)/2))]
	#入力される試合の結果
	points_of_team = [0 for l in range(number_of_team)]
	#勝ち点を保存するリスト
	
	
	#勝ち点の計算
	for low in result_matrix:
		if low[2] == low[3]:
			points_of_team[int(low[0])-1] += 1
			points_of_team[int(low[1])-1] += 1
		elif low[2] > low[3]:
			points_of_team[int(low[0])-1] += 3
		else:
			points_of_team[int(low[1])-1] += 3

	sort_list = sorted(points_of_team,reverse=True)
	result_list = [0 for i in range(number_of_team)]#出力用のリスト
	rank = 1
	pred = sort_list[0]
	for i in range(number_of_team):
		max_index = points_of_team.index(sort_list[i])
		if pred != sort_list[i]:
			pred = sort_list[i]
			rank = i+1			

		result_list[max_index] = rank
		points_of_team[max_index] = -1

	for i in range(number_of_team):
		print(result_list[i])
		
	

if __name__ == '__main__':
	main()


Measured memory_bytes: 6164
#include<bits/stdc++.h>
using namespace std;
int n,x,a[101],sum,ans,ans1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sum/=n;
	for(int i=1;i<=n;i++)
	{
		ans+=(a[i]-sum)*(a[i]-sum);
		ans1+=(a[i]-sum-1)*(a[i]-sum-1);
	}
	printf("%d",min(ans,ans1));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main() {
	using namespace std;
	int n, m,min;
	int *nary,*p,*x;
	cin >> n;
	nary = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> nary[i];
	}
	cin >> m;
	p = new int[m];
	x = new int[m];
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> x[i];
	}
	for (int i = 0; i < m; i++) {
		int sum = 0;
		for (int j = 0; j < n; j++) {
			if (j == p[i] - 1)
				sum += x[i];
			else
				sum += nary[j];
		}
		cout << sum << endl;
	}
	delete[] p;
	delete[] x;
	delete[] nary;
}

Measured memory_bytes: 256
L=[26**i for i in range(13)]
#print(L)
gun=[sum(L[1:i])for i in range(2,13)]
#print(gun)
N=int(input())
i=0
while N > gun[i]:
  i += 1
#print(i)
if i != 0:
  N = N - gun[i-1] #これを26進法
N -= 1
#print(N)
L=[]
for k in range(1,i+2):
   L.append(N//(26**(i+1-k)))
   N = N % (26**(i+1-k))
#print(L)
L=[chr(i+97) for i in L]
#print(L)
print(''.join(L))

Measured memory_bytes: 9100
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int a,b,c,d;
    cin >> a  >> b >> c >> d;
    int left = max(a,c);
    int right = min(b,d);
    if (right - left >= 0){
        cout << right - left << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import datetime
s = input()
tdatetime = datetime.datetime.strptime(s, '%Y/%m/%d')
tdate = datetime.date(tdatetime.year, tdatetime.month, tdatetime.day)
d = datetime.date(2019, 4, 30)
if tdate <= d:
    print('Heisei')
else:
    print('TBD')


Measured memory_bytes: 4464
h, w, k = map(int, input().split())
C = [list(input()) for i in range(h)]
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        cnt = 0
        for x in range(h):
            if (i>>x)&1 == 1:
                continue
            for y in range(w):
                if (j>>y)&1 == 1:
                    continue
                if C[x][y] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};

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

    vector<ll> a(N);
    for(int i = 0; i < N; ++i) {
      cin>> a[i];
    }
    int ans=1;
    int fugo=0;
    for(int i = 1; i < N; ++i) {
        if(fugo==0){

            fugo=a[i]-a[i-1];
            continue;
        }

        if(fugo*(a[i]-a[i-1])>=0) continue;
        fugo=0;
        ans++;

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


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

#define int long long 
#define dou double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n,i,b,c,sum=0,x,q;
	cin >> n;
	vector<int> v(n),cnt(100001,0);
	for(i=0;i<n;i++)
	{
		cin >> v[i];
		sum += v[i];
		cnt[v[i]]++;

	}
	cin >> q;
	for(i=0;i<q;i++)
	{
		cin >> b >> c;
		x = cnt[b];
		sum += c*x-b*x;
		cnt[c] += x;
		cnt[b] -= x;
		cout << sum << endl;
	}
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	return 0;
}

Measured memory_bytes: 4776
#include <iostream>  
#include <stdio.h>  
#include <string.h>  
using namespace std;    
char s[15];  
int pos[15];  
long long num(int l,int r)  
{  
    long long ans=0;    
    for(int i=l;i<=r;i++)  
    {  
        ans=ans*10+s[i]-'0';  
    }  
    return ans;  
}  
long long solve(int n)  
{  
    int l=-1,r=0;  
    long long ans=0;  
    pos[n]=1;  
    for(int i=0;i<=n;i++)  
    {  
        if(pos[i]==0)  
            r++;  
        else  
        {  
            ans+=num(l+1,i);  
            l=i;  
        }  
    }  
    return ans;  
}  
int main()  
{  
     while(cin>>s)  
     {  
         int n=strlen(s);  
         long long ans=0;  
         int R=(1<<(n-1))-1; 
        for(int i=0;i<=R;i++)  
        {  
            memset(pos,0,sizeof(pos));  
            int tot=0;  
            int temp=i;  
            while(temp)  
            {  
                pos[tot++]=temp%2;  
                temp=temp/2;  
            }   
            ans+=solve(n-1);  
        }  
        printf("%lld\n",ans);  
     }  
    return 0;  
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define fr(i,p,n) for(ll i=p;i<n;i++)
#define fr1(i,p,n) for(ll i=p;i>=n;i--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e9
#define precise cout << std::setprecision(12) << std::fixed;
#define endl "\n"
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FAST
    int t=1;
    //cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        int mn=x*2;
        int mx=x*4;
        if(y%2!=0) cout<<"No"<<endl;
        else
        {
            if(y>=mn && y<=mx) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 1; i < 100000; i++)
        {
            if (Floor(i * 0.08) == ab[0] && Floor(i * 0.1) == ab[1])
            {
                Console.WriteLine(i);
                return;
            }
        }
        Console.WriteLine(-1);
    }
}

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

int main () {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  string ans = "No";
  if (s < t) ans = "Yes";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>

int main(){
  int D,N;
  scanf("%d %d",&D,&N);
  if(N!=100){
    printf("%d", (int)pow(100,D)*N);
  }else{
    printf("%d",(int)pow(100,D)*(N+1));
  }
  return 0;
}




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

//#include <atcoder/all>

using namespace std;
// using namespace atcoder;

using ll = long long;

int main() {
  ll N;
  cin >> N;
  for (ll h = 1; h <= 3500; h++) {
    for (ll n = 1; n <= 3500; n++) {
      ll w1 = N * h * n;
      ll w2 = 4 * h * n - N * n - N * h;
      if (w2 <= 0 || w1 == 0) continue;
      if (w1 % w2 == 0) {
        cout << h << ' ' << n << ' ' << w1 / w2 << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3584
n = int(input())
h = list(map(int,input().split()))

dp = [10 ** 5 for i in range(n)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(n-2):
    dp[i+2] = min(dp[i] + abs(h[i+2] - h[i]), dp[i+1] + abs(h[i+2] - h[i+1]))
print(dp[-1])

Measured memory_bytes: 14036
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		int n2 = n * 2;
		int ab = 100 - c;
		int mod = 1000000007;
		NCR ncr = new NCR(n2, mod);

		long ans = 0;
		for (int i = n; i < n2; i++) {
			long val1 = ncr.calc(i - 1, n - 1);
			long val2 = power(a, n, mod) * power(b, i - n, mod);
			val2 += power(a, i - n, mod) * power(b, n, mod);
			val2 %= mod;
			ans += val1 * val2 % mod * i % mod * modinv(power(ab, i, mod), mod) % mod;
			ans %= mod;
		}

		long draw = 100 * modinv(ab, mod) % mod;
		ans *= draw;
		ans %= mod;
		System.out.println(ans);
	}

	static class NCR {
		long[] p, pi;
		int m;

		public NCR(int n, int mod) {
			n++;
			m = mod;
			p = new long[n];
			pi = new long[n];
			p[0] = 1;
			pi[0] = 1;
			for (int i = 1; i < n; i++) {
				p[i] = p[i - 1] * i % m;
			}
			pi[n - 1] = BigInteger.valueOf(p[n - 1])
					.modInverse(BigInteger.valueOf(m)).longValue();
			for (int i = n - 1; i > 1; i--) {
				pi[i - 1] = pi[i] * i % m;
			}
		}

		public long calc(int n, int r) {
			if (n < r) return 0;
			return p[n] * pi[r] % m * pi[n - r] % m;
		}
	}

	static long power(long x, long n, int m) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2, m);
		val = val * val % m;
		if (n % 2 == 1) {
			val = val * x % m;
		}
		return val;
	}

	static long modinv(long a, int m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int max = a[0], min = a[0];
  for(int i = 0; i < n; i++){
    if(a[i] > max) max = a[i];
    if(a[i] < min) min = a[i];
  }
  
  cout << max - min << endl;
  return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<int> mask(m, 0);
	FOR(i, 0, m)
	{
		int k, x;
		cin >> k;
		while(k--)
		{
			cin >> x;
			x--;
			mask[i] |= 1 << x;
		}
	}
	
	vector<int> p(m);
	FOR(i, 0, m) cin >> p[i];
	
	int ans = 0;
	
	FOR(i, 0, 1 << n)
	{
		bool ok = true;
		FOR(j, 0, m) ok &= (__builtin_popcount(mask[j] & i) & 1) == p[j];
		ans += ok;
	}
	
	
	cout << ans << endl;
	
	
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<tr1/unordered_set>
#include<tr1/unordered_map>
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007
#define Pi 3.14159
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define IN(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printPI(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define PI pair<int,int>
#define PL pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<VI>
#define vvl vector<VL>
#define vvvi vector<VVI>
#define vvvl vector<VVL>
#define vpi vector<PI>
#define vpl vector<PL>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
#define dbg(x, y) cout << x << " = " << y << endl
using namespace std;


const int Ntest = 1e5 + 5;


ll gcd(ll a, ll b) {ll temp; while (b > 0) {temp = a % b; a = b; b = temp;} return a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll fpow(ll  b, ll exp, ll mod) {if (exp == 0) return 1; ll t = fpow(b, exp / 2, mod); if (exp & 1) return t * t % mod * b % mod; return t * t % mod;}
ll divmod(ll i, ll j, ll mod) {i %= mod, j %= mod; return i * fpow(j, mod - 2, mod) % mod;}

clock_t time_p = clock();
void TimeTaken()
{
	time_p = clock() - time_p;
	cerr << "Completion time : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
vi v[100001];
int p[100001], k[100001];
bool ans = true;

void sol() {
	ll n, sum, ans;
	ll a[200005];
	cin >> n;

	sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum = sum ^ a[i];
	}
	for (int i = 0; i < n; i++) {
		ans = 0;
		if (i != 0)
			cout << ' ';
		ans = sum ^ a[i];
		cout << ans;
	}
	cout << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	while (t--)
		sol();

	return 0;
}

Measured memory_bytes: 7428
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    
    Scanner scan = new Scanner(System.in);
    int n1 = scan.nextInt();
    int n2 = scan.nextInt();
    int n3 = scan.nextInt();
    
    if (n1 == n2) {
    	System.out.println(String.valueOf(n3));
    }else if (n1 == n3) {
    	System.out.println(String.valueOf(n2));
    }else if (n2 == n3) {
    	System.out.println(String.valueOf(n1));
    }
	return;
  }
}



Measured memory_bytes: 23124
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

A,B=map(int,input().split())
a = divisor(A)
b = divisor(B)
ab = list(set(a) & set(b))
#print(ab)

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

ans = 0
for j in ab:
    if is_prime(j)==True:
        ans += 1
print(ans+1)

Measured memory_bytes: 5248
#include<cstdio>
#include<algorithm>
using namespace std;
int n, K;
struct point{
    int a, b;
}w[101000];
long long res;
void Calc(int a){
    int i;
    long long s = 0;
    for(i=0;i<n;i++)if((w[i].a&a)==w[i].a) s += w[i].b;
    res=max(res,s);
}
int main(){
    int i;
    scanf("%d%d",&n,&K);
    for(i=0;i<n;i++)scanf("%d%d",&w[i].a,&w[i].b);
    Calc(K);
    for(i=30;i>=0;i--){
        if((1<<i)&K){
            Calc((((K>>i) - 1) << i) + (1<<i) - 1);
        }
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 896
import java.util.*;

import static java.lang.System.*;

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

        if(A == B &&  B == C){
            out.println("Yes");
        } else {
            out.println("No");
        }
    }
}

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

int main(){

	int n;
	cin >> n;

	vector<int> a(n);
	vector<double> x(n),y(n);

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

	for ( int i = 0; i < n; i++){
		a[i] = i;
	}
	
	double sum = 0;
  	int count = 0;

	do{
		for( int i = 0; i < n-1; i++){
			sum += sqrt( (x[a[i]] - x[a[i+1]]) * (x[a[i]] - x[a[i+1]]) + (y[a[i]] - y[a[i+1]]) * (y[a[i]] - y[a[i+1]]));
		}
      	count++;
	}while(next_permutation(a.begin(),a.end()));

	cout << fixed << setprecision(10) << sum / count << endl;

	return 0;

}


Measured memory_bytes: 3784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			if (a == -1 && b == -1 && c == -1)
				break;
			if (a == -1 || b == -1)
				System.out.println("F");
			else if (a + b >= 80)
				System.out.println("A");
			else if (a + b >= 65)
				System.out.println("B");
			else if (a + b >= 50)
				System.out.println("C");
			else if (a + b >= 30)
				if (c >= 50)
					System.out.println("C");
				else
					System.out.println("D");
			else
				System.out.println("F");
		}

	}
}




Measured memory_bytes: 26480
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


// 68 11 55 - rank 3
// 69 12 19 - rank 3
// 70 12 34 - rank 100
// 71 12 58 - rank 4
// 72 13 24

ull gcd(ull a, ull b) {
    while (b != 0) {
        auto na = a % b;
        a = b;
        b = na;
    }
    return a;
}


void oneCase() {
    int x, t;
    cin >> x >> t;
    cout << max(0, x - t) << "\n";

}


int main() {
    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


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

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    int A, B;
    cin >> A >> B;
    int res = 0;
    if(A > B){
        res += A;
        A--;
    } else {
        res += B;
        B--;
    }
    if(A > B){
        res += A;
        A--;
    } else {
        res += B;
        B--;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	int N;
	int[] a;

	public void randomSort(int[] array){
		for(int i = 0;i < N;i++){
			int random = (int)(Math.random() * array.length);
			int tmp = array[random];
			array[random] = array[i];
			array[i] = tmp;
		}
	}

	public void solve() {
		N = nextInt();
		a = new int[3*N];
		for(int i = 0;i < 3*N;i++){
			a[i] = nextInt();
		}
		randomSort(a);
		Arrays.sort(a);

		int left = 0;
		int right = 3*N-1;
		long ans = 0;
		while(left < right){
			left++;
			right--;
			ans += a[right];
			right--;

		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 47240
def r;gets.split.map &:to_i;end
def rr(n);n.times.map{gets.chomp.chars.sort.join};end
N = gets.to_i
S = rr(N)
p S.group_by(&:itself).values.map(&:size).inject(0){|a,b|a += b*(b-1)/2}

Measured memory_bytes: 39676
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  queue<ll> q;
  int cnt = 0;
  for (ll i = 1; i < 10 ; i++ ) q.push(i);
  while ( !q.empty() ) {
    ll x = q.front();
    cnt++;
    if( cnt == k ) {
      cout << x << endl;
      break;
    }
    q.pop();
    if ( x % 10 != 0 ) {
      q.push( x * 10 + (x % 10) - 1 );
    }
    q.push( x * 10 + (x % 10)  );
    if ( x % 10 != 9 ) {
      q.push( x * 10 + (x % 10) + 1 );
    }
  }

  return 0;
}



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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	vector<string> v{"Sunny", "Cloudy", "Rainy"};
	string s;
	cin>>s;
	rep(i,0,v.size()){
		if(s==v[i]){
			ret(v[(i+1)%3]);
		}
	}	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll l(100);
  l[0] = 2, l[1] = 1;
  for(int i=2;i<=n;i++) l[i] = l[i-1]+l[i-2];
  std::cout << l[n] << '\n';
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
cnt = {i : 0 for i in range(N)}
for a in A:
    cnt[a] += 1
exist_ans = True
if N % 2:
    if cnt[0] != 1:
        exiet_ans = False
    for i in range(2, N, 2):
        if cnt[i] != 2:
            exist_ans = False
else:
    for i in range(1, N, 2):
        if cnt[1] != 2:
            exist_ans = False
if exist_ans:
    print(2**(N//2) % (10**9 +7))
else:
    print(0)



Measured memory_bytes: 20704
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/17/20 22:14:12
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,m; cin>>n>>m;
  vector<int> path[n];
  for (int i = 0; i < m; i++) {
    int a,b; cin>>a>>b; a--; b--;
    path[a].push_back(b);
    path[b].push_back(a);
  }
  auto solve = [&path, n](auto& f, int s, int d) {
    if (d == 2) {
      return s == n-1;
    }
    for (auto t:path[s]) {
      if (f(f, t, d+1))
        return true;
    }
    return false;
  };
  cout << (solve(solve, 0, 0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  return 0;
}


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

int main() {

	int a, b, c;
	string s;
	cin >> a >> b >> c;

	int num = a * 100 + b * 10 + c;

	s = num % 4 == 0 ? "YES" : "NO";

	cout << s << endl;
}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_A&lang=jp
// dp[i] = min(dp[i-c[j]]+1)
#include <bits/stdc++.h>
using namespace std;
int n, m;
int c[20], dp[50001];
int main() {
    scanf("%d%d",&n,&m);
    for (int i=0; i<m; i++) scanf("%d", &c[i]);
    sort(c, c+m);
    for (int i=1; i<=n; i++) {
        dp[i] = dp[i-c[0]]+1;
        for (int j=1; j<m; j++) {
            if (i < c[j]) break;
            dp[i] = min(dp[i], dp[i-c[j]]+1);
        }
    }
    printf("%d\n",dp[n]);
}

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

int main(){
	int sx,sy,tx,ty;cin>>sx>>sy>>tx>>ty;
	int x=tx-sx;int y=ty-sy;
	
	string s=string(y,'U')+string(x+1,'R')+string(y+1,'D')+string(x+1,'L')+"UL"+string(y+1,'U')+string(x+1,'R')+string(y+1,'D')+string(x,'L');
	cout<<s<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize (2)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
#define INF 0x3f3f3f3f
long long dp[2005];
int mod=1e9+7;
int main()
{
	dp[0]=0;
	dp[1]=0;
	dp[2]=0;
	dp[3]=1;
	int n;
	scanf("%d",&n);
	for(int i=4;i<=n;i++)
	{
		dp[i]=(dp[i-1]+dp[i-3])%mod;
	}
	printf("%d\n",dp[n]);
 } 

Measured memory_bytes: 3764
#include <iostream>
 
using namespace std;
 
 
#define MAX 500000
#define SENTINEL 2000000000
 
int L[MAX/2+2], R[MAX/2+2];
int cnt;
 
void merge(int A[],int n,int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
 
void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}
 
int main(void) {
  int A[MAX], n, i;
  cnt = 0;
 
    cin >> n;
  for(i=0;i<n;i++) cin >> A[i];
 
  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
    cout << A[i];
  }
  cout << endl;
 
  cout << cnt << endl;
 
  return 0;
}

Measured memory_bytes: 6984
# include <iostream>

int main()
{
    std::ios_base::sync_with_stdio(false);
    int n, w, h;
    std::cin >> w >> h >> n;
//    int a[n+2][n+2] = {};
    int l = 0, r = w, u = h, d = 0;
    for(int i = 0; i < n; i++) {
        int x, y, a;
        std::cin >> x >> y >> a;
        if(a == 1) {
            l = std::max(x, l);
        } else if(a == 2) {
            r = std::min(x, r);
        } else if(a == 3) {
            d = std::max(d, y);
        } else {
            u = std::min(u, y);
        }
    }

    if(l >= r || d >= u) {
        std::cout << 0;
    } else {
        std::cout << std::max(0, (r - l) * (u - d));
    }
}


Measured memory_bytes: 256
n = int(input())
s = input()

r = []
g = []
b = []

for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
    elif s[i] == "B":
        b.append(i)

ans = len(r) * len(g) * len(b)

j = 1
while j * 2 <= n:
    for k in range(n - 2 * j):
        if set([s[k], s[k + j] , s[k + 2 * j]]) == set(["R", "G", "B"]):
            ans -= 1
    j += 1

print(ans)

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

int main(){
	string N; cin>>N;
	ll S=0;
	for(int i=0;i<N.size();i++){
		S+=N[i]-'0';
	}
	if(S%9==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3772
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
struct edge {
	int from, to, cost;
};
int main() {
	int v, e, r; cin >> v >> e >> r;
	vector <edge> ed;
	for (int i = 0; i < e; i++) {
		int s, t, co; cin >> s >> t >> co;
		edge e1; e1.from = s; e1.to = t; e1.cost = co;
		ed.push_back(e1);
	}
	int *d = new int[v];
	fill(d, d + v, INF);
	d[r] = 0;
	while (true) {
		bool  update = false;
		for (int i = 0; i < ed.size(); i++) {
			edge ex = ed[i];
			if (d[ed[i].from] != INF && d[ed[i].to] > d[ed[i].from] + ex.cost) {
				d[ed[i].to] = d[ed[i].from] + ex.cost;
				//cout << "from " << d[ed[i].from] << " to " << d[ed[i].to] << " cost " << ex.cost << endl;
				update = true;
			}
		}
		if (!update)  break; 
	}
	for (int i = 0; i < v; i++) {
		if (d[i] == INF) cout << "INF" << endl;
		else  cout << d[i] << endl;
	}
	delete[] d;
	return 0;
}

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

import static java.lang.Integer.*;
import static java.lang.Long.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st;


        st = new StringTokenizer(in.readLine());
        int N = parseInt(st.nextToken()), M = parseInt(st.nextToken());
        Long K = parseLong(st.nextToken());
        st = new StringTokenizer(in.readLine());
        long[] A = new long[N + 1];
        long[] B = new long[M + 1];
        A[0] = 0;
        B[0] = 0;
        for (int i = 1; i <= N; i++) {
            A[i] += (A[i - 1] + parseLong(st.nextToken()));
        }
        st = new StringTokenizer(in.readLine());
        for (int i = 1; i <= M; i++) {
            B[i] += (B[i - 1] + parseLong(st.nextToken()));
        }
        pw.println(solve(A, B, N, K));
        pw.close();
    }

    static Long solve(long[] A, long[] B, int N, long K) {
        long res = 0;
        int j = B.length - 1;
        for (int i = 0; i <= N; i++) {
            if (A[i] > K) break;
            while (B[j] > (K - A[i])) {
                j--;
            }
            res = Math.max(res, (i + j));
        }
        return res;
    }
}

Measured memory_bytes: 62464
import java.util.*;
class Process{
    public String name;
    public int time;
    public String getName(){
	return this.name;
    }
    public int getTime(){
	return this.time;
    }
}
class Main{

    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt(),q = sc.nextInt();
	int ttltime = 0;
	
        ArrayList<Process> p = new ArrayList<Process>();
	
	for(int i = 0;i < n;i++){
	    Process ptmp = new Process();
	    ptmp.name = sc.next();
	    ptmp.time = sc.nextInt();
	    p.add(ptmp);
	}
	
	while(p.size() > 0){
	    int T = p.get(0).getTime();
	    Process ptmp2 = new Process();
	    ptmp2.name = p.get(0).getName();
	    if(T > q){
		p.remove(0);
		ptmp2.time = T - q;
		p.add(ptmp2);
		ttltime += q;
	    }
	    else{
		ttltime += T;
		System.out.println(p.get(0).getName()+" "+ttltime);
		p.remove(0);
	    }    
	}
       
    }

}


Measured memory_bytes: 73840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

struct UF {
	vi t;
	UF(int n){
		t.resize(n, -1);
	}
	int find(int a){
		return t[a]<0 ? a : t[a] = find(t[a]);
	}
	bool uni(int a, int b){
		a = find(a), b = find(b);
		if(a == b) return 0;
		if(t[a] < t[b]) swap(a,b);
		t[b] += t[a];
		t[a] = b;
		return 1;
	}
};

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vi as(n), bs(n);
	trav(a, as) cin >> a;
	trav(b, bs) cin >> b;
	int x = 0;
	trav(a, as) x ^= a;
	as.push_back(x);
	x = 0;
	trav(b, bs) x ^= b;
	bs.push_back(x);
	vi s = as, t = bs;
	sort(all(s)), sort(all(t));
	if(s != t){
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	rep(i,0,n) ans += as[i] != bs[i];

	map<int,int> ren;
	trav(x, as) ren[x] = 0;
	int ix = 0;
	trav(pa, ren) pa.second = ix++;
	ans += ix-1;
	UF uf(ix);
	rep(i,0,n) ans -= uf.uni(ren[as[i]], ren[bs[i]]);
	rep(i,0,ix) if(i != ren[as.back()] && uf.t[i] == -1) --ans;
	cout << ans << endl;
}

Measured memory_bytes: 6896
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a+b>=a*b&&a+b>=a-b)
	{
		cout<<a+b<<endl;
		return 0;
	}
	if(a-b>=a+b&&a-b>=a*b)
	{
		cout<<a-b<<endl;
		return 0;
	};
	cout<<a*b<<endl;
	return 0;
}

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

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

class UnionFind{
public:
    int n;
    vector<int> v;

    UnionFind():n{0}{}
    UnionFind(int n_in):n{n_in}{
        v.assign(n,-1);
    }
    
    int find(int x){
        assert(0<=x && x<n);
        if(v[x]<0) return x;
        v[x]=find(v[x]);
        return v[x];
    }
    
    bool same(int a,int b){
        assert(0<=a && a<n);
        assert(0<=b && b<n);
        if(find(a)==find(b)) return true;
        return false;
    }
    
    int merge(int a,int b){
        assert(0<=a && a<n);
        assert(0<=b && b<n);
        int a_p=find(a),b_p=find(b);
        if(a_p==b_p) return a_p;
        if(a_p>b_p) swap(a_p,b_p);
        v[a_p]+=v[b_p]; v[b_p]=a_p;
        return a_p;
    }
    
    int size(int a){
        assert(0<=a && a<n);
        return -v[find(a)];
    }

    int group_cnt(){
        int res=0;
        for(auto p:v)if(p<0) res++;
        return res;
    }
};


int main(){
    int n,q; cin>>n>>q;
    UnionFind uf(n);
    rep(_,q){
        int t,u,v; cin>>t>>u>>v;
        if(t==0){
            uf.merge(u,v);
        }
        else{
            printf("%d\n",(int)uf.same(u,v));
        }
    }
}

Measured memory_bytes: 3984
/*
    author: Salam_35
    Created at :

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    string s;
    cin >> s;
    string a,b,c,d,e;

    a=s;
    int n=s.size();
    reverse(ALL(a));
    if(a==s)
    {
        int one=(n+3)/2-1;
        b=s.substr(0,(n-1)/2);
        c=b;
        reverse(ALL(c));
        d=s.substr((n+3)/2-1,n-one);
        e=d;
        reverse(ALL(e));
        //cout<<b <<' '<<e<<endl;
        if(b==c and d==e)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
   int a,b;

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

   if ((a + b <= 16) && (a <= 8) && (b <= 8))
     printf("Yay!\n");
   else
     printf(":(\n");
   return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b,c,e,f=0;
  cin>>a>>b>>c;
  vector<int> d(a);
  fo(i,a)
    cin>>d[i];
  Sort(d);
  for(int i=0;i<a;i=i){
    f++;
    e=i;
    for(int j=0;j<b&&i<a&&e+j<a;j++){
      if(d[e+j]<=d[e]+c)
        i++;
      else
        break;
    }
  }
  cout<<f<<endl;
}

Measured memory_bytes: 1024
#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 reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e10
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<lli>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using lli = long long int;
template<typename T> bool chmax(T &a, T &b){ if(a<b) { a=b; return 1; }}
template<typename T> bool chmin(T &a, T &b){ if(b<a) { a=b; return 1; }}
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T arrdebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    lli n, buf;
    vector<lli> a;
    cin >> n;
    rep(i, n){
        cin >> buf;
        a.push_back(buf);
    }

    lli g = a[0];;
    reps(i, 1, n){
        g = gcd(g, a[i]);
    }

    cout << g << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>

using namespace std;
#define N 4
#define N2 16

static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle{
    int f[N2],space,MD;
    int cost;

    bool operator < (const Puzzle &p) const{
        for(int i=0;i<N2;i++){
            if(f[i]==p.f[i]) continue;
            return f[i]<p.f[i];
        }
        return false;
    }
};

struct State{
    Puzzle puzzle;
    int estimated;
    bool operator < (const State &s) const{
        return estimated>s.estimated;
    }
};

int getAllMD(Puzzle pz){
    int sum=0;
    for(int i=0;i<N2;i++){
        if(pz.f[i]==N2) continue;
        sum+=MDT[i][pz.f[i]-1];
    }
    return sum;
}

int astar(Puzzle s){
    priority_queue<State> PQ;
    s.MD=getAllMD(s);
    s.cost=0;
    map<Puzzle,bool> V;
    Puzzle u,v;
    State initial;
    initial.puzzle=s;
    initial.estimated=getAllMD(s);
    PQ.push(initial);

    while(!PQ.empty()){
        State st=PQ.top(); PQ.pop();
        u=st.puzzle;
        if(u.MD==0) return u.cost;
        V[u]=true;
        int sx=u.space/N;
        int sy=u.space%N;
        for(int r=0;r<4;r++){
            int tx=sx+dx[r];
            int ty=sy+dy[r];
            if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
            v=u;
            swap(v.f[sx*N+sy],v.f[tx*N+ty]);
            v.MD=getAllMD(v);
            v.space=tx*N+ty;
            if(!V[v]){
                v.cost++;
                State news;
                news.puzzle=v;
                news.estimated=v.cost+v.MD;
                PQ.push(news);
            }
        }
    }
    return -1;
}

int main(){
    for(int i=0;i<N2;i++){
        for(int j=0;j<N2;j++){
            MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
        }
    }
    Puzzle in;
    for(int i=0;i<N2;i++){
        cin>>in.f[i];
        if(in.f[i]==0){
            in.f[i]=N2;
            in.space=i;
        }
    }
    cout<<astar(in)<<endl;
}



Measured memory_bytes: 257596
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

unsigned long long dp[301][301];
unsigned long long yoko[301], tate[301];
const int cm = 1 << 12;
char cn[cm], * ci = cn, ct;

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


	fread(cn, 1, cm, stdin);
	int N = 0, M = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
	while ((ct = *ci++) >= '0') M = M * 10 + ct - '0';

	int xm[301][4], xM[301][4];
	rep1(i, N) {
		xm[i][1] = N;
		xm[i][2] = N;
		xM[i][2] = -1;
		xM[i][3] = -1;
	}
	rep(i, M) {
		int l = 0, r = 0;
		while ((ct = *ci++) >= '0') l = l * 10 + ct - '0';
		while ((ct = *ci++) >= '0') r = r * 10 + ct - '0';
		int x = *ci++ - '0';
		ci++;
		chmin(xm[r][x], l);
		chmax(xM[r][x], l);
	}

	const int mod = 1e9 + 7;
	dp[0][0] = 1;
	yoko[0] = 1;
	tate[0] = 1;
	int mj = 0;
	int mk = 0;
	unsigned long long yabai = 1;
	rep1(i, N) {
		for (int k = i - 1; k >= 0; k--) {
			dp[k][i] = yoko[k] + tate[k];
			if (dp[k][i] >= mod) dp[k][i] -= mod;
		}
		for (int k = i; k >= 0; k--) {
			yoko[k] += dp[k][i];
			if (yoko[k] >= mod) yoko[k] -= mod;
			tate[i] += dp[k][i];
		}
		tate[i] %= mod;

		for (int j = i; j > max(xm[i][2], mj - 1); j--) {
			if (yoko[j]) {
				for (int k = i; k >= max(j, mk); k--) {
					tate[k] += mod - dp[j][k];
					if (tate[k] >= mod) tate[k] -= mod;
					dp[j][k] = 0;
				}
				yoko[j] = 0;
			}
		}
		for (int j = xm[i][2]; j > max(xM[i][3], mj - 1); j--) {
			for (int k = i; k > max(max(xm[i][1], mk - 1), j - 1); k--) {
				yoko[j] += mod - dp[j][k];
				tate[k] += mod - dp[j][k];
				if (tate[k] >= mod) tate[k] -= mod;
				dp[j][k] = 0;
			}
			for (int k = xM[i][2]; k >= max(j, mk); k--) {
				yoko[j] += mod - dp[j][k];
				tate[k] += mod - dp[j][k];
				if (tate[k] >= mod) tate[k] -= mod;
				dp[j][k] = 0;
			}
			yoko[j] %= mod;
		}
		for (int j = xM[i][3]; j >= mj; j--) {
			if (yoko[j]) {
				for (int k = i; k >= max(j, mk); k--) {
					tate[k] += mod - dp[j][k];
					if (tate[k] >= mod) tate[k] -= mod;
					dp[j][k] = 0;
				}
				yoko[j] = 0;
			}
		}
		if (mj <= xM[i][3]) mj = xM[i][3] + 1;
		if (mk <= xM[i][2]) mk = xM[i][2] + 1;
	}

	ll kotae = 0;
	for (int j = mj; j <= N; j++) kotae += yoko[j];
	printf("%lld ", kotae% mod);

	Would you please return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    ll ans=0;
    vector<int>a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    vector<pair<int,int>>ab(n);
    rep(i,n){
        ab[i]=make_pair(a[i],b[i]);
    }
    sort(ab.begin(),ab.end());
    rep(i,n){
        int buy=min(m,ab[i].second);
            m-=buy;
            ans+=(ll)ab[i].first*buy;
    }
    cout<<ans<<endl;
}

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

using namespace std;

const int maxn = 2e5 + 5;

typedef long long LL;
LL c[maxn];
int n;

void add(int pos, LL val){
    for(int i = pos;i < maxn;i += i & -i){
        c[i] = max(c[i], val);
    } 
}

LL sum(int pos){
    LL res = 0;
    for(int i = pos;i > 0;i -= i & -i){
        res = max(res, c[i]);
    }
    return res;
}

pair<int, pair<int, int> > p[maxn];
LL dp[maxn];

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        scanf("%d", &p[i].first);
    }    
    for(int i = 1;i <= n;i++){
        scanf("%d", &p[i].second.first);
        p[i].second.second = i;
    }
    sort(p + 1,p + 1 + n);
    for(int i = 1;i <= n;i++){
        int id = p[i].second.second;
        LL pre = sum(id - 1);
        dp[id] = pre + p[i].second.first;
        add(id, dp[id]);
    }
    LL ans = 0;
    for(int i = 1;i <= n;i++){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760