akhauriyash/Code-Regression huggingface dataset:
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	LL x, k, d;
	inl2(x, k);inl(d);
	x = abs(x);
	LL q = x/d;
	if(q <= k) {
		LL ans = x-q*d;
		if((k-q)&1) ans = min(ans+d, abs(ans-d));
		finish(ans);
	}
	finish(x-k*d);
	
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3756
H, W, K = map(int, input().split())
maze = [list(input()) for i in range(H)]

ans = 0
'それぞれの選び方について'
for i in range(2 ** H):
    for j in range(2 ** W):
        cnt = 0
        for l in range(H):
            for m in range(W):
                if ((i >> l) & 1) and ((j >> m) & 1):
                    if maze[l][m] == '#':
                        cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Measured memory_bytes: 9200
#include<stdio.h>
int readint(void)
{
	int x;
	scanf("%d",&x);
	return x;
}
int main(void)
{
	int k=readint(),s=readint(),cnt=0;
    for(int x=0;x<=k;++x)
        for(int y=0;y<=k;++y)
            if(s-x-y>=0&&s-x-y<=k)++cnt;
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize(2) 
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=998244353;
long long a[100010];
long long n,x;
long long ksm(long long a,long long b){
	long long res=1;
	while(b){
		if(b&1){
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
 
int main(){
	//scanf("%lld",&n);
	cin>>n;
	int flag=0;
//	scanf("%lld",&x);
	cin>>x;
	long long  ans=x;
	if(x!=0) flag=1;
	for(int i=1;i<n;i++){
//		scanf("%lld",&x);
		cin>>x;
		a[x]++;
		if(x==0) flag=1;
		ans=max(ans,x);
	}
	if(flag){
	//	printf("0\n");
		cout<<0<<"\n";
	}
	else{
	long long sum=1;
		for(int i=1;i<ans;i++){
			if(a[i]==0){
				flag=1;
				break;
			}
			sum*=ksm(a[i],a[i+1]);
			sum%=mod;
		}
		if(flag) cout<<0<<"\n";//printf("0\n");
		else  cout<<sum<<"\n";//printf("%lld\n",sum);
	}
	return 0;
} 

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

bool isPrime(ll x){
    if(x == 2) return true;
    if(x < 2 or x % 2 == 0) return false;

    for(ll i = 3; i <= sqrt(x); i+=2){
        if(x % i == 0) return false;
    }
    return true;
}

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

    vector<ll> sum(101000);
    for(ll i = 3; i <= 100100; i++){
        sum[i] = sum[i-1];
        if(isPrime(i) && isPrime((i + 1) / 2)) sum[i]++;
    }

    ll q;
    cin >> q;

    while(q--){
        ll a,b;
        cin >> a >> b;

        cout << sum[b] - sum[a - 1] << endl;
    }
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
const double EPS = 1e-8;
 
double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)?????????´???????????????(c-a)?????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)?????????´???????????????(c-a)?????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}
 
P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}
 
vector<P> convex_cut(vector<P> G, L l){
  vector<P> res;
  for(int i=0;i<G.size();i++){
    P A = G[i];
    P B = G[(i+1)%G.size()];
    if(ccw(l.first, l.second, A) != -1) res.push_back(A);
    if(ccw(l.first, l.second, A) * ccw(l.first, l.second, B) < 0)
      res.push_back(crossPoint(L(A,B), l));
  }
  return res;
}
 
bool check(vector<P> G,double d){
  vector<P> pol=G;
  int n=G.size();
  for(int i=0;i<n;i++){
    P c=(G[(i+1)%n]-G[i]);
    P a=P(abs(c),d)*(c/abs(c))+G[i];
    pol=convex_cut(pol,L(a,a+c));
    if(pol.size()<3)return 0;
  }
  return  1;
}
 
int main(){
  int n;
  while(cin>>n,n){
    vector<P> pol(n);
    for(int i=0,x,y;i<n;i++)cin>>x>>y,pol[i]=P(x,y);
     
    double L=0,M,R=1e4;
    while(L<R){
      M=(L+R)/2;
      if(!check(pol,M)) R=M-EPS;
      else L=M+EPS;
    }
    printf("%lf\n",L);
  }
  return 0;
}

Measured memory_bytes: 3196
s = input()
t = input()
bool = 0
list = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in list:
  if s+i==t:
    print("Yes")
    bool+=1
    break
if bool==0:
  print("No")


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

