akhauriyash/Code-Regression huggingface dataset:
#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 FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int n;
    cin >> n;

    if(n <= 999) cout << "ABC" << endl;
    else cout << "ABD" << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

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

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

Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

bool be[52];
ll n, m, cnt = 0;
ll a[52], b[52], matrix[52][52] = {};

int dfs(int u){
    be[u] = true;
    rep(i, 1, n + 1){
        if(matrix[u][i] == 0 || be[i])continue;
        dfs(i);
    }
    return 0;
}

int main(){
    cin >> n >> m;
    REP(i, m){
        cin >> a[i] >> b[i];
        matrix[a[i]][b[i]]++;
        matrix[b[i]][a[i]]++;
    }
    bool f;
    REP(i, m){
        rep(i, 1, n + 1)be[i] = false;
        matrix[a[i]][b[i]]--;
        matrix[b[i]][a[i]]--;
        dfs(1);

        rep(i, 1, n + 1){
            if(be[i] == 0){
                cnt++;
                break;
            }
        }
        matrix[a[i]][b[i]]++;
        matrix[b[i]][a[i]]++;
    }
    print(cnt);
}

Measured memory_bytes: 764
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
const int INF = 1 << 30;

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

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

    int cost[n];
    fill(cost, cost+n, INF);
    cost[0] = 0;
    for (int i = 0; i < n-1; i++) {
        cost[i+1] = min(cost[i] + abs(h[i+1] - h[i]), cost[i+1]);
        if (i < n-2) {
            cost[i+2] = min(cost[i] + abs(h[i+2] - h[i]), cost[i+2]);
        }
    }

    cout << cost[n-1] << "\n";
    return 0;
}

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


using namespace std;
constexpr long long int mod = 1000000007, MOD = 998244353;
constexpr double PI = 3.14159265358979323846;

int main() {
	int N;
	cin >> N;
	long long U=1;
	vector<long long>A(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	for (size_t i = 0; i < N; i++)
	{
		
		if (log10(U) + log10(A.at(i)) > 18.01 ||U*A.at(i) > 1000000000000000000LL||U*A.at(i)<0) { cout << -1; return 0; }
U *= A.at(i);
	}
	cout << U;
}

Measured memory_bytes: 4056
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;

int main(){

    ll N;
    cin >> N;

    ll sum = 0;
    ll n_max = 0;
    for(int i = 1; i <= N; i++){
        sum += i;
        if(sum >= N){
            n_max = i;
            break;
        }
    }

    for(int i = n_max; i >= 1; i--){
        if(N >= i){
            N -= i;
            cout << i << endl;
        }
        if(N == 0) break;
    }


}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int x,y;
    cin >> x >> y;
    int xg,yg;
    if(x == 2) xg = 3;
    else if(x == 4 || x == 6 || x == 9 || x == 11) xg = 2;
    else xg = 1;
    if(y == 2) yg = 3;
    else if(y == 4 || y == 6 || y == 9 || y == 11) yg = 2;
    else yg = 1;
    if(xg == yg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n;
    cin>>n;
    map<ll, ll> m1;
    for (int i = 1; i <=100; ++i)
    {
        for (int j = 1; j<=100; ++j)
        {
            for (int k = 1; k<=100; ++k)
            {
                ll exp = (i*i)+(j*j)+(k*k)+((i*j)+(j*k)+(k*i));
                m1[exp]++;
            }
        }
    }

    for (int i = 1; i<=n; ++i)
    {
        cout<<m1[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 6068
#ceilevenoddformula
import math
import bisect
import copy
import time
from collections import Counter
from itertools import combinations
#map(int,input().split())
#int(x) for x in input().split()
s=input()
x=input()
if x in s:
	print(0)
else:
	ans=10**9
	for i in range(len(s)-len(x)+1):
		c=0
		for j in range(len(x)):
			if s[i+j]!=x[j]:
				c+=1
		ans=min(ans,c)
	print(ans)









































Measured memory_bytes: 74448
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll A, B, C, K, ans;
    cin >> A >> B >> C >> K;
    if ( K <= A ) ans = K;
    else if ( K <= A + B ) ans = A;
    else ans = A - ( K - A - B );
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

bool Ok(const string&s){
  int n = (int)s.size();
  bool f = true;
  for(int i = 0; 2*i < n-1; ++i){    
    f &= s[i] == s[n-1-i];
  }
  return f;
}

int main(){
  string s; cin >> s;
  if(Ok(s) && Ok(s.substr(0,s.size()/2)) && Ok(s.substr(s.size()/2+1,s.size()/2)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <tuple>
#include <cmath>
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
bool color[8];

int main(){
    int N;
    cin>>N;
    int cnt = 0;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        if(a<3200) color[a/400]=true;
        else cnt++;
    }
    int cnt2=0;
    for(int i=0;i<8;i++)cnt2+=color[i];
    int minimum;
    if(cnt2)minimum=cnt2;
    else minimum=1;
    int maximum=cnt2+cnt;
    cout<<minimum<<' '<<maximum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int A, B;
    cin >> A >> B;
    if (A % 2 == 0 || B % 2 == 0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;

inline char gc()
{
		static const int L = 1000;
		static char sxd[L], *sss = sxd, *ttt = sxd;
		if(sss == ttt)
		{
				ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
				if(sss == ttt)
						return EOF;
		}
		return *sss++;
}

#define dd c = getchar()
inline long long read(long long& x)
{
		x = 0;
		char dd;
		bool f = false;
		for(; !isdigit(c); dd)
		{
				if(c == EOF)
						return -1;
				if(c == '-')
						f = true;
		}
		for(; isdigit(c); dd)
				x = (x << 1) + (x << 3) + (c ^ 48);
		if(f)
				x = -x;
		return 1;
}
#undef dd

long long i,j,n,m,r[505][505],b[505][505];
char p[505][505],k;
int main()
{
	read(n);
	read(m);
    for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			cin>>k;
			if(k=='#')
			{
				r[i][j]=1;
				b[i][j]=1;
				p[i][j]=1;
			}
		} 
	}
    for(i=1;i<=n;i++) 
	{
		r[i][1]=1;
		b[i][m]=1;
	}
    for(i=1;i<=n;i++)
	{
		for(j=2;j<m;j++)
		{ 
			if(i&1) r[i][j]=1;
			  else b[i][j]=1;
		} 
	}
    for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		  printf("%c",r[i][j] ? '#' : '.');
		printf("\n"); 
	}
	puts("");
    for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		  printf("%c",b[i][j] ? '#' : '.');
		printf("\n");
	}
    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];

    int ans = 0;

    for (int i = 1; i < n; i++) {
        const int distance = x[i] - x[i - 1];
        const int walk_cost = a * distance;
        const int teleport_cost = b;

        ans += min(walk_cost, teleport_cost);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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 MOD = 1000000007;

void solve()
{	
	int n; cin >> n;
	string s; cin >> s;
	map<char,int> m;
	rep(i,n)m[s[i]]++;
	ll ans=1;
	for(auto e:m)
	{
		ans*=e.second+1;
		ans%=MOD;
	}
	ans--;
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

class Dice{
public:
	int d[6];
	void MoveN();
	void MoveS();
	void MoveE();
	void MoveW();
	void Shift();
};

void Dice::MoveN(){
	swap(d[0],d[1]);
	swap(d[1],d[4]);
	swap(d[1],d[5]);
}
void Dice::MoveS(){
	swap(d[0],d[1]);
	swap(d[0],d[4]);
	swap(d[4],d[5]);
}
void Dice::MoveE(){
	swap(d[0],d[3]);
	swap(d[2],d[3]);
	swap(d[3],d[5]);
}
void Dice::MoveW(){
	swap(d[0],d[2]);
	swap(d[2],d[3]);
	swap(d[2],d[5]);
}
void Dice::Shift(){
	swap(d[1],d[2]);
	swap(d[3],d[4]);
	swap(d[1],d[4]);
}
int main(){
	int n;
	cin>>n;
	Dice dc[100];
	bool ans=true;
	for(int i=0;i<n;i++){
		for(int j=0;j<6;j++) cin>>dc[i].d[j];
	}
	for(int x=0;x<n;x++){
		for(int y=0;y<n;y++){
			if(x==y) continue;
			for(int i=0;i<2;i++){
				for(int j=0;j<4;j++){
					dc[y].MoveN();
					for(int k=0;k<4;k++){
						dc[y].Shift();
						bool f=true;
						for(int l=0;l<6;l++){
							if(dc[x].d[l]!=dc[y].d[l]) f=false;
						}
						if(f) ans=false;
					}
				}
				dc[y].MoveE();
			}
		}
	}
	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

ll n , k , x;

int main()
{
    _FastIO;
    cin >> n >> k;

    multiset<ll> s;

    while(true){
        if(n > k)
            n %= k;
        else n = abs(n - k);
        if(s.count(n) > 1)  break;
        s.insert(n);
    }
    cout << *(s.begin()) << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

ans=A[0]
if N>2:
    p = (N-2)//2
    q = (N-2)%2
    ans += 2*sum(A[1:1+p])
    if q==1:
        ans += A[1+p]

print(ans)

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

int main(){
  int N; cin >> N;
  map<pair<int,int>,int> mp;
  vector<pair<int, int>> xy(N);
  for (int i=0;i<N; i++){
    cin >> xy[i].first >> xy[i].second;
  }
  for (int i=0; i<N-1; i++){
    for (int j=i+1; j<N; j++){
      mp[make_pair(xy[i].first-xy[j].first,xy[i].second-xy[j].second)]++;
      mp[make_pair(xy[j].first-xy[i].first,xy[j].second-xy[i].second)]++;
    }
  }
  int mx = 0;
  for (auto k: mp){
    mx = max(k.second, mx);
  }
  cout << N-mx << endl;
}


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

long ans(long n){
    int cnt1=0,cnt2=0,cnt3=0,i,j,k;
    for(i=1;i<=100;i++){
        for(j=i;j<=100;j++){
            for(k=j;k<=100;k++){
                long sum=i*i+j*j+k*k+i*j+j*k+k*i;
                if(sum==n){
                    if(i==j && j==k)cnt1++;
                    else if(i==j ||j==k ||k==i)cnt2++;
                    if(i!=j && i!=k && j!=k)cnt3++;
                }
                if(sum>n)break;
            }
        }
    }
    return cnt1+cnt2*3+cnt3*6;
}

int main() {
    long n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cout<<ans(i)<<endl;
    }
}

Measured memory_bytes: 3604
import java.lang.reflect.Array;
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String yyyyMMDD = sc.next();
        String[] arrays = yyyyMMDD.split("/");
        int year = Integer.valueOf(arrays[2]);
        int month = Integer.valueOf(arrays[1]);

        if (year > 2019) {
            System.out.println("TBD");
            return;
        }
        if (month > 4) {
            System.out.println("TBD");
            return;
        }
        System.out.println("Heisei");
    }
}

Measured memory_bytes: 21460
/* 
 * File:   main.c
 * Author: tatuyan
 *
 * Created on 2011/03/29, 22:25
 */

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

int main(void) {
    int m1,m2,n,i,moku;
    while(scanf("%d",&moku)&&moku!=0){
        n=0;
        for(i=0;i<12;i++){
            scanf("%d %d",&m1,&m2);
            moku-=m1-m2;
            if(n==0&&moku<=0) n=i+1;
        }
        if(n==0) printf("NA\n");
        else printf("%d\n",n);
    }
    return (EXIT_SUCCESS);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
//#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    ll p[a],q[b],r[c];
    rep(i,0,a-1)cin>>p[i];
    rep(i,0,b-1)cin>>q[i];
    rep(i,0,c-1)cin>>r[i];
    sort(p,p+a,greater<ll>());
    sort(q,q+b,greater<ll>());
    sort(r,r+c,greater<ll>());
    ll sum=0;
    rep(i,0,x-1)sum+=p[i];
    rep(i,0,y-1)sum+=q[i];
    ll fp=x-1,fq=y-1,fr=0;
    while(fr<=c-1 && ((fp>=0 && r[fr]>p[fp]) || (fq>=0 && r[fr]>q[fq]))){
        if(((fp>=0 && r[fr]>p[fp]) && (fq>=0 && r[fr]>q[fq]))){
            if(p[fp]<=q[fq]){
                sum-=p[fp];
                sum+=r[fr];
                fp--;
                fr++;
            }else{
                sum-=q[fq];
                sum+=r[fr];
                fq--;
                fr++;
            }
        }else if(fp>=0 && r[fr]>p[fp]){
            sum-=p[fp];
            sum+=r[fr];
            fp--;
            fr++;
        }else{
            sum-=q[fq];
            sum+=r[fr];
            fq--;
            fr++;
        }
        
    }
    cout<<sum<<endl;
    
    return 0;
}






Measured memory_bytes: 2560
def sol():
    h,n=map(int,input().split())
    l=[]
    ans=0
    for i in range(n):
        a,b=map(int,input().split())
        l.append((a,b))
    d=[0]*20005
    for i in range(h):
        for j in l:
            a,b=j[0],j[1]
            x=d[i]+b
            if i==0 or (d[i]!=0 and d[i+a]==0):
                if d[i+a]==0:
                    d[i+a]=x
                else:
                    d[i+a]=min(d[i+a],x)
            elif d[i]!=0 and d[i+a]!=0:
                d[i+a]=min(d[i+a],x)

    for i in range(h,20005):
        if ans==0:
            ans=d[i]
        elif d[i]!=0:
            ans=min(ans,d[i])
    print(ans)

if __name__=="__main__":
    sol()


Measured memory_bytes: 40688
#include<bits/stdc++.h>
using namespace std;
int n,A[100010];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]),A[i]--;
	for(int i=1;i<=n;i++){
		if(A[i]<A[i-1]){
			A[i]++;
			if(A[i]<A[i-1]){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}

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

int main(){
  long long int a,b,n;
  long long int ans=0;
  cin >> n >> a >> b;
  long long int x[n];
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n-1; i++) {
    long long int tmp = a * (x[i+1] - x[i]);
    if (b > tmp) ans += tmp;
    else ans += b;
  }
  
  cout << ans << endl;
}

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


int main() {
    string s;
    cin>>s;

    int n=s.size()-1;
    ll ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        ll tmp=0,x=s[0]-'0';
        rep(i,n){
            if(bit & (1<<i)){
                tmp+=x;
                x=s[i+1]-'0';
            }
            else{
                x*=10;
                x+=s[i+1]-'0';
            }
        }
        tmp+=x;
        //cout<<tmp<<endl;
        ans+=tmp;
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;

    vector<string> s(n);
    vector<ll> t(n);

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

    string x;
    cin >> x;

    ll ans = 0;

    for(int i=0;i<n;i++){
        ans += t[i];
        if(s[i] == x){
            ans = 0;
        }
    }

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

Measured memory_bytes: 3628
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,t,a[100010],b[100010],ans=0;
    pll ab[100010];
    cin>>n>>t;
    rep(i,n){
        cin>>a[i]>>b[i];
        ab[i]=mp(a[i],b[i]);
    }
    ll dp1[3010][3010],dp2[3010][3010];
    rep(i,3010)rep(j,3010) dp1[i][j]=0;
    rep(i,3010)rep(j,3010) dp2[i][j]=0;
    rep(i,n){
        rep(j,t){
            if(j<a[i]){
                dp1[i+1][j]=dp1[i][j];
            }
            else{
                dp1[i+1][j]=max(dp1[i][j],dp1[i][j-a[i]]+b[i]);

            }
        }
    }
    for(ll i=n-1;i>0;i--){
        rep(j,t){
            if(j<a[i]){
                dp2[i-1][j]=dp2[i][j];
            }
            else{
                dp2[i-1][j]=max(dp2[i][j],dp2[i][j-a[i]]+b[i]);
            }
        }
    }
    rep(i,n){
        rep(j,t){
            ans=max(ans,dp1[i][j]+dp2[i][t-1-j]+b[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);
    int N, K; cin >>N >> K;

    int ans = 1;

    rep(i,N) {
        if (ans*2<ans+K) ans*=2;
        else ans+=K;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Work[] works = new Work[n];
		for (int i = 0; i < n; i++) {
		    works[i] = new Work(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(works);
		int current = 0;
		for (int i = 0; i < n; i++) {
		    current += works[i].time;
		    if (current > works[i].dead) {
		        System.out.println("No");
		        return;
		    }
		}
		System.out.println("Yes");
   }
    
    static class Work implements Comparable<Work> {
        int time;
        int dead;
        
        public Work(int time, int dead) {
            this.time = time;
            this.dead = dead;
        }
        
        public int compareTo(Work another) {
            return dead - another.dead;
        }
    }
}



Measured memory_bytes: 103372
mod = 10**9 + 7

n, m = map(int, input().split())
a = [1] * (n + 1)

for i in range(m):
    a[int(input())] = 0

l = [-1] * (n + 1)
l[n] = 1
l[n-1] = a[n-1]

num = n - 2
while num >= 0:
    if a[num] == 1:
        l[num] = (l[num+1] + l[num+2]) % mod
    else:
        l[num] = 0
    num -= 1

print(l[0])

Measured memory_bytes: 7668
#include <iostream>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
	long n,k,a;
	cin>>n>>k;

     a=k*pow(k-1,n-1);
	cout<<a;
	return 0;
}

Measured memory_bytes: 3496
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int flg[][][] = new int[4][3][10];
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					flg[i][j][k] = 0;
				}
			}
		}
    	
    	int n = sc.nextInt();
        
        for (int i = 0; i < n; i++) {
        	int b,f,r,v;
        	b = sc.nextInt();
        	f = sc.nextInt();
        	r = sc.nextInt();
        	v = sc.nextInt();
        	flg[b-1][f-1][r-1] += v;
		}
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					System.out.print(" " + flg[i][j][k]);
				}
				System.out.println();
			}
			if (i != 3) {
				System.out.println("####################");
			}
		}
    }
}