int main() {
  int a,b;
  cin>>a>>b;
  int range=b-a+1;
  if(a>0&&b>0) {
    cout<<"Positive"<<endl;
    return 0;
  }
  if(a<=0&&b>=0){
    cout<<"Zero"<<endl;
    return 0;
  }
  if(b<0){
    if(range%2==1) cout<<"Negative"<<endl;
    else cout<<"Positive"<<endl;
    return 0;
  }


}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;


int main(){
  int n;
  cin>>n;
  bool ans=true;
  vector<string>vec(n);
  for(int i=0;i<n;i++)cin>>vec[i];
  for(int i=0;i<n-1;i++){
    int k=vec[i].size();
    if(vec[i][k-1]!=vec[i+1][0])ans=false;
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<n-1;i++){
    if(vec[i]==vec[i+1])ans=false;
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
    

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

struct Person
{
	int pos;
	long long health;
};

int n;
long long d, a;
Person per[200010];

struct Bomb
{
	int lPos;
	int rPos;
	long long count;
};

std::queue<Bomb> q;

bool compare(const Person &a, const Person &b)
{
	return a.pos < b.pos;
}


int main()
{
	scanf("%d%lld%lld", &n, &d, &a);
	
	for (int i = 0 ; i < n ; i++) {
		scanf("%d%d", &(per[i].pos), &(per[i].health));
	}
	
	sort(per, per + n, compare);
	
	long long curPosBombs = 0;	//当前炸弹数 
	long long count = 0;
	
	int p = 0;
	while (p < n) {
		per[p].health = per[p].health - curPosBombs * a;
		
		if (per[p].health > 0) {
			//添加新的炸弹
			Bomb newBomb;
			newBomb.count = per[p].health / a;
			if (per[p].health % a != 0)
				newBomb.count++;
			count = count + newBomb.count;
			curPosBombs = curPosBombs + newBomb.count;
			
			newBomb.lPos = per[p].pos;
			newBomb.rPos = newBomb.lPos + 2 * d;
			q.push(newBomb);
		}
		
		p++;
		if (p < n) {
			//清理炸弹数据
			while (q.empty() == false) {
				Bomb curBomb = q.front();
				if (curBomb.rPos < per[p].pos) {
					curPosBombs = curPosBombs - curBomb.count;
					q.pop();
				} else {
					break;
				}
			}
		}
	}
	
	
	printf("%lld\n", count);
	
	return 0;
}



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

int N,M;
int a[50],b[50];
bool graph[50][50];
bool vis[50];

void dfs(int v) {
  vis[v] = true;
  for (int v2 = 0; v2 < N; v2++ ) {
    if ( graph[v][v2] == false ) continue;
    if ( vis[v2] == true ) continue;
    dfs(v2);
  }

}

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

  for ( int i = 0; i < M; i++ ) {
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  int ans = 0;
  
  for ( int i = 0; i < M; i++ ) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    for ( int i = 0; i < N; i++ ) vis[i] = false;

    dfs(0);
    bool bridge = false;
    for ( int i = 0; i < N; i++ ) if ( vis[i] == false ) bridge = true;
    if(bridge) ans++;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%d", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define pr64(x) printf("%I64d", (x))
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define fill(a,v,n) memset((a),(v),sizeof(a[0])*(n))
#define copy(a,b,n) memcpy((a),(b),sizeof(a[0])*(n))
#define ALL(x) (x.begin(),x.end())
#define prf(x) printf("%.20f", x)
#define for_each_edge(u) for(int i = point[u];i;i=G[i].n)
typedef unsigned int uint;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100010
#define M 1024
#define MOD 1000000007
void _add(int &a, int b){a = (a+b)%MOD;}
void _sub(int &a, int b){a = (a+MOD-b)%MOD;}
void _mul(int &a, int b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pw(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll pwM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(){
	cnt = 0;
	SET(point,0);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n, m, k,q;
int main(){
//	freopen("1", "r", stdin);
	sc(n),sc(m);
	k = n*m-n-m+1;
	pr(k),ln;
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
	    printf("Case #%d: ", ca);
	}
*/
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k; cin >> n >> k;
    int res = k;
    rep(i, n - 1) res *= (k - 1);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,Wcount=0,count2=0,Wcount2=0;
  string S;
  cin>>N>>S;
  for(int i=0;i<N;i++){
    if(S.at(i)=='W')
      Wcount++;
    }
  int min2=N;
  for(int i=0;i<N;i++){
    if(S.at(i)=='W'){
      int O=Wcount2+N-i-1-Wcount+Wcount2+1;
      min2=min(min2,O);
      Wcount2++;
      }
    else{
      int O=Wcount2+N-i-1-Wcount+Wcount2;
      min2=min(min2,O);
      }
    }
  cout<<min2<<endl;
}

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

using namespace std;

void dfs(vector<vector<int> > &G, int node, vector<bool> &visited, vector<int> &topo){
    visited[node] = true;
    for(auto &e: G[node]){
        if(!visited[e])
            dfs(G, e, visited, topo);
    }
    topo.push_back(node);
}

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

    vector<vector<int> > G(N+1);
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
    }

    vector<int> topo;
    vector<bool> visited(N+1, false);
    for(int i=1; i<=N; i++){
        if(!visited[i]){
            dfs(G, i, visited, topo);
        }
    }

    reverse(topo.begin(), topo.end());

    vector<int> dp(N+1, 0);
    for(auto &v:topo){
        for(auto &u:G[v]){
            dp[u] = max(dp[u], dp[v] + 1);
        }
    }

    int ans = 0;
    for(auto &p:dp){
        ans = max(ans, p);
    }

    cout << ans << "\n";

    return 0; 
} 

Measured memory_bytes: 10104
///
// File:  alds1_7_c.cpp
// Author: ymiyamoto
//
// Created on Sat Oct 14 18:52:33 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

struct tree_t {
  int32_t parent;
  int32_t left;
  int32_t right;
  tree_t()
  {
    parent = -1;
    left = -1;
    right = -1;
  }
};

#define SIZE 100
#define NIL -1

static tree_t tree[SIZE];
static vector<int32_t> preorder;
static vector<int32_t> inorder;
static vector<int32_t> postorder;

void walk(int32_t index)
{
  preorder.push_back(index);
  if (tree[index].left != NIL) {
    walk(tree[index].left);
  }
  inorder.push_back(index);
  if (tree[index].right != NIL) {
    walk(tree[index].right);
  }
  postorder.push_back(index);
}

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

  for (int32_t i = 0; i < n; i++) {
    int32_t id, left, right;
    cin >> id >> left >> right;
    tree[id].left = left;
    tree[id].right = right;
    if (left != NIL) {
      tree[left].parent = id;
    }
    if (right != NIL) {
      tree[right].parent = id;
    }
  }

  int32_t root = NIL;
  for (int32_t i = 0; i < n; i++) {
    if (tree[i].parent == NIL) {
      root = i;
    }
  }

  walk(root);

  cout << "Preorder" << endl;
  for (uint32_t i = 0; i < preorder.size(); i++) {
    cout << " " << preorder[i];
  }
  cout << endl;

  cout << "Inorder" << endl;
  for (uint32_t i = 0; i < inorder.size(); i++) {
    cout << " " << inorder[i];
  }
  cout << endl;

  cout << "Postorder" << endl;
  for (uint32_t i = 0; i < postorder.size(); i++) {
    cout << " " << postorder[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    if(s[k-1]=='A')s[k-1]='a';
    if(s[k-1]=='B')s[k-1]='b';
    if(s[k-1]=='C')s[k-1]='c';
    cout<<s<<endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)




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

 ll n;
  cin >> n;
 vll a(n);
  rep(i,0,n) cin >> a[i];
 ll c=1,res=0;
  rep(i,0,n){
   if(a[i]==c) c++;
   else res++;
  }

  
  if(res==n) cout << -1 << endl;
  else cout << res << endl;  
  
} // main


Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}


int main() {
	int a, b, st;
	int x1, x2, y1, y2, z1, z2, q, t;


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

	x1 = 1;
	y1 = 0;
	z1 = a;
	x2 = 0;
	y2 = 1;
	z2 = b;
	st = gcd(a,b);
	while (z2 != st)
	{
		if (z2 == 0) break;
		q = (z1 - (z1 % z2)) / z2;
//printf("%da + %db = %d\n", x1, y1, z1);
		x1 = x1 - (q * x2);
		y1 = y1 - (q * y2);
		z1 = z1 - (q * z2);

		t = x1;
		x1 = x2;
		x2 = t;

		t = y1;
		y1 = y2;
		y2 = t;

		t = z1;
		z1 = z2;
		z2 = t;
	}

		printf("%d %d\n", x2, y2);

	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,a[1002],ans=0,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=k;i++)
	{
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
lis = [0,0,0,0,0]
n = int(input())
for i in range(n):
    a = input()
    if a[0] == "M":lis[0] += 1
    if a[0] == "A":lis[1] += 1
    if a[0] == "R":lis[2] += 1
    if a[0] == "C":lis[3] += 1
    if a[0] == "H":lis[4] += 1
ans = 0
for m in range(5):
    for l in range(5):
        if l > m:
            for h in range(5):
                if h > l:
                    ans += lis[m] * lis[l] *lis[h]
print(ans)


Measured memory_bytes: 3064
import java.math.BigInteger;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        TreeMap<Integer, Long> map = new TreeMap<>();
        for (int i = 0 ; i < N ; i++){
            int price = sc.nextInt();
            long max_buy = sc.nextInt();
            if(map.containsKey(price)){
                long max = map.get(price);
                map.put(price, max+max_buy);
            } else{
                map.put(price, max_buy);
            }
        }

        BigInteger ans = BigInteger.ZERO;
        for (Map.Entry<Integer, Long> entry : map.entrySet()){
            int price = entry.getKey();
            long quantity = entry.getValue();
            BigInteger need = BigInteger.valueOf(quantity);
            BigInteger pri = BigInteger.valueOf(price);
            if(quantity - M >= 0){
                BigInteger temp = BigInteger.valueOf(M).multiply(pri);
                ans = ans.add(temp);
                M = - 1;
            } else{
                BigInteger temp = need.multiply(pri);
                ans = ans.add(temp);
                M -= quantity;
            }
            if(M <= 0)
                break;
        }
        System.out.println(ans.toString());
        sc.close();
    }
}


Measured memory_bytes: 97444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    if(n%2==0){
        cout << (n-2)*n/2 <<endl;
        rep(i,n){
            repl(j,i+1,n){
                if(i+j+2==n+1)continue;
                cout << i+1 << " " << j+1 <<endl;
            }
        }
    }
    else{
        cout << (n-1)*(n-1)/2 <<endl;
        rep(i,n){
            repl(j,i+1,n){
                if(i+j+2==n)continue;
                cout << i+1 << " " << j+1 <<endl;
            }
        }
    }
}   