Measured memory_bytes: 29192
#include<stdio.h>
int main()
{

    long long int h,n,i,sum,a[100001];
    scanf("%lld %lld",&h,&n);
    sum=0;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        sum=sum+a[i];
    }
    if(sum>=h)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int a, b, c;
    a = N / 100;
    b = (N % 100) / 10;
    c = (N % 10);
    if (a == 7 || b == 7 || c == 7) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3648
n = int(input())
ans = 0
i = 2

while n>1 and i*i<=n:
  if n % i == 0:
    c = 0
    while n % i == 0:
      n = n / i
      c += 1
    Y=1
    U=2
    while c>=Y:
      ans=ans+1
      Y=Y+U
      U=U+1

  i = i + 1
      
    
if n > 1:
  ans = 1 + ans

print(ans)
  

Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200010
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    map<int,int>mp,mm;
    REP(i,n){
        int t=i+1+a[i];
        mp[t]++;
    }
    REP(i,n){
        int t=i+1-a[i];
        if(t>0){
            mm[t]++;
        }
    }
    ll ans=0;
    for(auto p:mp){
        ans+=(ll)p.second*mm[p.first];
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 22984
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
void matmul(ll x[2][2], ll y[2][2], ll m, ll ans[2][2]){
	for(int i=0; i<2; i++){
		for(int j=0; j<2; j++){
			ans[i][j]=0;
			for(int k=0; k<2; k++){
				ans[i][j]+=(x[i][k]*y[k][j]);
				ans[i][j]%=m;
			}
		}
	}
}
void matpow(ll x[2][2], ll k, ll m, ll ans[2][2]){
	ans[0][0]=1, ans[1][1]=1, ans[1][0]=0, ans[0][1]=0;
	ll xp[2][2];
	for(int i=0; i<2; i++) for(int j=0; j<2; j++) xp[i][j]=x[i][j];
	while(k){
		if(k&1){
			ll ans1[2][2];
			matmul(ans, xp, m, ans1);
			for(int i=0; i<2; i++) for(int j=0; j<2; j++) ans[i][j]=ans1[i][j];
		}
		ll ans1[2][2];
		matmul(xp, xp, m, ans1);
		for(int i=0; i<2; i++) for(int j=0; j<2; j++) xp[i][j]=ans1[i][j];
		k>>=1;
	}
}
ll fib(ll a){
	if(a==1) return 1;
	ll x[2][2], ans[2][2];
	x[0][0]=x[0][1]=x[1][0]=1, x[1][1]=0;
	matpow(x, a-1, MOD, ans);
	return (ans[1][0]*2+ans[1][1])%MOD;
}
int main()
{
	ll k;
	cin>>k;
	if(k==1){
		cout<<1<<endl;
		return 0;
	}
	ll n1=2, n2=2e9+1;
	while(n1!=n2){
		ll n=(n1+n2+1)/2;
		if(n&1){
			if((n/2+1)*(n/2)<k) n1=n;
			else n2=n-1;
		}else{
			if((n/2-1)*(n/2)+n/2<k) n1=n;
			else n2=n-1;
		}
	}
	ll n=n1, m, a, b;
	if(n&1) m=k-((n/2+1)*(n/2));
	else m=k-((n/2-1)*(n/2)+n/2);
	if(m<=((n+1)/2+1)/2) a=2*m-1, b=n+1-a;
	else{
		if((n+1)/2%2==0) a=(n+1)/2-2*(m-((n+1)/2+1)/2-1), b=n+1-a;
		else a=(n+1)/2-1-2*(m-((n+1)/2+1)/2-1), b=n+1-a;
	}
	cout<<fib(a)*fib(b)%MOD<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		map<string, int> m;
		int q;
		cin >> q;
		while( q-- ) {
			int cmd, x;
			string key;
			cin >> cmd;

			if( cmd == 0 ) {
				cin >> key >> x;
				m[key] = x;
			}
			else if( cmd == 1 ) {
				cin >> key;
				cout << m[key] << '\n';
			}
			else {
				cin >> key;
				m.erase( key );
			}
		}
	}
};

int main() {
	Solver().solve();
	return 0;
}



Measured memory_bytes: 25824
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
const char nl = '\n';
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
ll power(ll x, unsigned int y) {ll res = 1;	while (y > 0) { if (y & 1) res = res*x%mod; y = y>>1; x = x*x;} return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    int c=0;
    for(int i=0;i<n;i++)if(s[i]=='R')c++;
    int x=c;
    for(int i=0;i<c;i++){
  //  	cout<<i<<" "<<c<<" "<<s[i]<<"\n";
    	if(s[i]=='R')x--;
  
    }
    cout<<x;
    
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();
 
    
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int n;
    cin >> n;
    cout << 24 + (24-n) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            int sum1=0;
            int sum2=0;
            if(n==0){
                break;
            }
            int[] scores;
            scores=new int[n];
            for(int i=0;i<scores.length;i++){
                scores[i]=sc.nextInt();
                sum1=sum1+scores[i];
                sum2=sum2+scores[i]*scores[i];
            }
            double ave=0;
            ave=(double)sum1/n;
            double var=0;
            var=(double)sum2/n-ave*ave;
            System.out.println(Math.sqrt(var));
        }
    }
}


Measured memory_bytes: 31264
n=int(input())
al=[int(a) for a in input().split()]
cnt = {}
total=0