Measured memory_bytes: 3644
#include <stdio.h>
 
struct stack {
    int data[20000];
    int point;
};

int whereDownHill(struct stack *mountain);

void calculateWater(struct stack *mountain, struct stack *width);

int main(void) {
    char str[30000] = {};
    int i = 0;
    int j = 0;
    struct stack mountain = {};
    struct stack width = {};
    int tmp = 0;
    int tmp1 = 0;
    int sum = 0;
	int location_downhill = 0;
	
    for ( i = 0; i < 20000; i++ ) {
        mountain.data[i] = -3;
    }
     
    fgets(str,30000, stdin);
	
    i = 0;
    while(str[i] != '\0' ) {
        switch(str[i]) {
            case '\\':
                mountain.data[mountain.point] = 0;
                mountain.point++;
                //printf("aaaaa\n");
                break;
            case '_':
                mountain.data[mountain.point] = -1;
                mountain.point++;
                break;
             
            case '/':
                location_downhill = whereDownHill(&mountain);
                // printf("%d\n", location_downhill);
                if ( location_downhill >= 0 ) {
                    calculateWater(&mountain, &width);
                }
        		break;
        	
            default:
                break;
        }
        i++;
    }
	
	
    j = 0;
    for ( i = 0; i < mountain.point; i++ ) {
        if ( mountain.data[i] > 0) {
            j++;
            sum += mountain.data[i];
        }
    }
     
    printf("%d\n", sum);
    printf("%d", j);
    for ( i = 0; i < mountain.point; i++ ) {
        if ( mountain.data[i] > 0) {
            printf(" %d", mountain.data[i]);
        }
    }
    printf("\n");
     
    return 0;
}