for a in al:
	if a not in cnt:
		cnt[a] = 0
	cnt[a]+=1
#print(cnt)

for i in cnt.values():
	total += i*(i-1)//2
	#print("i: ",i)
#print(cnt.values())
for a in al:
	print(total - (cnt[a]-1))


Measured memory_bytes: 26140
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()

print(math.ceil(N / 2) / N)


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

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

#define rep(i, n) for (ll i = 0; i < n; i++)

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

    ll A, B, X;
    cin >> A >> B >> X;

    if (A <= X && A+B >= X) {
        YES;
    } else {
        NO;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	x := make([]int, M)
	for i := range x {
		fmt.Scan(&x[i])
	}
	sort.Ints(x)

	tmp := make([]int, M-1)
	for i := range tmp {
		tmp[i] = x[i+1] - x[i]
	}
	sort.Ints(tmp)

	ans := 0
	for i := 0; i < M-N; i++ {
		ans += tmp[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
struct State {
    int at;
    int cost;
    int prev;
    State(int at, int cost, int prev) : at(at), cost(cost), prev(prev) {}
    bool operator>(const State& s) const {
        if (cost != s.cost) return cost > s.cost;
        if (prev != s.prev) return prev > s.prev; //最短経路を辞書順最小にする(省略可)
        return at > s.at;
    }
};
 
struct Edge {
  int to;
  int cost;
  Edge(int to, int cost) : to(to), cost(cost) {}
};
 
typedef vector<vector<Edge> > AdjList; //隣接リスト
 
const int INF = 1000000000;
const int NONE = -1;
 
AdjList graph;
 
//sは始点、mincは最短経路のコスト、Prevは最短経路をたどる際の前の頂点
void dijkstra(int s, vector<int>& minc, vector<int>& Prev){
    priority_queue<State, vector<State>, greater<State> > pq;
    pq.push(State(s, 0, NONE));
    while(!pq.empty()) {
        State cur = pq.top();
        pq.pop();
        if (minc[cur.at] <= cur.cost) continue;
        minc[cur.at] = cur.cost;
        Prev[cur.at] = cur.prev;
        for(Edge e : graph[cur.at]) {
            int cost = cur.cost + e.cost;
            if (minc[e.to] <= cost) continue;
            pq.push(State(e.to, cost, cur.at));
        }
    }
}
 
const int MAX_K = 100000;
 
int solve(int x) {
    int res = 0;
    while (x > 0) {
        res += x % 10;
        x /= 10;
    }
    return res;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    graph.resize(MAX_K);
    for (int i = 0; i < MAX_K; i++) {
        for (int j = 0; j <= 9; j++) {
            int hoge = K * j + i;
            graph[i].emplace_back(hoge / 10, hoge % 10);
        }
    }
    vector<int> minc(MAX_K, INF);
    vector<int> Prev(MAX_K, NONE);
    dijkstra(0, minc, Prev);
    int ans = INF;
    for (int i = 1; i < MAX_K; i++) ans = min(ans, minc[i] + solve(i));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25712
#include <stdio.h>

#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++){
    if(A[j]<=x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i+1;
}

int main(){
  int i, q;

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

  q = partition(0, n-1);

  for(i=0; i<n; i++){
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d", A[i]);
    if(i==q) printf("]");
  }

  printf("\n");
  
  return 0;
}



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

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

 long long num[n];
 long long integers;
 long long min=0,max=0,sum=0;
 int count = 0;
 while(count<n){
   cin >> integers;
   num[count] = integers;

   if(count==0){
    min=num[count];
    max=num[count];
   }else{
    if(min>num[count]){
      min = num[count];
    }
    if(max<num[count]){
      max = num[count];
    }
   }

   sum += num[count];

   count++;
 }

 cout << min << " " << max <<  " " << sum << endl;

 return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#include <string>
#include <vector>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;


int main(){
    ll n;cin >> n;
    ll ans = 0;
    set<ll> div;
    for(int i = 1;i<=sqrt(n);i++){
        if(n%i==0) {
            div.insert(i);
            div.insert(n/i);
        }
    }
    div.insert(n);

    for(auto it=(--div.end());it!=div.begin();it--){
        if((*it)-1>sqrt(n)){
            ans += *it;
            ans -= 1;
        }else break;
    }

    cout << ans << endl;


 }

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> v(n);
    int x, l;
    rep (i, n) {
        cin >> x >> l;
        v[i] = {x + l, x - l};
    }

    sort(all(v));

    int cnt = 0;
    int endtime = -3e9;
    repall (p, v) {
        if (p.second >= endtime) {
            cnt++;
            endtime = p.first;
        }
    }
    print(cnt);

    return 0;
}


Measured memory_bytes: 1792
import java.util.*
import java.math.*
import java.lang.Math.*

val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1e9.toLong()+7
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)


fun solve(): Int {
    var res = 0
    return res
}


fun main(args: Array<String>) {
    val N = readInt()
    val A = readLongArray()

    if (A.contains(0L)) {
        println(0)
        return
    }

    var ans = 1L
    for (i in 0 until N) {
        if (ans > 1e18.toLong()/A[i]) {
            ans = -1L
            break
        }
        ans *= A[i]
    }

    println(ans)
}


Measured memory_bytes: 64168
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef vector<int> SV;
typedef vector<SV> SVV;

int n, m;

int dfs(const SVV &svv, const SV &pv, SV& state, int level, int use) {
  //  cout << "(" << level << "," << use << ")"
  //       << " ";

  if (level != -1) {
    state[level] = use;
  }

  if (level == (n - 1)) {
    //    cout << endl;
    int sum;
    for (int i = 0; i < m; i++) {
      sum = 0;
      //      cout << "pv: " << pv[i] << ", state: ";
      for (auto svi = svv[i].begin(); svi != svv[i].end(); svi++) {
        // cout << state[*svi] << " ";
        sum += state[*svi];
      }
      if (sum % 2 != pv[i]) {
        // cout << "result: " << 0 << endl;
        return 0;
      }
    }

    // cout << "result: " << 1 << endl;
    return 1;

  } else {
    return dfs(svv, pv, state, level + 1, 0) +
           dfs(svv, pv, state, level + 1, 1);
  }
}

int main(int argc, char const *argv[]) {
  cin >> n;
  cin >> m;

  SVV svv;

  int ki;
  int s;
  SV state;
  for (int i = 0; i < n; i++) {
    SV sv;
    cin >> ki;
    for (int j = 0; j < ki; j++) {
      cin >> s;
      sv.push_back(s - 1);
    }
    svv.push_back(sv);
    state.push_back(0);
  }

  SV pv;
  int p;
  for (int i = 0; i < m; i++) {
    cin >> p;
    pv.push_back(p);
  }

  cout << dfs(svv, pv, state, -1, 0);

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;

char dice[6][4] = {
	{5,2,1,4}, {1,1,3,0}, {0,3,2,2},
	{2,5,4,1}, {4,4,0,3}, {3,0,5,5}
};

int conv[6] = {2, 4, 5, 1, 0, 3};
int mask[3][3] = {
	{ 9, 1, 3},
	{ 8, 0, 2},
	{12, 4, 6}
};
int front[3] = {0, 1, 4};
int back[3]  = {2, 3, 5};
int up[3][4] = {
	{5, 1, 4, 3},
	{5, 2, 4, 0},
	{2, 1, 0, 3}
};

int main(){
	int step[6][6];
	memset(step, -1, sizeof(step));
	queue< pair<pair<int, int>, int> > qu;
	qu.push(make_pair(make_pair(0, 2), 0));
	qu.push(make_pair(make_pair(0, 5), 0));
	while(!qu.empty()){
		pair< pair<int,int>, int > p = qu.front(); qu.pop();
		int a = p.first.first, b = p.first.second, c = p.second;
		if(step[a][b] != -1) continue;
		step[a][b] = c;
		for(int i=0;i<4;i++)
			qu.push(make_pair(make_pair(dice[a][i], dice[b][i]), c+1));
	}
	string str[6][3];
	while(cin >> str[0][0]){
		if(str[0][0] == "#") break;
		cin >> str[0][1] >> str[0][2];
		for(int i=1;i<6;i++)
			for(int j=0;j<3;j++) cin >> str[i][i==5 ? 2-j : j];
		for(int i=0;i<2;i++)
			for(int j=0;j<3;j++) reverse(str[i][j].begin(), str[i][j].end());
		int ans = 1000000000;
		for(int i=0;i<3;i++){
			int mf = 0, mb = 0;
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++){
					if(str[front[i]][j][k] == '*') mf |= mask[j][k];
					if(str[back[i]][j][k]  == '*') mb |= mask[j][k];
				}
			int m = (mf&mb);
			for(int j=0;j<4;j++)
				if(m&(1<<j)){
					ans = min(ans, step[conv[up[i][j]]][conv[front[i]]]);
					ans = min(ans, step[conv[up[i][j]]][conv[back[i]]]);
				}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0