int whereDownHill(struct stack *mountain)
{
	int location_downhill = 0;
	location_downhill = mountain -> point;
	
	while ( mountain->data[location_downhill] != 0 ) {
		location_downhill--;
		if ( location_downhill < 0  ) {
			break; 
		}
	}
	return location_downhill;
}


void calculateWater(struct stack *mountain, struct stack *width)
{
	int sum_width = 0;
	int sum_water = 0;

	(mountain->point)--;
	while ( (mountain->data)[mountain->point] != 0 ) {
		if ( (mountain->data)[mountain->point] > 0 ) {
			(width->point)--;
			sum_width += (width->data)[width->point];
			sum_water += (mountain->data)[mountain->point];
		} else {
			sum_width++;
		}
		(mountain->point)--;
	}
	sum_water += 1 + sum_width;
	sum_width += 2;
	(mountain->data)[mountain->point] = sum_water;
	(width->data)[width->point] = sum_width;
	(width->point)++;
	(mountain->point)++;
}


Measured memory_bytes: 2116
N = int(input())
if 64 <= N:
    print(64)
elif 32 <= N:
    print(32)
elif 16 <= N:
    print(16)
elif 8 <= N:
    print(8)
elif 4 <= N:
    print(4)
elif 2 <= N:
    print(2)
else:
    print(1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b, x;
	cin >> a >> b >> x;
	if (a <= x && x <= a + b)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
int main(void){
    int i,j;
    string s;
    cin >> s;
    long long ans=0;
    for(i=0;i<1<<(s.size()-1);i++){
        long long tmp = s[0]-'0';
        for(j=0;j<s.size()-1;j++){
            if(i&(1<<j)){
                ans += tmp;
                tmp = (s[j+1]-'0');
            }
            else{
                tmp = tmp*10+(s[j+1]-'0');
            }
        }
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto x : v) cerr << x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int i = 0; i < (n); ++i) cerr << a[i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
const int MAXN = 100005;
int A[MAXN], B[MAXN], C[MAXN];
vector<int> E[MAXN];
bool used[MAXN];
int par[MAXN];
ll sumb[MAXN], dp[MAXN];
int root(int a) {
	if (par[a] == a) return a;
	return par[a] = root(par[a]);
}
int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	vector<pair<int, int>> order;
	for (int i = 1; i <= N; ++i) {
		scanf("%d%d", &A[i], &B[i]);
		C[i] = max(0, A[i] - B[i]);
		order.push_back({C[i], i});
		par[i] = i;
	}
	for (int i = 0; i < M; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	sort(order.begin(), order.end());
	for (auto ord : order) {
		int v = ord.second;
		set<int> trees;
		sumb[v] = B[v];
		for (int w : E[v]) {
			if (!used[w]) continue;
			int pw = root(w);
			if (trees.count(pw)) continue;
			sumb[v] += sumb[pw];
			trees.insert(pw);
		}
		used[v] = true;
		dp[v] = C[v] + sumb[v];
		for (int w : trees) {
			ll amt = sumb[v] - sumb[w] + max(dp[w], (ll)C[v]);
			dp[v] = min(dp[v], amt);
			par[w] = v;
		}
	}
	printf("%lld\n", dp[root(1)]);
}


Measured memory_bytes: 11508
n,q = map(int,input().split())

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

w = [A[0]]
for i in range(1,n):
    w.append(w[-1]+A[i])

w1 = [0]*n
for i in range(n):
    if (n-1-i)%2 == 0:
        w1[i] = A[i]
    if i > 0:
        w1[i] += w1[i-1]

def solve(x):
    l = 0
    r = n+1
    while r-l > 1:
        m = (r+l)//2
        if A[n-m] <= x:
            r = m
        else:
            if 2*m-1 > n:
                r = m
            else:
                if A[n-m]-x >= x-A[n-2*m+1]:
                    l = m
                else:
                    r = m
    ans = w[-1]-w[n-l-1]
    if n-2*l-1 >= 0:
        ans += w1[n-2*l-1]
    print(ans)

for _ in range(q):
    solve(int(input()))

Measured memory_bytes: 92872
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

 
int main() {
    ll N, M, K; cin >> N >> M >> K;
    ll A[200100], B[200100];
    rep(i,N) cin >> A[i];
    rep(j,M) cin >> B[j];
    ll a[200100], b[200100];
    a[0] = 0;
    rep(i,N) a[i+1] = a[i] + A[i];
    b[0] = 0;
    rep(j,M) b[j+1] = b[j] + B[j];

    ll ans = 0;
    ll t = 0;
    int i = 0;
    int m = M;
    while (i <= N && a[i] <= K) {
        per(j,m+1) {
            if (b[j] <= K - a[i]) {
                m = j;
                ans = max(ans, (ll)i+j);
                break;
            }
        }
        i++;
    }

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

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

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

  vector<u64> l(n);

  rep(i, n) { cin >> l[i]; }

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

  u64 ans = 0;

  if (n < 3) {
    cout << 0;
    return 0;
  }

  for (u32 i = 0; i < n - 2; i++) {
    for (u32 j = i + 1; j < n - 1; j++) {
      for (u32 k = j + 1; k < n; k++) {
        if ((l[i] != l[j] && l[k] != l[j])) {
          if (l[k] < l[i] + l[j]) {
            // cout << l[i] << " " << l[j] << " " << l[k] << endl;
            ans++;
          } else {
            break;
          }
        }
      }
    }
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 3624
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val x = new Array[Long](n)
    for (i <- 0 until n) {
      x(i) = sc.nextLong()
    }
    val sortedX = x.sorted
    val medLeft = sortedX(n / 2 - 1)
    val medRight = sortedX(n / 2)
    val pw = new java.io.PrintWriter(System.out)
    for (i <- 0 until n) {
      if (x(i) < medRight) {
        pw.println(medRight)
      } else {
        pw.println(medLeft)
      }
    }
    pw.flush()
  }
}


Measured memory_bytes: 76320
#include <stdio.h>
int main(void){
    // Your code here!
    int n,i,min,max,a[100000];
    long long sum=0;
    scanf("%d",&n);
    
    0<n<=10000;
    -1000000<=a[i];
    a[i]<=1000000;
    
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    
    max=min=a[0];
    
    for(i=1;i<n;i++){
        if(a[i]>max) max=a[i];
        if(a[i]<min) min=a[i];
    }
    
    printf("%d %d %lld\n",min,max,sum);
    
    return 0;
}



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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int ll
//#define endl '\n'

int n;
int a[maxn];
multiset<int> s;

int32_t main()
{
    IOS
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    for (int i=1;i<=n;i++)
    {
        s.erase(s.find(a[i]));
        cout<<(*(--s.end()))<<'\n';
        s.insert(a[i]);
    }
}



Measured memory_bytes: 13824
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
ll C;
ll X[2][112345];
ll V[112345];
ll sum[2][112345];
ll num[2][112345];
ll ans = 0;


int main(){
	
	cin>>N>>C;
	REP( i, N ){
		scanf("%lld %lld", X[0]+i, V+i );
		X[1][N-i-1] = C-X[0][i];
	}

	
	sum[0][0] = V[0];
	sum[1][0] = V[N-1];
	
	FOR( i, 1, N ){
		sum[0][i] = sum[0][i-1]+V[i];
		sum[1][i] = sum[1][i-1]+V[N-i-1];
	}
	

	
	REP( i, 2 ){
		num[i][0] = max( 0ll, sum[i][0]-X[i][0] );
		ans = max( ans, num[i][0] );
		FOR( j, 1, N ){
			num[i][j] = max( num[i][j-1], sum[i][j]-X[i][j] );
			ans = max( ans, num[i][j] );
		}
	}
	
	REP( i, 2 ){
		REP( j, N ){
			ans = max( ans, sum[i][j]-X[i][j]*2+num[i^1][N-j-2] );
		}
	}
	
	cout<<ans<<endl;
}



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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if(a >= k){
    cout << k << endl;
  }else if (a + b >= k){
    cout << a << endl;
  }else{
    cout << a - (k - a - b) << endl;
  }
}

Measured memory_bytes: 3620
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int a,b; cin >> a >> b;
  if (a+b<10){cout << a+b;}
  else {cout << "error";}

  return 0;
}


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

int main()
{
	int x;
	cin >> x;
	int hp = 0;
	while (x >= 500)
	{
		x = x - 500;
		hp = hp + 1000;
	}
	while (x >= 5)
	{
		x = x - 5;
		hp = hp + 5;
	}
	cout << hp;
}

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



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

	if(a == b && b != c){
		cout << "Yes" << endl;
	}
	else if(b == c && b != a){
		cout << "Yes" << endl;
	}
	else if(c == a && c!=b){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int n;
cin >> n;
int d = n % 10;

if(d == 3) {
    cout << "bon" << endl;
}
else if(d == 0 || d == 1 || d == 6 || d == 8) {
    cout << "pon" << endl;
}
else cout << "hon" << endl;

return 0;
}

Measured memory_bytes: 3608
int main(){
    int n;
    scanf("%d",&n);
    for(int i=3;i<=n;i++){
        if(i%3==0){
            printf(" %d",i);
        }else{
            for(int j=i;j>0;j/=10){
                if(j%10==3){
                    printf(" %d",i);
                    break;
                }
            }
        }
    }
    putchar('\n');
}


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

#define pb push_back
#define fst first
#define snd second
#define ALL(s) s.begin(),s.end()
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define SZ(x) ((int)(x).size())
#define PI 3.1415926535897932384626433832795
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
using namespace std;

const int MAXN = 2005;
ll mod = 1e9+7;
ll c[MAXN][MAXN];

int main() {FIN;
    c[0][0] = 1;
    fore(n,1,MAXN){
        c[n][0] = c[n][n] = 1;
        fore(k,1,n)
            c[n][k] = (c[n-1][k-1]%mod + c[n-1][k]%mod)%mod;
    }
    ll n,k; cin>>n>>k;
    fore(i,0,k){
        ll a = c[n-k+1][i+1];
        ll b = c[k-1][i];
        ll ans = a*b;
        ans %= mod;
        cout<<ans<<"\n";
    }
    return 0;
}



Measured memory_bytes: 30208
n,m = map(int,input().split())
lst = list(map(int,input().split()))
prev = 0
for i in range(m -1):
    m = abs(lst[i] - lst[i+1])
    if m > prev:
        prev = m
last = n - lst[-1] + lst[0]
k = max(prev, last)
print(n - k)

Measured memory_bytes: 26436
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
#include <cmath>
#include <iomanip> //setprecision(2)
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
        string s;

        cin >> s;
        s[3]='8';
        cout << s << endl;

        return 0;
}


Measured memory_bytes: 256
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

min_number = 10 ** 10
max_number = 0

for k in A:
    if k > max_number:
        max_number = k
    if k < min_number:
        min_number = k

print(max_number - min_number)

Measured memory_bytes: 3060
module UnionFind
    implicit none
    public
        type :: Union_Find
            integer(8),allocatable,dimension(:) :: par
        end type Union_Find
    contains
        subroutine init(p,n)
            implicit none
            type(Union_Find)  p
            integer(8) n,i
            allocate( p%par(n) )
            do i=1,n
                p%par(i) = i
            enddo
        end subroutine init
        recursive function root(p,n) result(ret)
            implicit none
            type(Union_Find) p
            integer(8) ret,n
            if(p%par(n)==n)then
                ret = n
                return
            else
                p%par(n) = root(p,p%par(n))
                ret = p%par(n)
                return
            endif
        end
        subroutine unite(p,a,b)
            implicit none
            type(Union_Find) p
            integer(8) a,b
            a = root(p,a)
            b = root(p,b)
            if(a/=b)then
                p%par(a) = b
            endif
        end
end module UnionFind








program atcoder
    use UnionFind
    implicit none
    type(Union_Find) uf
    integer(8) :: n,k,i,ans=0_8,j,h,w
    integer(8),allocatable,dimension(:) :: a1,a2,ind,r,c
    read*,n,h,w
    call init(uf,h+w+5)
    allocate( a1(n),a2(n),ind(n),r(n),c(n) )
    do i=1,n
        read(*,*)r(i),c(i),a1(i)
        ind(i) = i;
        a2(i) = a1(i);
    enddo
    call sort(a1,ind)
    a1 = a2
    call sort(a1,r)
    a1 = a2
    call sort(a1,c)

    do i = n,1,-1
        if(root(uf,r(i))/=root(uf,c(i)+h))then
            call unite(uf,r(i),c(i)+h)
            ans = ans + a1(i)
        else if(root(uf,r(i))/=root(uf,h+w+3))then
            ans = ans + a1(i)
            call unite(uf,r(i),h+w+3)
        endif
    enddo
    write(*,'(I0)')ans


  !----------------------functions--------------------------
  contains
  recursive subroutine mergesort(a, p, r, b,ia,ib)
  integer(8) a(:), b(:),ia(:),ib(:)
  integer(8) p, r
  integer(8) q
  if (p < r) then
    q = (p+r)/2
    call mergesort(a, p, q, b,ia,ib)
    call mergesort(a, q+1, r, b,ia,ib)
    call merge(a, p, q, r, b, ia,ib)
  end if
  end subroutine mergesort
  subroutine merge(a, p, q, r, b, ia,ib)
    integer(8) a(:), b(:),ia(:),ib(:)
    integer(8) p, r, q, i, j, k
    integer(8) t,ti
    k = p;   i = p;   j = q+1
    do
      if (.not. (k <= r)) exit
      if (j > r) then
        t = a(i); ti = ia(i); i = i+1
      else if (i > q) then
        t = a(j); ti = ia(j); j = j+1
        
      else if (a(i) <= a(j)) then
        t = a(i); ti = ia(i); i = i+1
      else
        t = a(j); ti = ia(j); j = j+1
      end if
      b(k) = t; ib(k) = ti; k = k+1

    end do
    do i = p, r
      a(i) = b(i)
      ia(i) = ib(i)
    end do
  end subroutine merge
  subroutine sort(a,ia)
    integer(8) a(:), b(size(a)),n,ia(:),ib(size(a))
    n = size(a)
    call mergesort(a,1_8,n,b,ia,ib)
  end subroutine sort
  end program atcoder








Measured memory_bytes: 7296
// C - Base -2 Number

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	string ans = "";

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

	while(N != 0) {
		int r = N % (-2);

		if (r == 1 || r == -1) ans = '1' + ans;
		else ans = '0' + ans;

		if (r != 0) N--;
		N /= (-2);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3544
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {

        try (final Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            String S = sc.next();
            // 累積和つくる
            int[] bSum = new int[N + 1];
            int[] wSum = new int[N + 1];
            for (int i = 0; i < N; i++) {
                char c = S.charAt(i);
                bSum[i + 1] = bSum[i] + (c == '#' ? 1 : 0);
                wSum[i + 1] = wSum[i] + (c == '.' ? 1 : 0);
            }
            // 各位置における（左の黒の数＋右の白の数）を求めて、そのうち一番小さいものを採用する
            int min = Integer.MAX_VALUE;
            for (int i = 0; i <= N; i++) {
                int leftB = bSum[i];
                int rightW = wSum[N] - wSum[i];
                min = Math.min(min, leftB + rightW);
            }
            System.out.println(min);
        }
    }

}


Measured memory_bytes: 30572
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	unordered_map<char, vector<long>> a;
	for (int i = 0; i < s.size(); ++i) a[s[i]].push_back(i);
	if (a.end() == a.find(t.front())) cout << -1;
	else {
		int i;
		long ans = 1 + a[t.front()][0], b = a[t.front()][0];
		for (i = 1; i < t.size(); ++i) {
			if (a.end() == a.find(t[i])) break;
			else {
				vector<long>::iterator c = upper_bound(a[t[i]].begin(), a[t[i]].end(), b);
				if (a[t[i]].end() == c) {
					ans += a[t[i]][0] + s.size() - b;
					b = a[t[i]][0];
				}
				else {
					ans += *c - b;
					b = *c;
				}
			}
		}
		if (i == t.size()) cout << ans;
		else cout << -1;
	}
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL gcd(LL x, LL y){
  if(y == 0) return x;
  return gcd(y, x%y);
}

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

  LL p, q; cin >> p >> q;
  LL g = gcd(p,q);
  LL n = q / g;
  LL ans = 1;
  LL ub = n;
  for(LL i=2;i*i<=ub;++i){
	if(n % i == 0)
	  ans *= i;
	while(n % i == 0) n /= i;
  }
  if(n > 1) ans *= n;
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3204
#include<cstdio>

using namespace std;

inline int In(){
	char c=getchar(); int x=0,ft=1;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') ft=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x*ft;
}

int main(){
	int K=In();
	if(K<=500){
		int n=K; printf("%d\n",n);
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
		printf("%d%c",i,j==n?'\n':' ');
	}
	if(K>500){
		int n=(K+3)/4*2; printf("%d\n",n);
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j){
			int val=(i+j)%n+(i&1?0:n)+1; if(val>K) val-=n;
			printf("%d%c",val,j==n?'\n':' ');
		}
	}
	return 0;
}

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

ll C[51][51];
 
void comb_table(int n){
	rep(i,n+1)rep(j,i+1){
		if(j == 0 || j == i){
			C[i][j] = 1LL;
		}
		else{
			C[i][j] = (C[i-1][j-1] + C[i-1][j]);
		}
	}
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, p;
    cin >> n >> p;
    ll even = 0, odd = 0;
    rep(i,n){
        int a;
        cin >> a;
        if(a%2 == 0) ++even;
        else ++odd;
    }
    comb_table(n);
    ll ans = pow(2, even), mul = 0;
    for(int i = (p == 1 ? 1 : 0); i <= odd; i+=2){
        mul += C[odd][i];
    }
    ans *= mul;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define int long long

signed main()
{
	int N;
	while (cin >> N, N)
	{
		vector<bool> latte;
		for (int i = 0; i < N; i++)
		{
			string s;
			cin >> s;
			if (s == "lu" || s == "ru") latte.push_back(true);
			else latte.push_back(false);
		}
		int cnt = 0;
		for (int i = 1; i < N; i++)
		{
			if (latte[i] == latte[i - 1]) cnt++;
		}
		printf("%lld\n", cnt);
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    string s;
    cin >> s;
    bool ac = s.find("AC") != string::npos;
    cout << (ac ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 764